Java Code Examples for rx.exceptions.Exceptions#propagate()

The following examples show how to use rx.exceptions.Exceptions#propagate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrinterDbEntityMapper.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
public static Func1<List<PrinterDbEntity>, List<Printer>> mapToPrinters() {
    return new Func1<List<PrinterDbEntity>, List<Printer>>() {
        @Override
        public List<Printer> call(List<PrinterDbEntity> printerDbEntities) {
            try {
                List<Printer> printers = new ArrayList<>();
                for (PrinterDbEntity printerDbEntity : printerDbEntities) {
                    printers.add(printerDbEntityToPrinter(printerDbEntity));
                }
                return printers;
            } catch (Exception e) {
                throw Exceptions.propagate(new EntityMapperException(e));
            }
        }
    };
}
 
Example 2
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Func1<PrinterDbEntity, ConnectionEntity> getConnectionInDb() {
    return new Func1<PrinterDbEntity, ConnectionEntity>() {
        @Override
        public ConnectionEntity call(PrinterDbEntity printerDbEntity) {
            try {
                String json = printerDbEntity.getConnectionJson();
                ConnectionEntity entity = mEntitySerializer.deserialize(json, ConnectionEntity.class);
                if (entity == null) throw Exceptions.propagate(new PrinterDataNotFoundException());
                return entity;
            } catch (Exception e) {
                throw Exceptions.propagate(new PrinterDataNotFoundException(e));
            }
        }
    };
}
 
Example 3
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Func1<VersionEntity, VersionEntity> putVersionInDb() {
    return new Func1<VersionEntity, VersionEntity>() {
        @Override
        public VersionEntity call(VersionEntity versionEntity) {
            try {
                PrinterDbEntity printerDbEntity = mDbHelper.getActivePrinterDbEntity();
                String versionJson = mEntitySerializer.serialize(versionEntity);
                printerDbEntity.setVersionJson(versionJson);
                mDbHelper.insertOrReplace(printerDbEntity);
                return versionEntity;
            } catch (Exception e) {
                throw Exceptions.propagate(new ErrorSavingException(e));
            }
        }
    };
}
 
Example 4
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Action1<ConnectionEntity> putConnectionInDb() {
    return new Action1<ConnectionEntity>() {
        @Override
        public void call(ConnectionEntity connectionEntity) {
            try {
                PrinterDbEntity printerDbEntity = mDbHelper.getActivePrinterDbEntity();
                String connectionJson = mEntitySerializer.serialize(connectionEntity);
                printerDbEntity.setConnectionJson(connectionJson);
                mDbHelper.insertOrReplace(printerDbEntity);
            } catch (Exception e) {
                throw Exceptions.propagate(new ErrorSavingException());
            }
        }
    };
}
 
Example 5
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This is used to sync the database when deleting from account manager.
 */
@Override
public Func1<PrinterDbEntity, Boolean> syncDbAndAccountDeletion() {
    return new Func1<PrinterDbEntity, Boolean>() {
        @Override
        public Boolean call(PrinterDbEntity printerDbEntity) {
            PrinterDbEntity old = mDbHelper.getPrinterFromDbByName(printerDbEntity.getName());
            if (old == null) {
                throw Exceptions.propagate(new PrinterDataNotFoundException());
            }

            // DO NOT CALL any methods related to deleting from account or you will infinite loop!
            // ie: mAccountManager.removeAccount()

            if (mPrefHelper.isPrinterActive(old)) mPrefHelper.resetActivePrinter();
            mDbHelper.deletePrinterInDb(old);
            return true;
        }
    };
}
 
Example 6
Source File: PrinterDbEntityMapper.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
public static Func1<PrinterDbEntity, Printer> maptoPrinter() {
    return new Func1<PrinterDbEntity, Printer>() {
        @Override
        public Printer call(PrinterDbEntity printerDbEntity) {
            try {
                return printerDbEntityToPrinter(printerDbEntity);
            } catch (Exception e) {
                throw Exceptions.propagate(new EntityMapperException(e));
            }
        }
    };
}
 
Example 7
Source File: FilesEntityMapper.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
public static Func1<FilesEntity, Files> mapToFiles(final EntitySerializer entitySerializer) {
    return new Func1<FilesEntity, Files>() {
        @Override
        public Files call(FilesEntity filesEntity) {
            try {
                return entitySerializer.transform(filesEntity, Files.class);
            } catch (Exception e) {
                throw Exceptions.propagate(new EntityMapperException());
            }
        }
    };
}
 
Example 8
Source File: ConnectionEntityMapper.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
public static Func1<ConnectionEntity, Connection> mapToConnection(final EntitySerializer entitySerializer) {
    return new Func1<ConnectionEntity, Connection>() {
        @Override
        public Connection call(ConnectionEntity connectionEntity) {
            try {
                return entitySerializer.transform(connectionEntity, Connection.class);
            } catch (Exception e) {
                throw Exceptions.propagate(new EntityMapperException(e));
            }
        }
    };
}
 
Example 9
Source File: WebsocketInterceptor.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private String getWebsocketUrl(PrinterDbEntity printerDbEntity) {
    String scheme = printerDbEntity.getScheme();
    String host = printerDbEntity.getHost();
    String path = printerDbEntity.getWebsocketPath();

    String socketScheme = scheme.replace("http", "ws"); // Also works for https
    try {
        return new URI(socketScheme, host, path, null).toString();
    } catch (URISyntaxException e) {
        throw Exceptions.propagate(new URISyntaxException(e.getInput(), e.getReason()));
    }
}
 
Example 10
Source File: WebcamManagerImpl.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private String getStreamUrl(PrinterDbEntity printerDbEntity) {
    String scheme = printerDbEntity.getScheme();
    String host = printerDbEntity.getHost();
    int port = printerDbEntity.getPort();
    String pathQuery = printerDbEntity.getWebcamPathQuery();

    try {
        return new URI(scheme, null, host, port, null, null, null).toString() + pathQuery;
    } catch (URISyntaxException e) {
        throw Exceptions.propagate(new URISyntaxException(e.getInput(), e.getReason()));
    }
}
 
Example 11
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Action1<Throwable> deleteUnverifiedPrinter(final long previousActiveId) {
    return new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) {
            try {
                PrinterDbEntity printerDbEntity = mDbHelper.getActivePrinterDbEntity();
                syncDeletePrinter(printerDbEntity);
                mPrefHelper.setActivePrinter(previousActiveId);
            } catch (Exception e) {
                throw Exceptions.propagate(new PrinterDataNotFoundException(e));
            }
        }
    };
}
 
Example 12
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Func1<PrinterDbEntity, Boolean> deletePrinterById() {
    return new Func1<PrinterDbEntity, Boolean>() {
        @Override
        public Boolean call(PrinterDbEntity printerDbEntity) {
            try {
                syncDeletePrinter(printerDbEntity);
                return true;
            } catch (Exception e) {
                throw Exceptions.propagate(e);
            }
        }
    };
}
 
Example 13
Source File: DiskManagerImpl.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Func1<PrinterDbEntity, PrinterDbEntity> putPrinterInPrefs() {
    return new Func1<PrinterDbEntity, PrinterDbEntity>() {
        @Override
        public PrinterDbEntity call(PrinterDbEntity printerDbEntity) {
            try {
                mPrefHelper.setPrinterDbEntityToPrefs(printerDbEntity);
                return printerDbEntity;
            } catch (Exception e) {
                throw Exceptions.propagate(new ErrorSavingException());
            }
        }
    };
}
 
Example 14
Source File: ImportRunner.java    From newts with Apache License 2.0 5 votes vote down vote up
public static Func1<String, Observable<ObservableHttpResponse>> postJSON(final String baseURL, final CloseableHttpAsyncClient httpClient) {

        final URI baseURI = URI.create(baseURL);

        return new Func1<String, Observable<ObservableHttpResponse>>() {
            @Override
            public Observable<ObservableHttpResponse> call(String json) {
                try {
                    return ObservableHttp.createRequest(HttpAsyncMethods.createPost(baseURI, json, ContentType.APPLICATION_JSON), httpClient).toObservable();
                } catch (UnsupportedEncodingException e) {
                    throw Exceptions.propagate(e);
                }
            }
        };
    }
 
Example 15
Source File: DataSnapshotMapper.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
@Override
public RxFirebaseChildEvent<U> call(final RxFirebaseChildEvent<DataSnapshot> rxFirebaseChildEvent) {
    DataSnapshot dataSnapshot = rxFirebaseChildEvent.getValue();
    if (dataSnapshot.exists()) {
        return new RxFirebaseChildEvent<U>(
                dataSnapshot.getKey(),
                getDataSnapshotTypedValue(dataSnapshot, clazz),
                rxFirebaseChildEvent.getPreviousChildName(),
                rxFirebaseChildEvent.getEventType());
    } else {
        throw Exceptions.propagate(new RuntimeException("child dataSnapshot doesn't exist"));
    }
}
 
Example 16
Source File: DataSnapshotMapper.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
private static <U> U getDataSnapshotTypedValue(DataSnapshot dataSnapshot, Class<U> clazz) {
    U value = dataSnapshot.getValue(clazz);
    if (value == null) {
        throw Exceptions.propagate(new RxFirebaseDataCastException(
                "unable to cast firebase data response to " + clazz.getSimpleName()));
    }
    return value;
}
 
Example 17
Source File: CommonObjectMappers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static <T> T readValue(ObjectMapper objectMapper, String json, Class<T> clazz) {
    try {
        return objectMapper.readValue(json, clazz);
    } catch (IOException e) {
        throw Exceptions.propagate(e);
    }
}
 
Example 18
Source File: CommonObjectMappers.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static String writeValueAsString(ObjectMapper objectMapper, Object object) {
    try {
        return objectMapper.writeValueAsString(object);
    } catch (JsonProcessingException e) {
        throw Exceptions.propagate(e);
    }
}
 
Example 19
Source File: CassandraJobStore.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private void checkIfJobAlreadyExists(String jobId) {
    if (isJobActive(jobId)) {
        throw Exceptions.propagate(JobStoreException.jobAlreadyExists(jobId));
    }
}
 
Example 20
Source File: CassandraJobStore.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private void checkIfJobIsActive(String jobId) {
    if (!isJobActive(jobId)) {
        throw Exceptions.propagate(JobStoreException.jobMustBeActive(jobId));
    }
}