@Test( expected = MetadataImportException.class ) public void containerMetadataId() throws Exception { final JsonNode jsonNode = readJson( "contained_id_metadata.json" ); final MetadataImportParams params = new MetadataImportParams(); params.setUpdateResourceMappings( true ); params.setUpdateCodes( true ); params.setUpdateScripts( true ); try { service.imp( jsonNode, params ); } catch ( MetadataImportException e ) { Assert.assertFalse( e.getResult().isSuccess() ); Assert.assertEquals( 1, e.getResult().getMessages().size() ); Assert.assertThat( e.getResult().getMessages().get( 0 ).getMessage(), Matchers.containsString( "Contained metadata must not contain an ID." ) ); throw e; } }
@Nonnull @Override @Transactional public MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ) { final MetadataImportResult result = new MetadataImportResult( params ); final MetadataImportContext context = new MetadataImportContext( params, result ); final MetadataExport metadataExport; if ( jsonNode instanceof ObjectNode ) { final ObjectNode objectNode = (ObjectNode) jsonNode; objectNode.remove( VERSION_INFO_FIELD_NAME ); if ( !params.isUpdateResourceMappings() ) { objectNode.remove( FHIR_RESOURCE_MAPPINGS_FIELD_NAME ); } } final ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); for ( final MetadataExportField field : MetadataExportField.values() ) { final JsonNode node = jsonNode.get( field.getPluralFieldName() ); if ( node != null ) { objectNode.set( field.getPluralFieldName(), node ); } } try { metadataExport = mapper.readerFor( MetadataExport.class ) .withAttribute( MetadataImportContext.ATTR_NAME, context ).treeToValue( objectNode, MetadataExport.class ); } catch ( JsonProcessingException e ) { result.add( new MetadataImportMessage( MetadataImportSeverity.ERROR, "Error when processing JSON: " + e.getMessage() ) ); throw new MetadataImportException( result ); } if ( !result.isAnyError() ) { removeFiltered( metadataExport, params ); validate( metadataExport, result ); } if ( !result.isAnyError() ) { persist( metadataExport, result ); } if ( result.isAnyError() ) { throw new MetadataImportException( result ); } result.setSuccess( true ); TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override public void afterCommit() { cacheManager.getCacheNames().forEach( cacheName -> Objects.requireNonNull( cacheManager.getCache( cacheName ) ).clear() ); } } ); return result; }
MetadataImportServiceImpl extends AbstractMetadataService implements MetadataImportService, MetadataImportResolver { @Nonnull @Override @Transactional public MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ) { final MetadataImportResult result = new MetadataImportResult( params ); final MetadataImportContext context = new MetadataImportContext( params, result ); final MetadataExport metadataExport; if ( jsonNode instanceof ObjectNode ) { final ObjectNode objectNode = (ObjectNode) jsonNode; objectNode.remove( VERSION_INFO_FIELD_NAME ); if ( !params.isUpdateResourceMappings() ) { objectNode.remove( FHIR_RESOURCE_MAPPINGS_FIELD_NAME ); } } final ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); for ( final MetadataExportField field : MetadataExportField.values() ) { final JsonNode node = jsonNode.get( field.getPluralFieldName() ); if ( node != null ) { objectNode.set( field.getPluralFieldName(), node ); } } try { metadataExport = mapper.readerFor( MetadataExport.class ) .withAttribute( MetadataImportContext.ATTR_NAME, context ).treeToValue( objectNode, MetadataExport.class ); } catch ( JsonProcessingException e ) { result.add( new MetadataImportMessage( MetadataImportSeverity.ERROR, "Error when processing JSON: " + e.getMessage() ) ); throw new MetadataImportException( result ); } if ( !result.isAnyError() ) { removeFiltered( metadataExport, params ); validate( metadataExport, result ); } if ( !result.isAnyError() ) { persist( metadataExport, result ); } if ( result.isAnyError() ) { throw new MetadataImportException( result ); } result.setSuccess( true ); TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override public void afterCommit() { cacheManager.getCacheNames().forEach( cacheName -> Objects.requireNonNull( cacheManager.getCache( cacheName ) ).clear() ); } } ); return result; } }
MetadataImportServiceImpl extends AbstractMetadataService implements MetadataImportService, MetadataImportResolver { @Nonnull @Override @Transactional public MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ) { final MetadataImportResult result = new MetadataImportResult( params ); final MetadataImportContext context = new MetadataImportContext( params, result ); final MetadataExport metadataExport; if ( jsonNode instanceof ObjectNode ) { final ObjectNode objectNode = (ObjectNode) jsonNode; objectNode.remove( VERSION_INFO_FIELD_NAME ); if ( !params.isUpdateResourceMappings() ) { objectNode.remove( FHIR_RESOURCE_MAPPINGS_FIELD_NAME ); } } final ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); for ( final MetadataExportField field : MetadataExportField.values() ) { final JsonNode node = jsonNode.get( field.getPluralFieldName() ); if ( node != null ) { objectNode.set( field.getPluralFieldName(), node ); } } try { metadataExport = mapper.readerFor( MetadataExport.class ) .withAttribute( MetadataImportContext.ATTR_NAME, context ).treeToValue( objectNode, MetadataExport.class ); } catch ( JsonProcessingException e ) { result.add( new MetadataImportMessage( MetadataImportSeverity.ERROR, "Error when processing JSON: " + e.getMessage() ) ); throw new MetadataImportException( result ); } if ( !result.isAnyError() ) { removeFiltered( metadataExport, params ); validate( metadataExport, result ); } if ( !result.isAnyError() ) { persist( metadataExport, result ); } if ( result.isAnyError() ) { throw new MetadataImportException( result ); } result.setSuccess( true ); TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override public void afterCommit() { cacheManager.getCacheNames().forEach( cacheName -> Objects.requireNonNull( cacheManager.getCache( cacheName ) ).clear() ); } } ); return result; } MetadataImportServiceImpl( @Nonnull MessageSource messageSource, @Nonnull MappedTrackerProgramRepository trackerProgramRepository,
        @Nonnull ProgramStageRuleRepository programStageRuleRepository,
        @Nonnull FhirResourceMappingRepository fhirResourceMappingRepository,
        @Nonnull List<? extends MetadataValidator<? extends Metadata>> validators,
        @Nonnull List<? extends MetadataRepository<? extends Metadata>> repositories,
        @Nonnull EntityManager entityManager, @Nonnull @Qualifier( "metadataCacheManager" ) CacheManager cacheManager ); }
MetadataImportServiceImpl extends AbstractMetadataService implements MetadataImportService, MetadataImportResolver { @Nonnull @Override @Transactional public MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ) { final MetadataImportResult result = new MetadataImportResult( params ); final MetadataImportContext context = new MetadataImportContext( params, result ); final MetadataExport metadataExport; if ( jsonNode instanceof ObjectNode ) { final ObjectNode objectNode = (ObjectNode) jsonNode; objectNode.remove( VERSION_INFO_FIELD_NAME ); if ( !params.isUpdateResourceMappings() ) { objectNode.remove( FHIR_RESOURCE_MAPPINGS_FIELD_NAME ); } } final ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); for ( final MetadataExportField field : MetadataExportField.values() ) { final JsonNode node = jsonNode.get( field.getPluralFieldName() ); if ( node != null ) { objectNode.set( field.getPluralFieldName(), node ); } } try { metadataExport = mapper.readerFor( MetadataExport.class ) .withAttribute( MetadataImportContext.ATTR_NAME, context ).treeToValue( objectNode, MetadataExport.class ); } catch ( JsonProcessingException e ) { result.add( new MetadataImportMessage( MetadataImportSeverity.ERROR, "Error when processing JSON: " + e.getMessage() ) ); throw new MetadataImportException( result ); } if ( !result.isAnyError() ) { removeFiltered( metadataExport, params ); validate( metadataExport, result ); } if ( !result.isAnyError() ) { persist( metadataExport, result ); } if ( result.isAnyError() ) { throw new MetadataImportException( result ); } result.setSuccess( true ); TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override public void afterCommit() { cacheManager.getCacheNames().forEach( cacheName -> Objects.requireNonNull( cacheManager.getCache( cacheName ) ).clear() ); } } ); return result; } MetadataImportServiceImpl( @Nonnull MessageSource messageSource, @Nonnull MappedTrackerProgramRepository trackerProgramRepository,
        @Nonnull ProgramStageRuleRepository programStageRuleRepository,
        @Nonnull FhirResourceMappingRepository fhirResourceMappingRepository,
        @Nonnull List<? extends MetadataValidator<? extends Metadata>> validators,
        @Nonnull List<? extends MetadataRepository<? extends Metadata>> repositories,
        @Nonnull EntityManager entityManager, @Nonnull @Qualifier( "metadataCacheManager" ) CacheManager cacheManager ); @Nonnull @Override @Transactional MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ); @SuppressWarnings( "unchecked" ) @Nullable @Override T resolve( @Nonnull Class<T> metadataClass, @Nonnull UUID id ); }
MetadataImportServiceImpl extends AbstractMetadataService implements MetadataImportService, MetadataImportResolver { @Nonnull @Override @Transactional public MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ) { final MetadataImportResult result = new MetadataImportResult( params ); final MetadataImportContext context = new MetadataImportContext( params, result ); final MetadataExport metadataExport; if ( jsonNode instanceof ObjectNode ) { final ObjectNode objectNode = (ObjectNode) jsonNode; objectNode.remove( VERSION_INFO_FIELD_NAME ); if ( !params.isUpdateResourceMappings() ) { objectNode.remove( FHIR_RESOURCE_MAPPINGS_FIELD_NAME ); } } final ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); for ( final MetadataExportField field : MetadataExportField.values() ) { final JsonNode node = jsonNode.get( field.getPluralFieldName() ); if ( node != null ) { objectNode.set( field.getPluralFieldName(), node ); } } try { metadataExport = mapper.readerFor( MetadataExport.class ) .withAttribute( MetadataImportContext.ATTR_NAME, context ).treeToValue( objectNode, MetadataExport.class ); } catch ( JsonProcessingException e ) { result.add( new MetadataImportMessage( MetadataImportSeverity.ERROR, "Error when processing JSON: " + e.getMessage() ) ); throw new MetadataImportException( result ); } if ( !result.isAnyError() ) { removeFiltered( metadataExport, params ); validate( metadataExport, result ); } if ( !result.isAnyError() ) { persist( metadataExport, result ); } if ( result.isAnyError() ) { throw new MetadataImportException( result ); } result.setSuccess( true ); TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override public void afterCommit() { cacheManager.getCacheNames().forEach( cacheName -> Objects.requireNonNull( cacheManager.getCache( cacheName ) ).clear() ); } } ); return result; } MetadataImportServiceImpl( @Nonnull MessageSource messageSource, @Nonnull MappedTrackerProgramRepository trackerProgramRepository,
        @Nonnull ProgramStageRuleRepository programStageRuleRepository,
        @Nonnull FhirResourceMappingRepository fhirResourceMappingRepository,
        @Nonnull List<? extends MetadataValidator<? extends Metadata>> validators,
        @Nonnull List<? extends MetadataRepository<? extends Metadata>> repositories,
        @Nonnull EntityManager entityManager, @Nonnull @Qualifier( "metadataCacheManager" ) CacheManager cacheManager ); @Nonnull @Override @Transactional MetadataImportResult imp( @Nonnull JsonNode jsonNode, @Nonnull MetadataImportParams params ); @SuppressWarnings( "unchecked" ) @Nullable @Override T resolve( @Nonnull Class<T> metadataClass, @Nonnull UUID id );  }