use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class CsvMetadataImportTest method testDataElementImport.
@Test
public void testDataElementImport() throws Exception {
input = new ClassPathResource("metadata/dataElements.csv").getInputStream();
Metadata metadata = csvImportService.fromCsv(input, DataElement.class);
assertEquals(2, metadata.getDataElements().size());
MetadataImportParams params = new MetadataImportParams();
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
ImportReport importReport = importService.importMetadata(params);
assertEquals(2, importReport.getStats().getCreated());
Collection<DataElement> dataElements = dataElementService.getAllDataElements();
assertEquals(2, dataElements.size());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithCharts1.
@Test
public void testCreateMetadataWithCharts1() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_charts1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<Chart> charts = manager.getAll(Chart.class);
assertEquals(1, dataSets.size());
assertEquals(1, organisationUnits.size());
assertEquals(4, dataElements.size());
assertEquals(3, charts.size());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithReportTables1.
@Test
public void testCreateMetadataWithReportTables1() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_rt1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<ReportTable> reportTables = manager.getAll(ReportTable.class);
assertEquals(1, dataSets.size());
assertEquals(1, organisationUnits.size());
assertEquals(4, dataElements.size());
assertEquals(3, reportTables.size());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataExportServiceTest method testMetadataExportWithCustomQueries.
@Test
public void testMetadataExportWithCustomQueries() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
User user = createUser('A');
manager.save(user);
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setUser(user);
manager.save(deg1);
Query deQuery = Query.from(schemaService.getDynamicSchema(DataElement.class));
Disjunction disjunction = deQuery.disjunction();
disjunction.add(Restrictions.eq("id", de1.getUid()));
disjunction.add(Restrictions.eq("id", de2.getUid()));
deQuery.add(disjunction);
Query degQuery = Query.from(schemaService.getDynamicSchema(DataElementGroup.class));
degQuery.add(Restrictions.eq("id", "INVALID UID"));
MetadataExportParams params = new MetadataExportParams();
params.addQuery(deQuery);
params.addQuery(degQuery);
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
assertFalse(metadata.containsKey(User.class));
assertFalse(metadata.containsKey(DataElementGroup.class));
assertTrue(metadata.containsKey(DataElement.class));
assertEquals(2, metadata.get(DataElement.class).size());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataExportServiceTest method testMetadataExportWithCustomClasses.
@Test
public void testMetadataExportWithCustomClasses() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
User user = createUser('A');
manager.save(user);
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setUser(user);
manager.save(deg1);
MetadataExportParams params = new MetadataExportParams();
params.addClass(DataElement.class);
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
assertFalse(metadata.containsKey(User.class));
assertFalse(metadata.containsKey(DataElementGroup.class));
assertTrue(metadata.containsKey(DataElement.class));
assertEquals(3, metadata.get(DataElement.class).size());
}
Aggregations