@Test public void update() throws IOException { mockServer.expect( ExpectedCount.once(), requestTo( "http: .andExpect( content().contentTypeCompatibleWith( MediaType.APPLICATION_JSON ) ) .andExpect( content().json( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/updateEnrollment.json", StandardCharsets.UTF_8 ) ) ) .andExpect( method( HttpMethod.PUT ) ).andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/updateEnrollment-response.json" ), MediaType.APPLICATION_JSON ) ); final Event event = new Event(); event.setId( "jShdkweusi2" ); event.setEventDate( ZonedDateTime.of( 2018, 10, 5, 22, 12, 34, 998000000, ZoneId.systemDefault() ) ); event.setDueDate( ZonedDateTime.of( 2018, 10, 6, 22, 12, 34, 998000000, ZoneId.systemDefault() ) ); event.setStatus( EventStatus.ACTIVE ); event.setTrackedEntityInstanceId( "jdhshdfj" ); event.setProgramId( "kgdyunhUgg" ); event.setProgramStageId( "gjddShhdfgh" ); event.setOrgUnitId( "jhgtJgrygffg" ); event.setCoordinate( new Location( 64.89767, -86.78866 ) ); event.setDataValues( Collections.emptyList() ); final Enrollment enrollment = new Enrollment( false ); enrollment.setStatus( EnrollmentStatus.ACTIVE ); enrollment.setId( "Jskdsjeua1s" ); enrollment.setTrackedEntityInstanceId( "hsdgshdjSa2" ); enrollment.setOrgUnitId( "pMEnu7BjqMz" ); enrollment.setProgramId( "ur1Edk5Oe2n" ); enrollment.setEvents( Collections.singletonList( event ) ); final Enrollment createdEnrollment = service.createOrUpdate( enrollment ); Assert.assertSame( enrollment, createdEnrollment ); Assert.assertFalse( createdEnrollment.isNewResource() ); mockServer.verify(); }
@HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) public Enrollment createOrUpdate( @Nonnull Enrollment enrollment ) { return resourceRepositoryTemplate.save( enrollment, e -> { if ( e.getEvents() != null ) { e.getEvents().forEach( event -> { event.setEnrollment( e ); eventService.createOrMinimalUpdate( event ); } ); } } ); }
EnrollmentServiceImpl implements EnrollmentService, LocalDhisRepositoryPersistCallback<Enrollment> { @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) public Enrollment createOrUpdate( @Nonnull Enrollment enrollment ) { return resourceRepositoryTemplate.save( enrollment, e -> { if ( e.getEvents() != null ) { e.getEvents().forEach( event -> { event.setEnrollment( e ); eventService.createOrMinimalUpdate( event ); } ); } } ); } }
EnrollmentServiceImpl implements EnrollmentService, LocalDhisRepositoryPersistCallback<Enrollment> { @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) public Enrollment createOrUpdate( @Nonnull Enrollment enrollment ) { return resourceRepositoryTemplate.save( enrollment, e -> { if ( e.getEvents() != null ) { e.getEvents().forEach( event -> { event.setEnrollment( e ); eventService.createOrMinimalUpdate( event ); } ); } } ); } @Autowired  EnrollmentServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull EventService eventService, @Nonnull RequestCacheService requestCacheService ); }
EnrollmentServiceImpl implements EnrollmentService, LocalDhisRepositoryPersistCallback<Enrollment> { @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) public Enrollment createOrUpdate( @Nonnull Enrollment enrollment ) { return resourceRepositoryTemplate.save( enrollment, e -> { if ( e.getEvents() != null ) { e.getEvents().forEach( event -> { event.setEnrollment( e ); eventService.createOrMinimalUpdate( event ); } ); } } ); } @Autowired  EnrollmentServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull EventService eventService, @Nonnull RequestCacheService requestCacheService ); @Nonnull @Override DhisResourceType getDhisResourceType(); @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override DhisResourceResult<Enrollment> find( @Nonnull UriFilterApplier uriFilterApplier, int from, int max ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @CachePut( key = "{'findLatestActive', #a0, #a1}", condition = "#a2 == false", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) Optional<Enrollment> findLatestActiveRefreshed( @Nonnull String programId, @Nonnull String trackedEntityInstanceId, boolean localOnly ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @Cacheable( key = "{'findLatestActive', #a0, #a1}", condition = "#a2 == false", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) Optional<Enrollment> findLatestActive( @Nonnull String programId, @Nonnull String trackedEntityInstanceId, boolean localOnly ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override Optional<Enrollment> findOneById( @Nonnull String id ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) Enrollment createOrUpdate( @Nonnull Enrollment enrollment ); @Override void persistSave( @Nonnull Collection<Enrollment> resources, boolean create, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override @Nonnull Enrollment persistSave( @Nonnull Enrollment resource ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Override boolean delete( @Nonnull String enrollmentId ); @Override void persistDeleteById( @Nonnull Collection<String> ids, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override boolean persistDeleteById( @Nonnull String id ); }
EnrollmentServiceImpl implements EnrollmentService, LocalDhisRepositoryPersistCallback<Enrollment> { @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) public Enrollment createOrUpdate( @Nonnull Enrollment enrollment ) { return resourceRepositoryTemplate.save( enrollment, e -> { if ( e.getEvents() != null ) { e.getEvents().forEach( event -> { event.setEnrollment( e ); eventService.createOrMinimalUpdate( event ); } ); } } ); } @Autowired  EnrollmentServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull EventService eventService, @Nonnull RequestCacheService requestCacheService ); @Nonnull @Override DhisResourceType getDhisResourceType(); @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override DhisResourceResult<Enrollment> find( @Nonnull UriFilterApplier uriFilterApplier, int from, int max ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @CachePut( key = "{'findLatestActive', #a0, #a1}", condition = "#a2 == false", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) Optional<Enrollment> findLatestActiveRefreshed( @Nonnull String programId, @Nonnull String trackedEntityInstanceId, boolean localOnly ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override @Cacheable( key = "{'findLatestActive', #a0, #a1}", condition = "#a2 == false", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) Optional<Enrollment> findLatestActive( @Nonnull String programId, @Nonnull String trackedEntityInstanceId, boolean localOnly ); @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override Optional<Enrollment> findOneById( @Nonnull String id ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Nonnull @Override @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" ) Enrollment createOrUpdate( @Nonnull Enrollment enrollment ); @Override void persistSave( @Nonnull Collection<Enrollment> resources, boolean create, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override @Nonnull Enrollment persistSave( @Nonnull Enrollment resource ); @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } ) @Override boolean delete( @Nonnull String enrollmentId ); @Override void persistDeleteById( @Nonnull Collection<String> ids, @Nullable Consumer<LocalDhisRepositoryPersistResult> resultConsumer ); @Override boolean persistDeleteById( @Nonnull String id );  }