Ejemplo n.º 1
0
  @Override
  @Secured
  public TestExecution updateTestExecution(TestExecution testExecution) throws ServiceException {
    TestExecution execEntity = testExecutionDAO.get(testExecution.getId());
    if (execEntity == null) {
      throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName());
    }
    // this is what can be updated here
    execEntity.setName(testExecution.getName());
    execEntity.setStarted(testExecution.getStarted());
    execEntity.setComment(testExecution.getComment());
    execEntity.setTags(new ArrayList<>());

    for (Tag tag : testExecution.getTags()) {
      Tag tagEntity = tagDAO.findByName(tag.getName());
      if (tagEntity == null) {
        Tag newTag = new Tag();
        newTag.setName(tag.getName());
        tagEntity = tagDAO.create(newTag);
      }

      Collection<TestExecution> tagTestExecutions = tagEntity.getTestExecutions();
      if (tagTestExecutions == null) {
        tagEntity.setTestExecutions(new ArrayList<>());
      }

      tagEntity.getTestExecutions().add(execEntity);
      execEntity.getTags().add(tagEntity);
    }
    TestExecution execClone = cloneAndFetch(execEntity, true, true, true, true, true);
    return execClone;
  }
Ejemplo n.º 2
0
  @Override
  public void addTagsToTestExecutions(
      Collection<String> tags, Collection<TestExecution> testExecutions) {
    for (TestExecution testExecutionItem : testExecutions) {
      TestExecution testExecution = testExecutionDAO.get(testExecutionItem.getId());
      if (testExecution == null) {
        continue;
      }

      for (String tagName : tags) {
        if (!testExecution.getTags().contains(tagName)) {
          Tag tag = tagDAO.findByName(tagName);
          if (tag == null) {
            Tag newTag = new Tag();
            newTag.setName(tagName);
            tag = tagDAO.create(newTag);
          }

          Collection<TestExecution> tagTestExecutions = tag.getTestExecutions();
          if (tagTestExecutions == null) {
            tag.setTestExecutions(new ArrayList<>());
          }

          tag.getTestExecutions().add(testExecution);
          testExecution.getTags().add(tag);
        }
      }

      testExecutionDAO.update(testExecution);
    }
  }
Ejemplo n.º 3
0
  @Override
  @Secured
  public void removeTestExecution(TestExecution testExecution) throws ServiceException {
    TestExecution freshTestExecution = testExecutionDAO.get(testExecution.getId());
    if (freshTestExecution == null) {
      throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName());
    }
    for (TestExecutionParameter testExecutionParameter : freshTestExecution.getParameters()) {
      testExecutionParameterDAO.remove(testExecutionParameter);
    }
    for (Value value : freshTestExecution.getValues()) {
      for (ValueParameter valueParameter : value.getParameters()) {
        valueParameterDAO.remove(valueParameter);
      }
      valueDAO.remove(value);
    }

    Iterator<TestExecutionAttachment> allTestExecutionAttachments =
        freshTestExecution.getAttachments().iterator();
    while (allTestExecutionAttachments.hasNext()) {
      testExecutionAttachmentDAO.remove(allTestExecutionAttachments.next());
      allTestExecutionAttachments.remove();
    }
    testExecutionDAO.remove(freshTestExecution);
  }
Ejemplo n.º 4
0
 @Override
 @Secured
 public void removeParameter(TestExecutionParameter tep) throws ServiceException {
   TestExecution exec = testExecutionDAO.get(tep.getTestExecution().getId());
   if (exec == null) {
     throw new ServiceException(
         "serviceException.testExecutionNotFound", tep.getTestExecution().getName());
   }
   TestExecutionParameter tepRemove = testExecutionParameterDAO.get(tep.getId());
   testExecutionParameterDAO.remove(tepRemove);
 }
Ejemplo n.º 5
0
 @Override
 @Secured
 public Long addAttachment(TestExecutionAttachment attachment) throws ServiceException {
   TestExecution exec = testExecutionDAO.get(attachment.getTestExecution().getId());
   if (exec == null) {
     throw new ServiceException(
         "serviceException.addAttachment.testExecutionNotFound",
         attachment.getTestExecution().getName());
   }
   attachment.setTestExecution(exec);
   TestExecutionAttachment newAttachment = testExecutionAttachmentDAO.create(attachment);
   return newAttachment.getId();
 }
Ejemplo n.º 6
0
 @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);
 }
Ejemplo n.º 7
0
 @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;
 }
Ejemplo n.º 8
0
 @Override
 @Secured
 public void removeAttachment(TestExecutionAttachment attachment) throws ServiceException {
   TestExecution exec = testExecutionDAO.get(attachment.getTestExecution().getId());
   if (exec == null) {
     throw new ServiceException(
         "serviceException.removeAttachment.testExecutionNotFound",
         attachment.getTestExecution().getName());
   }
   TestExecutionAttachment freshAttachment = testExecutionAttachmentDAO.get(attachment.getId());
   if (freshAttachment != null) {
     testExecutionAttachmentDAO.remove(freshAttachment);
   }
 }
Ejemplo n.º 9
0
  @Override
  @Secured
  public TestExecutionParameter updateParameter(TestExecutionParameter tep)
      throws ServiceException {
    TestExecution exec = testExecutionDAO.get(tep.getTestExecution().getId());
    if (exec == null) {
      throw new ServiceException(
          "serviceException.testExecutionNotFound", tep.getTestExecution().getName());
    }
    if (testExecutionParameterDAO.hasTestParam(exec.getId(), tep)) {
      throw new ServiceException("serviceException.parameterExists", tep.getName());
    }

    return testExecutionParameterDAO.update(tep);
  }
Ejemplo n.º 10
0
  @Override
  public void removeTagsFromTestExecutions(
      Collection<String> tags, Collection<TestExecution> testExecutions) {
    for (TestExecution testExecutionItem : testExecutions) {
      TestExecution testExecution = testExecutionDAO.get(testExecutionItem.getId());
      if (testExecution == null) {
        continue;
      }

      for (Tag tag : testExecution.getTags()) {
        if (tags.contains(tag.getName())) {
          testExecution.getTags().remove(tag);
        }
      }

      testExecutionDAO.update(testExecution);
    }
  }
Ejemplo n.º 11
0
 @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;
 }
Ejemplo n.º 12
0
 @Override
 public TestExecution getFullTestExecution(Long id) {
   return cloneAndFetch(testExecutionDAO.get(id), true, true, true, true, true);
 }