use of org.hisp.dhis.common.BaseIdentifiableObject in project dhis2-core by dhis2.
the class IdentifiableObjectBundleHook method preUpdate.
@Override
public void preUpdate(IdentifiableObject object, IdentifiableObject persistedObject, ObjectBundle bundle) {
BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
identifiableObject.setAutoFields();
identifiableObject.setLastUpdatedBy(bundle.getUser());
Schema schema = schemaService.getDynamicSchema(object.getClass());
handleAttributeValues(object, bundle, schema);
}
use of org.hisp.dhis.common.BaseIdentifiableObject in project dhis2-core by dhis2.
the class AbstractCrudController method putXmlObject.
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
public void putXmlObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
}
User user = currentUserService.getCurrentUser();
if (!aclService.canUpdate(user, objects.get(0))) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T parsed = deserializeXmlEntity(request, response);
((BaseIdentifiableObject) parsed).setUid(pvUid);
preUpdateEntity(objects.get(0), parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.UPDATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = WebMessageUtils.objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postUpdateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
webMessageService.send(webMessage, response, request);
}
use of org.hisp.dhis.common.BaseIdentifiableObject in project dhis2-core by dhis2.
the class GetDataValuesForDataSetAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
// ---------------------------------------------------------------------
// Validation
// ---------------------------------------------------------------------
DataSet dataSet = dataSetService.getDataSet(dataSetId);
Period period = PeriodType.getPeriodFromIsoString(periodId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
if (organisationUnit == null || period == null || dataSet == null) {
log.warn("Illegal input, org unit: " + organisationUnit + ", period: " + period + ", data set: " + dataSet);
return SUCCESS;
}
Set<OrganisationUnit> children = organisationUnit.getChildren();
// ---------------------------------------------------------------------
// Attributes
// ---------------------------------------------------------------------
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
// ---------------------------------------------------------------------
// Data values & Min-max data elements
// ---------------------------------------------------------------------
minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(organisationUnit, dataSet.getDataElements()));
if (!multiOrganisationUnit) {
dataValues.addAll(dataValueService.getDataValues(organisationUnit, period, dataSet.getDataElements(), attributeOptionCombo));
} else {
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
dataValues.addAll(dataValueService.getDataValues(ou, period, dataSet.getDataElements(), attributeOptionCombo));
minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(ou, dataSet.getDataElements()));
}
}
}
// ---------------------------------------------------------------------
// File resource meta-data
// ---------------------------------------------------------------------
List<String> fileResourceUids = dataValues.stream().filter(dv -> dv.getDataElement().isFileType()).map(DataValue::getValue).collect(Collectors.toList());
dataValueFileResourceMap.putAll(fileResourceService.getFileResources(fileResourceUids).stream().collect(Collectors.toMap(BaseIdentifiableObject::getUid, f -> f)));
if (!multiOrganisationUnit) {
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, attributeOptionCombo);
if (registration != null) {
complete = true;
date = registration.getDate();
storedBy = registration.getStoredBy();
}
locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
} else {
complete = true;
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
if (locked) {
break;
}
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, ou, attributeOptionCombo);
if (complete && registration == null) {
complete = false;
}
}
}
}
return SUCCESS;
}
Aggregations