Search in sources :

Example 61 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class LocaleController method delete.

@PreAuthorize("hasRole('ALL') or hasRole('F_LOCALE_DELETE')")
@DeleteMapping(path = "/dbLocales/{uid}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void delete(@PathVariable String uid) throws Exception {
    I18nLocale i18nLocale = localeService.getI18nLocaleByUid(uid);
    if (i18nLocale == null) {
        throw new WebMessageException(notFound("Cannot find Locale with uid " + uid));
    }
    localeService.deleteI18nLocale(i18nLocale);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 62 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class LocaleController method getObject.

@GetMapping(value = "/dbLocales/{uid}", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public I18nLocale getObject(@PathVariable("uid") String uid, HttpServletResponse response) throws Exception {
    response.setHeader(ContextUtils.HEADER_CACHE_CONTROL, CacheControl.noCache().cachePrivate().getHeaderValue());
    I18nLocale locale = localeService.getI18nLocaleByUid(uid);
    if (locale == null) {
        throw new WebMessageException(notFound("Cannot find Locale with uid: " + uid));
    }
    return locale;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class MessageConversationController method addRecipientsToMessageConversation.

@PostMapping("/{uid}/recipients")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void addRecipientsToMessageConversation(@PathVariable("uid") String uid, @RequestBody MessageConversation messageConversation) throws Exception {
    org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation(uid);
    if (conversation == null) {
        throw new WebMessageException(notFound("Message conversation does not exist: " + uid));
    }
    Set<User> additionalUsers = getUsersToMessageConversation(messageConversation, messageConversation.getUsers());
    additionalUsers.forEach(user -> {
        if (!conversation.getUsers().contains(user)) {
            conversation.addUserMessage(new UserMessage(user, false));
        }
    });
    messageService.updateMessageConversation(conversation);
}
Also used : CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UserMessage(org.hisp.dhis.message.UserMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 64 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class MessageConversationController method getMessage.

/**
 * /* Returns the specified message after making sure the user has access to
 * it.
 *
 * @param mcUid the message conversation UID.
 * @param msgUid the message UID.
 * @param user the user.
 * @return a {@link Message}.
 * @throws WebMessageException
 */
private Message getMessage(String mcUid, String msgUid, User user) throws WebMessageException {
    org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation(mcUid);
    if (conversation == null) {
        throw new WebMessageException(notFound(String.format("No message conversation with uid '%s'", mcUid)));
    }
    if (!canReadMessageConversation(user, conversation)) {
        throw new AccessDeniedException("Not authorized to access this conversation.");
    }
    List<Message> messages = conversation.getMessages().stream().filter(msg -> msg.getUid().equals(msgUid)).collect(Collectors.toList());
    if (messages.size() < 1) {
        throw new WebMessageException(notFound(String.format("No message with uid '%s' in messageConversation '%s", msgUid, mcUid)));
    }
    Message message = messages.get(0);
    if (message.isInternal() && !configurationService.isUserInFeedbackRecipientUserGroup(user)) {
        throw new WebMessageException(conflict("Not authorized to access this message"));
    }
    return message;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) Order(org.hisp.dhis.query.Order) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) UserMessage(org.hisp.dhis.message.UserMessage) WebMessageUtils.created(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.created) Pagination(org.hisp.dhis.query.Pagination) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) MessageService(org.hisp.dhis.message.MessageService) CurrentUser(org.hisp.dhis.user.CurrentUser) MessageConversationStatus(org.hisp.dhis.message.MessageConversationStatus) MessageConversation(org.hisp.dhis.webapi.webdomain.MessageConversation) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) Message(org.hisp.dhis.message.Message) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) Query(org.hisp.dhis.query.Query) UserService(org.hisp.dhis.user.UserService) MessageConversationPriority(org.hisp.dhis.message.MessageConversationPriority) MessageType(org.hisp.dhis.message.MessageType) UserGroup(org.hisp.dhis.user.UserGroup) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) Set(java.util.Set) Junction(org.hisp.dhis.query.Junction) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Defaults(org.hisp.dhis.fieldfilter.Defaults) SimpleNode(org.hisp.dhis.node.types.SimpleNode) List(java.util.List) FileResourceUtils(org.hisp.dhis.webapi.utils.FileResourceUtils) UserGroupService(org.hisp.dhis.user.UserGroupService) WebMessageUtils.conflict(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.conflict) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) User(org.hisp.dhis.user.User) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) QueryParserException(org.hisp.dhis.query.QueryParserException) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) Pager(org.hisp.dhis.common.Pager) FileResource(org.hisp.dhis.fileresource.FileResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) MessageConversationSchemaDescriptor(org.hisp.dhis.schema.descriptors.MessageConversationSchemaDescriptor) AccessDeniedException(org.springframework.security.access.AccessDeniedException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) HttpStatus(org.springframework.http.HttpStatus) ConfigurationService(org.hisp.dhis.configuration.ConfigurationService) FileResourceDomain(org.hisp.dhis.fileresource.FileResourceDomain) Collections(java.util.Collections) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserMessage(org.hisp.dhis.message.UserMessage) Message(org.hisp.dhis.message.Message) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException)

Example 65 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class ReportController method getReportDesign.

@GetMapping("/{uid}/design")
public void getReportDesign(@PathVariable("uid") String uid, HttpServletResponse response) throws Exception {
    Report report = reportService.getReport(uid);
    if (report == null) {
        throw new WebMessageException(notFound("Report not found for identifier: " + uid));
    }
    if (report.getDesignContent() == null) {
        throw new WebMessageException(conflict("Report has no design content: " + uid));
    }
    if (report.isTypeHtml()) {
        contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE, filenameEncode(report.getName()) + ".html", true);
    } else {
        contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, filenameEncode(report.getName()) + ".jrxml", true);
    }
    response.getWriter().write(report.getDesignContent());
}
Also used : Report(org.hisp.dhis.report.Report) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)92 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 Event (org.hisp.dhis.dxf2.events.event.Event)39 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)34 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)29 GetMapping (org.springframework.web.bind.annotation.GetMapping)28 User (org.hisp.dhis.user.User)23 Test (org.junit.jupiter.api.Test)21 HashMap (java.util.HashMap)19 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)19 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)19 InputStream (java.io.InputStream)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)18 ArrayList (java.util.ArrayList)17 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 List (java.util.List)16 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)16 DataElement (org.hisp.dhis.dataelement.DataElement)15 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)15