public void postObject(
      HttpServletResponse response, HttpServletRequest request, Message message) {
    List<User> users = new ArrayList<User>(message.getUsers());
    message.getUsers().clear();

    for (OrganisationUnit ou : message.getOrganisationUnits()) {
      OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou.getUid());

      if (organisationUnit == null) {
        ContextUtils.conflictResponse(response, "Organisation Unit does not exist: " + ou.getUid());
        return;
      }

      message.getUsers().addAll(organisationUnit.getUsers());
    }

    for (User u : users) {
      User user = userService.getUser(u.getUid());

      if (user == null) {
        ContextUtils.conflictResponse(response, "User does not exist: " + u.getUid());
        return;
      }

      message.getUsers().add(user);
    }

    for (UserGroup ug : message.getUserGroups()) {
      UserGroup userGroup = userGroupService.getUserGroup(ug.getUid());

      if (userGroup == null) {
        ContextUtils.conflictResponse(response, "User Group does not exist: " + ug.getUid());
        return;
      }

      message.getUsers().addAll(userGroup.getMembers());
    }

    if (message.getUsers().isEmpty()) {
      ContextUtils.conflictResponse(response, "No recipients selected.");
      return;
    }

    String metaData =
        MessageService.META_USER_AGENT + request.getHeader(ContextUtils.HEADER_USER_AGENT);

    int id =
        messageService.sendMessage(
            message.getSubject(), message.getText(), metaData, message.getUsers());

    MessageConversation conversation = messageService.getMessageConversation(id);

    ContextUtils.createdResponse(
        response,
        "Message conversation created",
        MessageConversationController.RESOURCE_PATH + "/" + conversation.getUid());
  }
  @RequestMapping(value = "/feedback", method = RequestMethod.POST)
  public void postMessageConversationFeedback(
      @RequestParam("subject") String subject,
      @RequestBody String body,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    String metaData =
        MessageService.META_USER_AGENT + request.getHeader(ContextUtils.HEADER_USER_AGENT);

    messageService.sendFeedback(subject, body, metaData);

    ContextUtils.createdResponse(response, "Feedback created", null);
  }
  @RequestMapping(value = "/{uid}", method = RequestMethod.POST)
  public void postMessageConversationReply(
      @PathVariable("uid") String uid,
      @RequestBody String body,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    String metaData =
        MessageService.META_USER_AGENT + request.getHeader(ContextUtils.HEADER_USER_AGENT);

    MessageConversation conversation = messageService.getMessageConversation(uid);

    if (conversation == null) {
      ContextUtils.conflictResponse(response, "Message conversation does not exist: " + uid);
      return;
    }

    messageService.sendReply(conversation, body, metaData);

    ContextUtils.createdResponse(
        response,
        "Message conversation created",
        MessageConversationController.RESOURCE_PATH + "/" + conversation.getUid());
  }
예제 #4
0
  @RequestMapping(method = RequestMethod.POST, produces = "text/plain")
  public void saveDataValue(
      @RequestParam String de,
      @RequestParam String cc,
      @RequestParam String pe,
      @RequestParam String ou,
      @RequestParam String value,
      HttpServletResponse response) {
    DataElement dataElement = dataElementService.getDataElement(de);

    if (dataElement == null) {
      ContextUtils.conflictResponse(response, "Illegal data element identifier: " + de);
      return;
    }

    DataElementCategoryOptionCombo categoryOptionCombo =
        categoryService.getDataElementCategoryOptionCombo(cc);

    if (categoryOptionCombo == null) {
      ContextUtils.conflictResponse(response, "Illegal category option combo identifier: " + cc);
      return;
    }

    Period period = PeriodType.getPeriodFromIsoString(pe);

    if (period == null) {
      ContextUtils.conflictResponse(response, "Illegal period identifier: " + pe);
      return;
    }

    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);

    if (organisationUnit == null) {
      ContextUtils.conflictResponse(response, "Illegal organisation unit identifier: " + ou);
      return;
    }

    if (dataSetService.isLocked(dataElement, period, organisationUnit, null)) {
      ContextUtils.conflictResponse(response, "Data set is locked");
      return;
    }

    value = StringUtils.trimToNull(value);

    String storedBy = currentUserService.getCurrentUsername();

    Date now = new Date();

    DataValue dataValue =
        dataValueService.getDataValue(organisationUnit, dataElement, period, categoryOptionCombo);

    if (dataValue == null) {
      if (value != null) {
        dataValue =
            new DataValue(
                dataElement,
                period,
                organisationUnit,
                value,
                storedBy,
                now,
                null,
                categoryOptionCombo);
        dataValueService.addDataValue(dataValue);
      }
    } else {
      dataValue.setValue(value);
      dataValue.setTimestamp(now);
      dataValue.setStoredBy(storedBy);

      dataValueService.updateDataValue(dataValue);
    }
  }