Пример #1
0
  @Override
  public DataResponse<Iterable<TestResult>> search(TestResultRequest request) {
    Component component = componentRepository.findOne(request.getComponentId());
    if (!component.getCollectorItems().containsKey(CollectorType.Test)) {
      return new DataResponse<>(null, 0L);
    }
    List<TestResult> result = new ArrayList<>();

    for (CollectorItem item : component.getCollectorItems().get(CollectorType.Test)) {

      QTestResult testResult = new QTestResult("testResult");
      BooleanBuilder builder = new BooleanBuilder();

      builder.and(testResult.collectorItemId.eq(item.getId()));

      if (request.validStartDateRange()) {
        builder.and(
            testResult.startTime.between(request.getStartDateBegins(), request.getStartDateEnds()));
      }
      if (request.validEndDateRange()) {
        builder.and(
            testResult.endTime.between(request.getEndDateBegins(), request.getEndDateEnds()));
      }

      if (request.validDurationRange()) {
        builder.and(
            testResult.duration.between(
                request.getDurationGreaterThan(), request.getDurationLessThan()));
      }

      if (!request.getTypes().isEmpty()) {
        builder.and(testResult.testCapabilities.any().type.in(request.getTypes()));
      }

      if (request.getMax() == null) {
        result.addAll(
            Lists.newArrayList(
                testResultRepository.findAll(builder.getValue(), testResult.timestamp.desc())));
      } else {
        PageRequest pageRequest =
            new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp");
        result.addAll(
            Lists.newArrayList(
                testResultRepository.findAll(builder.getValue(), pageRequest).getContent()));
      }
    }
    // One collector per Type. get(0) is hardcoded.
    if (!CollectionUtils.isEmpty(component.getCollectorItems().get(CollectorType.Test))
        && (component.getCollectorItems().get(CollectorType.Test).get(0) != null)) {
      Collector collector =
          collectorRepository.findOne(
              component.getCollectorItems().get(CollectorType.Test).get(0).getCollectorId());
      if (collector != null) {
        return new DataResponse<>(
            pruneToDepth(result, request.getDepth()), collector.getLastExecuted());
      }
    }

    return new DataResponse<>(null, 0L);
  }
Пример #2
0
 private Collector createCollector() {
   CollectorRequest collectorReq = new CollectorRequest();
   collectorReq.setName("JenkinsCucumberTest");
   collectorReq.setCollectorType(CollectorType.Test);
   Collector col = collectorReq.toCollector();
   col.setEnabled(true);
   col.setOnline(true);
   col.setLastExecuted(System.currentTimeMillis());
   return collectorService.createCollector(col);
 }
Пример #3
0
 private CollectorItem createCollectorItem(Collector collector, TestDataCreateRequest request)
     throws HygieiaException {
   CollectorItem tempCi = new CollectorItem();
   tempCi.setCollectorId(collector.getId());
   tempCi.setDescription(request.getDescription());
   tempCi.setPushed(true);
   tempCi.setLastUpdated(System.currentTimeMillis());
   Map<String, Object> option = new HashMap<>();
   option.put("jobName", request.getTestJobName());
   option.put("jobUrl", request.getTestJobUrl());
   option.put("instanceUrl", request.getServerUrl());
   tempCi.getOptions().putAll(option);
   tempCi.setNiceName(request.getNiceName());
   if (StringUtils.isEmpty(tempCi.getNiceName())) {
     return collectorService.createCollectorItem(tempCi);
   }
   return collectorService.createCollectorItemByNiceNameAndJobName(
       tempCi, request.getTestJobName());
 }