コード例 #1
0
  @GET
  @Produces(JSON_UTF8)
  @Path("suppliers")
  public String suppliers(
      @QueryParam("userID") String userID, @QueryParam("access_token") String access_token) {
    checkToken(access_token);
    Set<Supplier> suppliers = Bennu.getInstance().getSuppliersSet();
    JsonArray toReturn = new JsonArray();
    for (Supplier supplier : suppliers) {
      if (supplier != null) {
        JsonObject obj = new JsonObject();

        obj.addProperty("supplierID", supplier.getExternalId());
        obj.addProperty("fiscalID", supplier.getFiscalIdentificationCode());
        obj.addProperty("name", supplier.getName());
        obj.addProperty("shortName", supplier.getAbbreviatedName());
        obj.addProperty("limit", supplier.getSupplierLimit().toFormatString());
        JsonArray contacts = new JsonArray();
        for (SupplierContact contact : supplier.getSupplierContactSet()) {
          JsonObject contactObj = new JsonObject();
          if (contact.getAddress() != null) {
            JsonObject addressObj = new JsonObject();
            addressObj.addProperty("line1", contact.getAddress().getLine1());
            addressObj.addProperty("line2", contact.getAddress().getLine2());
            addressObj.addProperty("country", contact.getAddress().getCountry());
            contactObj.add("address", addressObj);
          }
          contactObj.addProperty("phone", contact.getPhone());
          contactObj.addProperty("fax", contact.getFax());
          contactObj.addProperty("email", contact.getEmail());
          contacts.add(contactObj);
        }
        obj.add("contacts", contacts);
        obj.addProperty("totalAllocated", supplier.getTotalAllocated().toFormatString());
        JsonArray byCpv = new JsonArray();
        for (CPVReference cpv : supplier.getAllocationsByCPVReference().keySet()) {
          if (cpv != null) {
            JsonObject cpvObj = new JsonObject();
            cpvObj.addProperty("cpvCode", cpv.getCode());
            cpvObj.addProperty("cpvDescription", cpv.getDescription());
            cpvObj.addProperty("totalAllocated", supplier.getTotalAllocated(cpv).toFormatString());
            byCpv.add(cpvObj);
            ;
          }
        }
        obj.add("allocationsByCPV", byCpv);
        toReturn.add(obj);
      }
    }

    return gson.toJson(toReturn);
  }
コード例 #2
0
  @POST
  @Produces(JSON_UTF8)
  @Path("allocateFunds")
  public Response allocateFunds(
      @QueryParam("supplierID") String supplierID,
      @QueryParam("value") String value,
      @QueryParam("valueVat") String valueVAT,
      @QueryParam("cpvCode") String cpvcode,
      @QueryParam("goodsOrService") String goodsOrServices,
      @QueryParam("description") String description,
      @QueryParam("userID") String userID,
      @QueryParam("access_token") String access_token) {

    checkToken(access_token);
    login(User.findByUsername(userID));
    try {

      AfterTheFactAcquisitionProcessBean bean = new AfterTheFactAcquisitionProcessBean();

      Set<Supplier> suppliers = Bennu.getInstance().getSuppliersSet();
      Supplier supplier = null;

      for (Supplier sup : suppliers) {
        if (sup.getExternalId().equals(supplierID)) {
          supplier = sup;
          break;
        }
      }
      if (supplier == null) {
        return respondWithError(Status.NOT_FOUND, "supplier.not.found");
      }

      bean.setSupplier(supplier);
      bean.setAfterTheFactAcquisitionType(AfterTheFactAcquisitionType.PURCHASE);

      Money itemValue = new Money(value);
      bean.setValue(itemValue);

      double VAT = Double.parseDouble(valueVAT);
      bean.setVatValue(new BigDecimal(VAT));

      bean.setYear(new LocalDate().getYear());
      bean.setDescription(description);
      bean.setClassification(AcquisitionItemClassification.valueOf(goodsOrServices.toUpperCase()));
      CPVReference cpvReference = CPVReference.getCPVCode(cpvcode);
      if (cpvReference == null) {
        return respondWithError(Status.NOT_FOUND, "cpv.reference.not.found");
      }
      bean.setCpvReference(cpvReference);

      AfterTheFactAcquisitionProcess process;

      try {
        process = AfterTheFactAcquisitionProcess.createNewAfterTheFactAcquisitionProcess(bean);
      } catch (DomainException e) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "precondition_failed");
      }

      JsonObject obj = new JsonObject();
      obj.addProperty("processID", process.getProcessNumber());
      return Response.ok().entity(gson.toJson(obj)).build();
    } finally {
      logout();
    }
  }