Search in sources :

Example 51 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class MinMaxDataElementController method getObjectList.

//--------------------------------------------------------------------------
// GET
//--------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getObjectList(MinMaxDataElementQueryParams query) throws QueryParserException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    query.setFilters(filters);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<MinMaxDataElement> minMaxDataElements = minMaxService.getMinMaxDataElements(query);
    RootNode rootNode = NodeUtils.createMetadata();
    if (!query.isSkipPaging()) {
        query.setTotal(minMaxService.countMinMaxDataElements(query));
        rootNode.addChild(NodeUtils.createPager(query.getPager()));
    }
    rootNode.addChild(fieldFilterService.filter(MinMaxDataElement.class, minMaxDataElements, fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 52 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class PeriodTypeController method getPeriodTypes.

@GetMapping
public RootNode getPeriodTypes() {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<PeriodTypeDTO> periodTypes = periodService.getAllPeriodTypes().stream().map(PeriodTypeDTO::new).collect(Collectors.toList());
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(PeriodTypeDTO.class, periodTypes, fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) PeriodTypeDTO(org.hisp.dhis.webapi.webdomain.PeriodTypeDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 53 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class MessageConversationController method setMessageStatus.

//--------------------------------------------------------------------------
// Assign status
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/status", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setMessageStatus(@PathVariable String uid, @RequestParam MessageConversationStatus messageConversationStatus, HttpServletResponse response) {
    RootNode responseNode = new RootNode("response");
    User user = currentUserService.getCurrentUser();
    if (!canModifyUserConversation(user, user) && (messageService.hasAccessToManageFeedbackMessages(user))) {
        throw new UpdateAccessDeniedException("Not authorized to modify this object.");
    }
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(uid);
    if (messageConversation == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversation found for the given ID."));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode(messageConversationStatus.name()));
    marked.setWrapping(false);
    messageConversation.setStatus(messageConversationStatus);
    messageService.updateMessageConversation(messageConversation);
    marked.addChild(new SimpleNode("uid", messageConversation.getUid()));
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 54 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class MessageConversationController method setMessagePriority.

//--------------------------------------------------------------------------
// Assign priority
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/priority", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setMessagePriority(@PathVariable String uid, @RequestParam MessageConversationPriority messageConversationPriority, HttpServletResponse response) {
    RootNode responseNode = new RootNode("response");
    User user = currentUserService.getCurrentUser();
    if (!canModifyUserConversation(user, user) && (messageService.hasAccessToManageFeedbackMessages(user))) {
        throw new UpdateAccessDeniedException("Not authorized to modify this object.");
    }
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(uid);
    if (messageConversation == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversation found for the given ID."));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode(messageConversationPriority.name()));
    marked.setWrapping(false);
    messageConversation.setPriority(messageConversationPriority);
    messageService.updateMessageConversation(messageConversation);
    marked.addChild(new SimpleNode("uid", messageConversation.getUid()));
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 55 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class EnrollmentController method getEnrollments.

// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT') or hasRole('F_PROGRAM_UNENROLLMENT') or hasRole('F_PROGRAM_ENROLLMENT_READ')")
@ResponseBody
public RootNode getEnrollments(@RequestParam(required = false) String ou, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) String program, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date programStartDate, @RequestParam(required = false) Date programEndDate, @RequestParam(required = false) String trackedEntity, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String enrollment, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add("enrollment,created,lastUpdated,trackedEntity,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
    }
    Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
    List<Enrollment> enrollments;
    if (enrollment == null) {
        ProgramInstanceQueryParams params = programInstanceService.getFromUrl(orgUnits, ouMode, lastUpdated, program, programStatus, programStartDate, programEndDate, trackedEntity, trackedEntityInstance, followUp, page, pageSize, totalPages, skipPaging);
        enrollments = new ArrayList<>(enrollmentService.getEnrollments(programInstanceService.getProgramInstances(params)));
    } else {
        Set<String> enrollmentIds = TextUtils.splitToArray(enrollment, TextUtils.SEMICOLON);
        enrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
    }
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(Enrollment.class, enrollments, fields));
    return rootNode;
}
Also used : DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) WebMessageService(org.hisp.dhis.webapi.service.WebMessageService) ArrayList(java.util.ArrayList) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Map(java.util.Map) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) WebMessageUtils(org.hisp.dhis.dxf2.webmessage.WebMessageUtils) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) ContextService(org.hisp.dhis.webapi.service.ContextService) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Collectors(java.util.stream.Collectors) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStatus(org.hisp.dhis.program.ProgramStatus) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) RootNode(org.hisp.dhis.node.types.RootNode) TextUtils(org.hisp.dhis.commons.util.TextUtils) InputStream(java.io.InputStream) RootNode(org.hisp.dhis.node.types.RootNode) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RootNode (org.hisp.dhis.node.types.RootNode)60 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)33 CollectionNode (org.hisp.dhis.node.types.CollectionNode)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)30 SimpleNode (org.hisp.dhis.node.types.SimpleNode)27 ComplexNode (org.hisp.dhis.node.types.ComplexNode)14 ArrayList (java.util.ArrayList)12 User (org.hisp.dhis.user.User)11 Pager (org.hisp.dhis.common.Pager)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)9 Node (org.hisp.dhis.node.Node)8 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)7 List (java.util.List)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Date (java.util.Date)4 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)4 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)4 Lists (com.google.common.collect.Lists)3 IOException (java.io.IOException)3