@Test public void findOneById() { final LocalDhisResourceRepositoryImpl<TrackedEntityInstance> resourceRepository = new LocalDhisResourceRepositoryImpl<>( TrackedEntityInstance.class ); final WritableTrackedEntityType trackedEntityType = new WritableTrackedEntityType(); trackedEntityType.setAttributes( Collections.emptyList() ); final TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance( trackedEntityType, "a1234567890", true ); Assert.assertSame( trackedEntityInstance, resourceRepository.save( trackedEntityInstance, null ) ); final TrackedEntityInstance found = resourceRepository.findOneById( "a1234567890" ).orElse( null ); Assert.assertSame( trackedEntityInstance, found ); Assert.assertEquals( "a1234567890", trackedEntityInstance.getId() ); }
@Override @Nonnull public Optional<T> findOneById( @Nonnull String id ) { final LocalDhisResource<T> local = resourcesById.get( id ); return local == null ? Optional.empty() : Optional.of( local.getResource() ); }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Optional<T> findOneById( @Nonnull String id ) { final LocalDhisResource<T> local = resourcesById.get( id ); return local == null ? Optional.empty() : Optional.of( local.getResource() ); } }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Optional<T> findOneById( @Nonnull String id ) { final LocalDhisResource<T> local = resourcesById.get( id ); return local == null ? Optional.empty() : Optional.of( local.getResource() ); } LocalDhisResourceRepositoryImpl( @Nonnull Class<T> resourceClass ); }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Optional<T> findOneById( @Nonnull String id ) { final LocalDhisResource<T> local = resourcesById.get( id ); return local == null ? Optional.empty() : Optional.of( local.getResource() ); } LocalDhisResourceRepositoryImpl( @Nonnull Class<T> resourceClass ); @Override @Nonnull T save( @Nonnull T resource, @Nullable Object resourceKey ); @Override boolean deleteById( @Nonnull String id, @Nullable Object resourceKey, @Nonnull Function<String, T> prototypeFunction ); @Override boolean containsCollectionKey( @Nonnull String key ); @Override @Nonnull Collection<T> found( @Nonnull Collection<T> resources, @Nonnull String key ); @Override @Nonnull Optional<T> findOneById( @Nonnull String id ); @Override @Nonnull Collection<T> find( @Nonnull Predicate<T> filter ); @Override @Nonnull Collection<T> find( @Nonnull String trackedEntityInstanceId, @Nonnull Predicate<T> filter ); @Override void applySaves( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback ); @Override void applyDeletes( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback ); }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Optional<T> findOneById( @Nonnull String id ) { final LocalDhisResource<T> local = resourcesById.get( id ); return local == null ? Optional.empty() : Optional.of( local.getResource() ); } LocalDhisResourceRepositoryImpl( @Nonnull Class<T> resourceClass ); @Override @Nonnull T save( @Nonnull T resource, @Nullable Object resourceKey ); @Override boolean deleteById( @Nonnull String id, @Nullable Object resourceKey, @Nonnull Function<String, T> prototypeFunction ); @Override boolean containsCollectionKey( @Nonnull String key ); @Override @Nonnull Collection<T> found( @Nonnull Collection<T> resources, @Nonnull String key ); @Override @Nonnull Optional<T> findOneById( @Nonnull String id ); @Override @Nonnull Collection<T> find( @Nonnull Predicate<T> filter ); @Override @Nonnull Collection<T> find( @Nonnull String trackedEntityInstanceId, @Nonnull Predicate<T> filter ); @Override void applySaves( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback ); @Override void applyDeletes( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback );  }