Exemple #1
0
 @Restrict(UnitRole.DEFECTDELETE)
 public static void deleteDefect(Long defectId) {
   Defect defect = Lookups.getDefect(defectId);
   if (defect == null) {
     Logger.error(Logger.LogType.TECHNICAL, "Could not find defect for deletion %s", defectId);
     notFound("Sorry, the selected defect could not be found. Please refresh the page");
   }
   try {
     defect.delete();
   } catch (Throwable t) {
     Logger.error(Logger.LogType.DB, "Error deleting defect %s", defectId);
     error(
         String.format(
             "An error occurred while deleting defect %s, please try again", defect.naturalId));
   }
   ok();
 }
Exemple #2
0
 @Restrict(UnitRole.DEFECTEDIT)
 public static void addComment(DefectComment comment, Long defectId) {
   Defect defect = Defect.find("id=?", defectId).first();
   TMUser tmUser = TMUser.find("id=?", getConnectedUserId()).first();
   Project project = Project.find("id=?", getActiveProjectId()).first();
   comment.submittedBy = tmUser;
   comment.defect = defect;
   comment.project = project;
   comment.account = tmUser.account;
   comment.save();
   ok();
 }
Exemple #3
0
 @Restrict(UnitRole.DEFECTEDIT)
 public static void updateDefect(@Valid Defect defect) {
   Defect d = Lookups.getDefect(defect.getId());
   if (d == null) {
     Logger.error(Logger.LogType.TECHNICAL, "Could not find defect with ID %s", defect.getId());
     notFound("Sorry, the selected defect could not be found. Please refresh the page");
   }
   d.name = defect.name;
   d.description = defect.description;
   d.assignedTo = defect.assignedTo;
   d.status = defect.status;
   try {
     d.save();
   } catch (Throwable t) {
     Logger.error(Logger.LogType.DB, "Error updating defect");
     error("An error occurred while saving the defect, please try again.");
   }
   ok();
 }
Exemple #4
0
  @Restrict(UnitRole.DEFECTCREATE)
  public static void createDefect(@Valid Defect defect) {
    defect.submittedBy = getConnectedUser();
    defect.account = getConnectedUserAccount();
    defect.project = getActiveProject();
    defect.status = DefectStatus.getDefaultDefectStatus();
    boolean created = defect.create();
    if (!created) {
      Logger.error(Logger.LogType.DB, "Error while creating defect");
      error("An error occurred while saving the defect, please try again");
    }

    // linking to test instance
    String runIdParam = params.get("runId");
    if (StringUtils.isNotEmpty(runIdParam)) {
      try {
        Long runId = Long.valueOf(runIdParam);
        if (runId != null) {
          Instance instance =
              Run.find("select r.instance from Run r where r.id = ?", runId).first();
          instance.defects.add(defect);
          try {
            instance.save();
          } catch (Throwable t) {
            Logger.error(
                Logger.LogType.DB,
                "Error while updating defect instance during linking to defefct %s",
                defect.getId());
            error(
                String.format(
                    "An error occurred while linking the newly created defect %s to test instance %s. Please try again.",
                    defect.naturalId, instance.naturalId));
          }
        }
      } catch (NumberFormatException nfe) {
        Logger.error(
            Logger.LogType.SECURITY,
            "Invalid value '%s' for runId parameter passed during defect creation",
            runIdParam);
        error();
      }
    }

    ok();
  }
Exemple #5
0
  @Restrict(UnitRole.DEFECTVIEW)
  public static void defects(
      String tableId,
      Integer iDisplayStart,
      Integer iDisplayLength,
      String sColumns,
      String sEcho,
      String title,
      String titleCase,
      String tags,
      String status,
      Long assignedToId,
      Long submittedById,
      Date dateFrom,
      Date dateTo,
      Integer iSortCol_0,
      String sSortDir_0) {

    FilterQuery fq = new FilterQuery(Defect.class);

    fq.addFilter("project", "=", getActiveProject());

    if (StringUtils.isNotEmpty(title)) {
      StringMatcherType type = null;
      if (titleCase == null) {
        type = StringMatcherType.CONTAINS;
      } else {
        type = StringMatcherType.valueOf(titleCase.toUpperCase());
      }
      switch (type) {
        case EQUALS:
          fq.addFilter("name", "=", title);
          break;
        case CONTAINS:
          fq.addFilter("name", "like", '%' + title + '%');
          break;
        case STARTSWITH:
          fq.addFilter("name", "like", title + '%');
          break;
        case ENDSWITH:
          fq.addFilter("name", "not like", '%' + title + '%');
          break;
      }
    }
    if (tags != null && StringUtils.isNotEmpty(tags)) {
      fq.addJoin("tags", "o", "t");
      fq.setDistinct(true);
      fq.addWhere("t.name in (:tags)", "tags", Arrays.asList(tags.split(",")));
      fq.addAfterWhere("group by o.id having count(t.id) = " + tags.split(",").length);
    }
    if (StringUtils.isNotEmpty(status)) {
      fq.addFilter("status.name", "=", status);
    }
    if (assignedToId != null) {
      fq.addFilter("assignedTo.id", "=", assignedToId);
    }
    if (submittedById != null) {
      fq.addFilter("submittedBy.id", "=", submittedById);
    }
    if (dateFrom != null) {
      fq.addWhere("o.created >= :dateFrom", "dateFrom", dateFrom);
    }
    if (dateTo != null) {
      fq.addWhere("o.created <= :dateTo", "dateTo", dateTo);
    }

    Query query = fq.build();

    if (iDisplayStart != null) {
      query.setFirstResult(iDisplayStart);
    }
    if (iDisplayLength != null) {
      query.setMaxResults(iDisplayLength);
    }

    try {
      List defects = query.getResultList();
      TableController.renderJSON(defects, Defect.class, Defect.count(), sColumns, sEcho);
    } catch (Throwable t) {
      t.printStackTrace();
      error("An error occurred while listing the defects, please reload the page");
    }
  }