use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractManagementController method editContractAdminPage.
/**
* @param contractId
* @param request
* @param response
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.EDIT_CONTRACT_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String editContractAdminPage(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, HttpServletRequest request, HttpServletResponse response, Model model) {
Long lContractId;
try {
lContractId = Long.valueOf(contractId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
Contract contract = getContractDataService().read(lContractId);
if (contract == null) {
throw new ForbiddenPageException();
}
request.getSession().setAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
return prepateDataAndReturnCreateContractView(model, contract.getUser(), contract, ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(getContractOptionFormFieldBuilderMap()), TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractSortCommandHelper method prepareContract.
/**
* This methods retrieves and prepare contract info
*
* @param user
* @param csc the ContractSortCommand
* @param displayOptionFieldsBuilderList
* @param model
* @return
*/
public static Collection<Contract> prepareContract(User user, ContractSortCommand csc, List<FormFieldBuilder> displayOptionFieldsBuilderList, Model model) {
csc = prepareDataForSortConsole(user.getId(), csc, displayOptionFieldsBuilderList, model);
List<Contract> contractSet = new LinkedList();
List<String> inclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(inclusionContractSortKey).toString().split(";"));
List<String> exclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(exclusionContractSortKey).toString().split(";"));
for (Contract contract : user.getContractSet()) {
if (isContractLabelIncluded(inclusionSortOccurence, contract.getLabel()) && !isContractLabelExcluded(exclusionSortOccurence, contract.getLabel())) {
contractSet.add(contract);
}
}
sortContractSetRegardingCommand(contractSet, csc);
return contractSet;
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractSortCommandHelper method prepareContractInfo.
/**
* This methods retrieves and prepare contract info
*
* @param user
* @param csc the ContractSortCommand
* @param displayOptionFieldsBuilderList
* @param model
* @return
*/
public static Collection<ContractInfo> prepareContractInfo(User user, ContractSortCommand csc, List<FormFieldBuilder> displayOptionFieldsBuilderList, Model model) {
csc = prepareDataForSortConsole(user.getId(), csc, displayOptionFieldsBuilderList, model);
List<ContractInfo> contractInfoSet = new LinkedList();
List<String> inclusionSortOccurence;
if (csc.getSortOptionMap().containsKey(inclusionContractSortKey)) {
inclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(inclusionContractSortKey).toString().split(";"));
} else {
inclusionSortOccurence = new ArrayList();
}
List<String> exclusionSortOccurence;
if (csc.getSortOptionMap().containsKey(exclusionContractSortKey)) {
exclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(exclusionContractSortKey).toString().split(";"));
} else {
exclusionSortOccurence = new ArrayList();
}
for (Contract contract : user.getContractSet()) {
if (isContractLabelIncluded(inclusionSortOccurence, contract.getLabel()) && !isContractLabelExcluded(exclusionSortOccurence, contract.getLabel())) {
contractInfoSet.add(ContractInfoFactory.getInstance().getContractInfo(contract));
}
}
if (csc.getSortOptionMap().containsKey(sortOrderKey)) {
sortContractInfoSetRegardingCommand(contractInfoSet, csc);
}
return contractInfoSet;
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditLauncherController method launchAudit.
/**
* This methods enables an authenticated user to launch an audit.
*
* @param auditSetUpCommand
* @param locale
* @param model
* @return
*/
public String launchAudit(final AuditSetUpCommand auditSetUpCommand, final Locale locale, Model model) {
Contract contract = getContractDataService().read(auditSetUpCommand.getContractId());
if (isContractExpired(contract)) {
return displayContractView(contract, model);
} else {
// before launching the audit, we check whether any restriction on the
//contract forbids it.
ScopeEnum scope = auditSetUpCommand.getScope();
String checkResult = restrictionHandler.checkRestriction(contract, getClientIpAddress(), scope);
if (!checkResult.equalsIgnoreCase(TgolKeyStore.ACT_ALLOWED)) {
return checkResult;
}
if (scope.equals(ScopeEnum.PAGE) || scope.equals(ScopeEnum.FILE)) {
return preparePageAudit(auditSetUpCommand, contract, locale, scope, model);
}
String url = getContractDataService().getUrlFromContractOption(contract);
if (scope.equals(ScopeEnum.DOMAIN)) {
asqatasunExecutor.auditSite(contract, url, getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
model.addAttribute(TgolKeyStore.TESTED_URL_KEY, url);
} else if (scope.equals(ScopeEnum.SCENARIO)) {
asqatasunExecutor.auditScenario(contract, auditSetUpCommand.getScenarioId(), getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
model.addAttribute(TgolKeyStore.SCENARIO_NAME_KEY, auditSetUpCommand.getScenarioName());
model.addAttribute(TgolKeyStore.SCENARIO_ID_KEY, auditSetUpCommand.getScenarioId());
}
model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
return TgolKeyStore.AUDIT_IN_PROGRESS_VIEW_NAME;
}
}
use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AbstractAuditSetUpController method displayAuditSetUpView.
/**
*
* @param viewName
* @param contractId
* @param scenarioId
* @param optionFormFieldBuilderMap
* @param scope
* @param model
* @return
*/
protected String displayAuditSetUpView(String viewName, String contractId, String scenarioId, Map<String, List<AuditSetUpFormFieldBuilderImpl>> optionFormFieldBuilderMap, ScopeEnum scope, Model model) {
Long contractIdValue;
try {
contractIdValue = Long.valueOf(contractId);
} catch (NumberFormatException nfe) {
throw new ForbiddenPageException(getCurrentUser());
}
Contract contract = getContractDataService().read(contractIdValue);
if (isUserAllowedToDisplaySetUpPage(contract, viewName)) {
Collection<String> authorisedReferentialList = getAuthorisedReferentialCodeFromContract(contract);
// Get a fresh list of the auditSetUpFormField that handles the choice
// of the referential and its level
List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
String defaultRef = getDefaultReferential(authorisedReferentialList);
AuditSetUpFormFieldHelper.selectDefaultLevelFromRefValue(refAndLevelFormFieldList, defaultRef);
// Get a fresh map of auditSetUpFormField. The value of the field is
// them set by Parameter mapping handled by the AuditSetUpCommandObject
Map<String, List<AuditSetUpFormField>> optionFormFieldMap = this.getFreshAuditSetUpFormFieldMap(contract, optionFormFieldBuilderMap);
AuditSetUpCommand asuc;
// instance of AuditSetUpCommand
switch(scope) {
case DOMAIN:
asuc = AuditSetUpCommandFactory.getInstance().getSiteAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
break;
case FILE:
case GROUPOFFILES:
asuc = AuditSetUpCommandFactory.getInstance().getUploadAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
break;
case SCENARIO:
asuc = AuditSetUpCommandFactory.getInstance().getScenarioAuditSetUpCommand(contract, scenarioId, refAndLevelFormFieldList, optionFormFieldMap);
break;
case PAGE:
case GROUPOFPAGES:
default:
asuc = AuditSetUpCommandFactory.getInstance().getPageAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
}
model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, asuc);
model.addAttribute(TgolKeyStore.DEFAULT_PARAM_SET_KEY, asuc.isDefaultParamSet());
this.prepareFormModel(model, contract, refAndLevelFormFieldList, optionFormFieldMap);
return viewName;
} else {
return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
}
}
Aggregations