Search in sources :

Example 11 with BaseIdentifiableObject

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);
}
Also used : BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Schema(org.hisp.dhis.schema.Schema)

Example 12 with BaseIdentifiableObject

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);
}
Also used : User(org.hisp.dhis.user.User) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with BaseIdentifiableObject

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)13 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)5 User (org.hisp.dhis.user.User)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)3 Period (org.hisp.dhis.period.Period)3 Schema (org.hisp.dhis.schema.Schema)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ArrayList (java.util.ArrayList)2 DeletedObjectQuery (org.hisp.dhis.deletedobject.DeletedObjectQuery)2 Property (org.hisp.dhis.schema.Property)2 UserGroup (org.hisp.dhis.user.UserGroup)2 Lists (com.google.common.collect.Lists)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1