@Test public void find() throws IOException { mockServer.expect( requestTo( "http: "coordinates,lastUpdated,attributes%5Battribute,value,lastUpdated,storedBy%5D" ) ) .andExpect( method( HttpMethod.GET ) ).andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/trackedEntityInstances.json" ), MediaType.APPLICATION_JSON ) ); Collection<TrackedEntityInstance> trackedEntityInstances = service.findByAttrValue( "ur1Edk5Oe2n", "tPeQKGUIowE", "PT_72983", 2 ); Assert.assertEquals( 1, trackedEntityInstances.size() ); }
@HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) { final DhisPagingQuery pagingQuery = DhisPagingUtils.createPagingQuery( from, max ); final List<String> variables = new ArrayList<>(); final String uri = uriFilterApplier.add( UriComponentsBuilder.newInstance(), variables ).path( "/trackedEntityInstances.json" ) .queryParam( "skipPaging", "false" ).queryParam( "page", pagingQuery.getPage() ).queryParam( "pageSize", pagingQuery.getPageSize() ) .queryParam( "trackedEntityType", trackedEntityTypeId ).queryParam( "ouMode", uriFilterApplier.containsQueryParam( "ou" ) ? "SELECTED" : "ACCESSIBLE" ) .queryParam( "fields", TEI_FIELDS ).build().toString(); final ResponseEntity<TrackedEntityInstances> result; try { result = restTemplate.getForEntity( uri, TrackedEntityInstances.class, variables.toArray() ); } catch ( HttpClientErrorException e ) { if ( e.getStatusCode() == HttpStatus.BAD_REQUEST || e.getStatusCode() == HttpStatus.CONFLICT ) { throw new DhisFindException( e.getMessage(), e ); } throw e; } final TrackedEntityInstances instances = Objects.requireNonNull( result.getBody() ); return new DhisResourceResult<>( (instances.getTrackedEntityInstances().size() > pagingQuery.getResultOffset()) ? instances.getTrackedEntityInstances().subList( pagingQuery.getResultOffset(), instances.getTrackedEntityInstances().size() ) : Collections.emptyList(), (instances.getTrackedEntityInstances().size() >= pagingQuery.getPageSize()) ); }
TrackedEntityServiceImpl implements TrackedEntityService, LocalDhisRepositoryPersistCallback<TrackedEntityInstance> { @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) { final DhisPagingQuery pagingQuery = DhisPagingUtils.createPagingQuery( from, max ); final List<String> variables = new ArrayList<>(); final String uri = uriFilterApplier.add( UriComponentsBuilder.newInstance(), variables ).path( "/trackedEntityInstances.json" ) .queryParam( "skipPaging", "false" ).queryParam( "page", pagingQuery.getPage() ).queryParam( "pageSize", pagingQuery.getPageSize() ) .queryParam( "trackedEntityType", trackedEntityTypeId ).queryParam( "ouMode", uriFilterApplier.containsQueryParam( "ou" ) ? "SELECTED" : "ACCESSIBLE" ) .queryParam( "fields", TEI_FIELDS ).build().toString(); final ResponseEntity<TrackedEntityInstances> result; try { result = restTemplate.getForEntity( uri, TrackedEntityInstances.class, variables.toArray() ); } catch ( HttpClientErrorException e ) { if ( e.getStatusCode() == HttpStatus.BAD_REQUEST || e.getStatusCode() == HttpStatus.CONFLICT ) { throw new DhisFindException( e.getMessage(), e ); } throw e; } final TrackedEntityInstances instances = Objects.requireNonNull( result.getBody() ); return new DhisResourceResult<>( (instances.getTrackedEntityInstances().size() > pagingQuery.getResultOffset()) ? instances.getTrackedEntityInstances().subList( pagingQuery.getResultOffset(), instances.getTrackedEntityInstances().size() ) : Collections.emptyList(), (instances.getTrackedEntityInstances().size() >= pagingQuery.getPageSize()) ); } }
TrackedEntityServiceImpl implements TrackedEntityService, LocalDhisRepositoryPersistCallback<TrackedEntityInstance> { @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) { final DhisPagingQuery pagingQuery = DhisPagingUtils.createPagingQuery( from, max ); final List<String> variables = new ArrayList<>(); final String uri = uriFilterApplier.add( UriComponentsBuilder.newInstance(), variables ).path( "/trackedEntityInstances.json" ) .queryParam( "skipPaging", "false" ).queryParam( "page", pagingQuery.getPage() ).queryParam( "pageSize", pagingQuery.getPageSize() ) .queryParam( "trackedEntityType", trackedEntityTypeId ).queryParam( "ouMode", uriFilterApplier.containsQueryParam( "ou" ) ? "SELECTED" : "ACCESSIBLE" ) .queryParam( "fields", TEI_FIELDS ).build().toString(); final ResponseEntity<TrackedEntityInstances> result; try { result = restTemplate.getForEntity( uri, TrackedEntityInstances.class, variables.toArray() ); } catch ( HttpClientErrorException e ) { if ( e.getStatusCode() == HttpStatus.BAD_REQUEST || e.getStatusCode() == HttpStatus.CONFLICT ) { throw new DhisFindException( e.getMessage(), e ); } throw e; } final TrackedEntityInstances instances = Objects.requireNonNull( result.getBody() ); return new DhisResourceResult<>( (instances.getTrackedEntityInstances().size() > pagingQuery.getResultOffset()) ? instances.getTrackedEntityInstances().subList( pagingQuery.getResultOffset(), instances.getTrackedEntityInstances().size() ) : Collections.emptyList(), (instances.getTrackedEntityInstances().size() >= pagingQuery.getPageSize()) ); } @Autowired  TrackedEntityServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull RequestCacheService requestCacheService,
        @Nonnull TrackedEntityMetadataService metadataService, @Nonnull StoredDhisResourceService storedItemService ); }
TrackedEntityServiceImpl implements TrackedEntityService, LocalDhisRepositoryPersistCallback<TrackedEntityInstance> { @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) { final DhisPagingQuery pagingQuery = DhisPagingUtils.createPagingQuery( from, max ); final List<String> variables = new ArrayList<>(); final String uri = uriFilterApplier.add( UriComponentsBuilder.newInstance(), variables ).path( "/trackedEntityInstances.json" ) .queryParam( "skipPaging", "false" ).queryParam( "page", pagingQuery.getPage() ).queryParam( "pageSize", pagingQuery.getPageSize() ) .queryParam( "trackedEntityType", trackedEntityTypeId ).queryParam( "ouMode", uriFilterApplier.containsQueryParam( "ou" ) ? "SELECTED" : "ACCESSIBLE" ) .queryParam( "fields", TEI_FIELDS ).build().toString(); final ResponseEntity<TrackedEntityInstances> result; try { result = restTemplate.getForEntity( uri, TrackedEntityInstances.class, variables.toArray() ); } catch ( HttpClientErrorException e ) { if ( e.getStatusCode() == HttpStatus.BAD_REQUEST || e.getStatusCode() == HttpStatus.CONFLICT ) { throw new DhisFindException( e.getMessage(), e ); } throw e; } final TrackedEntityInstances instances = Objects.requireNonNull( result.getBody() ); return new DhisResourceResult<>( (instances.getTrackedEntityInstances().size() > pagingQuery.getResultOffset()) ? instances.getTrackedEntityInstances().subList( pagingQuery.getResultOffset(), instances.getTrackedEntityInstances().size() ) : Collections.emptyList(), (instances.getTrackedEntityInstances().size() >= pagingQuery.getPageSize()) ); } @Autowired  TrackedEntityServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull RequestCacheService requestCacheService,
        @Nonnull TrackedEntityMetadataService metadataService, @Nonnull StoredDhisResourceService storedItemService ); @Nonnull @Override DhisResourceType getDhisResourceType(); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Override void updateGeneratedValues( @Nonnull TrackedEntityInstance trackedEntityInstance, @Nonnull TrackedEntityType type, @Nonnull Map<RequiredValueType, String> requiredValues ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @CachePut( key = "{'findOneById', #a0}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances" ) Optional<TrackedEntityInstance> findOneByIdRefreshed( @Nonnull String id ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @Cacheable( key = "{'findOneById', #a0}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances" ) Optional<TrackedEntityInstance> findOneById( @Nonnull String id ); @Override boolean isLocal( @Nonnull String id ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @CachePut( key = "{'findByAttrValue', #a0, #a1, #a2, #a3}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances", unless = "#result.size() == 0" ) Collection<TrackedEntityInstance> findByAttrValueRefreshed( @Nonnull String typeId, @Nonnull String attributeId, @Nonnull String value, int maxResult ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @Cacheable( key = "{'findByAttrValue', #a0, #a1, #a2, #a3}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances", unless = "#result.size() == 0" ) Collection<TrackedEntityInstance> findByAttrValue( @Nonnull String typeId, @Nonnull String attributeId, @Nonnull String value, int maxResult ); @Nonnull @Override Instant poll( @Nonnull DhisSyncGroup group, @Nonnull Instant lastUpdated, int toleranceMillis, int maxSearchCount, @Nonnull Set<String> excludedStoredBy, @Nonnull Consumer<Collection<ProcessedItemInfo>> consumer ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override TrackedEntityInstance createOrUpdate( @Nonnull TrackedEntityInstance trackedEntityInstance ); @Override void persistSave( @Nonnull Collection<TrackedEntityInstance> resources, boolean create, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override @Nonnull TrackedEntityInstance persistSave( @Nonnull TrackedEntityInstance resource ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Override boolean delete( @Nonnull String trackedEntityInstanceId ); @Override void persistDeleteById( @Nonnull Collection<String> ids, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override boolean persistDeleteById( @Nonnull String id ); @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ); }
TrackedEntityServiceImpl implements TrackedEntityService, LocalDhisRepositoryPersistCallback<TrackedEntityInstance> { @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) { final DhisPagingQuery pagingQuery = DhisPagingUtils.createPagingQuery( from, max ); final List<String> variables = new ArrayList<>(); final String uri = uriFilterApplier.add( UriComponentsBuilder.newInstance(), variables ).path( "/trackedEntityInstances.json" ) .queryParam( "skipPaging", "false" ).queryParam( "page", pagingQuery.getPage() ).queryParam( "pageSize", pagingQuery.getPageSize() ) .queryParam( "trackedEntityType", trackedEntityTypeId ).queryParam( "ouMode", uriFilterApplier.containsQueryParam( "ou" ) ? "SELECTED" : "ACCESSIBLE" ) .queryParam( "fields", TEI_FIELDS ).build().toString(); final ResponseEntity<TrackedEntityInstances> result; try { result = restTemplate.getForEntity( uri, TrackedEntityInstances.class, variables.toArray() ); } catch ( HttpClientErrorException e ) { if ( e.getStatusCode() == HttpStatus.BAD_REQUEST || e.getStatusCode() == HttpStatus.CONFLICT ) { throw new DhisFindException( e.getMessage(), e ); } throw e; } final TrackedEntityInstances instances = Objects.requireNonNull( result.getBody() ); return new DhisResourceResult<>( (instances.getTrackedEntityInstances().size() > pagingQuery.getResultOffset()) ? instances.getTrackedEntityInstances().subList( pagingQuery.getResultOffset(), instances.getTrackedEntityInstances().size() ) : Collections.emptyList(), (instances.getTrackedEntityInstances().size() >= pagingQuery.getPageSize()) ); } @Autowired  TrackedEntityServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull RequestCacheService requestCacheService,
        @Nonnull TrackedEntityMetadataService metadataService, @Nonnull StoredDhisResourceService storedItemService ); @Nonnull @Override DhisResourceType getDhisResourceType(); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Override void updateGeneratedValues( @Nonnull TrackedEntityInstance trackedEntityInstance, @Nonnull TrackedEntityType type, @Nonnull Map<RequiredValueType, String> requiredValues ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @CachePut( key = "{'findOneById', #a0}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances" ) Optional<TrackedEntityInstance> findOneByIdRefreshed( @Nonnull String id ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @Cacheable( key = "{'findOneById', #a0}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances" ) Optional<TrackedEntityInstance> findOneById( @Nonnull String id ); @Override boolean isLocal( @Nonnull String id ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @CachePut( key = "{'findByAttrValue', #a0, #a1, #a2, #a3}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances", unless = "#result.size() == 0" ) Collection<TrackedEntityInstance> findByAttrValueRefreshed( @Nonnull String typeId, @Nonnull String attributeId, @Nonnull String value, int maxResult ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @Cacheable( key = "{'findByAttrValue', #a0, #a1, #a2, #a3}", cacheManager = "dhisCacheManager", cacheNames = "trackedEntityInstances", unless = "#result.size() == 0" ) Collection<TrackedEntityInstance> findByAttrValue( @Nonnull String typeId, @Nonnull String attributeId, @Nonnull String value, int maxResult ); @Nonnull @Override Instant poll( @Nonnull DhisSyncGroup group, @Nonnull Instant lastUpdated, int toleranceMillis, int maxSearchCount, @Nonnull Set<String> excludedStoredBy, @Nonnull Consumer<Collection<ProcessedItemInfo>> consumer ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override TrackedEntityInstance createOrUpdate( @Nonnull TrackedEntityInstance trackedEntityInstance ); @Override void persistSave( @Nonnull Collection<TrackedEntityInstance> resources, boolean create, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override @Nonnull TrackedEntityInstance persistSave( @Nonnull TrackedEntityInstance resource ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Override boolean delete( @Nonnull String trackedEntityInstanceId ); @Override void persistDeleteById( @Nonnull Collection<String> ids, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override boolean persistDeleteById( @Nonnull String id ); @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override DhisResourceResult<TrackedEntityInstance> find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max );  }