@Override public List<String> getTagsByPrefix(String prefix) { List<String> tags = new ArrayList<String>(); for (Tag tag : tagDAO.findByPrefix(prefix)) { tags.add(tag.getName()); } return tags; }
@Override public List<TestExecution> getTestExecutions(List<String> tags, List<String> testUIDs) { List<TestExecution> result = new ArrayList<TestExecution>(); for (String tag : tags) { result.addAll(testExecutionDAO.getTestExecutions(Arrays.asList(tag.split(" ")), testUIDs)); } return result; }
@Override public List<String> getParametersByPrefix(String prefix) { List<TestExecutionParameter> parameters = testExecutionParameterDAO.findByPrefix(prefix); List<String> result = new ArrayList<>(); for (TestExecutionParameter parameter : parameters) { result.add(parameter.getName()); } return result; }
@Override public List<TestExecution> getAllFullTestExecutions() { List<TestExecution> r = testExecutionDAO.getAll(); List<TestExecution> rcopy = new ArrayList<TestExecution>(r.size()); for (TestExecution exec : r) { rcopy.add(getFullTestExecution(exec.getId())); } return rcopy; }
@Override public List<Test> getAllFullTests() { List<Test> r = testDAO.getAll(); List<Test> rcopy = new ArrayList<Test>(r.size()); for (Test t : r) { rcopy.add(getFullTest(t.getId())); } return rcopy; }
@Override public List<String> getTestsByPrefix(String prefix) { List<Test> tests = testDAO.findByUIDPrefix(prefix); List<String> testuids = new ArrayList<String>(); for (Test test : tests) { if (userService.isLoggedUserInGroup(test.getGroupId())) { testuids.add(test.getUid()); } } return testuids; }
@Override public List<TestExecution> getFullTestExecutions(Collection<Long> ids) { List<TestExecution> result = new ArrayList<TestExecution>(); for (Long id : ids) { TestExecution testExecution = getFullTestExecution(id); if (testExecution != null) { result.add(testExecution); } } return result; }
@Override @Secured public Value addValue(Value value) throws ServiceException { TestExecution exec = testExecutionDAO.get(value.getTestExecution().getId()); if (exec == null) { throw new ServiceException( "serviceException.addValue.testExecutionNotFound", value.getTestExecution().getName()); } Metric metric = null; if (value.getMetric().getId() != null) { metric = metricDAO.get(value.getMetric().getId()); } else { List<Metric> metrics = metricDAO.getMetricByNameAndGroup( value.getMetric().getName(), exec.getTest().getGroupId()); if (metrics.size() > 0) { metric = metricDAO.get(metrics.get(0).getId()); } } if (metric == null) { throw new ServiceException("serviceException.metricNotFound", value.getMetric().getName()); } value.setTestExecution(exec); value.setMetric(metric); // check if other values for given metric exist, if yes, we can only add one if both old and new // one have at least one parameter List<Value> existingValuesForMetric = valueDAO.find(exec.getId(), metric.getId()); if (!existingValuesForMetric.isEmpty()) { for (Value v : existingValuesForMetric) { if (!v.hasParameters()) { throw new ServiceException("serviceException.unparametrizedMultiValue"); } } if (!value.hasParameters()) { throw new ServiceException("serviceException.unparametrizedMultiValue"); } } Value freshValue = valueDAO.create(value); Value freshValueClone = freshValue.clone(); List<ValueParameter> newParams = new ArrayList<ValueParameter>(); if (value.hasParameters()) { for (ValueParameter valueParameter : value.getParameters()) { valueParameter.setValue(freshValue); newParams.add(valueParameterDAO.create(valueParameter).clone()); newParams.get(newParams.size() - 1).setValue(freshValueClone); } } freshValueClone.setParameters(newParams.isEmpty() ? null : newParams); return freshValueClone; }
@Override public Test getFullTest(Long id) { Test test = testDAO.get(id); if (test == null) { return null; } test = test.clone(); // TODO: return by named query, with optimized fetching Collection<Metric> metrics = test.getMetrics(); if (metrics != null) { List<Metric> clonedMetrics = new ArrayList<Metric>(); for (Metric metric : metrics) { clonedMetrics.add(metric); } test.setMetrics(clonedMetrics); } Collection<User> subscribers = test.getSubscribers(); if (subscribers != null) { List<User> subscribersClone = new ArrayList<>(); for (User subscriber : subscribers) { subscribersClone.add(subscriber.clone()); } test.setSubscribers(subscribersClone); } Collection<Alert> alerts = test.getAlerts(); if (alerts != null) { List<Alert> alertsClone = new ArrayList<>(); for (Alert alert : alerts) { List<Tag> tagsClone = new ArrayList<>(); for (Tag tag : alert.getTags()) { tagsClone.add(tag.clone()); } Alert alertClone = alert.clone(); alertClone.setTags(tagsClone); alertsClone.add(alertClone); } test.setAlerts(alertsClone); } return test; }
@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; }