Search in sources :

Example 31 with WebMessageUtils.notFound

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

the class MeController method getSetting.

@RequestMapping(value = "/settings/{key}")
public void getSetting(HttpServletResponse response, @PathVariable String key) throws IOException, WebMessageException, NotAuthenticatedException {
    User currentUser = currentUserService.getCurrentUser();
    if (currentUser == null) {
        throw new NotAuthenticatedException();
    }
    Optional<UserSettingKey> keyEnum = UserSettingKey.getByName(key);
    if (!keyEnum.isPresent()) {
        throw new WebMessageException(WebMessageUtils.conflict("Key is not supported: " + key));
    }
    Serializable value = userSettingService.getUserSetting(keyEnum.get(), currentUser);
    if (value == null) {
        throw new WebMessageException(WebMessageUtils.notFound("User setting not found for key: " + key));
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    renderService.toJson(response.getOutputStream(), value);
}
Also used : Serializable(java.io.Serializable) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException)

Example 32 with WebMessageUtils.notFound

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

the class MinMaxDataElementController method deleteObject.

//--------------------------------------------------------------------------
// DELETE
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.DELETE, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_MINMAX_DATAELEMENT_DELETE')")
public void deleteObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
    MinMaxDataElement minMax = renderService.fromJson(request.getInputStream(), MinMaxDataElement.class);
    validate(minMax);
    minMax = getReferences(minMax);
    MinMaxDataElement persisted = minMaxService.getMinMaxDataElement(minMax.getSource(), minMax.getDataElement(), minMax.getOptionCombo());
    if (Objects.isNull(persisted)) {
        throw new WebMessageException(WebMessageUtils.notFound("Can not find MinMaxDataElement."));
    }
    minMaxService.deleteMinMaxDataElement(persisted);
    webMessageService.send(WebMessageUtils.ok("MinMaxDataElement deleted."), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with WebMessageUtils.notFound

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

the class LegendSetController method putJsonObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_PUBLIC_ADD') or hasRole('F_LEGEND_SET_PRIVATE_ADD')  or hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putJsonObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    LegendSet legendSet = legendSetService.getLegendSet(uid);
    if (legendSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Legend set does not exist: " + uid));
    }
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
    LegendSet newLegendSet = renderService.fromJson(request.getInputStream(), LegendSet.class);
    newLegendSet.setUser(currentUserService.getCurrentUser());
    newLegendSet.setUid(legendSet.getUid());
    mergeService.merge(new MergeParams<>(newLegendSet, legendSet).setMergeMode(params.getMergeMode()));
    legendSetService.updateLegendSet(legendSet);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MergeParams(org.hisp.dhis.schema.MergeParams) LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with WebMessageUtils.notFound

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

the class LegendSetController method deleteObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_DELETE') or hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    LegendSet legendSet = legendSetService.getLegendSet(uid);
    if (legendSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Legend set does not exist: " + uid));
    }
    legendSet.getLegends().clear();
    legendSetService.deleteLegendSet(legendSet);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with WebMessageUtils.notFound

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

the class EventController method postJsonEventForNote.

@RequestMapping(value = "/{uid}/note", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postJsonEventForNote(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws IOException, WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event event = renderService.fromJson(inputStream, Event.class);
    event.setEvent(uid);
    eventService.updateEventForNote(event);
    webMessageService.send(WebMessageUtils.ok("Event updated: " + uid), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)59 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)17 User (org.hisp.dhis.user.User)12 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)11 InputStream (java.io.InputStream)7 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)7 Dashboard (org.hisp.dhis.dashboard.Dashboard)7 Property (org.hisp.dhis.schema.Property)7 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)6 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)6 Schema (org.hisp.dhis.schema.Schema)6 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)5 Event (org.hisp.dhis.dxf2.events.event.Event)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)5 IOException (java.io.IOException)4 DataElement (org.hisp.dhis.dataelement.DataElement)4