use of org.hisp.dhis.datavalue.DataValueAudit 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.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class HibernateDataValueAuditStore method getDataValueAuditPredicates.
/**
* Returns a list of Predicates generated from given parameters. Returns an
* empty list if given Period does not exist in database.
*
* @param builder the {@link CriteriaBuilder}.
* @param dataElements the list of data elements.
* @param periods the list of periods.
* @param organisationUnits the list of organisation units.
* @param categoryOptionCombo the category option combo.
* @param attributeOptionCombo the attribute option combo.
* @param auditType the audit type.
*/
private List<Function<Root<DataValueAudit>, Predicate>> getDataValueAuditPredicates(CriteriaBuilder builder, List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, CategoryOptionCombo categoryOptionCombo, CategoryOptionCombo attributeOptionCombo, AuditType auditType) {
List<Period> storedPeriods = new ArrayList<>();
if (periods != null && !periods.isEmpty()) {
for (Period period : periods) {
Period storedPeriod = periodStore.reloadPeriod(period);
if (storedPeriod != null) {
storedPeriods.add(storedPeriod);
}
}
}
List<Function<Root<DataValueAudit>, Predicate>> predicates = new ArrayList<>();
if (!storedPeriods.isEmpty()) {
predicates.add(root -> root.get("period").in(storedPeriods));
} else if (periods != null && !periods.isEmpty()) {
return predicates;
}
if (dataElements != null && !dataElements.isEmpty()) {
predicates.add(root -> root.get("dataElement").in(dataElements));
}
if (organisationUnits != null && !organisationUnits.isEmpty()) {
predicates.add(root -> root.get("organisationUnit").in(organisationUnits));
}
if (categoryOptionCombo != null) {
predicates.add(root -> builder.equal(root.get("categoryOptionCombo"), categoryOptionCombo));
}
if (attributeOptionCombo != null) {
predicates.add(root -> builder.equal(root.get("attributeOptionCombo"), attributeOptionCombo));
}
if (auditType != null) {
predicates.add(root -> builder.equal(root.get("auditType"), auditType));
}
return predicates;
}
use of org.hisp.dhis.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class HibernateDataValueAuditStore method getDataValueAudits.
@Override
public List<DataValueAudit> getDataValueAudits(List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, CategoryOptionCombo categoryOptionCombo, CategoryOptionCombo attributeOptionCombo, AuditType auditType) {
CriteriaBuilder builder = getSession().getCriteriaBuilder();
List<Function<Root<DataValueAudit>, Predicate>> predicates = getDataValueAuditPredicates(builder, dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
if (!predicates.isEmpty()) {
return getList(builder, newJpaParameters().addPredicate(root -> builder.and(predicates.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[predicates.size()]))).addOrder(root -> builder.desc(root.get("created"))));
} else {
return new ArrayList<>();
}
}
use of org.hisp.dhis.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class FileResourceCleanUpJobTest method testRetention.
@Test
void testRetention() {
when(fileResourceContentStore.fileResourceContentExists(any(String.class))).thenReturn(true);
systemSettingManager.saveSystemSetting(SettingKey.FILE_RESOURCE_RETENTION_STRATEGY, FileResourceRetentionStrategy.THREE_MONTHS);
content = "filecontentA".getBytes(StandardCharsets.UTF_8);
dataValueA = createFileResourceDataValue('A', content);
assertNotNull(fileResourceService.getFileResource(dataValueA.getValue()));
content = "filecontentB".getBytes(StandardCharsets.UTF_8);
dataValueB = createFileResourceDataValue('B', content);
assertNotNull(fileResourceService.getFileResource(dataValueB.getValue()));
content = "fileResourceC".getBytes(StandardCharsets.UTF_8);
FileResource fileResource = createFileResource('C', content);
dataValueB.setValue(fileResource.getUid());
dataValueService.updateDataValue(dataValueB);
fileResource.setAssigned(true);
DataValueAudit audit = dataValueAuditService.getDataValueAudits(dataValueB).get(0);
audit.setCreated(getDate(2000, 1, 1));
dataValueAuditStore.updateDataValueAudit(audit);
cleanUpJob.execute(null, NoopJobProgress.INSTANCE);
assertNotNull(fileResourceService.getFileResource(dataValueA.getValue()));
assertTrue(fileResourceService.getFileResource(dataValueA.getValue()).isAssigned());
assertNull(dataValueService.getDataValue(dataValueA.getDataElement(), dataValueA.getPeriod(), dataValueA.getSource(), null));
assertNull(fileResourceService.getFileResource(dataValueB.getValue()));
}
use of org.hisp.dhis.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValueSetXmlPreheatCache.
@Test
void testImportDataValueSetXmlPreheatCache() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setPreheatCache(true);
ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
assertNotNull(summary);
assertNotNull(summary.getImportCount());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertHasNoConflicts(summary);
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
assertEquals("10002", ((List<DataValue>) dataValues).get(1).getValue());
assertEquals("10003", ((List<DataValue>) dataValues).get(2).getValue());
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
assertNotNull(registration);
assertEquals(dsA, registration.getDataSet());
assertEquals(peA, registration.getPeriod());
assertEquals(ouA, registration.getSource());
assertEquals(getDate(2012, 1, 9), registration.getDate());
assertEquals(0, auditValues.size());
}
Aggregations