@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(); }
@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(); }