@Test @SuppressWarnings( { "unchecked" } ) public void exportAll() { Mockito.when( trackerProgramRepository.findAll() ) .thenReturn( Arrays.asList( trackerProgram1, trackerProgram2 ) ); Mockito.when( programStageRuleRepository.findAllByProgram( (Collection<MappedTrackerProgram>) argThat( containsInAnyOrder( trackerProgram1, trackerProgram2 ) ) ) ).thenReturn( Arrays.asList( programStageRule1, programStageRule2, programStageRule3 ) ); Mockito.when( fhirResourceMappingRepository.findAllByFhirResourceTypes( (Collection<FhirResourceType>) argThat( containsInAnyOrder( FhirResourceType.PATIENT, FhirResourceType.OBSERVATION, FhirResourceType.IMMUNIZATION ) ), Mockito.eq( FhirResourceType.PATIENT ) ) ) .thenReturn( Arrays.asList( fhirResourceMappingPatient, fhirResourceMappingObservation, fhirResourceMappingImmunization ) ); final MetadataExportParams params = new MetadataExportParams(); params.setIncludeResourceMappings( true ); params.setIncludeTrackedEntities( true ); final JsonNode node = service.exp( params ); Assert.assertTrue( node.isObject() ); Assert.assertEquals( 7, node.size() ); Assert.assertNotNull( node.get( "versionInfo" ) ); Assert.assertEquals( 1, node.get( "versionInfo" ).size() ); Assert.assertNotNull( node.get( "trackerPrograms" ) ); Assert.assertEquals( 2, node.get( "trackerPrograms" ).size() ); Assert.assertNotNull( node.get( "trackedEntityRules" ) ); Assert.assertEquals( 1, node.get( "trackedEntityRules" ).size() ); Assert.assertNotNull( node.get( "programStageRules" ) ); Assert.assertEquals( 3, node.get( "programStageRules" ).size() ); Assert.assertNotNull( node.get( "fhirResourceMappings" ) ); Assert.assertEquals( 3, node.get( "fhirResourceMappings" ).size() ); Assert.assertNotNull( node.get( "codeSets" ) ); Assert.assertEquals( 1, node.get( "codeSets" ).size() ); Assert.assertNotNull( node.get( "codes" ) ); Assert.assertEquals( 2, node.get( "codes" ).size() ); }
@Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) public JsonNode exp( @Nonnull MetadataExportParams params ) { final TypedMetadataObjectContainer typedContainer = new TypedMetadataObjectContainer(); final List<MappedTrackerProgram> trackerPrograms = params.getTrackerProgramIds().isEmpty() ? trackerProgramRepository.findAll() : trackerProgramRepository.findAllById( params.getTrackerProgramIds() ); typedContainer.addObjects( trackerPrograms ); if ( !trackerPrograms.isEmpty() ) { typedContainer.addObjects( programStageRuleRepository.findAllByProgram( trackerPrograms ) ); if ( params.isIncludeTrackedEntities() ) { typedContainer.addObjects( trackerPrograms.stream().map( MappedTrackerProgram::getTrackedEntityRule ) .collect( Collectors.toList() ) ); } } if ( params.isIncludeResourceMappings() ) { processFhirResourceTypes( typedContainer, params ); } final Set<Class<? extends Metadata>> processedTypes = new HashSet<>(); final Map<Class<? extends Metadata>, JsonNode> typedNodes = new HashMap<>(); if ( !params.isIncludeTrackedEntities() ) { processedTypes.add( MappedTrackedEntity.class ); processedTypes.add( TrackedEntityRule.class ); } if ( !params.isIncludeResourceMappings() ) { processedTypes.add( FhirResourceMapping.class ); } do { final Set<Class<? extends Metadata>> remainingTypes = new HashSet<>( typedContainer.getTypes() ); remainingTypes.removeAll( processedTypes ); remainingTypes.stream().sorted( Comparator.comparing( MetadataExportField::getByClass ).reversed() ).forEach( type -> { final ObjectWriter objectWriter = mapper.writerFor( type ).with( new SimpleFilterProvider() .addFilter( SecuredPropertyFilter.FILTER_NAME, emptyPropertyFilter ) .addFilter( AdapterBeanPropertyFilter.FILTER_NAME, new MetadataExportPropertyFilter( params, repositoryNames.keySet(), typedContainer, metadataExportDependencyResolvers ) ) ); final ArrayNode nodes = JsonNodeFactory.instance.arrayNode(); new ArrayList<>( typedContainer.getContainer( type ).getObjects() ) .forEach( o -> nodes.add( valueToTree( o, objectWriter ) ) ); if ( typedNodes.put( type, nodes ) != null ) { throw new IllegalStateException( "Type " + type + " has already been processed." ); } processedTypes.add( type ); } ); } while ( !processedTypes.containsAll( typedContainer.getTypes() ) ); final ObjectNode rootNode = JsonNodeFactory.instance.objectNode(); rootNode.set( MetadataVersionInfo.VERSION_INFO_FIELD_NAME, mapper.valueToTree( createVersionInfo() ) ); typedNodes.forEach( ( type, node ) -> rootNode.set( getMetadataPluralName( type ), node ) ); return rootNode; }
MetadataExportServiceImpl extends AbstractMetadataService implements MetadataExportService { @Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) public JsonNode exp( @Nonnull MetadataExportParams params ) { final TypedMetadataObjectContainer typedContainer = new TypedMetadataObjectContainer(); final List<MappedTrackerProgram> trackerPrograms = params.getTrackerProgramIds().isEmpty() ? trackerProgramRepository.findAll() : trackerProgramRepository.findAllById( params.getTrackerProgramIds() ); typedContainer.addObjects( trackerPrograms ); if ( !trackerPrograms.isEmpty() ) { typedContainer.addObjects( programStageRuleRepository.findAllByProgram( trackerPrograms ) ); if ( params.isIncludeTrackedEntities() ) { typedContainer.addObjects( trackerPrograms.stream().map( MappedTrackerProgram::getTrackedEntityRule ) .collect( Collectors.toList() ) ); } } if ( params.isIncludeResourceMappings() ) { processFhirResourceTypes( typedContainer, params ); } final Set<Class<? extends Metadata>> processedTypes = new HashSet<>(); final Map<Class<? extends Metadata>, JsonNode> typedNodes = new HashMap<>(); if ( !params.isIncludeTrackedEntities() ) { processedTypes.add( MappedTrackedEntity.class ); processedTypes.add( TrackedEntityRule.class ); } if ( !params.isIncludeResourceMappings() ) { processedTypes.add( FhirResourceMapping.class ); } do { final Set<Class<? extends Metadata>> remainingTypes = new HashSet<>( typedContainer.getTypes() ); remainingTypes.removeAll( processedTypes ); remainingTypes.stream().sorted( Comparator.comparing( MetadataExportField::getByClass ).reversed() ).forEach( type -> { final ObjectWriter objectWriter = mapper.writerFor( type ).with( new SimpleFilterProvider() .addFilter( SecuredPropertyFilter.FILTER_NAME, emptyPropertyFilter ) .addFilter( AdapterBeanPropertyFilter.FILTER_NAME, new MetadataExportPropertyFilter( params, repositoryNames.keySet(), typedContainer, metadataExportDependencyResolvers ) ) ); final ArrayNode nodes = JsonNodeFactory.instance.arrayNode(); new ArrayList<>( typedContainer.getContainer( type ).getObjects() ) .forEach( o -> nodes.add( valueToTree( o, objectWriter ) ) ); if ( typedNodes.put( type, nodes ) != null ) { throw new IllegalStateException( "Type " + type + " has already been processed." ); } processedTypes.add( type ); } ); } while ( !processedTypes.containsAll( typedContainer.getTypes() ) ); final ObjectNode rootNode = JsonNodeFactory.instance.objectNode(); rootNode.set( MetadataVersionInfo.VERSION_INFO_FIELD_NAME, mapper.valueToTree( createVersionInfo() ) ); typedNodes.forEach( ( type, node ) -> rootNode.set( getMetadataPluralName( type ), node ) ); return rootNode; } }
MetadataExportServiceImpl extends AbstractMetadataService implements MetadataExportService { @Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) public JsonNode exp( @Nonnull MetadataExportParams params ) { final TypedMetadataObjectContainer typedContainer = new TypedMetadataObjectContainer(); final List<MappedTrackerProgram> trackerPrograms = params.getTrackerProgramIds().isEmpty() ? trackerProgramRepository.findAll() : trackerProgramRepository.findAllById( params.getTrackerProgramIds() ); typedContainer.addObjects( trackerPrograms ); if ( !trackerPrograms.isEmpty() ) { typedContainer.addObjects( programStageRuleRepository.findAllByProgram( trackerPrograms ) ); if ( params.isIncludeTrackedEntities() ) { typedContainer.addObjects( trackerPrograms.stream().map( MappedTrackerProgram::getTrackedEntityRule ) .collect( Collectors.toList() ) ); } } if ( params.isIncludeResourceMappings() ) { processFhirResourceTypes( typedContainer, params ); } final Set<Class<? extends Metadata>> processedTypes = new HashSet<>(); final Map<Class<? extends Metadata>, JsonNode> typedNodes = new HashMap<>(); if ( !params.isIncludeTrackedEntities() ) { processedTypes.add( MappedTrackedEntity.class ); processedTypes.add( TrackedEntityRule.class ); } if ( !params.isIncludeResourceMappings() ) { processedTypes.add( FhirResourceMapping.class ); } do { final Set<Class<? extends Metadata>> remainingTypes = new HashSet<>( typedContainer.getTypes() ); remainingTypes.removeAll( processedTypes ); remainingTypes.stream().sorted( Comparator.comparing( MetadataExportField::getByClass ).reversed() ).forEach( type -> { final ObjectWriter objectWriter = mapper.writerFor( type ).with( new SimpleFilterProvider() .addFilter( SecuredPropertyFilter.FILTER_NAME, emptyPropertyFilter ) .addFilter( AdapterBeanPropertyFilter.FILTER_NAME, new MetadataExportPropertyFilter( params, repositoryNames.keySet(), typedContainer, metadataExportDependencyResolvers ) ) ); final ArrayNode nodes = JsonNodeFactory.instance.arrayNode(); new ArrayList<>( typedContainer.getContainer( type ).getObjects() ) .forEach( o -> nodes.add( valueToTree( o, objectWriter ) ) ); if ( typedNodes.put( type, nodes ) != null ) { throw new IllegalStateException( "Type " + type + " has already been processed." ); } processedTypes.add( type ); } ); } while ( !processedTypes.containsAll( typedContainer.getTypes() ) ); final ObjectNode rootNode = JsonNodeFactory.instance.objectNode(); rootNode.set( MetadataVersionInfo.VERSION_INFO_FIELD_NAME, mapper.valueToTree( createVersionInfo() ) ); typedNodes.forEach( ( type, node ) -> rootNode.set( getMetadataPluralName( type ), node ) ); return rootNode; } MetadataExportServiceImpl( @Nonnull MappedTrackerProgramRepository trackerProgramRepository,
        @Nonnull ProgramStageRuleRepository programStageRuleRepository,
        @Nonnull FhirResourceMappingRepository fhirResourceMappingRepository,
        @Nonnull List<? extends MetadataRepository<? extends Metadata>> repositories,
        @Nonnull List<MetadataExportDependencyResolver> metadataExportDependencyResolvers,
        @Nullable BuildProperties buildProperties ); }
MetadataExportServiceImpl extends AbstractMetadataService implements MetadataExportService { @Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) public JsonNode exp( @Nonnull MetadataExportParams params ) { final TypedMetadataObjectContainer typedContainer = new TypedMetadataObjectContainer(); final List<MappedTrackerProgram> trackerPrograms = params.getTrackerProgramIds().isEmpty() ? trackerProgramRepository.findAll() : trackerProgramRepository.findAllById( params.getTrackerProgramIds() ); typedContainer.addObjects( trackerPrograms ); if ( !trackerPrograms.isEmpty() ) { typedContainer.addObjects( programStageRuleRepository.findAllByProgram( trackerPrograms ) ); if ( params.isIncludeTrackedEntities() ) { typedContainer.addObjects( trackerPrograms.stream().map( MappedTrackerProgram::getTrackedEntityRule ) .collect( Collectors.toList() ) ); } } if ( params.isIncludeResourceMappings() ) { processFhirResourceTypes( typedContainer, params ); } final Set<Class<? extends Metadata>> processedTypes = new HashSet<>(); final Map<Class<? extends Metadata>, JsonNode> typedNodes = new HashMap<>(); if ( !params.isIncludeTrackedEntities() ) { processedTypes.add( MappedTrackedEntity.class ); processedTypes.add( TrackedEntityRule.class ); } if ( !params.isIncludeResourceMappings() ) { processedTypes.add( FhirResourceMapping.class ); } do { final Set<Class<? extends Metadata>> remainingTypes = new HashSet<>( typedContainer.getTypes() ); remainingTypes.removeAll( processedTypes ); remainingTypes.stream().sorted( Comparator.comparing( MetadataExportField::getByClass ).reversed() ).forEach( type -> { final ObjectWriter objectWriter = mapper.writerFor( type ).with( new SimpleFilterProvider() .addFilter( SecuredPropertyFilter.FILTER_NAME, emptyPropertyFilter ) .addFilter( AdapterBeanPropertyFilter.FILTER_NAME, new MetadataExportPropertyFilter( params, repositoryNames.keySet(), typedContainer, metadataExportDependencyResolvers ) ) ); final ArrayNode nodes = JsonNodeFactory.instance.arrayNode(); new ArrayList<>( typedContainer.getContainer( type ).getObjects() ) .forEach( o -> nodes.add( valueToTree( o, objectWriter ) ) ); if ( typedNodes.put( type, nodes ) != null ) { throw new IllegalStateException( "Type " + type + " has already been processed." ); } processedTypes.add( type ); } ); } while ( !processedTypes.containsAll( typedContainer.getTypes() ) ); final ObjectNode rootNode = JsonNodeFactory.instance.objectNode(); rootNode.set( MetadataVersionInfo.VERSION_INFO_FIELD_NAME, mapper.valueToTree( createVersionInfo() ) ); typedNodes.forEach( ( type, node ) -> rootNode.set( getMetadataPluralName( type ), node ) ); return rootNode; } MetadataExportServiceImpl( @Nonnull MappedTrackerProgramRepository trackerProgramRepository,
        @Nonnull ProgramStageRuleRepository programStageRuleRepository,
        @Nonnull FhirResourceMappingRepository fhirResourceMappingRepository,
        @Nonnull List<? extends MetadataRepository<? extends Metadata>> repositories,
        @Nonnull List<MetadataExportDependencyResolver> metadataExportDependencyResolvers,
        @Nullable BuildProperties buildProperties ); @Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) JsonNode exp( @Nonnull MetadataExportParams params ); }
MetadataExportServiceImpl extends AbstractMetadataService implements MetadataExportService { @Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) public JsonNode exp( @Nonnull MetadataExportParams params ) { final TypedMetadataObjectContainer typedContainer = new TypedMetadataObjectContainer(); final List<MappedTrackerProgram> trackerPrograms = params.getTrackerProgramIds().isEmpty() ? trackerProgramRepository.findAll() : trackerProgramRepository.findAllById( params.getTrackerProgramIds() ); typedContainer.addObjects( trackerPrograms ); if ( !trackerPrograms.isEmpty() ) { typedContainer.addObjects( programStageRuleRepository.findAllByProgram( trackerPrograms ) ); if ( params.isIncludeTrackedEntities() ) { typedContainer.addObjects( trackerPrograms.stream().map( MappedTrackerProgram::getTrackedEntityRule ) .collect( Collectors.toList() ) ); } } if ( params.isIncludeResourceMappings() ) { processFhirResourceTypes( typedContainer, params ); } final Set<Class<? extends Metadata>> processedTypes = new HashSet<>(); final Map<Class<? extends Metadata>, JsonNode> typedNodes = new HashMap<>(); if ( !params.isIncludeTrackedEntities() ) { processedTypes.add( MappedTrackedEntity.class ); processedTypes.add( TrackedEntityRule.class ); } if ( !params.isIncludeResourceMappings() ) { processedTypes.add( FhirResourceMapping.class ); } do { final Set<Class<? extends Metadata>> remainingTypes = new HashSet<>( typedContainer.getTypes() ); remainingTypes.removeAll( processedTypes ); remainingTypes.stream().sorted( Comparator.comparing( MetadataExportField::getByClass ).reversed() ).forEach( type -> { final ObjectWriter objectWriter = mapper.writerFor( type ).with( new SimpleFilterProvider() .addFilter( SecuredPropertyFilter.FILTER_NAME, emptyPropertyFilter ) .addFilter( AdapterBeanPropertyFilter.FILTER_NAME, new MetadataExportPropertyFilter( params, repositoryNames.keySet(), typedContainer, metadataExportDependencyResolvers ) ) ); final ArrayNode nodes = JsonNodeFactory.instance.arrayNode(); new ArrayList<>( typedContainer.getContainer( type ).getObjects() ) .forEach( o -> nodes.add( valueToTree( o, objectWriter ) ) ); if ( typedNodes.put( type, nodes ) != null ) { throw new IllegalStateException( "Type " + type + " has already been processed." ); } processedTypes.add( type ); } ); } while ( !processedTypes.containsAll( typedContainer.getTypes() ) ); final ObjectNode rootNode = JsonNodeFactory.instance.objectNode(); rootNode.set( MetadataVersionInfo.VERSION_INFO_FIELD_NAME, mapper.valueToTree( createVersionInfo() ) ); typedNodes.forEach( ( type, node ) -> rootNode.set( getMetadataPluralName( type ), node ) ); return rootNode; } MetadataExportServiceImpl( @Nonnull MappedTrackerProgramRepository trackerProgramRepository,
        @Nonnull ProgramStageRuleRepository programStageRuleRepository,
        @Nonnull FhirResourceMappingRepository fhirResourceMappingRepository,
        @Nonnull List<? extends MetadataRepository<? extends Metadata>> repositories,
        @Nonnull List<MetadataExportDependencyResolver> metadataExportDependencyResolvers,
        @Nullable BuildProperties buildProperties ); @Nonnull @Override @Transactional( readOnly = true, isolation = Isolation.REPEATABLE_READ ) JsonNode exp( @Nonnull MetadataExportParams params ); static final String GIT_COMMIT_ID_PROPERTY_NAME; }