예제 #1
0
  @Override
  public void add(String id, String uuid, String type) throws OKMException {
    try {
      StapleGroup stapleGroup = StapleGroupDAO.findByPk(Integer.valueOf(id));
      boolean found = false;

      for (Staple st : stapleGroup.getStaples()) {
        if (st.getUuid().equals(uuid)) {
          found = true;
          break;
        }
      }

      // Only we add if document not exists
      if (!found) {
        Staple staple = new Staple();
        staple.setUuid(uuid);
        staple.setType(type);
        stapleGroup.getStaples().add(staple); // Added first
        StapleGroupDAO.update(stapleGroup); // Updating
      }
    } catch (NumberFormatException e) {
      log.error(e.getMessage(), e);
      throw new OKMException(
          ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_NumberFormat),
          e.getMessage());
    } catch (DatabaseException e) {
      log.error(e.getMessage(), e);
      throw new OKMException(
          ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_Database),
          e.getMessage());
    }
  }
예제 #2
0
  @Override
  public String create(String user, String uuid, String type, String uuid2, String type2)
      throws OKMException {
    StapleGroup stapleGroup = new StapleGroup();
    stapleGroup.setUser(user);

    try {
      // Creating stapling group
      int id = StapleGroupDAO.create(stapleGroup);

      // Adding stapling elements
      stapleGroup = StapleGroupDAO.findByPk(id);
      Staple staple = new Staple();
      staple.setUuid(uuid);
      staple.setType(type);
      stapleGroup.getStaples().add(staple); // Added first
      staple = new Staple();
      staple.setUuid(uuid2);
      staple.setType(type2);
      stapleGroup.getStaples().add(staple); // Added second
      StapleGroupDAO.update(stapleGroup); // Updating
      return String.valueOf(id);
    } catch (DatabaseException e) {
      log.error(e.getMessage(), e);
      throw new OKMException(
          ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_Database),
          e.getMessage());
    }
  }