if (result.hasErrors()) {
return FormRestResponse.failure("Found some errors.",result);
} else {
DefectTracker databaseDefectTracker = defectTrackerService.loadDefectTracker(defectTracker.getName().trim());
if (databaseDefectTracker != null)
result.rejectValue("name", MessageConstants.ERROR_NAMETAKEN);
if (defectTracker.getDefectTrackerType() == null) {
result.rejectValue("defectTrackerType.id", MessageConstants.ERROR_INVALID,
new String [] { "Defect Tracker Type" }, null );
} else if (defectTrackerService.loadDefectTrackerType(defectTracker.getDefectTrackerType().getId()) == null) {
result.rejectValue("defectTrackerType.id", MessageConstants.ERROR_INVALID,
new String [] { defectTracker.getDefectTrackerType().getId().toString() }, null );
} else if (!defectTrackerService.checkUrl(defectTracker, result)) {
if (!result.hasFieldErrors("url")) {
result.rejectValue("url", MessageConstants.ERROR_INVALID, new String [] { "URL" }, null);
} else if (result.getFieldError("url").getDefaultMessage() != null &&
result.getFieldError("url").getDefaultMessage().equals(
AbstractDefectTracker.INVALID_CERTIFICATE) ){
result.rejectValue("url", null, null, MessageConstants.ERROR_SELF_CERTIFICATE);
}
}
if (result.hasErrors()) {
return FormRestResponse.failure("Found some errors.",result);
}
defectTracker.setDefectTrackerType(defectTrackerService.loadDefectTrackerType(defectTracker.getDefectTrackerType().getId()));
defectTrackerService.storeDefectTracker(defectTracker);
String user = SecurityContextHolder.getContext().getAuthentication().getName();
log.info(user + " has successfully created a Defect Tracker with the name " + defectTracker.getName() +
", the URL " + defectTracker.getUrl() +
", the type " + defectTracker.getDefectTrackerType().getName() +
", and the ID " + defectTracker.getId());
model.addAttribute("defectTracker", new DefectTracker());
return RestResponse.success(defectTracker);
}
}