use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditResultController method displayTestResult.
/**
* @param webresourceId
* @param testId
* @param model
* @return the test-result view name
*/
@RequestMapping(value = TgolKeyStore.TEST_RESULT_CONTRACT_URL, method = RequestMethod.GET)
public String displayTestResult(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, @RequestParam(TgolKeyStore.TEST_CODE_KEY) String testId, Model model) {
Long wrId;
Long tstId;
try {
wrId = Long.valueOf(webresourceId);
tstId = Long.valueOf(testId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException(getCurrentUser());
}
WebResource webResource = webResourceDataService.ligthRead(wrId);
if (webResource == null) {
throw new ForbiddenPageException();
}
Audit audit = getAuditFromWebResource(webResource);
if (isUserAllowedToDisplayResult(audit)) {
Contract contract = retrieveContractFromAudit(audit);
// Attributes for breadcrumb
model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
model.addAttribute(TgolKeyStore.URL_KEY, webResource.getURL());
Test test = testDataService.read(tstId);
model.addAttribute(TgolKeyStore.TEST_LABEL_KEY, test.getLabel());
model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
if (!test.getScope().equals(pageScope)) {
model.addAttribute(TgolKeyStore.SITE_SCOPE_TEST_DETAILS_KEY, true);
} else {
// Add a boolean used to display the breadcrumb.
model.addAttribute(TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit));
}
model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY, testResultFactory.getTestResultListFromTest(webResource, test));
return TgolKeyStore.TEST_RESULT_VIEW_NAME;
} else {
throw new ForbiddenPageException();
}
}
use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditSetUpController method submitAuditSetUpForm.
/**
* Submit in case of site audit
* @param auditSetUpCommand
* @param result
* @param model
* @param request
* @return
*/
@RequestMapping(value = { AUDIT_PAGE_SET_UP_CONTRACT_URL, AUDIT_SITE_SET_UP_CONTRACT_URL, AUDIT_UPLOAD_SET_UP_CONTRACT_URL }, method = RequestMethod.POST)
@Secured({ ROLE_USER_KEY, ROLE_ADMIN_KEY })
public String submitAuditSetUpForm(@ModelAttribute(AUDIT_SET_UP_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
Contract contract = contractDataService.read(auditSetUpCommand.getContractId());
Map<String, List<AuditSetUpFormField>> formFielMap = null;
AuditSetUpFormValidator auditSetUpFormValidator = null;
if (auditSetUpCommand.getRelaunch()) {
return launchAudit(contract, auditSetUpCommand, model, request);
}
switch(auditSetUpCommand.getScope()) {
case DOMAIN:
formFielMap = getFreshAuditSetUpFormFieldMap(contract, siteOptionFormFieldBuilderMap);
auditSetUpFormValidator = auditSiteSetUpFormValidator;
break;
case PAGE:
formFielMap = getFreshAuditSetUpFormFieldMap(contract, pageOptionFormFieldBuilderMap);
auditSetUpFormValidator = auditPageSetUpFormValidator;
break;
case FILE:
formFielMap = getFreshAuditSetUpFormFieldMap(contract, uploadOptionFormFieldBuilderMap);
auditSetUpFormValidator = auditUploadSetUpFormValidator;
break;
}
return submitForm(contract, auditSetUpCommand, formFielMap, auditSetUpFormValidator, model, result, request);
}
use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractController method displayContractPage.
/**
* @param request
* @param model
* @param contractId
* @return
*/
private String displayContractPage(HttpServletRequest request, Model model, Long contractId) {
model.addAttribute(TgolKeyStore.LOCALE_KEY, localeResolver.resolveLocale(request));
Contract contract = contractDataService.read(contractId);
if (isContractExpired(contract)) {
throw new ForbiddenUserException(getCurrentUser());
}
if (isContractHasFunctionalityAllowingTrend(contract)) {
model.addAttribute(TgolKeyStore.DISPLAY_RESULT_TREND_KEY, true);
}
if (isContractHasFunctionalityAllowingManualAudit(contract)) {
model.addAttribute(TgolKeyStore.CONTRACT_WITH_MANUAL_AUDIT_KEY, true);
}
return displayContractView(contract, model);
}
use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class UserManagementController method submitAddContractAdminPage.
/**
* @param ccc the CreateContractCommand
* @param result
* @param request
* @param response
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.ADD_CONTRACT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitAddContractAdminPage(@ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand ccc, BindingResult result, HttpServletRequest request, HttpServletResponse response, Model model) {
Map<String, List<ContractOptionFormField>> optionFormFieldMap = ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(contractOptionFormFieldBuilderMap);
createContractFormValidator.setContractOptionFormFieldMap(optionFormFieldMap);
// We check whether the form is valid
createContractFormValidator.validateMultipleUsers(ccc, result);
if (result.hasErrors()) {
return displayFormWithErrors(model, ccc, null, null, optionFormFieldMap, TgolKeyStore.ADD_CONTRACT_VIEW_NAME);
}
Collection<User> userList = ccc.getUserList();
StringBuilder strb = new StringBuilder();
for (User user : userList) {
if (user != null) {
Contract contract = contractDataService.create();
contract.setUser(user);
contract = createContractCommandFactory.updateContractFromCommand(ccc, contract);
contractDataService.saveOrUpdate(contract);
strb.append(user.getEmail1());
strb.append(", ");
}
}
request.getSession().setAttribute(TgolKeyStore.ADDED_CONTRACT_NAME_KEY, ccc.getLabel());
request.getSession().setAttribute(TgolKeyStore.ADDED_CONTRACT_USERS_NAME_KEY, strb.toString());
return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class UserManagementController method displayDeleteUserAuditsConfirmationPage.
/**
* @param request
* @param response
* @param model
* @return the name of the view that displays the confirmation page
* when trying to delete all the audits of a user
*/
@RequestMapping(value = TgolKeyStore.DELETE_USER_AUDITS_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserAuditsConfirmationPage(HttpServletRequest request, HttpServletResponse response, Model model) {
Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
Long lUserId;
if (userId instanceof Long) {
lUserId = (Long) userId;
} else {
try {
lUserId = Long.valueOf(userId.toString());
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
}
User userToDelete = userDataService.read(lUserId);
for (Contract contract : userToDelete.getContractSet()) {
deleteAllAuditsFromContract(contract);
}
request.getSession().removeAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
request.getSession().setAttribute(TgolKeyStore.DELETED_USER_AUDITS_KEY, userToDelete.getEmail1());
return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
Aggregations