Search in sources :

Example 46 with WebMessageUtils.conflict

use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.

the class InterpretationController method writeEventReportInterpretation.

@RequestMapping(value = "/eventReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeEventReportInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    EventReport eventReport = idObjectManager.get(EventReport.class, uid);
    if (eventReport == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Event report does not exist or is not accessible: " + uid));
    }
    OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, eventReport, currentUserService.getCurrentUser());
    createIntepretation(new Interpretation(eventReport, orgUnit, text), request, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Interpretation(org.hisp.dhis.interpretation.Interpretation) EventReport(org.hisp.dhis.eventreport.EventReport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with WebMessageUtils.conflict

use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.

the class InterpretationController method writeEventChartInterpretation.

@RequestMapping(value = "/eventChart/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeEventChartInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    EventChart eventChart = idObjectManager.get(EventChart.class, uid);
    if (eventChart == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Event chart does not exist or is not accessible: " + uid));
    }
    OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, eventChart, currentUserService.getCurrentUser());
    createIntepretation(new Interpretation(eventChart, orgUnit, text), request, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventChart(org.hisp.dhis.eventchart.EventChart) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with WebMessageUtils.conflict

use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.

the class InterpretationController method writeMapInterpretation.

@RequestMapping(value = "/map/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeMapInterpretation(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    Map map = idObjectManager.get(Map.class, uid);
    if (map == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Map does not exist or is not accessible: " + uid));
    }
    createIntepretation(new Interpretation(map, text), request, response);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Interpretation(org.hisp.dhis.interpretation.Interpretation) Map(org.hisp.dhis.mapping.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 49 with WebMessageUtils.conflict

use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.

the class DefaultCollectionService method clearCollectionItems.

@Override
@SuppressWarnings("unchecked")
public void clearCollectionItems(IdentifiableObject object, String pvProperty) throws WebMessageException, InvocationTargetException, IllegalAccessException {
    Schema schema = schemaService.getDynamicSchema(object.getClass());
    if (!schema.haveProperty(pvProperty)) {
        throw new WebMessageException(WebMessageUtils.notFound("Property " + pvProperty + " does not exist on " + object.getClass().getName()));
    }
    Property property = schema.getProperty(pvProperty);
    if (!property.isCollection() || !property.isIdentifiableObject()) {
        throw new WebMessageException(WebMessageUtils.conflict("Only identifiable collections are allowed to be cleared."));
    }
    Collection<IdentifiableObject> collection = (Collection<IdentifiableObject>) property.getGetterMethod().invoke(object);
    manager.refresh(object);
    if (property.isOwner()) {
        collection.clear();
        manager.update(object);
    } else {
        for (IdentifiableObject itemObject : collection) {
            Schema itemSchema = schemaService.getDynamicSchema(property.getItemKlass());
            Property itemProperty = itemSchema.propertyByRole(property.getOwningRole());
            Collection<IdentifiableObject> itemCollection = (Collection<IdentifiableObject>) itemProperty.getGetterMethod().invoke(itemObject);
            itemCollection.remove(object);
            manager.update(itemObject);
            manager.refresh(itemObject);
        }
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Schema(org.hisp.dhis.schema.Schema) Collection(java.util.Collection) Property(org.hisp.dhis.schema.Property) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 50 with WebMessageUtils.conflict

use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict in project dhis2-core by dhis2.

the class DefaultCollectionService method addCollectionItems.

@Override
@SuppressWarnings("unchecked")
public void addCollectionItems(IdentifiableObject object, String propertyName, List<IdentifiableObject> objects) throws Exception {
    Schema schema = schemaService.getDynamicSchema(object.getClass());
    if (!aclService.canUpdate(currentUserService.getCurrentUser(), object)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
    }
    if (!schema.haveProperty(propertyName)) {
        throw new WebMessageException(WebMessageUtils.notFound("Property " + propertyName + " does not exist on " + object.getClass().getName()));
    }
    Property property = schema.getProperty(propertyName);
    if (!property.isCollection() || !property.isIdentifiableObject()) {
        throw new WebMessageException(WebMessageUtils.conflict("Only identifiable object collections can be added to."));
    }
    Collection<String> itemCodes = objects.stream().map(IdentifiableObject::getUid).collect(Collectors.toList());
    if (itemCodes.isEmpty()) {
        return;
    }
    List<? extends IdentifiableObject> items = manager.get(((Class<? extends IdentifiableObject>) property.getItemKlass()), itemCodes);
    manager.refresh(object);
    if (property.isOwner()) {
        Collection<IdentifiableObject> collection = (Collection<IdentifiableObject>) property.getGetterMethod().invoke(object);
        for (IdentifiableObject item : items) {
            if (!collection.contains(item))
                collection.add(item);
        }
        manager.update(object);
    } else {
        Schema owningSchema = schemaService.getDynamicSchema(property.getItemKlass());
        Property owningProperty = owningSchema.propertyByRole(property.getOwningRole());
        for (IdentifiableObject item : items) {
            try {
                Collection<IdentifiableObject> collection = (Collection<IdentifiableObject>) owningProperty.getGetterMethod().invoke(item);
                if (!collection.contains(object)) {
                    collection.add(object);
                    manager.update(item);
                }
            } catch (Exception ex) {
            }
        }
    }
    dbmsManager.clearSession();
    cacheManager.clearCache();
}
Also used : UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Schema(org.hisp.dhis.schema.Schema) Collection(java.util.Collection) Property(org.hisp.dhis.schema.Property) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)51 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Period (org.hisp.dhis.period.Period)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)11 DataSet (org.hisp.dhis.dataset.DataSet)10 Interpretation (org.hisp.dhis.interpretation.Interpretation)10 ArrayList (java.util.ArrayList)9 User (org.hisp.dhis.user.User)9 Date (java.util.Date)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Serializable (java.io.Serializable)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 DataValue (org.hisp.dhis.datavalue.DataValue)4 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)4 ByteSource (com.google.common.io.ByteSource)3