@RequestMapping(value = "/distributions", method = POST, headers = ACCEPT_JSON)
  public ResponseEntity<OpenLmisResponse> create(
      @RequestBody Distribution distribution, HttpServletRequest request) {
    Distribution existingDistribution = distributionService.get(distribution);

    if (existingDistribution != null) {
      return returnInitiatedDistribution(distribution, existingDistribution);
    }

    distribution.setCreatedBy(loggedInUserId(request));
    distribution.setModifiedBy(loggedInUserId(request));

    Distribution initiatedDistribution = distributionService.create(distribution);

    OpenLmisResponse openLmisResponse = new OpenLmisResponse("distribution", initiatedDistribution);
    openLmisResponse.addData(
        SUCCESS,
        messageService.message(
            "message.distribution.created.success",
            distribution.getDeliveryZone().getName(),
            distribution.getProgram().getName(),
            distribution.getPeriod().getName()));
    return openLmisResponse.response(CREATED);
  }
  private ResponseEntity<OpenLmisResponse> returnInitiatedDistribution(
      Distribution distribution, Distribution existingDistribution) {
    existingDistribution.setDeliveryZone(distribution.getDeliveryZone());
    existingDistribution.setPeriod(distribution.getPeriod());
    existingDistribution.setProgram(distribution.getProgram());

    OpenLmisResponse openLmisResponse = new OpenLmisResponse("distribution", existingDistribution);
    User createdByUser = userService.getById(existingDistribution.getCreatedBy());
    openLmisResponse.addData(
        "message",
        messageService.message(
            "message.distribution.already.exists",
            createdByUser.getUserName(),
            DATE_FORMAT.format(existingDistribution.getCreatedDate())));
    openLmisResponse.addData(
        SUCCESS,
        messageService.message(
            "message.distribution.created.success",
            distribution.getDeliveryZone().getName(),
            distribution.getProgram().getName(),
            distribution.getPeriod().getName()));
    return openLmisResponse.response(OK);
  }