target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testLoad() { when(repository.load(MyEntity.class, 3L)).thenReturn(instance); assertEquals(instance, AbstractEntity.load(MyEntity.class, 3L)); }
public static <T extends Entity> T load(Class<T> clazz, Serializable id) { return getRepository().load(clazz, id); }
AbstractEntity extends BaseEntity { public static <T extends Entity> T load(Class<T> clazz, Serializable id) { return getRepository().load(clazz, id); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> T load(Class<T> clazz, Serializable id) { return getRepository().load(clazz, id); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> T load(Class<T> clazz, Serializable id) { return getRepository().load(clazz, id); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
AbstractEntity extends BaseEntity { public static <T extends Entity> T load(Class<T> clazz, Serializable id) { return getRepository().load(clazz, id); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
@Test public void testFindAll() { List list = Arrays.asList("a", "b"); CriteriaQuery query = mock(CriteriaQuery.class); when(repository.createCriteriaQuery(MyEntity.class)).thenReturn(query); when(query.list()).thenReturn(list); assertEquals(list, AbstractEntity.findAll(MyEntity.class)); }
public static <T extends Entity> List<T> findAll(Class<T> clazz) { return getRepository().createCriteriaQuery(clazz).list(); }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findAll(Class<T> clazz) { return getRepository().createCriteriaQuery(clazz).list(); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findAll(Class<T> clazz) { return getRepository().createCriteriaQuery(clazz).list(); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findAll(Class<T> clazz) { return getRepository().createCriteriaQuery(clazz).list(); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findAll(Class<T> clazz) { return getRepository().createCriteriaQuery(clazz).list(); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
@Test public void testFindByProperty() { List list = Collections.singletonList(instance); when(repository.findByProperty(MyEntity.class, "name", "abc")).thenReturn(list); assertEquals(list, AbstractEntity.findByProperty(MyEntity.class, "name", "abc")); }
public static <T extends Entity> List<T> findByProperty(Class<T> clazz, String propName, Object value) { return getRepository().findByProperty(clazz, propName, value); }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperty(Class<T> clazz, String propName, Object value) { return getRepository().findByProperty(clazz, propName, value); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperty(Class<T> clazz, String propName, Object value) { return getRepository().findByProperty(clazz, propName, value); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperty(Class<T> clazz, String propName, Object value) { return getRepository().findByProperty(clazz, propName, value); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperty(Class<T> clazz, String propName, Object value) { return getRepository().findByProperty(clazz, propName, value); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
@Test public void testFindByProperties() { List list = Collections.singletonList(instance); Map props = Collections.singletonMap("name", "abc"); when(repository.findByProperties(MyEntity.class, NamedParameters.create(props))).thenReturn(list); assertEquals(list, AbstractEntity.findByProperties(MyEntity.class, props)); }
public static <T extends Entity> List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues) { return getRepository().findByProperties(clazz, NamedParameters.create(propValues)); }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues) { return getRepository().findByProperties(clazz, NamedParameters.create(propValues)); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues) { return getRepository().findByProperties(clazz, NamedParameters.create(propValues)); } }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues) { return getRepository().findByProperties(clazz, NamedParameters.create(propValues)); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
AbstractEntity extends BaseEntity { public static <T extends Entity> List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues) { return getRepository().findByProperties(clazz, NamedParameters.create(propValues)); } @Override Long getId(); void setId(Long id); int getVersion(); void setVersion(int version); void save(); void remove(); static T get(Class<T> clazz, Serializable id); static T getUnmodified(Class<T> clazz, T entity); static T load(Class<T> clazz, Serializable id); static List<T> findAll(Class<T> clazz); static List<T> findByProperty(Class<T> clazz, String propName, Object value); static List<T> findByProperties(Class<T> clazz, Map<String, Object> propValues); }
@Test public void testCriteriaQueryFind() { CriteriaQuery query = new CriteriaQuery(repository, Dictionary.class) .eq("category", education); List<Dictionary> results = repository.find(query); assertTrue(results.contains(graduate)); assertTrue(results.contains(undergraduate)); }
@Override public <T> List<T> find(CriteriaQuery criteriaQuery) { Query query = getEntityManager().createQuery(criteriaQuery.getQueryString()); processQuery(query, criteriaQuery.getParameters(), criteriaQuery.getFirstResult(), criteriaQuery.getMaxResults()); return query.getResultList(); }
EntityRepositoryJpa implements EntityRepository { @Override public <T> List<T> find(CriteriaQuery criteriaQuery) { Query query = getEntityManager().createQuery(criteriaQuery.getQueryString()); processQuery(query, criteriaQuery.getParameters(), criteriaQuery.getFirstResult(), criteriaQuery.getMaxResults()); return query.getResultList(); } }
EntityRepositoryJpa implements EntityRepository { @Override public <T> List<T> find(CriteriaQuery criteriaQuery) { Query query = getEntityManager().createQuery(criteriaQuery.getQueryString()); processQuery(query, criteriaQuery.getParameters(), criteriaQuery.getFirstResult(), criteriaQuery.getMaxResults()); return query.getResultList(); } EntityRepositoryJpa(); EntityRepositoryJpa(EntityManager entityManager); EntityRepositoryJpa(EntityManagerFactory entityManagerFactory); EntityRepositoryJpa(NamedQueryParser namedQueryParser, EntityManagerFactory entityManagerFactory); }
EntityRepositoryJpa implements EntityRepository { @Override public <T> List<T> find(CriteriaQuery criteriaQuery) { Query query = getEntityManager().createQuery(criteriaQuery.getQueryString()); processQuery(query, criteriaQuery.getParameters(), criteriaQuery.getFirstResult(), criteriaQuery.getMaxResults()); return query.getResultList(); } EntityRepositoryJpa(); EntityRepositoryJpa(EntityManager entityManager); EntityRepositoryJpa(EntityManagerFactory entityManagerFactory); EntityRepositoryJpa(NamedQueryParser namedQueryParser, EntityManagerFactory entityManagerFactory); final void setNamedQueryParser(NamedQueryParser namedQueryParser); @Override T save(T entity); @Override void remove(Entity entity); @Override boolean exists(final Class<T> clazz, final Serializable id); @Override T get(final Class<T> clazz, final Serializable id); @Override T load(final Class<T> clazz, final Serializable id); @Override T getUnmodified(final Class<T> clazz, final T entity); @Override T getByBusinessKeys(Class<T> clazz, NamedParameters keyValues); @Override List<T> findAll(final Class<T> clazz); @Override CriteriaQuery createCriteriaQuery(Class<T> entityClass); @Override List<T> find(CriteriaQuery criteriaQuery); @Override T getSingleResult(CriteriaQuery criteriaQuery); @Override List<T> find(Class<T> entityClass, QueryCriterion criterion); @Override T getSingleResult(Class<T> entityClass, QueryCriterion criterion); @Override JpqlQuery createJpqlQuery(String jpql); @Override List<T> find(JpqlQuery jpqlQuery); @Override T getSingleResult(JpqlQuery jpqlQuery); @Override int executeUpdate(JpqlQuery jpqlQuery); @Override NamedQuery createNamedQuery(String queryName); @Override List<T> find(NamedQuery namedQuery); @Override T getSingleResult(NamedQuery namedQuery); @Override int executeUpdate(NamedQuery namedQuery); @Override SqlQuery createSqlQuery(String sql); @Override List<T> find(SqlQuery sqlQuery); @Override T getSingleResult(SqlQuery sqlQuery); @Override int executeUpdate(SqlQuery sqlQuery); @Override List<T> findByExample( final E example, final ExampleSettings<T> settings); @Override List<T> findByProperty(Class<T> clazz, String propertyName, Object propertyValue); @Override List<T> findByProperties(Class<T> clazz, NamedParameters properties); @Override String getQueryStringOfNamedQuery(String queryName); @Override void flush(); @Override void refresh(Entity entity); @Override void clear(); }
EntityRepositoryJpa implements EntityRepository { @Override public <T> List<T> find(CriteriaQuery criteriaQuery) { Query query = getEntityManager().createQuery(criteriaQuery.getQueryString()); processQuery(query, criteriaQuery.getParameters(), criteriaQuery.getFirstResult(), criteriaQuery.getMaxResults()); return query.getResultList(); } EntityRepositoryJpa(); EntityRepositoryJpa(EntityManager entityManager); EntityRepositoryJpa(EntityManagerFactory entityManagerFactory); EntityRepositoryJpa(NamedQueryParser namedQueryParser, EntityManagerFactory entityManagerFactory); final void setNamedQueryParser(NamedQueryParser namedQueryParser); @Override T save(T entity); @Override void remove(Entity entity); @Override boolean exists(final Class<T> clazz, final Serializable id); @Override T get(final Class<T> clazz, final Serializable id); @Override T load(final Class<T> clazz, final Serializable id); @Override T getUnmodified(final Class<T> clazz, final T entity); @Override T getByBusinessKeys(Class<T> clazz, NamedParameters keyValues); @Override List<T> findAll(final Class<T> clazz); @Override CriteriaQuery createCriteriaQuery(Class<T> entityClass); @Override List<T> find(CriteriaQuery criteriaQuery); @Override T getSingleResult(CriteriaQuery criteriaQuery); @Override List<T> find(Class<T> entityClass, QueryCriterion criterion); @Override T getSingleResult(Class<T> entityClass, QueryCriterion criterion); @Override JpqlQuery createJpqlQuery(String jpql); @Override List<T> find(JpqlQuery jpqlQuery); @Override T getSingleResult(JpqlQuery jpqlQuery); @Override int executeUpdate(JpqlQuery jpqlQuery); @Override NamedQuery createNamedQuery(String queryName); @Override List<T> find(NamedQuery namedQuery); @Override T getSingleResult(NamedQuery namedQuery); @Override int executeUpdate(NamedQuery namedQuery); @Override SqlQuery createSqlQuery(String sql); @Override List<T> find(SqlQuery sqlQuery); @Override T getSingleResult(SqlQuery sqlQuery); @Override int executeUpdate(SqlQuery sqlQuery); @Override List<T> findByExample( final E example, final ExampleSettings<T> settings); @Override List<T> findByProperty(Class<T> clazz, String propertyName, Object propertyValue); @Override List<T> findByProperties(Class<T> clazz, NamedParameters properties); @Override String getQueryStringOfNamedQuery(String queryName); @Override void flush(); @Override void refresh(Entity entity); @Override void clear(); }
@Test public void testUtil() { System.out.println(Util.ip2long("255.255.255.0")); }
public static long ip2long( String ip ) { String[] p = ip.split("\\."); if ( p.length != 4 ) return 0; int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000); int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000); int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00); int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF); return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL); }
Util { public static long ip2long( String ip ) { String[] p = ip.split("\\."); if ( p.length != 4 ) return 0; int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000); int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000); int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00); int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF); return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL); } }
Util { public static long ip2long( String ip ) { String[] p = ip.split("\\."); if ( p.length != 4 ) return 0; int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000); int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000); int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00); int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF); return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL); } }
Util { public static long ip2long( String ip ) { String[] p = ip.split("\\."); if ( p.length != 4 ) return 0; int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000); int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000); int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00); int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF); return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL); } static void write( byte[] b, int offset, long v, int bytes); static void writeIntLong( byte[] b, int offset, long v ); static long getIntLong( byte[] b, int offset ); static int getInt3( byte[] b, int offset ); static int getInt2( byte[] b, int offset ); static int getInt1( byte[] b, int offset ); static long ip2long( String ip ); static String long2ip( long ip ); static boolean isIpAddress( String ip ); }
Util { public static long ip2long( String ip ) { String[] p = ip.split("\\."); if ( p.length != 4 ) return 0; int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000); int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000); int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00); int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF); return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL); } static void write( byte[] b, int offset, long v, int bytes); static void writeIntLong( byte[] b, int offset, long v ); static long getIntLong( byte[] b, int offset ); static int getInt3( byte[] b, int offset ); static int getInt2( byte[] b, int offset ); static int getInt1( byte[] b, int offset ); static long ip2long( String ip ); static String long2ip( long ip ); static boolean isIpAddress( String ip ); }
@Test public void notConflictedFavorite_finishesActivityWithSuccess() { SyncState state = new SyncState(SyncState.State.SYNCED); Favorite favorite = new Favorite(defaultFavorite, state); when(localFavorites.get(eq(favoriteId))) .thenReturn(Single.just(favorite)); presenter.subscribe(); verify(repository).refreshFavorites(); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void populateFavorite_callsRepositoryAndUpdateViewOnSuccess() { final String favoriteId = defaultFavorite.getId(); when(repository.getFavorite(favoriteId)).thenReturn(Single.just(defaultFavorite)); AddEditFavoritePresenter presenter = new AddEditFavoritePresenter( repository, view, viewModel, schedulerProvider, settings, favoriteId); presenter.populateFavorite(); verify(repository).getFavorite(favoriteId); verify(viewModel).populateFavorite(any(Favorite.class)); }
@Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void populateFavorite_callsRepositoryAndShowsWarningOnError() { final String favoriteId = defaultFavorite.getId(); when(repository.getFavorite(favoriteId)).thenReturn(Single.error(new NoSuchElementException())); AddEditFavoritePresenter presenter = new AddEditFavoritePresenter( repository, view, viewModel, schedulerProvider, settings, favoriteId); presenter.populateFavorite(); verify(repository).getFavorite(favoriteId); verify(viewModel, never()).populateFavorite(any(Favorite.class)); verify(viewModel).showFavoriteNotFoundSnackbar(); }
@Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateFavorite() { if (favoriteId == null) { throw new RuntimeException("populateFavorite() was called but favoriteId is null"); } favoriteDisposable.clear(); Disposable disposable = repository.getFavorite(favoriteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateFavorite, throwable -> { favoriteId = null; viewModel.showFavoriteNotFoundSnackbar(); }); favoriteDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void loadEmptyListOfFavorites_showsEmptyList() { when(repository.getFavorites()).thenReturn(Observable.fromIterable(Collections.emptyList())); presenter.loadFavorites(true); verify(view).showFavorites(favoriteListCaptor.capture()); assertEquals(favoriteListCaptor.getValue().size(), 0); }
@Override public void loadFavorites(final boolean forceUpdate) { loadFavorites(forceUpdate, false); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void loadFavorites(final boolean forceUpdate) { loadFavorites(forceUpdate, false); } }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void loadFavorites(final boolean forceUpdate) { loadFavorites(forceUpdate, false); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void loadFavorites(final boolean forceUpdate) { loadFavorites(forceUpdate, false); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void loadFavorites(final boolean forceUpdate) { loadFavorites(forceUpdate, false); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_FAVORITES_FILTER_TYPE; }
@Test public void clickOnAddFavorite_showAddFavoriteUi() { presenter.showAddFavorite(); verify(view).startAddFavoriteActivity(); }
@Override public void showAddFavorite() { view.startAddFavoriteActivity(); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void showAddFavorite() { view.startAddFavoriteActivity(); } }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void showAddFavorite() { view.startAddFavoriteActivity(); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void showAddFavorite() { view.startAddFavoriteActivity(); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void showAddFavorite() { view.startAddFavoriteActivity(); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_FAVORITES_FILTER_TYPE; }
@Test public void clickOnEditFavorite_showEditFavoriteUi() { final String favoriteId = FAVORITES.get(0).getId(); presenter.onEditClick(favoriteId); verify(view).showEditFavorite(eq(favoriteId)); }
@Override public void onEditClick(@NonNull String favoriteId) { checkNotNull(favoriteId); view.showEditFavorite(favoriteId); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String favoriteId) { checkNotNull(favoriteId); view.showEditFavorite(favoriteId); } }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String favoriteId) { checkNotNull(favoriteId); view.showEditFavorite(favoriteId); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String favoriteId) { checkNotNull(favoriteId); view.showEditFavorite(favoriteId); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String favoriteId) { checkNotNull(favoriteId); view.showEditFavorite(favoriteId); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_FAVORITES_FILTER_TYPE; }
@Test public void clickOnDeleteFavorite_showsConfirmFavoritesRemoval() { ArrayList<String> selectedIds = new ArrayList<String>() {{ add(FAVORITES.get(0).getId()); add(FAVORITES.get(2).getId()); }}; when(viewModel.getSelectedIds()).thenReturn(selectedIds); presenter.onDeleteClick(); verify(view).confirmFavoritesRemoval(eq(selectedIds)); }
@Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmFavoritesRemoval(selectedIds); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmFavoritesRemoval(selectedIds); } }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmFavoritesRemoval(selectedIds); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmFavoritesRemoval(selectedIds); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
FavoritesPresenter extends BaseItemPresenter implements FavoritesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmFavoritesRemoval(selectedIds); } @Inject FavoritesPresenter( Repository repository, FavoritesContract.View view, FavoritesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddFavorite(); @Override void loadFavorites(final boolean forceUpdate); @Override void onFavoriteClick(String favoriteId, boolean isConflicted); @Override boolean onFavoriteLongClick(String favoriteId); @Override void onCheckboxClick(String favoriteId); @Override void selectFavoriteFilter(); @Override void onEditClick(@NonNull String favoriteId); @Override void onToLinksClick(@NonNull Favorite favoriteFilter); @Override void onToNotesClick(@NonNull Favorite favoriteFilter); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedFavorite(@NonNull final String favoriteId); @Override void deleteFavorites(@NonNull ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String favoriteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override void updateTabNormalState(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_FAVORITES_FILTER_TYPE; }
@Test public void notConflictedNote_finishesActivityWithSuccess() { SyncState state = new SyncState(SyncState.State.SYNCED); Note note = new Note(defaultNote, state); when(localNotes.get(eq(noteId))).thenReturn(Single.just(note)); presenter.subscribe(); verify(repository).refreshNotes(); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void wrongId_finishesActivityWithSuccess() { when(localNotes.get(eq(noteId))).thenReturn(Single.error(new NoSuchElementException())); presenter.subscribe(); verify(repository).refreshNotes(); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void databaseError_showsErrorThenTriesToLoadCloudNote() { when(localNotes.get(eq(noteId))).thenReturn(Single.error(new NullPointerException())); when(cloudNotes.download(eq(noteId))).thenReturn(Single.just(defaultNote)); presenter.subscribe(); verify(viewModel).showDatabaseError(); verify(viewModel).populateCloudNote(eq(defaultNote), eq(false)); }
@Override public void subscribe() { populate(); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
NotesConflictResolutionPresenter implements NotesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject NotesConflictResolutionPresenter( Repository repository, Settings settings, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LocalLinks<Link> localLinks, NotesConflictResolutionContract.View view, NotesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @NoteId String noteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void loadAllTagsFromRepository_loadsItIntoView() { List<Tag> tags = defaultNote.getTags(); assertNotNull(tags); when(repository.getTags()).thenReturn(Observable.fromIterable(tags)); presenter.loadTags(); verify(view).swapTagsCompletionViewItems(eq(tags)); }
@Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void wrongId_finishesActivityWithSuccess() { when(localFavorites.get(eq(favoriteId))) .thenReturn(Single.error(new NoSuchElementException())); presenter.subscribe(); verify(repository).refreshFavorites(); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void loadEmptyListOfTags_loadsEmptyListIntoView() { when(repository.getTags()).thenReturn(Observable.fromIterable(Collections.emptyList())); presenter.loadTags(); verify(view).swapTagsCompletionViewItems(tagListCaptor.capture()); assertEquals(tagListCaptor.getValue().size(), 0); }
@Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveNewNoteToRepository_finishesActivity() { String noteNote = defaultNote.getNote(); String linkId = defaultNote.getLinkId(); List<Tag> noteTags = defaultNote.getTags(); when(repository.saveNote(any(Note.class), eq(false))) .thenReturn(Observable.just(DataSource.ItemState.DEFERRED)); presenter.saveNote(noteNote, noteTags); verify(repository, never()).refreshNotes(); verify(view).finishActivity(any(String.class), eq(linkId)); }
@Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveEmptyNote_showsEmptyError() { presenter.saveNote("", new ArrayList<>()); presenter.saveNote("", defaultNote.getTags()); verify(viewModel, times(2)).showEmptyNoteSnackbar(); }
@Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveExistingNote_finishesActivity() { String noteId = defaultNote.getId(); String linkId = defaultNote.getLinkId(); String noteNote = defaultNote.getNote(); List<Tag> noteTags = defaultNote.getTags(); when(repository.saveNote(any(Note.class), eq(false))) .thenReturn(Observable.just(DataSource.ItemState.DEFERRED)); AddEditNotePresenter presenter = new AddEditNotePresenter( repository, view, viewModel, schedulerProvider, settings, noteId, linkId); presenter.saveNote(noteNote, noteTags); verify(repository, never()).refreshNotes(); verify(view).finishActivity(eq(noteId), eq(linkId)); }
@Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveNote(String noteNote, List<Tag> noteTags) { if (isNewNote()) { createNote(noteNote, noteTags); } else { updateNote(noteNote, noteTags); } } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void populateNote_callsRepositoryAndUpdateViewOnSuccess() { final String noteId = defaultNote.getId(); when(repository.getNote(noteId)).thenReturn(Single.just(defaultNote)); AddEditNotePresenter presenter = new AddEditNotePresenter( repository, view, viewModel, schedulerProvider, settings, noteId, defaultNote.getLinkId()); presenter.populateNote(); verify(repository).getNote(noteId); verify(viewModel).populateNote(any(Note.class)); }
@Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void populateNote_callsRepositoryAndShowsWarningOnError() { final String noteId = defaultNote.getId(); when(repository.getNote(noteId)).thenReturn(Single.error(new NoSuchElementException())); AddEditNotePresenter presenter = new AddEditNotePresenter( repository, view, viewModel, schedulerProvider, settings, noteId, defaultNote.getLinkId()); presenter.populateNote(); verify(repository).getNote(noteId); verify(viewModel, never()).populateNote(any(Note.class)); verify(viewModel).showNoteNotFoundSnackbar(); }
@Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditNotePresenter implements AddEditNoteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateNote() { if (noteId == null) { throw new RuntimeException("populateNote() was called but noteId is null"); } noteDisposable.clear(); Disposable disposable = repository.getNote(noteId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(note -> { viewModel.populateNote(note); linkId = note.getLinkId(); populateLink(); }, throwable -> { noteId = null; viewModel.showNoteNotFoundSnackbar(); }); noteDisposable.add(disposable); } @Inject AddEditNotePresenter( Repository repository, AddEditNoteContract.View view, AddEditNoteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @NoteId String noteId, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewNote(); @Override void populateNote(); @Override void saveNote(String noteNote, List<Tag> noteTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void loadAllNotesFromRepository_loadsItIntoView() { when(repository.getNotes()).thenReturn(Observable.fromIterable(NOTES)); presenter.loadNotes(true); verify(view).showNotes(NOTES); }
@Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_NOTES_FILTER_TYPE; }
@Test public void loadEmptyListOfNotes_showsEmptyList() { when(repository.getNotes()).thenReturn(Observable.fromIterable(Collections.emptyList())); presenter.loadNotes(true); verify(view).showNotes(noteListCaptor.capture()); assertEquals(noteListCaptor.getValue().size(), 0); }
@Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void loadNotes(final boolean forceUpdate) { loadNotes(forceUpdate, false); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_NOTES_FILTER_TYPE; }
@Test public void clickOnAddNote_showAddNoteUiForUnboundNote() { presenter.showAddNote(); verify(view).startAddNoteActivity(eq(null)); }
@Override public void showAddNote() { view.startAddNoteActivity(filterType == FilterType.LINK ? linkFilterId : null); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void showAddNote() { view.startAddNoteActivity(filterType == FilterType.LINK ? linkFilterId : null); } }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void showAddNote() { view.startAddNoteActivity(filterType == FilterType.LINK ? linkFilterId : null); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void showAddNote() { view.startAddNoteActivity(filterType == FilterType.LINK ? linkFilterId : null); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void showAddNote() { view.startAddNoteActivity(filterType == FilterType.LINK ? linkFilterId : null); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_NOTES_FILTER_TYPE; }
@Test public void clickOnEditNote_showEditNoteUi() { final String noteId = NOTES.get(0).getId(); presenter.onEditClick(noteId); verify(view).showEditNote(eq(noteId)); }
@Override public void onEditClick(@NonNull String noteId) { checkNotNull(noteId); view.showEditNote(noteId); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String noteId) { checkNotNull(noteId); view.showEditNote(noteId); } }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String noteId) { checkNotNull(noteId); view.showEditNote(noteId); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String noteId) { checkNotNull(noteId); view.showEditNote(noteId); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String noteId) { checkNotNull(noteId); view.showEditNote(noteId); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_NOTES_FILTER_TYPE; }
@Test public void databaseError_showsErrorThenTriesToLoadCloudFavorite() { when(localFavorites.get(eq(favoriteId))) .thenReturn(Single.error(new NullPointerException())); when(cloudFavorites.download(eq(favoriteId))) .thenReturn(Single.just(defaultFavorite)); presenter.subscribe(); verify(viewModel).showDatabaseError(); verify(viewModel).populateCloudFavorite(eq(defaultFavorite)); }
@Override public void subscribe() { populate(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void clickOnDeleteNote_showsConfirmNotesRemoval() { ArrayList<String> selectedIds = new ArrayList<String>() {{ add(NOTES.get(0).getId()); add(NOTES.get(2).getId()); }}; when(viewModel.getSelectedIds()).thenReturn(selectedIds); presenter.onDeleteClick(); verify(view).confirmNotesRemoval(eq(selectedIds)); }
@Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmNotesRemoval(selectedIds); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmNotesRemoval(selectedIds); } }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmNotesRemoval(selectedIds); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmNotesRemoval(selectedIds); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
NotesPresenter extends BaseItemPresenter implements NotesContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmNotesRemoval(selectedIds); } @Inject NotesPresenter( Repository repository, NotesContract.View view, NotesContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddNote(); @Override void loadNotes(final boolean forceUpdate); @Override void onNoteClick(String noteId, boolean isConflicted); @Override boolean onNoteLongClick(String noteId); @Override void onCheckboxClick(String noteId); @Override void selectNoteFilter(); @Override void onEditClick(@NonNull String noteId); @Override void onToLinksClick(@NonNull String noteId); @Override void onToggleClick(@NonNull String noteId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedNote(final String linkId, @NonNull final String noteId); @Override void deleteNotes(ArrayList<String> selectedIds); @Override void updateSyncStatus(); @Override int getPosition(String noteId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isLinkFilter(); @Override boolean isExpandNotes(); @Override void updateTabNormalState(); @Override boolean isNotesLayoutModeReading(); @Override boolean toggleNotesLayoutMode(); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_NOTES_FILTER_TYPE; }
@Test public void notConflictedLink_finishesActivityWithSuccess() { SyncState state = new SyncState(SyncState.State.SYNCED); Link link = new Link(defaultLink, state); when(localLinks.get(eq(linkId))).thenReturn(Single.just(link)); presenter.subscribe(); verify(repository).refreshLinks(); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void wrongId_finishesActivityWithSuccess() { when(localLinks.get(eq(linkId))).thenReturn(Single.error(new NoSuchElementException())); presenter.subscribe(); verify(repository).refreshLinks(); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void databaseError_showsErrorThenTriesToLoadCloudLink() { when(localLinks.get(eq(linkId))).thenReturn(Single.error(new NullPointerException())); when(cloudLinks.download(eq(linkId))).thenReturn(Single.just(defaultLink)); presenter.subscribe(); verify(viewModel).showDatabaseError(); verify(viewModel).populateCloudLink(eq(defaultLink)); }
@Override public void subscribe() { populate(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void duplicatedLinkWithNoMainRecord_resolvesConflictAutomatically() { SyncState state = new SyncState(E_TAGL, 1); Link link = new Link(defaultLink, state); String linkId = link.getId(); when(localLinks.get(eq(linkId))).thenReturn(Single.just(link)); when(localLinks.getMain(eq(link.getDuplicatedKey()))) .thenReturn(Single.error(new NoSuchElementException())); when(viewModel.isCloudPopulated()).thenReturn(true); when(localLinks.update(eq(linkId), any(SyncState.class))).thenReturn(Single.just(true)); presenter.subscribe(); verify(viewModel).populateCloudLink(eq(link)); verify(repository).refreshLink(eq(linkId)); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
LinksConflictResolutionPresenter implements LinksConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject LinksConflictResolutionPresenter( Repository repository, Settings settings, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes, LinksConflictResolutionContract.View view, LinksConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void loadAllLinksFromRepository_loadsItIntoView() { when(repository.getLinks()).thenReturn(Observable.fromIterable(LINKS)); presenter.loadLinks(true); verify(view).showLinks(LINKS); }
@Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_LINKS_FILTER_TYPE; }
@Test public void loadEmptyListOfLinks_showsEmptyList() { when(repository.getLinks()).thenReturn(Observable.fromIterable(Collections.emptyList())); presenter.loadLinks(true); verify(view).showLinks(linkListCaptor.capture()); assertEquals(linkListCaptor.getValue().size(), 0); }
@Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void loadLinks(final boolean forceUpdate) { loadLinks(forceUpdate, false); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_LINKS_FILTER_TYPE; }
@Test public void clickOnAddLink_showAddLinkUi() { presenter.showAddLink(); verify(view).startAddLinkActivity(); }
@Override public void showAddLink() { view.startAddLinkActivity(); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void showAddLink() { view.startAddLinkActivity(); } }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void showAddLink() { view.startAddLinkActivity(); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void showAddLink() { view.startAddLinkActivity(); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void showAddLink() { view.startAddLinkActivity(); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_LINKS_FILTER_TYPE; }
@Test public void clickOnEditLink_showEditLinkUi() { final String linkId = LINKS.get(0).getId(); presenter.onEditClick(linkId); verify(view).showEditLink(eq(linkId)); }
@Override public void onEditClick(@NonNull String linkId) { checkNotNull(linkId); view.showEditLink(linkId); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String linkId) { checkNotNull(linkId); view.showEditLink(linkId); } }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String linkId) { checkNotNull(linkId); view.showEditLink(linkId); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String linkId) { checkNotNull(linkId); view.showEditLink(linkId); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onEditClick(@NonNull String linkId) { checkNotNull(linkId); view.showEditLink(linkId); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_LINKS_FILTER_TYPE; }
@Test public void clickOnDeleteLink_showsConfirmLinksRemoval() { ArrayList<String> selectedIds = new ArrayList<String>() {{ add(LINKS.get(0).getId()); add(LINKS.get(2).getId()); }}; when(viewModel.getSelectedIds()).thenReturn(selectedIds); presenter.onDeleteClick(); verify(view).confirmLinksRemoval(eq(selectedIds)); }
@Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmLinksRemoval(selectedIds); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmLinksRemoval(selectedIds); } }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmLinksRemoval(selectedIds); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmLinksRemoval(selectedIds); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); }
LinksPresenter extends BaseItemPresenter implements LinksContract.Presenter, DataSource.Callback { @Override public void onDeleteClick() { ArrayList<String> selectedIds = viewModel.getSelectedIds(); view.confirmLinksRemoval(selectedIds); } @Inject LinksPresenter( Repository repository, LinksContract.View view, LinksContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, LaanoUiManager laanoUiManager, Settings settings); @Override void subscribe(); @Override void unsubscribe(); @Override void onTabSelected(); @Override void onTabDeselected(); @Override void showAddLink(); @Override void loadLinks(final boolean forceUpdate); @Override void onLinkClick(String linkId, boolean isConflicted, int numNotes); @Override boolean onLinkLongClick(String linkId); @Override void onCheckboxClick(String linkId); @Override void selectLinkFilter(); @Override void onEditClick(@NonNull String linkId); @Override void onLinkOpenClick(@NonNull String linkId); @Override void onToNotesClick(@NonNull String linkId); @Override void onAddNoteClick(@NonNull String linkId); @Override void onToggleClick(@NonNull String linkId); @Override void onDeleteClick(); @Override void onSelectAllClick(); @Override void syncSavedLink(@NonNull final String linkId); @Override void syncSavedNote(@NonNull final String linkId, @NonNull final String noteId); @Override void deleteLinks( @NonNull final ArrayList<String> selectedIds, final boolean deleteNotes); @Override void updateSyncStatus(); @Override int getPosition(String linkId); @Override void setFilterType(@NonNull FilterType filterType); @Override @NonNull FilterType getFilterType(); @Override @Nullable Boolean isFavoriteAndGate(); @Override boolean isFavoriteFilter(); @Override boolean isNoteFilter(); @Override boolean isExpandLinks(); @Override void updateTabNormalState(); @Override void setShowConflictResolutionWarning(boolean show); @Override void onRepositoryDelete(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void onRepositorySave(@NonNull String id, @NonNull DataSource.ItemState itemState); @Override void setFilterIsChanged(boolean filterIsChanged); static final String SETTING_LINKS_FILTER_TYPE; }
@Test public void duplicatedFavoriteWithNoMainRecord_resolvesConflictAutomatically() { SyncState state = new SyncState(E_TAGL, 1); Favorite favorite = new Favorite(defaultFavorite, state); String favoriteId = favorite.getId(); when(localFavorites.get(eq(favoriteId))).thenReturn(Single.just(favorite)); when(localFavorites.getMain(eq(favorite.getDuplicatedKey()))) .thenReturn(Single.error(new NoSuchElementException())); when(viewModel.isCloudPopulated()).thenReturn(true); when(localFavorites.update(eq(favoriteId), any(SyncState.class))) .thenReturn(Single.just(true)); presenter.subscribe(); verify(viewModel).populateCloudFavorite(eq(favorite)); verify(repository).refreshFavorite(eq(favoriteId)); verify(view).finishActivity(); }
@Override public void subscribe() { populate(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
FavoritesConflictResolutionPresenter implements FavoritesConflictResolutionContract.Presenter { @Override public void subscribe() { populate(); } @Inject FavoritesConflictResolutionPresenter( Repository repository, Settings settings, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, FavoritesConflictResolutionContract.View view, FavoritesConflictResolutionContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void onLocalDeleteClick(); @Override void onCloudDeleteClick(); @Override void onCloudRetryClick(); @Override void onLocalUploadClick(); @Override void onCloudDownloadClick(); }
@Test public void loadAllTagsFromRepository_loadsItIntoView() { List<Tag> tags = defaultLink.getTags(); assertNotNull(tags); when(repository.getTags()).thenReturn(Observable.fromIterable(tags)); presenter.loadTags(); verify(view).swapTagsCompletionViewItems(eq(tags)); }
@Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void loadEmptyListOfTags_loadsEmptyListIntoView() { when(repository.getTags()).thenReturn(Observable.fromIterable(Collections.emptyList())); presenter.loadTags(); verify(view).swapTagsCompletionViewItems(tagListCaptor.capture()); assertEquals(tagListCaptor.getValue().size(), 0); }
@Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveNewLinkToRepository_finishesActivity() { String linkLink = defaultLink.getLink(); String linkName = defaultLink.getName(); boolean linkDisabled = defaultLink.isDisabled(); List<Tag> linkTags = defaultLink.getTags(); when(repository.saveLink(any(Link.class), eq(false))) .thenReturn(Observable.just(DataSource.ItemState.DEFERRED)); presenter.saveLink(linkLink, linkName, linkDisabled, linkTags); verify(repository, never()).refreshLinks(); verify(view).finishActivity(any(String.class)); }
@Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveEmptyLink_showsEmptyError() { presenter.saveLink(null, "", false, new ArrayList<>()); presenter.saveLink("", defaultLink.getName(), true, defaultLink.getTags()); verify(viewModel, times(2)).showEmptyLinkSnackbar(); }
@Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveExistingLink_finishesActivity() { String linkId = defaultLink.getId(); String linkLink = defaultLink.getLink(); String linkName = defaultLink.getName(); boolean linkDisabled = defaultLink.isDisabled(); List<Tag> linkTags = defaultLink.getTags(); when(repository.saveLink(any(Link.class), eq(false))) .thenReturn(Observable.just(DataSource.ItemState.DEFERRED)); AddEditLinkPresenter presenter = new AddEditLinkPresenter( repository, view, viewModel, schedulerProvider, settings, linkId); presenter.saveLink(linkLink, linkName, linkDisabled, linkTags); verify(repository, never()).refreshLinks(); verify(view).finishActivity(eq(linkId)); }
@Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void saveLinkWithExistedName_showsDuplicateError() { String linkId = defaultLink.getId(); String linkLink = defaultLink.getLink(); String linkName = defaultLink.getName(); boolean linkDisabled = defaultLink.isDisabled(); List<Tag> linkTags = defaultLink.getTags(); when(repository.saveLink(any(Link.class), eq(false))) .thenReturn(Observable.error(new SQLiteConstraintException())); presenter.saveLink(linkLink, linkName, linkDisabled, linkTags); verify(view, never()).finishActivity(eq(linkId)); verify(viewModel).showDuplicateKeyError(); }
@Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags) { if (isNewLink()) { createLink(linkLink, linkName, linkDisabled, linkTags); } else { updateLink(linkLink, linkName, linkDisabled, linkTags); } } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void populateLink_callsRepositoryAndUpdateViewOnSuccess() { final String linkId = defaultLink.getId(); when(repository.getLink(linkId)).thenReturn(Single.just(defaultLink)); AddEditLinkPresenter presenter = new AddEditLinkPresenter( repository, view, viewModel, schedulerProvider, settings, linkId); presenter.populateLink(); verify(repository).getLink(linkId); verify(viewModel).populateLink(any(Link.class)); }
@Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void populateLink_callsRepositoryAndShowsWarningOnError() { final String linkId = defaultLink.getId(); when(repository.getLink(linkId)).thenReturn(Single.error(new NoSuchElementException())); AddEditLinkPresenter presenter = new AddEditLinkPresenter( repository, view, viewModel, schedulerProvider, settings, linkId); presenter.populateLink(); verify(repository).getLink(linkId); verify(viewModel, never()).populateLink(any(Link.class)); verify(viewModel).showLinkNotFoundSnackbar(); }
@Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
AddEditLinkPresenter implements AddEditLinkContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void populateLink() { if (linkId == null) { throw new RuntimeException("populateLink() was called but linkId is null"); } linkDisposable.clear(); Disposable disposable = repository.getLink(linkId) .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) .subscribe(viewModel::populateLink, throwable -> { linkId = null; viewModel.showLinkNotFoundSnackbar(); }); linkDisposable.add(disposable); } @Inject AddEditLinkPresenter( Repository repository, AddEditLinkContract.View view, AddEditLinkContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @LinkId String linkId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewLink(); @Override void populateLink(); @Override void saveLink( String linkLink, String linkName, boolean linkDisabled, List<Tag> linkTags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag token); @Override void onTokenRemoved(Tag token); @Override void onDuplicateRemoved(Tag token); }
@Test public void newLocalFavorite_goesToUploadThenChangesStateToSynced() { Favorite favorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS); assertNotNull(favorite); String favoriteId = favorite.getId(); setLocalFavorites(localFavorites, singletonList(favorite)); setCloudFavorites(cloudFavorites, Collections.emptyList()); RemoteOperationResult result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK); ArrayList<Object> data = new ArrayList<>(); JsonFile file = new JsonFile(REMOTE_PATH); file.setETag(E_TAGC); data.add(file); result.setData(data); when(cloudFavorites.upload(any(Favorite.class), eq(ownCloudClient))) .thenReturn(Single.just(result)); when(localFavorites.update(eq(favoriteId), any(SyncState.class))) .thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).upload(eq(favorite), eq(ownCloudClient)); verify(localFavorites).update(eq(favoriteId), syncStateCaptor.capture()); assertEquals(syncStateCaptor.getValue().isSynced(), true); verify(syncNotifications).sendSyncBroadcast( any(String.class), eq(SyncNotifications.STATUS_UPLOADED), any(String.class), any(int.class)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void newCloudFavorite_goesToLocalWithSyncedState() { Favorite favorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS); assertNotNull(favorite); String favoriteId = favorite.getId(); SyncState state = new SyncState(E_TAGC, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite(favorite, state); setLocalFavorites(localFavorites, Collections.emptyList()); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); when(cloudFavorites.download(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(cloudFavorite)); when(localFavorites.save(eq(cloudFavorite))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).download(eq(favoriteId), eq(ownCloudClient)); verify(localFavorites).save(eq(cloudFavorite)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_CREATED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void loadAllTagsFromRepository_loadsItIntoView() { List<Tag> tags = defaultFavorite.getTags(); assertNotNull(tags); when(repository.getTags()).thenReturn(Observable.fromIterable(tags)); presenter.loadTags(); verify(view).swapTagsCompletionViewItems(eq(tags)); }
@Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void localUnsyncedFavorite_ifEqualUpdateLocalETag() { SyncState localState = new SyncState(E_TAGL, SyncState.State.UNSYNCED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); SyncState cloudState = new SyncState(E_TAGC, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite( favoriteId, "Favorite", false, TestUtils.TAGS, cloudState); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); when(cloudFavorites.download(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(cloudFavorite)); when(localFavorites.update(eq(favoriteId), any(SyncState.class))) .thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).download(eq(favoriteId), eq(ownCloudClient)); verify(localFavorites).update(eq(favoriteId), syncStateCaptor.capture()); assertEquals(syncStateCaptor.getValue().isSynced(), true); assertEquals(syncStateCaptor.getValue().getETag(), E_TAGC); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_UPDATED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void localDeletedFavoriteAgainstUpdatedCloud_ifEqualDeleteCloudAndLocal() { SyncState localState = new SyncState(E_TAGL, SyncState.State.DELETED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); SyncState cloudState = new SyncState(E_TAGC, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite( favoriteId, "Favorite", false, TestUtils.TAGS, cloudState); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); when(cloudFavorites.download(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(cloudFavorite)); RemoteOperationResult result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK); when(cloudFavorites.delete(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(result)); when(localFavorites.delete(eq(favoriteId))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).download(eq(favoriteId), eq(ownCloudClient)); verify(cloudFavorites).delete(eq(favoriteId), eq(ownCloudClient)); verify(localFavorites).delete(eq(favoriteId)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_DELETED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void localUnsyncedFavorite_ifNotEqualLocalGoesToConflictedState() { SyncState localState = new SyncState(E_TAGL, SyncState.State.UNSYNCED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); SyncState cloudState = new SyncState(E_TAGC, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite( favoriteId, "Favorite #2", false, TestUtils.TAGS, cloudState); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); when(cloudFavorites.download(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(cloudFavorite)); when(localFavorites.update(eq(favoriteId), any(SyncState.class))) .thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).download(eq(favoriteId), eq(ownCloudClient)); verify(localFavorites).update(eq(favoriteId), syncStateCaptor.capture()); assertEquals(syncStateCaptor.getValue().isConflicted(), true); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_UPDATED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void cloudFavoriteUpdatedWhenLocalSynced_downloadCloudAndUpdateLocal() { SyncState localState = new SyncState(E_TAGL, SyncState.State.SYNCED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); SyncState cloudState = new SyncState(E_TAGC, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite( favoriteId, "Favorite #2", false, TestUtils.TAGS, cloudState); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); when(cloudFavorites.download(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(cloudFavorite)); when(localFavorites.save(eq(cloudFavorite))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).download(eq(favoriteId), eq(ownCloudClient)); verify(localFavorites).save(eq(cloudFavorite)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_UPDATED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void localNeverSyncedFavorite_deleteLocalOnly() { SyncState localState = new SyncState(SyncState.State.DELETED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, Collections.emptyList()); when(localFavorites.delete(eq(favoriteId))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(localFavorites).delete(eq(favoriteId)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_DELETED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void localDeletedFavoriteWithCloudETag_deleteCloudAndLocal() { SyncState localState = new SyncState(E_TAGL, SyncState.State.DELETED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); SyncState cloudState = new SyncState(E_TAGL, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite( favoriteId, "Favorite", false, TestUtils.TAGS, cloudState); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); RemoteOperationResult result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK); when(cloudFavorites.delete(eq(favoriteId), eq(ownCloudClient))) .thenReturn(Single.just(result)); when(localFavorites.delete(eq(favoriteId))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).delete(eq(favoriteId), eq(ownCloudClient)); verify(localFavorites).delete(eq(favoriteId)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_DELETED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void cloudDeletedFavoriteAgainstLocalSynced_deleteLocal() { SyncState localState = new SyncState(E_TAGL, SyncState.State.SYNCED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, Collections.emptyList()); when(localFavorites.delete(eq(favoriteId))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(localFavorites).delete(eq(favoriteId)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_DELETED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void cloudDeletedFavoriteAgainstLocalUnsynced_localGoesToConflictedState() { SyncState localState = new SyncState(E_TAGL, SyncState.State.UNSYNCED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, Collections.emptyList()); when(localFavorites.update(eq(favoriteId), any(SyncState.class))) .thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(localFavorites).update(eq(favoriteId), syncStateCaptor.capture()); assertEquals(syncStateCaptor.getValue().isDeleted(), false); assertEquals(syncStateCaptor.getValue().isConflicted(), true); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_UPDATED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void cloudDeletedFavoriteAgainstLocalDeleted_deleteLocal() { SyncState localState = new SyncState(E_TAGL, SyncState.State.DELETED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, Collections.emptyList()); when(localFavorites.delete(eq(favoriteId))).thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(localFavorites).delete(eq(favoriteId)); verify(syncNotifications).sendSyncBroadcast(eq(SyncNotifications.ACTION_SYNC_FAVORITES), eq(SyncNotifications.STATUS_DELETED), eq(favoriteId)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void localUnsyncedFavoriteWithCloudETag_uploadIfNotDuplicated() { SyncState localState = new SyncState(E_TAGC, SyncState.State.UNSYNCED); Favorite localFavorite = new Favorite( TestUtils.KEY_PREFIX + 'A', "Favorite #2", false, TestUtils.TAGS, localState); assertNotNull(localFavorite); String favoriteId = localFavorite.getId(); SyncState cloudState = new SyncState(E_TAGC, SyncState.State.SYNCED); Favorite cloudFavorite = new Favorite( favoriteId, "Favorite", false, TestUtils.TAGS, cloudState); setLocalFavorites(localFavorites, singletonList(localFavorite)); setCloudFavorites(cloudFavorites, singletonList(cloudFavorite)); RemoteOperationResult result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK); ArrayList<Object> data = new ArrayList<>(); JsonFile file = new JsonFile(REMOTE_PATH); file.setETag(E_TAGC); data.add(file); result.setData(data); when(cloudFavorites.upload(any(Favorite.class), eq(ownCloudClient))) .thenReturn(Single.just(result)); when(localFavorites.update(eq(favoriteId), any(SyncState.class))) .thenReturn(Single.just(true)); when(localSyncResults.cleanup()).thenReturn(Single.just(0)); when(localFavorites.logSyncResult(any(long.class), eq(favoriteId), any(LocalContract.SyncResultEntry.Result.class))).thenReturn(Single.just(true)); syncAdapter.onPerformSync(null, extras, null, null, null); verify(cloudFavorites).upload(eq(localFavorite), eq(ownCloudClient)); verify(localFavorites).update(eq(favoriteId), syncStateCaptor.capture()); assertEquals(syncStateCaptor.getValue().isSynced(), true); verify(syncNotifications).sendSyncBroadcast( any(String.class), eq(SyncNotifications.STATUS_UPLOADED), any(String.class), any(int.class)); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); }
SyncAdapter extends AbstractThreadedSyncAdapter { @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { manualMode = extras.getBoolean(SYNC_MANUAL_MODE, false); long started = currentTimeMillis(); syncNotifications.setAccountName(CloudUtils.getAccountName(account)); OwnCloudClient ocClient = CloudUtils.getOwnCloudClient(account, context); if (ocClient == null) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_login), resources.getString(R.string.sync_adapter_text_failed_login)); return; } syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_START); boolean updated = CloudUtils.updateUserProfile(account, ocClient, accountManager); if (!updated) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_profile)); return; } int numRows = localSyncResults.cleanup().blockingGet(); Log.d(TAG, "onPerformSync(): cleanupSyncResults() [" + numRows + "]"); boolean fatalError; SyncItemResult favoritesSyncResult, linksSyncResult = null, notesSyncResult = null; syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_START); SyncItem<Favorite> syncFavorites = new SyncItem<>(ocClient, localFavorites, cloudFavorites, syncNotifications, SyncNotifications.ACTION_SYNC_FAVORITES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); favoritesSyncResult = syncFavorites.sync(); settings.updateLastFavoritesSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_FAVORITES, SyncNotifications.STATUS_SYNC_STOP); fatalError = favoritesSyncResult.isFatal(); if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_START); SyncItem<Link> syncLinks = new SyncItem<>(ocClient, localLinks, cloudLinks, syncNotifications, SyncNotifications.ACTION_SYNC_LINKS, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); linksSyncResult = syncLinks.sync(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_LINKS, SyncNotifications.STATUS_SYNC_STOP); fatalError = linksSyncResult.isFatal(); } if (!fatalError) { syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_START); SyncItem<Note> syncNotes = new SyncItem<>(ocClient, localNotes, cloudNotes, syncNotifications, SyncNotifications.ACTION_SYNC_NOTES, settings.isSyncUploadToEmpty(), settings.isSyncProtectLocal(), started); notesSyncResult = syncNotes.sync(); settings.updateLastNotesSyncTime(); settings.updateLastLinksSyncTime(); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC_NOTES, SyncNotifications.STATUS_SYNC_STOP); fatalError = notesSyncResult.isFatal(); } boolean success = !fatalError && favoritesSyncResult.isSuccess() && linksSyncResult.isSuccess() && notesSyncResult.isSuccess(); saveLastSyncStatus(success); syncNotifications.sendSyncBroadcast( SyncNotifications.ACTION_SYNC, SyncNotifications.STATUS_SYNC_STOP); if (fatalError) { SyncItemResult fatalResult = favoritesSyncResult; if (linksSyncResult != null) fatalResult = linksSyncResult; if (notesSyncResult != null) fatalResult = notesSyncResult; if (fatalResult.isDbAccessError()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_database), resources.getString(R.string.sync_adapter_text_failed_database)); } else if (fatalResult.isSourceNotReady()) { syncNotifications.notifyFailedSynchronization( resources.getString(R.string.sync_adapter_title_failed_cloud), resources.getString(R.string.sync_adapter_text_failed_cloud_access)); } } else { List<String> failSources = new ArrayList<>(); int linkFailsCount = linksSyncResult.getFailsCount(); if (linkFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_links, linkFailsCount, linkFailsCount)); } int favoriteFailsCount = favoritesSyncResult.getFailsCount(); if (favoriteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_favorites, favoriteFailsCount, favoriteFailsCount)); } int noteFailsCount = notesSyncResult.getFailsCount(); if (noteFailsCount > 0) { failSources.add(resources.getQuantityString( R.plurals.count_notes, noteFailsCount, noteFailsCount)); } if (!failSources.isEmpty()) { syncNotifications.notifyFailedSynchronization(resources.getString( R.string.sync_adapter_text_failed, Joiner.on(", ").join(failSources))); } } } SyncAdapter( Context context, Settings settings, boolean autoInitialize, AccountManager accountManager, SyncNotifications syncNotifications, LocalSyncResults localSyncResults, LocalLinks<Link> localLinks, CloudItem<Link> cloudLinks, LocalFavorites<Favorite> localFavorites, CloudItem<Favorite> cloudFavorites, LocalNotes<Note> localNotes, CloudItem<Note> cloudNotes); @Override void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult); static final int SYNC_STATUS_UNKNOWN; static final int SYNC_STATUS_SYNCED; static final int SYNC_STATUS_UNSYNCED; static final int SYNC_STATUS_ERROR; static final int SYNC_STATUS_CONFLICT; static final String SYNC_MANUAL_MODE; }
@Test public void loadEmptyListOfTags_loadsEmptyListIntoView() { when(repository.getTags()).thenReturn(Observable.fromIterable(Collections.emptyList())); presenter.loadTags(); verify(view).swapTagsCompletionViewItems(tagListCaptor.capture()); assertEquals(tagListCaptor.getValue().size(), 0); }
@Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void loadTags() { tagsDisposable.clear(); Disposable disposable = repository.getTags() .subscribeOn(schedulerProvider.computation()) .toList() .observeOn(schedulerProvider.ui()) .subscribe(view::swapTagsCompletionViewItems, throwable -> { CommonUtils.logStackTrace(TAG_E, throwable); view.swapTagsCompletionViewItems(new ArrayList<>()); }); tagsDisposable.add(disposable); } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void saveNewFavoriteToRepository_finishesActivity() { String favoriteName = defaultFavorite.getName(); boolean favoriteAndGate = defaultFavorite.isAndGate(); List<Tag> favoriteTags = defaultFavorite.getTags(); when(repository.saveFavorite(any(Favorite.class), eq(false))) .thenReturn(Observable.just(DataSource.ItemState.DEFERRED)); presenter.saveFavorite(favoriteName, favoriteAndGate, favoriteTags); verify(repository, never()).refreshFavorites(); verify(view).finishActivity(any(String.class)); }
@Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void saveEmptyFavorite_showsEmptyError() { presenter.saveFavorite(defaultFavorite.getName(), false, new ArrayList<>()); presenter.saveFavorite(defaultFavorite.getName(), true, new ArrayList<>()); presenter.saveFavorite("", false, new ArrayList<>()); presenter.saveFavorite("", true, new ArrayList<>()); presenter.saveFavorite("", false, defaultFavorite.getTags()); presenter.saveFavorite("", true, defaultFavorite.getTags()); verify(viewModel, times(6)).showEmptyFavoriteSnackbar(); }
@Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void saveExistingFavorite_finishesActivity() { String favoriteId = defaultFavorite.getId(); boolean favoriteAndGate = defaultFavorite.isAndGate(); String favoriteName = defaultFavorite.getName(); List<Tag> favoriteTags = defaultFavorite.getTags(); when(repository.saveFavorite(any(Favorite.class), eq(false))) .thenReturn(Observable.just(DataSource.ItemState.DEFERRED)); AddEditFavoritePresenter presenter = new AddEditFavoritePresenter( repository, view, viewModel, schedulerProvider, settings, favoriteId); presenter.saveFavorite(favoriteName, favoriteAndGate, favoriteTags); verify(repository, never()).refreshFavorites(); verify(view).finishActivity(eq(favoriteId)); }
@Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void saveFavoriteWithExistedName_showsDuplicateError() { String favoriteId = defaultFavorite.getId(); boolean favoriteAndGate = defaultFavorite.isAndGate(); String favoriteName = defaultFavorite.getName(); List<Tag> favoriteTags = defaultFavorite.getTags(); when(repository.saveFavorite(any(Favorite.class), eq(false))) .thenReturn(Observable.error(new SQLiteConstraintException())); presenter.saveFavorite(favoriteName, favoriteAndGate, favoriteTags); verify(view, never()).finishActivity(eq(favoriteId)); verify(viewModel).showDuplicateKeyError(); }
@Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
AddEditFavoritePresenter implements AddEditFavoriteContract.Presenter, TokenCompleteTextView.TokenListener<Tag> { @Override public void saveFavorite(String name, boolean andGate, List<Tag> tags) { if (isNewFavorite()) { createFavorite(name, andGate, tags); } else { updateFavorite(name, andGate, tags); } } @Inject AddEditFavoritePresenter( Repository repository, AddEditFavoriteContract.View view, AddEditFavoriteContract.ViewModel viewModel, BaseSchedulerProvider schedulerProvider, Settings settings, @Nullable @FavoriteId String favoriteId); @Override void subscribe(); @Override void unsubscribe(); @Override void loadTags(); @Override boolean isNewFavorite(); @Override void populateFavorite(); @Override void saveFavorite(String name, boolean andGate, List<Tag> tags); @Override void onClipboardChanged(int clipboardType, boolean force); @Override void onClipboardLinkExtraReady(boolean force); @Override void setShowFillInFormInfo(boolean show); @Override boolean isShowFillInFormInfo(); @Override void onTokenAdded(Tag tag); @Override void onTokenRemoved(Tag tag); @Override void onDuplicateRemoved(Tag tag); }
@Test public void issues() throws Exception { assertThat(new IssueRegistry().getIssues()).contains( InjectedFieldInJobNotTransientDetector.ISSUE); }
@Override public List<Issue> getIssues() { return Arrays.asList(InjectedFieldInJobNotTransientDetector.ISSUE); }
IssueRegistry extends com.android.tools.lint.client.api.IssueRegistry { @Override public List<Issue> getIssues() { return Arrays.asList(InjectedFieldInJobNotTransientDetector.ISSUE); } }
IssueRegistry extends com.android.tools.lint.client.api.IssueRegistry { @Override public List<Issue> getIssues() { return Arrays.asList(InjectedFieldInJobNotTransientDetector.ISSUE); } }
IssueRegistry extends com.android.tools.lint.client.api.IssueRegistry { @Override public List<Issue> getIssues() { return Arrays.asList(InjectedFieldInJobNotTransientDetector.ISSUE); } @Override List<Issue> getIssues(); }
IssueRegistry extends com.android.tools.lint.client.api.IssueRegistry { @Override public List<Issue> getIssues() { return Arrays.asList(InjectedFieldInJobNotTransientDetector.ISSUE); } @Override List<Issue> getIssues(); }
@Test public void si_la_fecha_de_nacimiento_del_asociado_es_nula_no_valida_el_dni() throws Exception { asociado.setDni("AAA"); asociado.setFechaNacimiento(null); assertTrue(validador.isValid(asociado, context)); }
@Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } @Override void initialize(ValidarDniNie constraintAnnotation); @Override boolean isValid(Asociado asociado, ConstraintValidatorContext context); static boolean validarDniNie(String value, ConstraintValidatorContext context); }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } @Override void initialize(ValidarDniNie constraintAnnotation); @Override boolean isValid(Asociado asociado, ConstraintValidatorContext context); static boolean validarDniNie(String value, ConstraintValidatorContext context); static final String MSG_DIGITO_CONTROL; static final String DIGITO_CONTROL; }
@Test public void el_dni_es_requerido_cuando_el_asociado_es_mayor_de_18_años() throws Exception { asociado.setDni(null); asociado.setFechaNacimiento(LocalDate.now().minus(30, ChronoUnit.YEARS)); assertFalse(validador.isValid(asociado, context)); asociado.setDni(""); assertFalse(validador.isValid(asociado, context)); }
@Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } @Override void initialize(ValidarDniNie constraintAnnotation); @Override boolean isValid(Asociado asociado, ConstraintValidatorContext context); static boolean validarDniNie(String value, ConstraintValidatorContext context); }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } @Override void initialize(ValidarDniNie constraintAnnotation); @Override boolean isValid(Asociado asociado, ConstraintValidatorContext context); static boolean validarDniNie(String value, ConstraintValidatorContext context); static final String MSG_DIGITO_CONTROL; static final String DIGITO_CONTROL; }
@Test public void el_dni_puede_ser_nulo_cuando_el_asociado_es_menor_de_18_años() throws Exception { asociado.setDni(null); asociado.setFechaNacimiento(LocalDate.now().minus(10, ChronoUnit.YEARS)); assertTrue(validador.isValid(asociado, context)); asociado.setDni(""); assertTrue(validador.isValid(asociado, context)); }
@Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } @Override void initialize(ValidarDniNie constraintAnnotation); @Override boolean isValid(Asociado asociado, ConstraintValidatorContext context); static boolean validarDniNie(String value, ConstraintValidatorContext context); }
ValidadorDniNie implements ConstraintValidator<ValidarDniNie, Asociado> { @Override public boolean isValid(Asociado asociado, ConstraintValidatorContext context) { if (asociado == null || asociado.getFechaNacimiento() == null) return true; context.disableDefaultConstraintViolation(); if (Strings.isNullOrEmpty(asociado.getDni())) { boolean mayorDeEdad = asociado.getFechaNacimiento().plus(18, ChronoUnit.YEARS).isBefore(LocalDate.now()); if (mayorDeEdad) { context.buildConstraintViolationWithTemplate(MSG_REQUERIDO_MAYOR_EDAD).addConstraintViolation(); return false; } else { return true; } } return validarDniNie(asociado.getDni(), context); } @Override void initialize(ValidarDniNie constraintAnnotation); @Override boolean isValid(Asociado asociado, ConstraintValidatorContext context); static boolean validarDniNie(String value, ConstraintValidatorContext context); static final String MSG_DIGITO_CONTROL; static final String DIGITO_CONTROL; }
@Test public void testConstructQuery() throws Exception { String queryString = "PREFIX nn: <http: "PREFIX test: <http: "\n" + "construct { ?s test:test \"0\"} WHERE {?s nn:childOf nn:Eve . }"; GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString); GraphQueryResult results = graphQuery.evaluate(); Statement st1 = results.next(); Assert.assertEquals("http: Statement st2 = results.next(); Assert.assertEquals("http: results.close(); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test public void testPrepareTupleQueryWithOptimizeLevel() throws Exception{ String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 10 "; TupleQuery tupleQuery = conn.prepareTupleQuery(queryString,"http: conn.setOptimizeLevel(0); TupleQueryResult results = tupleQuery.evaluate(); Assert.assertNotNull(results); conn.setOptimizeLevel(null); results.close(); }
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
@Test public void testConstructQueryWithOptimizeLevel() throws Exception { String queryString = "PREFIX nn: <http: "PREFIX test: <http: "\n" + "construct { ?s test:test \"0\"} WHERE {?s nn:childOf nn:Eve . }"; conn.setOptimizeLevel(0); GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString); GraphQueryResult results = graphQuery.evaluate(); Assert.assertNotNull(results); results.close(); conn.setOptimizeLevel(null); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test public void testSPARQLQueryBindings() throws Exception { String queryString = "select ?s ?p ?o { ?s ?p ?o . filter (?s = ?b) filter (?p = ?c) }"; TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleQuery.setBinding("b", SimpleValueFactory.getInstance().createIRI("http: tupleQuery.setBinding("c", SimpleValueFactory.getInstance().createIRI("http: tupleQuery.removeBinding("c"); Assert.assertEquals(null, tupleQuery.getBindings().getBinding("c")); tupleQuery.clearBindings(); Assert.assertEquals(null, tupleQuery.getBindings().getBinding("b")); tupleQuery.setBinding("b", SimpleValueFactory.getInstance().createIRI("http: tupleQuery.setBinding("c", SimpleValueFactory.getInstance().createIRI("http: TupleQueryResult results = tupleQuery.evaluate(); Assert.assertEquals(results.getBindingNames().get(0), "s"); Assert.assertEquals(results.getBindingNames().get(1), "p"); Assert.assertEquals(results.getBindingNames().get(2), "o"); logger.info(results.getBindingNames().toString()); Assert.assertTrue(results.hasNext()); BindingSet bindingSet = results.next(); Value sV = bindingSet.getValue("s"); Value pV = bindingSet.getValue("p"); Value oV = bindingSet.getValue("o"); Assert.assertEquals("http: Assert.assertEquals("http: Assert.assertEquals("http: results.close(); }
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
@Test(expected=org.eclipse.rdf4j.query.QueryEvaluationException.class) public void testSPARQLQueryQueryEvaluationException() throws Exception { String queryString = "select * <http: TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult results = tupleQuery.evaluate(); Assert.assertFalse(results.hasNext()); results.close(); }
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
@Test(expected=org.eclipse.rdf4j.query.QueryEvaluationException.class) public void testSPARQLMalformedException() throws Exception { String queryString = "select1 * <http: TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult results = tupleQuery.evaluate(); Assert.assertFalse(results.hasNext()); results.close(); }
@Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
MarkLogicTupleQuery extends MarkLogicQuery implements TupleQuery,MarkLogicQueryDependent { @Override public TupleQueryResult evaluate() throws QueryEvaluationException { return evaluate(this.start,this.pageLength); } MarkLogicTupleQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override TupleQueryResult evaluate(); TupleQueryResult evaluate(long start, long pageLength); @Override void evaluate(TupleQueryResultHandler resultHandler); void evaluate(TupleQueryResultHandler resultHandler,long start, long pageLength); }
@Test public void testBooleanQueryWithOptimizeLevel() throws Exception { String queryString = "ASK {GRAPH <http: conn.setOptimizeLevel(0); BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean results = booleanQuery.evaluate(); Assert.assertEquals(false, results); conn.setOptimizeLevel(null); }
@Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override boolean evaluate(); }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override boolean evaluate(); }
@Test(expected=org.eclipse.rdf4j.query.QueryEvaluationException.class) public void testBooleanQueryQueryEvaluationException() throws Exception { String queryString = "ASK GRAPH <http: BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean results = booleanQuery.evaluate(); }
@Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override boolean evaluate(); }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override boolean evaluate(); }
@Test public void testGraphQueryWithBaseURIInline() throws Exception { String queryString ="BASE <http: "PREFIX nn: <http: "PREFIX test: <http: "construct { ?s test:test <relative>} WHERE {?s nn:childOf nn:Eve . }"; GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString); GraphQueryResult results = graphQuery.evaluate(); Statement st1 = results.next(); Assert.assertEquals("http: Assert.assertEquals("http: Statement st2 = results.next(); Assert.assertEquals("http: results.close(); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test(expected=org.eclipse.rdf4j.query.QueryEvaluationException.class) public void testBooleanQueryMalformedException() throws Exception { String queryString = "ASK1 GRAPH <http: BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean results = booleanQuery.evaluate(); }
@Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override boolean evaluate(); }
MarkLogicBooleanQuery extends MarkLogicQuery implements BooleanQuery,MarkLogicQueryDependent { @Override public boolean evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendBooleanQuery(getQueryString(), getBindings(), getIncludeInferred(),getBaseURI()); }catch (RepositoryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (MalformedQueryException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch (IOException e) { throw new QueryEvaluationException(e.getMessage(), e); }catch(FailedRequestException e){ throw new QueryEvaluationException(e.getMessage(), e); } } MarkLogicBooleanQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override boolean evaluate(); }
@Test public void testUpdateQuery() throws Exception { String defGraphQuery = "INSERT DATA { GRAPH <http: String checkQuery = "ASK WHERE { <http: Update updateQuery = conn.prepareUpdate(QueryLanguage.SPARQL, defGraphQuery); updateQuery.execute(); BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, checkQuery); boolean results = booleanQuery.evaluate(); Assert.assertEquals(true, results); conn.clear(conn.getValueFactory().createIRI("http: }
@Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
@Test public void testUpdateQueryWithBaseURI() throws Exception { String defGraphQuery = "INSERT DATA { GRAPH <http: String checkQuery = "ASK WHERE { <http: Update updateQuery = conn.prepareUpdate(QueryLanguage.SPARQL, defGraphQuery,"http: updateQuery.execute(); BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, checkQuery,"http: boolean results = booleanQuery.evaluate(); Assert.assertEquals(true, results); conn.clear(conn.getValueFactory().createIRI("http: }
@Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
@Test public void testUpdateQueryWithExistingBaseURI() throws Exception { String defGraphQuery = "BASE <http: String checkQuery = "BASE <http: MarkLogicUpdateQuery updateQuery = conn.prepareUpdate(QueryLanguage.SPARQL, defGraphQuery,"http: updateQuery.execute(); BooleanQuery booleanQuery = conn.prepareBooleanQuery(QueryLanguage.SPARQL, checkQuery); boolean results = booleanQuery.evaluate(); Assert.assertEquals(true, results); conn.clear(conn.getValueFactory().createIRI("http: }
@Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
@Test(expected=org.eclipse.rdf4j.query.UpdateExecutionException.class) public void testUpdateQueryUpdateExecutionException() throws Exception { String defGraphQuery = "INSERT DATA GRAPH <http: Update updateQuery = conn.prepareUpdate(QueryLanguage.SPARQL, defGraphQuery); updateQuery.execute(); }
@Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
@Test(expected=org.eclipse.rdf4j.query.UpdateExecutionException.class) public void testUpdateQueryMalformedException() throws Exception { String defGraphQuery = "INSERT1 DATA GRAPH <http: Update updateQuery = conn.prepareUpdate(QueryLanguage.SPARQL, defGraphQuery); updateQuery.execute(); }
@Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
MarkLogicUpdateQuery extends MarkLogicQuery implements Update,MarkLogicQueryDependent { @Override public void execute() throws UpdateExecutionException { try { sync(); getMarkLogicClient().sendUpdateQuery(getQueryString(), getBindings(), getIncludeInferred(), getBaseURI()); }catch(ForbiddenUserException | FailedRequestException e){ throw new UpdateExecutionException(e); } catch (RepositoryException e) { throw new UpdateExecutionException(e); } catch (MalformedQueryException e) { throw new UpdateExecutionException(e); } catch (IOException e) { throw new UpdateExecutionException(e); } } MarkLogicUpdateQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override void execute(); }
@Test public void testGetRepository() throws Exception { MarkLogicRepositoryConfig config = new MarkLogicRepositoryConfig(); config.setHost(host); config.setPort(port); config.setUser(adminUser); config.setPassword(adminPassword); config.setAuth("DIGEST"); RepositoryFactory factory = new MarkLogicRepositoryFactory(); Assert.assertEquals("marklogic:MarkLogicRepository", factory.getRepositoryType()); Repository repo = factory.getRepository(config); repo.initialize(); Assert.assertTrue(repo.getConnection() instanceof MarkLogicRepositoryConnection); Repository otherrepo = factory.getRepository(config); otherrepo.initialize(); RepositoryConnection oconn = otherrepo.getConnection(); Assert.assertTrue(oconn instanceof MarkLogicRepositoryConnection); }
@Override public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException { MarkLogicRepository repo = null; MarkLogicRepositoryConfig cfg = (MarkLogicRepositoryConfig) config; if (cfg.getHost() != null && cfg.getPort() != 0) { repo = new MarkLogicRepository(cfg.getHost(),cfg.getPort(),cfg.getUser(),cfg.getPassword(),cfg.getAuth()); } else if (cfg.getHost() == null) { try { repo = new MarkLogicRepository(new URL(cfg.getQueryEndpointUrl())); } catch (MalformedURLException e) { logger.debug(e.getMessage()); throw new RepositoryConfigException(e.getMessage()); } }else{ throw new RepositoryConfigException("Invalid configuration class: " + config.getClass()); } return repo; }
MarkLogicRepositoryFactory implements RepositoryFactory { @Override public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException { MarkLogicRepository repo = null; MarkLogicRepositoryConfig cfg = (MarkLogicRepositoryConfig) config; if (cfg.getHost() != null && cfg.getPort() != 0) { repo = new MarkLogicRepository(cfg.getHost(),cfg.getPort(),cfg.getUser(),cfg.getPassword(),cfg.getAuth()); } else if (cfg.getHost() == null) { try { repo = new MarkLogicRepository(new URL(cfg.getQueryEndpointUrl())); } catch (MalformedURLException e) { logger.debug(e.getMessage()); throw new RepositoryConfigException(e.getMessage()); } }else{ throw new RepositoryConfigException("Invalid configuration class: " + config.getClass()); } return repo; } }
MarkLogicRepositoryFactory implements RepositoryFactory { @Override public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException { MarkLogicRepository repo = null; MarkLogicRepositoryConfig cfg = (MarkLogicRepositoryConfig) config; if (cfg.getHost() != null && cfg.getPort() != 0) { repo = new MarkLogicRepository(cfg.getHost(),cfg.getPort(),cfg.getUser(),cfg.getPassword(),cfg.getAuth()); } else if (cfg.getHost() == null) { try { repo = new MarkLogicRepository(new URL(cfg.getQueryEndpointUrl())); } catch (MalformedURLException e) { logger.debug(e.getMessage()); throw new RepositoryConfigException(e.getMessage()); } }else{ throw new RepositoryConfigException("Invalid configuration class: " + config.getClass()); } return repo; } }
MarkLogicRepositoryFactory implements RepositoryFactory { @Override public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException { MarkLogicRepository repo = null; MarkLogicRepositoryConfig cfg = (MarkLogicRepositoryConfig) config; if (cfg.getHost() != null && cfg.getPort() != 0) { repo = new MarkLogicRepository(cfg.getHost(),cfg.getPort(),cfg.getUser(),cfg.getPassword(),cfg.getAuth()); } else if (cfg.getHost() == null) { try { repo = new MarkLogicRepository(new URL(cfg.getQueryEndpointUrl())); } catch (MalformedURLException e) { logger.debug(e.getMessage()); throw new RepositoryConfigException(e.getMessage()); } }else{ throw new RepositoryConfigException("Invalid configuration class: " + config.getClass()); } return repo; } @Override /** * getter for repository type. * */ String getRepositoryType(); @Override /** * returns config * */ RepositoryImplConfig getConfig(); @Override /** * Instantiate and return repository object. * */ Repository getRepository(RepositoryImplConfig config); }
MarkLogicRepositoryFactory implements RepositoryFactory { @Override public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException { MarkLogicRepository repo = null; MarkLogicRepositoryConfig cfg = (MarkLogicRepositoryConfig) config; if (cfg.getHost() != null && cfg.getPort() != 0) { repo = new MarkLogicRepository(cfg.getHost(),cfg.getPort(),cfg.getUser(),cfg.getPassword(),cfg.getAuth()); } else if (cfg.getHost() == null) { try { repo = new MarkLogicRepository(new URL(cfg.getQueryEndpointUrl())); } catch (MalformedURLException e) { logger.debug(e.getMessage()); throw new RepositoryConfigException(e.getMessage()); } }else{ throw new RepositoryConfigException("Invalid configuration class: " + config.getClass()); } return repo; } @Override /** * getter for repository type. * */ String getRepositoryType(); @Override /** * returns config * */ RepositoryImplConfig getConfig(); @Override /** * Instantiate and return repository object. * */ Repository getRepository(RepositoryImplConfig config); static final String REPOSITORY_TYPE; }
@Test public void testMarkLogicRepositoryConnectionOpen() throws Exception { Assert.assertEquals(true, conn.isOpen()); }
@Override public boolean isOpen() throws RepositoryException { return super.isOpen(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean isOpen() throws RepositoryException { return super.isOpen(); } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean isOpen() throws RepositoryException { return super.isOpen(); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean isOpen() throws RepositoryException { return super.isOpen(); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean isOpen() throws RepositoryException { return super.isOpen(); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
@Test public void testMarkLogicRepositoryConnection() throws Exception { Assert.assertNotNull("Expected repository to exist.", rep); Assert.assertTrue("Expected repository to be initialized.", rep.isInitialized()); rep.shutDown(); Properties props = new Properties(); try { props.load(new FileInputStream("gradle.properties")); } catch (IOException e) { System.err.println("problem loading properties file."); System.exit(1); } String host = props.getProperty("mlHost"); int port = Integer.parseInt(props.getProperty("mlRestPort")); String user = props.getProperty("validUsername"); String pass = props.getProperty("validPassword"); rep = new MarkLogicRepository(host, port, user, pass, "DIGEST"); Assert.assertNotNull("Expected repository to exist.", rep); Assert.assertFalse("Expected repository to not be initialized.", rep.isInitialized()); rep.initialize(); conn = rep.getConnection(); Assert.assertTrue("Expected repository to be initialized.", rep.isInitialized()); rep.shutDown(); Assert.assertFalse("Expected repository to not be initialized.", rep.isInitialized()); rep.initialize(); conn = rep.getConnection(); Assert.assertNotNull("Expected repository to exist.", rep); }
public MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode) { super(repository); this.client = client; this.quadMode = true; this.defaultGraphPerms = client.emptyGraphPerms(); client.setValueFactory(repository.getValueFactory()); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode) { super(repository); this.client = client; this.quadMode = true; this.defaultGraphPerms = client.emptyGraphPerms(); client.setValueFactory(repository.getValueFactory()); } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode) { super(repository); this.client = client; this.quadMode = true; this.defaultGraphPerms = client.emptyGraphPerms(); client.setValueFactory(repository.getValueFactory()); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode) { super(repository); this.client = client; this.quadMode = true; this.defaultGraphPerms = client.emptyGraphPerms(); client.setValueFactory(repository.getValueFactory()); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode) { super(repository); this.client = client; this.quadMode = true; this.defaultGraphPerms = client.emptyGraphPerms(); client.setValueFactory(repository.getValueFactory()); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
@Test public void testGetStatements() throws Exception{ File inputFile = new File(TESTFILE_OWL); conn.add(inputFile,null,RDFFormat.RDFXML); ValueFactory f= conn.getValueFactory(); IRI subj = f.createIRI("http: RepositoryResult<Statement> statements = conn.getStatements(subj, null, null, true); Assert.assertTrue(statements.hasNext()); conn.clear(conn.getValueFactory().createIRI("http: }
public RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred) throws RepositoryException { try { if (isQuadMode()) { TupleQuery tupleQuery = prepareTupleQuery(GET_STATEMENTS); setBindings(tupleQuery, subj, pred, obj); tupleQuery.setIncludeInferred(includeInferred); TupleQueryResult qRes = tupleQuery.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>( toStatementIteration(qRes, subj, pred, obj)) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } else if (subj != null && pred != null && obj != null) { if (hasStatement(subj, pred, obj, includeInferred)) { ValueFactory vf = SimpleValueFactory.getInstance(); Statement st = vf.createStatement(subj, pred, obj); CloseableIteration<Statement, RepositoryException> cursor; cursor = new SingletonIteration<Statement, RepositoryException>(st); return new RepositoryResult<Statement>(cursor); } else { return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>()); } } GraphQuery query = prepareGraphQuery(EVERYTHING); query.setIncludeInferred(includeInferred); setBindings(query, subj, pred, obj); GraphQueryResult result = query.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>(result) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred) throws RepositoryException { try { if (isQuadMode()) { TupleQuery tupleQuery = prepareTupleQuery(GET_STATEMENTS); setBindings(tupleQuery, subj, pred, obj); tupleQuery.setIncludeInferred(includeInferred); TupleQueryResult qRes = tupleQuery.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>( toStatementIteration(qRes, subj, pred, obj)) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } else if (subj != null && pred != null && obj != null) { if (hasStatement(subj, pred, obj, includeInferred)) { ValueFactory vf = SimpleValueFactory.getInstance(); Statement st = vf.createStatement(subj, pred, obj); CloseableIteration<Statement, RepositoryException> cursor; cursor = new SingletonIteration<Statement, RepositoryException>(st); return new RepositoryResult<Statement>(cursor); } else { return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>()); } } GraphQuery query = prepareGraphQuery(EVERYTHING); query.setIncludeInferred(includeInferred); setBindings(query, subj, pred, obj); GraphQueryResult result = query.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>(result) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred) throws RepositoryException { try { if (isQuadMode()) { TupleQuery tupleQuery = prepareTupleQuery(GET_STATEMENTS); setBindings(tupleQuery, subj, pred, obj); tupleQuery.setIncludeInferred(includeInferred); TupleQueryResult qRes = tupleQuery.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>( toStatementIteration(qRes, subj, pred, obj)) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } else if (subj != null && pred != null && obj != null) { if (hasStatement(subj, pred, obj, includeInferred)) { ValueFactory vf = SimpleValueFactory.getInstance(); Statement st = vf.createStatement(subj, pred, obj); CloseableIteration<Statement, RepositoryException> cursor; cursor = new SingletonIteration<Statement, RepositoryException>(st); return new RepositoryResult<Statement>(cursor); } else { return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>()); } } GraphQuery query = prepareGraphQuery(EVERYTHING); query.setIncludeInferred(includeInferred); setBindings(query, subj, pred, obj); GraphQueryResult result = query.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>(result) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred) throws RepositoryException { try { if (isQuadMode()) { TupleQuery tupleQuery = prepareTupleQuery(GET_STATEMENTS); setBindings(tupleQuery, subj, pred, obj); tupleQuery.setIncludeInferred(includeInferred); TupleQueryResult qRes = tupleQuery.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>( toStatementIteration(qRes, subj, pred, obj)) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } else if (subj != null && pred != null && obj != null) { if (hasStatement(subj, pred, obj, includeInferred)) { ValueFactory vf = SimpleValueFactory.getInstance(); Statement st = vf.createStatement(subj, pred, obj); CloseableIteration<Statement, RepositoryException> cursor; cursor = new SingletonIteration<Statement, RepositoryException>(st); return new RepositoryResult<Statement>(cursor); } else { return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>()); } } GraphQuery query = prepareGraphQuery(EVERYTHING); query.setIncludeInferred(includeInferred); setBindings(query, subj, pred, obj); GraphQueryResult result = query.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>(result) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred) throws RepositoryException { try { if (isQuadMode()) { TupleQuery tupleQuery = prepareTupleQuery(GET_STATEMENTS); setBindings(tupleQuery, subj, pred, obj); tupleQuery.setIncludeInferred(includeInferred); TupleQueryResult qRes = tupleQuery.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>( toStatementIteration(qRes, subj, pred, obj)) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } else if (subj != null && pred != null && obj != null) { if (hasStatement(subj, pred, obj, includeInferred)) { ValueFactory vf = SimpleValueFactory.getInstance(); Statement st = vf.createStatement(subj, pred, obj); CloseableIteration<Statement, RepositoryException> cursor; cursor = new SingletonIteration<Statement, RepositoryException>(st); return new RepositoryResult<Statement>(cursor); } else { return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>()); } } GraphQuery query = prepareGraphQuery(EVERYTHING); query.setIncludeInferred(includeInferred); setBindings(query, subj, pred, obj); GraphQueryResult result = query.evaluate(); return new RepositoryResult<Statement>( new ExceptionConvertingIteration<Statement, RepositoryException>(result) { @Override protected RepositoryException convert(Exception e) { return new RepositoryException(e); } }); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
@Test public void testGraphQueryWithBaseURI() throws Exception { String queryString = "PREFIX nn: <http: "PREFIX test: <http: "construct { ?s test:test <relative>} WHERE {?s nn:childOf nn:Eve . }"; GraphQuery graphQuery = conn.prepareGraphQuery(queryString, "http: GraphQueryResult results = graphQuery.evaluate(); Statement st1 = results.next(); Assert.assertEquals("http: Statement st2 = results.next(); Assert.assertEquals("http: results.close(); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test public void testHasStatement() throws Exception { Resource context1 = conn.getValueFactory().createIRI("http: ValueFactory f= conn.getValueFactory(); IRI alice = f.createIRI("http: IRI name = f.createIRI("http: Literal alicesName = f.createLiteral("Alice"); Statement st1 = f.createStatement(alice, name, alicesName); conn.add(st1, context1); Assert.assertTrue(conn.hasStatement(st1, false, context1)); Assert.assertTrue(conn.hasStatement(st1, false, context1, null)); Assert.assertFalse(conn.hasStatement(st1, false, (Resource) null)); Assert.assertFalse(conn.hasStatement(st1, false, (Resource) null)); Assert.assertTrue(conn.hasStatement(st1, false)); Assert.assertTrue(conn.hasStatement(null, null, null, false)); conn.clear(context1); }
@Override public boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts) throws RepositoryException { return hasStatement(st.getSubject(),st.getPredicate(),st.getObject(),includeInferred,contexts); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts) throws RepositoryException { return hasStatement(st.getSubject(),st.getPredicate(),st.getObject(),includeInferred,contexts); } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts) throws RepositoryException { return hasStatement(st.getSubject(),st.getPredicate(),st.getObject(),includeInferred,contexts); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts) throws RepositoryException { return hasStatement(st.getSubject(),st.getPredicate(),st.getObject(),includeInferred,contexts); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts) throws RepositoryException { return hasStatement(st.getSubject(),st.getPredicate(),st.getObject(),includeInferred,contexts); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
@Test public void testExportStatements() throws Exception { Resource context1 = conn.getValueFactory().createIRI("http: ValueFactory f = conn.getValueFactory(); final IRI alice = f.createIRI("http: IRI name = f.createIRI("http: Literal alicesName = f.createLiteral("Alice"); Statement st1 = f.createStatement(alice, name, alicesName); conn.add(st1, context1); ByteArrayOutputStream out = new ByteArrayOutputStream(); RDFXMLWriter rdfWriter = new RDFXMLWriter(out); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<rdf:RDF\n" + "\txmlns:rdf=\"http: "\n" + "<rdf:Description rdf:about=\"http: "\t<name xmlns=\"http: "</rdf:Description>\n" + "\n" + "</rdf:RDF>"; conn.exportStatements(alice, null, alicesName, true, rdfWriter, context1); Assert.assertEquals(expected, out.toString()); conn.clear(context1); }
@Override public void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { RepositoryResult<Statement> st = this.getStatements(subject, predicate, object, includeInferred, contexts); handler.startRDF(); QueryResults.stream(st).forEach(handler::handleStatement); handler.endRDF(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { RepositoryResult<Statement> st = this.getStatements(subject, predicate, object, includeInferred, contexts); handler.startRDF(); QueryResults.stream(st).forEach(handler::handleStatement); handler.endRDF(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { RepositoryResult<Statement> st = this.getStatements(subject, predicate, object, includeInferred, contexts); handler.startRDF(); QueryResults.stream(st).forEach(handler::handleStatement); handler.endRDF(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { RepositoryResult<Statement> st = this.getStatements(subject, predicate, object, includeInferred, contexts); handler.startRDF(); QueryResults.stream(st).forEach(handler::handleStatement); handler.endRDF(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { RepositoryResult<Statement> st = this.getStatements(subject, predicate, object, includeInferred, contexts); handler.startRDF(); QueryResults.stream(st).forEach(handler::handleStatement); handler.endRDF(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
@Test public void testDatabaseClientAccess() { DatabaseClient databaseClient = conn.getDatabaseClient(); Assert.assertEquals(host, databaseClient.getHost()); Assert.assertEquals(port, databaseClient.getPort()); }
public DatabaseClient getDatabaseClient() { return this.client.getClient().getDatabaseClient(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public DatabaseClient getDatabaseClient() { return this.client.getClient().getDatabaseClient(); } }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public DatabaseClient getDatabaseClient() { return this.client.getClient().getDatabaseClient(); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public DatabaseClient getDatabaseClient() { return this.client.getClient().getDatabaseClient(); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
MarkLogicRepositoryConnection extends AbstractRepositoryConnection implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { public DatabaseClient getDatabaseClient() { return this.client.getClient().getDatabaseClient(); } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, IRI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, IRI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, IRI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); void setOptimizeLevel(Integer optimizeLevel); Integer getOptimizeLevel(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); DatabaseClient getDatabaseClient(); Transaction getTransaction(); }
@Test public void negativeTestRepo2() throws Exception { Repository rep = new MarkLogicRepository(host, port, new DatabaseClientFactory.DigestAuthContext(user, password)); rep.initialize(); rep.shutDown(); exception.expect(RepositoryException.class); exception.expectMessage("MarkLogicRepository not initialized."); @SuppressWarnings("unused") RepositoryConnection conn = rep.getConnection(); }
@Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override File getDataDir(); @Override void setDataDir(File dataDir); @Override boolean isWritable(); @Override MarkLogicRepositoryConnection getConnection(); @Override synchronized MarkLogicClient getMarkLogicClient(); @Override synchronized void setMarkLogicClient(MarkLogicClient client); boolean isQuadMode(); void setQuadMode(boolean quadMode); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override File getDataDir(); @Override void setDataDir(File dataDir); @Override boolean isWritable(); @Override MarkLogicRepositoryConnection getConnection(); @Override synchronized MarkLogicClient getMarkLogicClient(); @Override synchronized void setMarkLogicClient(MarkLogicClient client); boolean isQuadMode(); void setQuadMode(boolean quadMode); }
@Test public void TestRepoWithJavaAPIClientDatabaseClient() throws Exception { DatabaseClient databaseClient = DatabaseClientFactory.newClient(host, port, new DatabaseClientFactory.DigestAuthContext(user, password)); Repository rep = new MarkLogicRepository(databaseClient); rep.initialize(); Assert.assertTrue(rep instanceof Repository); RepositoryConnection conn = rep.getConnection(); Assert.assertTrue(conn instanceof RepositoryConnection); conn.close(); rep.shutDown(); }
@Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override File getDataDir(); @Override void setDataDir(File dataDir); @Override boolean isWritable(); @Override MarkLogicRepositoryConnection getConnection(); @Override synchronized MarkLogicClient getMarkLogicClient(); @Override synchronized void setMarkLogicClient(MarkLogicClient client); boolean isQuadMode(); void setQuadMode(boolean quadMode); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override File getDataDir(); @Override void setDataDir(File dataDir); @Override boolean isWritable(); @Override MarkLogicRepositoryConnection getConnection(); @Override synchronized MarkLogicClient getMarkLogicClient(); @Override synchronized void setMarkLogicClient(MarkLogicClient client); boolean isQuadMode(); void setQuadMode(boolean quadMode); }
@Test public void testMultipleReposWithDifferentUsers() throws RepositoryException, MalformedQueryException, UpdateExecutionException { readerRep.initialize(); MarkLogicRepositoryConnection testReaderCon = readerRep.getConnection(); exception.expect(Exception.class); testReaderCon.prepareUpdate("CREATE GRAPH <abc>").execute(); writerRep.initialize(); MarkLogicRepositoryConnection testWriterCon = writerRep.getConnection(); testWriterCon.prepareUpdate("CREATE GRAPH <abcdef10>").execute(); writerRep.shutDown(); readerRep.shutDown(); }
@Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override File getDataDir(); @Override void setDataDir(File dataDir); @Override boolean isWritable(); @Override MarkLogicRepositoryConnection getConnection(); @Override synchronized MarkLogicClient getMarkLogicClient(); @Override synchronized void setMarkLogicClient(MarkLogicClient client); boolean isQuadMode(); void setQuadMode(boolean quadMode); }
MarkLogicRepository extends AbstractRepository implements Repository,MarkLogicClientDependent { @Override public MarkLogicRepositoryConnection getConnection() throws RepositoryException { if (!isInitialized()) { throw new RepositoryException("MarkLogicRepository not initialized."); } return new MarkLogicRepositoryConnection(this, getMarkLogicClient(), quadMode); } MarkLogicRepository(URL connectionString); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String auth); @Deprecated MarkLogicRepository(String host, int port, String user, String password, String database, String auth); MarkLogicRepository(String host, int port, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(String host, int port, String database, DatabaseClientFactory.SecurityContext securityContext); MarkLogicRepository(DatabaseClient databaseClient); ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override File getDataDir(); @Override void setDataDir(File dataDir); @Override boolean isWritable(); @Override MarkLogicRepositoryConnection getConnection(); @Override synchronized MarkLogicClient getMarkLogicClient(); @Override synchronized void setMarkLogicClient(MarkLogicClient client); boolean isQuadMode(); void setQuadMode(boolean quadMode); }
@Ignore @Test public void testGraphQueryWithBaseURIWithEmptyBaseURI() throws Exception { String queryString = "PREFIX nn: <http: "PREFIX test: <http: "construct { ?s test:test <relative>} WHERE {?s nn:childOf nn:Eve . }"; GraphQuery graphQuery = conn.prepareGraphQuery(queryString, ""); exception.expect(QueryEvaluationException.class); GraphQueryResult results = graphQuery.evaluate(); Statement st1 = results.next(); Assert.assertEquals("http: @SuppressWarnings("unused") Statement st2 = results.next(); Assert.assertEquals("http: results.close(); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test public void testDescribeQuery() throws Exception { String queryString = "DESCRIBE <http: GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString); GraphQueryResult results = graphQuery.evaluate(); Statement st1 = results.next(); Assert.assertEquals("http: Assert.assertEquals("http: Assert.assertEquals("http: results.close(); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test public void testPrepareGraphQueryWithSingleResult() throws Exception { Resource context1 = conn.getValueFactory().createIRI("http: ValueFactory f= conn.getValueFactory(); IRI alice = f.createIRI("http: IRI name = f.createIRI("http: Literal alicesName = f.createLiteral("Alice1"); Statement st1 = f.createStatement(alice, name, alicesName); conn.add(st1,context1); String query = " DESCRIBE <http: GraphQuery queryObj = conn.prepareGraphQuery(query); GraphQueryResult result = queryObj.evaluate(); Assert.assertTrue(result != null); Assert.assertTrue(result.hasNext()); @SuppressWarnings("unused") Statement st = result.next(); Assert.assertFalse(result.hasNext()); result.close(); conn.clear(context1); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
@Test public void testPrepareGraphQueryWithNoResult() throws Exception { String query = "DESCRIBE <http: GraphQuery queryObj = conn.prepareGraphQuery(query); GraphQueryResult result = queryObj.evaluate(); Assert.assertTrue(result != null); Assert.assertFalse(result.hasNext()); result.close(); }
@Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }
MarkLogicGraphQuery extends MarkLogicQuery implements GraphQuery,MarkLogicQueryDependent { @Override public GraphQueryResult evaluate() throws QueryEvaluationException { try { sync(); return getMarkLogicClient().sendGraphQuery(getQueryString(),getBindings(),getIncludeInferred(),getBaseURI()); } catch (IOException e) { throw new QueryEvaluationException(e); } catch (MarkLogicRdf4jException e) { throw new QueryEvaluationException(e); } } MarkLogicGraphQuery(MarkLogicClient client, SPARQLQueryBindingSet bindingSet, String baseUri, String queryString, GraphPermissions graphPerms, QueryDefinition queryDef, SPARQLRuleset[] rulesets); @Override GraphQueryResult evaluate(); @Override void evaluate(RDFHandler resultHandler); }