use of org.asqatasun.webapp.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.
the class AuditSetUpCommandFactory method extractAndSetLevelValueFromAuditSetUpFormFieldList.
/**
* The way to set and retrieve the referential and the level is always the
* same, regardless the auditType.
*
* @return
*/
private boolean extractAndSetLevelValueFromAuditSetUpFormFieldList(Contract contract, List<SelectFormField> levelFormFieldList, AuditSetUpCommand auditSetUpCommand) {
// We retrieve the default value of the Parameter associated
// with the level ParameterElement
String defaultValue = getParameterDataService().getDefaultLevelParameter().getValue();
Logger.getLogger(this.getClass()).debug("default level value " + defaultValue);
ScopeEnum scope = auditSetUpCommand.getScope();
boolean isDefaultValue = true;
if (scope == ScopeEnum.DOMAIN || scope == ScopeEnum.SCENARIO) {
String lastUserValue = retrieveParameterValueFromLastAudit(contract, getLevelParameterElement(), auditSetUpCommand);
Logger.getLogger(this.getClass()).debug("lastUserValue " + lastUserValue);
if (lastUserValue != null && !StringUtils.equals(lastUserValue, defaultValue)) {
// we override the auditParameter with the last user value
defaultValue = lastUserValue;
// If the level is overidden from the parameters of the last audit,
// we need to update the UI elements regarding this value (set this
// element as default)
AuditSetUpFormFieldHelper.selectDefaultLevelFromLevelValue(levelFormFieldList, defaultValue);
isDefaultValue = false;
}
}
auditSetUpCommand.setLevel(defaultValue);
return isDefaultValue;
}
use of org.asqatasun.webapp.entity.contract.ScopeEnum 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.ScopeEnum in project Asqatasun by Asqatasun.
the class AuditResultController method displaySourceCodeFromContract.
/**
*
* @param webresourceId
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = TgolKeyStore.SOURCE_CODE_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displaySourceCodeFromContract(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, HttpServletRequest request, HttpServletResponse response, Model model) {
WebResource webResource;
try {
webResource = getWebResourceDataService().ligthRead(Long.valueOf(webresourceId));
} catch (NumberFormatException nfe) {
throw new ForbiddenPageException();
}
if (webResource instanceof Site) {
throw new ForbiddenPageException();
}
Audit audit = getAuditFromWebResource(webResource);
if (isUserAllowedToDisplayResult(audit)) {
Page page = (Page) webResource;
SSP ssp = getContentDataService().findSSP(page, page.getURL());
model.addAttribute(TgolKeyStore.SOURCE_CODE_KEY, highlightSourceCode(ssp));
ScopeEnum scope = getActDataService().getActFromAudit(audit).getScope().getCode();
if (scope.equals(ScopeEnum.GROUPOFPAGES) || scope.equals(ScopeEnum.PAGE)) {
model.addAttribute(TgolKeyStore.IS_GENERATED_HTML_KEY, true);
}
return TgolKeyStore.SOURCE_CODE_PAGE_VIEW_NAME;
} else {
throw new ForbiddenUserException(getCurrentUser());
}
}
use of org.asqatasun.webapp.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.
the class AbstractAuditSetUpController method displayFormWithErrors.
/**
*
* @param model
* @param contract
* @param auditSetUpCommand
* @param authorisedReferentialList
* @param parametersMap
* @return
*/
private String displayFormWithErrors(Model model, Contract contract, AuditSetUpCommand auditSetUpCommand, Collection<String> authorisedReferentialList, Map<String, List<AuditSetUpFormField>> parametersMap) {
model.addAttribute(TgolKeyStore.EXPANDED_KEY, TgolKeyStore.EXPANDED_VALUE);
model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, auditSetUpCommand);
model.addAttribute(TgolKeyStore.PARAMETERS_MAP_KEY, parametersMap);
// Get a fresh list of the auditSetUpFormField that handles the choice
// of the referential and its level
List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
// Otherwise it corresponds to the default behaviour;
// The selection of default level is delegated to the helper.
// When the form is on error, the default level value corresponds to the
// one the user has chosen.
AuditSetUpFormFieldHelper.selectDefaultLevelFromLevelValue(refAndLevelFormFieldList, auditSetUpCommand.getLevel());
model.addAttribute(TgolKeyStore.LEVEL_LIST_KEY, refAndLevelFormFieldList);
// if the user is authenticated, the url of the form is under
// /home/contract/. To display error pages, we need to precise the
// backward relative path and to add the breadCrumb.
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
ScopeEnum auditScope = auditSetUpCommand.getScope();
switch(auditScope) {
case DOMAIN:
return TgolKeyStore.AUDIT_SITE_SET_UP_VIEW_NAME;
case PAGE:
return TgolKeyStore.AUDIT_PAGE_SET_UP_VIEW_NAME;
case FILE:
return TgolKeyStore.AUDIT_UPLOAD_SET_UP_VIEW_NAME;
}
return TgolKeyStore.OUPS_VIEW_NAME;
}
Aggregations