@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; }
@Override public List<Metric> getAvailableMetrics(Test test) { Test t = testDAO.get(test.getId()); return EntityUtils.removeAllById(metricDAO.getMetricByGroup(t.getGroupId()), t.getMetrics()); }