use of org.asqatasun.webapp.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(getContractOptionFormFieldBuilderMap());
getCreateContractFormValidator().setContractOptionFormFieldMap(optionFormFieldMap);
// We check whether the form is valid
getCreateContractFormValidator().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 = getContractDataService().create();
contract.setUser(user);
contract = CreateContractCommandFactory.getInstance().updateContractFromCommand(ccc, contract);
getContractDataService().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.webapp.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(method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitAuditSetUpForm(@ModelAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
Contract contract = getContractDataService().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, getSiteOptionFormFieldBuilderMap());
auditSetUpFormValidator = getAuditSiteSetUpFormValidator();
break;
case PAGE:
formFielMap = getFreshAuditSetUpFormFieldMap(contract, getPageOptionFormFieldBuilderMap());
auditSetUpFormValidator = getAuditPageSetUpFormValidator();
break;
case FILE:
formFielMap = getFreshAuditSetUpFormFieldMap(contract, getUploadOptionFormFieldBuilderMap());
auditSetUpFormValidator = getAuditUploadSetUpFormValidator();
break;
}
return submitForm(contract, auditSetUpCommand, formFielMap, auditSetUpFormValidator, model, result, request);
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditSynthesisController method displayAuditSynthesisFromContract.
/**
*
* @param auditId
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = TgolKeyStore.AUDIT_SYNTHESIS_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAuditSynthesisFromContract(@RequestParam(TgolKeyStore.AUDIT_ID_KEY) String auditId, HttpServletRequest request, HttpServletResponse response, Model model) {
Long aId;
try {
aId = Long.valueOf(auditId);
} catch (NumberFormatException nfe) {
throw new ForbiddenPageException();
}
Audit audit = getAuditDataService().read(aId);
if (isUserAllowedToDisplayResult(audit)) {
if (isAuthorizedScopeForSynthesis(audit)) {
Contract contract = retrieveContractFromAudit(audit);
model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, auditId);
model.addAttribute(TgolKeyStore.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
return prepareSynthesisSiteData(audit, model);
} else {
throw new ForbiddenPageException();
}
} else {
throw new ForbiddenUserException();
}
}
use of org.asqatasun.webapp.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 = getContractDataService().read(contractId);
if (isContractExpired(contract)) {
throw new ForbiddenUserException(getCurrentUser());
}
// model.addAttribute(TgolKeyStore.CONTRACT_ACTION_LIST_KEY, actionHandler.getActionList(contract));
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.webapp.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 = getUserDataService().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