@Override @Secured public void removeValue(Value value) throws ServiceException { TestExecution exec = testExecutionDAO.get(value.getTestExecution().getId()); if (exec == null) { throw new ServiceException( "serviceException.removeValue.testExecutionNotFound", value.getTestExecution().getName()); } Value v = valueDAO.get(value.getId()); for (ValueParameter vp : v.getParameters()) { valueParameterDAO.remove(vp); } valueDAO.remove(v); }
@Override @Secured public Value updateValue(Value value) throws ServiceException { TestExecution exec = testExecutionDAO.get(value.getTestExecution().getId()); if (exec == null) { throw new ServiceException( "serviceException.updateValue.testExecutionNotFound", value.getTestExecution().getName()); } Value oldValue = valueDAO.get(value.getId()); if (oldValue == null) { throw new ServiceException("serviceException.valueNotFound"); } Value freshValue = valueDAO.update(value); Value freshValueClone = freshValue.clone(); freshValueClone.setMetric(freshValue.getMetric().clone()); freshValueClone.getMetric().setValues(null); UpdateSet<ValueParameter> updateSet = EntityUtils.updateSet(oldValue.getParameters(), value.getParameters()); if (!updateSet.removed.isEmpty()) { throw new ServiceException("serviceException.staleCollection"); } List<ValueParameter> newParams = new ArrayList<ValueParameter>(); for (ValueParameter vp : updateSet.toAdd) { vp.setValue(freshValue); newParams.add(valueParameterDAO.create(vp).clone()); newParams.get(newParams.size() - 1).setValue(freshValueClone); } for (ValueParameter vp : updateSet.toUpdate) { newParams.add(valueParameterDAO.update(vp).clone()); newParams.get(newParams.size() - 1).setValue(freshValueClone); } for (ValueParameter vp : updateSet.toRemove) { valueParameterDAO.remove(vp); } freshValueClone.setParameters(newParams.isEmpty() ? null : newParams); return freshValueClone; }