use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractManagementController method submitEditContractAdminPage.
/**
* @param createContractCommand
* @param result
* @param request
* @param response
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.EDIT_CONTRACT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitEditContractAdminPage(@ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand createContractCommand, BindingResult result, HttpServletRequest request, HttpServletResponse response, Model model) {
Object contractId = request.getSession().getAttribute(TgolKeyStore.CONTRACT_ID_KEY);
Long lContractId;
if (contractId instanceof Long) {
lContractId = (Long) contractId;
} else {
try {
lContractId = Long.valueOf(contractId.toString());
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
}
Contract contract = getContractDataService().read(lContractId);
Map<String, List<ContractOptionFormField>> optionFormFieldMap = ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(getContractOptionFormFieldBuilderMap());
getCreateContractFormValidator().setContractOptionFormFieldMap(optionFormFieldMap);
// We check whether the form is valid
getCreateContractFormValidator().validate(createContractCommand, result);
// If the form has some errors, we display it again with errors' details
if (result.hasErrors()) {
return displayFormWithErrors(model, createContractCommand, contract.getUser().getEmail1(), contract.getUser().getId(), optionFormFieldMap, TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
}
contract = CreateContractCommandFactory.getInstance().updateContractFromCommand(createContractCommand, contract);
saveOrUpdateContract(contract);
request.getSession().setAttribute(TgolKeyStore.UPDATED_CONTRACT_NAME_KEY, contract.getLabel());
model.addAttribute(TgolKeyStore.USER_ID_KEY, contract.getUser().getId());
request.getSession().removeAttribute(TgolKeyStore.CONTRACT_ID_KEY);
return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractManagementController method deleteContractAuditsConfirmationPage.
/**
*
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = TgolKeyStore.DELETE_CONTRACT_AUDITS_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String deleteContractAuditsConfirmationPage(HttpServletRequest request, HttpServletResponse response, Model model) {
Object contractId = request.getSession().getAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY);
Long lContractId;
if (contractId instanceof Long) {
lContractId = (Long) contractId;
} else {
try {
lContractId = Long.valueOf(contractId.toString());
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
}
Contract contractToDelete = getContractDataService().read(lContractId);
deleteAllAuditsFromContract(contractToDelete);
request.getSession().removeAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY);
request.getSession().setAttribute(TgolKeyStore.DELETED_CONTRACT_AUDITS_NAME_KEY, contractToDelete.getLabel());
model.addAttribute(TgolKeyStore.USER_ID_KEY, contractToDelete.getUser().getId());
return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
use of org.asqatasun.webapp.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 = getWebResourceDataService().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 = getTestDataService().read(tstId);
model.addAttribute(TgolKeyStore.TEST_LABEL_KEY, test.getLabel());
model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
if (!test.getScope().equals(getPageScope())) {
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.getInstance().getTestResultListFromTest(webResource, test));
return TgolKeyStore.TEST_RESULT_VIEW_NAME;
} else {
throw new ForbiddenPageException();
}
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditResultController method displayCriterionResult.
/**
*
* @param webresourceId
* @param criterionId
* @param model
* @return the test-result view name
*/
@RequestMapping(value = TgolKeyStore.CRITERION_RESULT_CONTRACT_URL, method = RequestMethod.GET)
public String displayCriterionResult(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, @RequestParam(TgolKeyStore.CRITERION_CODE_KEY) String criterionId, Model model) {
Long wrId;
Long critId;
try {
wrId = Long.valueOf(webresourceId);
critId = Long.valueOf(criterionId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException(getCurrentUser());
}
WebResource webResource = getWebResourceDataService().ligthRead(wrId);
if (webResource == null || webResource instanceof Site) {
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());
Criterion crit = criterionDataService.read(critId);
model.addAttribute(TgolKeyStore.CRITERION_LABEL_KEY, crit.getLabel());
model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
// 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.getInstance().getTestResultListFromCriterion(webResource, crit));
return TgolKeyStore.CRITERION_RESULT_VIEW_NAME;
} else {
throw new ForbiddenPageException();
}
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditScenarioController method deleteScenarioFile.
@RequestMapping(value = TgolKeyStore.DELETE_SCENARIO_URL_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String deleteScenarioFile(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletRequest request, HttpServletResponse response, Model model) {
Contract contract = getContractDataService().read(Long.valueOf(contractId));
if (contract.getUser().getId().equals(getCurrentUser().getId())) {
for (Scenario scenario : contract.getScenarioSet()) {
if (scenario.getId().equals(Long.valueOf(scenarioId))) {
deleteScenario(scenario, contract);
model.addAttribute(TgolKeyStore.DELETED_SCENARIO_NAME_KEY, scenario.getLabel());
prepareScenarioManagementData(model, contractId);
return TgolKeyStore.SCENARIO_MANAGEMENT_VIEW_NAME;
}
}
throw new ForbiddenPageException(getCurrentUser());
} else {
throw new ForbiddenPageException(getCurrentUser());
}
}
Aggregations