use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testUpdateMetadataWithValidationRules.
@Test
public void testUpdateMetadataWithValidationRules() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_vr.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_vr_update.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
bundle = objectBundleService.create(params);
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<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
assertFalse(dataSets.isEmpty());
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(2, validationRules.size());
ValidationRule validationRule1 = manager.get(ValidationRule.class, "ztzsVjSIWg7");
assertNotNull(validationRule1.getLeftSide());
assertNotNull(validationRule1.getRightSide());
ValidationRule validationRule2 = manager.get(ValidationRule.class, "TGvH4Hiyduc");
assertNotNull(validationRule2.getLeftSide());
assertNotNull(validationRule2.getRightSide());
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateMetadataWithDuplicateDataElementCode.
@Test
public void testCreateMetadataWithDuplicateDataElementCode() throws IOException {
createUserAndInjectSecurityContext(true);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_duplicate_code.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setAtomicMode(AtomicMode.NONE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
objectBundleValidationService.validate(bundle);
objectBundleService.commit(bundle);
assertEquals(1, manager.getAll(DataElement.class).size());
DataElement dataElement = manager.getByCode(DataElement.class, "DataElementCodeA");
assertEquals("SG4HuKlNEFH", dataElement.getUid());
assertEquals("DataElementA", dataElement.getName());
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateAndUpdateMetadata1.
@Test
public void testCreateAndUpdateMetadata1() throws IOException {
defaultSetup();
Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
assertEquals(4, dataElementMap.size());
assertNotNull(userGroup);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_create_and_update1.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);
assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
objectBundleService.commit(bundle);
DataElement dataElementA = dataElementMap.get("deabcdefghA");
DataElement dataElementB = dataElementMap.get("deabcdefghB");
DataElement dataElementC = dataElementMap.get("deabcdefghC");
DataElement dataElementD = dataElementMap.get("deabcdefghD");
assertNotNull(dataElementA);
assertNotNull(dataElementB);
assertNotNull(dataElementC);
assertNotNull(dataElementD);
assertEquals("DEA", dataElementA.getName());
assertEquals("DEB", dataElementB.getName());
assertEquals("DEC", dataElementC.getName());
assertEquals("DED", dataElementD.getName());
assertEquals("DECA", dataElementA.getCode());
assertEquals("DECB", dataElementB.getCode());
assertEquals("DECC", dataElementC.getCode());
assertEquals("DECD", dataElementD.getCode());
assertEquals("DESA", dataElementA.getShortName());
assertEquals("DESB", dataElementB.getShortName());
assertEquals("DESC", dataElementC.getShortName());
assertEquals("DESD", dataElementD.getShortName());
assertEquals("DEDA", dataElementA.getDescription());
assertEquals("DEDB", dataElementB.getDescription());
assertEquals("DEDC", dataElementC.getDescription());
assertEquals("DEDD", dataElementD.getDescription());
assertEquals(1, dataElementA.getUserGroupAccesses().size());
assertEquals(0, dataElementB.getUserGroupAccesses().size());
assertEquals(1, dataElementC.getUserGroupAccesses().size());
assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class AuditController method getAggregateDataValueAudit.
@RequestMapping(value = "dataValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getAggregateDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> ds, @RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> pe, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<DataElement> dataElements = new ArrayList<>();
dataElements.addAll(getDataElements(de));
dataElements.addAll(getDataElementsByDataSet(ds));
List<Period> periods = getPeriods(pe);
List<OrganisationUnit> organisationUnits = getOrganisationUnit(ou);
DataElementCategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
DataElementCategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
List<DataValueAudit> dataValueAudits;
Pager pager = null;
if (skipPaging) {
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
} else {
int total = dataValueAuditService.countDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
pager = new Pager(page, total, pageSize);
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("dataValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(DataValueAudit.class, dataValueAudits, fields).getChildren());
return rootNode;
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testFilteriLikeOk.
@Test
public void testFilteriLikeOk() throws Exception {
MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
DataElement de = createDataElement('A');
manager.save(de);
mvc.perform(get("/dataElements?filter=name:ilike:DataElementA").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.pager.total", new GreaterThan<Integer>(0)));
}
Aggregations