@Test public void findOneByIdNoLocal() { final TrackedEntityInstance tei = new TrackedEntityInstance(); Assert.assertSame( tei, template.findOneById( "h1234567890", id -> tei ).orElse( null ) ); Mockito.verifyZeroInteractions( resourceRepository ); Mockito.verifyZeroInteractions( persistCallback ); }
@Nonnull public Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ) { final RequestCacheContext context = requestCacheService.getCurrentRequestCacheContext(); final Optional<LocalDhisResourceRepository<T>> repository = getRepository( context ); T result = null; if ( repository.isPresent() ) { result = repository.get().findOneById( id ).orElse( null ); } if ( result == null ) { result = callback.apply( id ); } return Optional.ofNullable( result ); }
LocalDhisResourceRepositoryTemplate { @Nonnull public Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ) { final RequestCacheContext context = requestCacheService.getCurrentRequestCacheContext(); final Optional<LocalDhisResourceRepository<T>> repository = getRepository( context ); T result = null; if ( repository.isPresent() ) { result = repository.get().findOneById( id ).orElse( null ); } if ( result == null ) { result = callback.apply( id ); } return Optional.ofNullable( result ); } }
LocalDhisResourceRepositoryTemplate { @Nonnull public Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ) { final RequestCacheContext context = requestCacheService.getCurrentRequestCacheContext(); final Optional<LocalDhisResourceRepository<T>> repository = getRepository( context ); T result = null; if ( repository.isPresent() ) { result = repository.get().findOneById( id ).orElse( null ); } if ( result == null ) { result = callback.apply( id ); } return Optional.ofNullable( result ); } LocalDhisResourceRepositoryTemplate( @Nonnull Class<T> resourceClass, @Nonnull RequestCacheService requestCacheService,
        @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ); }
LocalDhisResourceRepositoryTemplate { @Nonnull public Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ) { final RequestCacheContext context = requestCacheService.getCurrentRequestCacheContext(); final Optional<LocalDhisResourceRepository<T>> repository = getRepository( context ); T result = null; if ( repository.isPresent() ) { result = repository.get().findOneById( id ).orElse( null ); } if ( result == null ) { result = callback.apply( id ); } return Optional.ofNullable( result ); } LocalDhisResourceRepositoryTemplate( @Nonnull Class<T> resourceClass, @Nonnull RequestCacheService requestCacheService,
        @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ); @Nonnull T save( @Nonnull T resource ); @Nonnull T save( @Nonnull T resource, @Nullable Consumer<T> localResourceConsumer ); boolean deleteById( @Nonnull String id, @Nonnull Function<String, T> prototypeFunction ); @Nonnull Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ); boolean isLocal( @Nonnull String id ); @Nonnull Collection<T> find( @Nonnull Predicate<T> filter, @Nonnull Supplier<Collection<T>> collectionSupplier, boolean localOnly, @Nonnull String methodName, @Nonnull Object... args ); @Nonnull Collection<T> find( @Nullable String trackedEntityInstanceId, @Nonnull Predicate<T> filter, @Nonnull Supplier<Collection<T>> collectionSupplier, boolean localOnly, @Nonnull String methodName, @Nonnull Object... args ); }
LocalDhisResourceRepositoryTemplate { @Nonnull public Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ) { final RequestCacheContext context = requestCacheService.getCurrentRequestCacheContext(); final Optional<LocalDhisResourceRepository<T>> repository = getRepository( context ); T result = null; if ( repository.isPresent() ) { result = repository.get().findOneById( id ).orElse( null ); } if ( result == null ) { result = callback.apply( id ); } return Optional.ofNullable( result ); } LocalDhisResourceRepositoryTemplate( @Nonnull Class<T> resourceClass, @Nonnull RequestCacheService requestCacheService,
        @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ); @Nonnull T save( @Nonnull T resource ); @Nonnull T save( @Nonnull T resource, @Nullable Consumer<T> localResourceConsumer ); boolean deleteById( @Nonnull String id, @Nonnull Function<String, T> prototypeFunction ); @Nonnull Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ); boolean isLocal( @Nonnull String id ); @Nonnull Collection<T> find( @Nonnull Predicate<T> filter, @Nonnull Supplier<Collection<T>> collectionSupplier, boolean localOnly, @Nonnull String methodName, @Nonnull Object... args ); @Nonnull Collection<T> find( @Nullable String trackedEntityInstanceId, @Nonnull Predicate<T> filter, @Nonnull Supplier<Collection<T>> collectionSupplier, boolean localOnly, @Nonnull String methodName, @Nonnull Object... args ); static final String CONTAINER_REQUEST_CACHE_ATTRIBUTE_NAME; static final String RESOURCE_KEY_REQUEST_CACHE_ATTRIBUTE_NAME; }