@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()); } }
@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()); } }
@Override public void removeAllStapleByUuid(String uuid) throws OKMException { try { List<String> idToDelete = new ArrayList<String>(); for (StapleGroup sg : StapleGroupDAO.findAll(uuid)) { for (Staple staple : sg.getStaples()) { if (staple.getUuid().equals(uuid)) { idToDelete.add(String.valueOf(staple.getId())); } } } for (String id : idToDelete) { StapleGroupDAO.deleteStaple(Integer.parseInt(id)); } } catch (DatabaseException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_Database), e.getMessage()); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_Repository), e.getMessage()); } }
@Override public List<GWTStapleGroup> getAll(String uuid) throws OKMException { List<GWTStapleGroup> stapList = new ArrayList<GWTStapleGroup>(); try { for (StapleGroup sg : StapleGroupDAO.findAll(uuid)) { stapList.add(GWTUtil.copy(sg)); } } catch (DatabaseException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_Database), e.getMessage()); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_Repository), e.getMessage()); } catch (PathNotFoundException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStaplingService, ErrorCode.CAUSE_PathNotFound), e.getMessage()); } return stapList; }
@Override public void removeStaple(String id) throws OKMException { try { StapleGroupDAO.deleteStaple(Integer.parseInt(id)); } 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()); } }