use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AbstractAuditDataHandlerController method isUserAllowedToDisplayResult.
/**
* This methods checks whether the current user is allowed to display the
* audit result of a given audit. To do so, we verify that the act
* associated with the audit belongs to the current user and
* that the current contract is not expired
*
* @param audit
* @return
* true if the user is allowed to display the result, false otherwise.
*/
protected boolean isUserAllowedToDisplayResult(Audit audit) {
if (audit == null) {
throw new ForbiddenPageException();
}
User user = getCurrentUser();
Contract contract = actDataService.getActFromAudit(audit).getContract();
if (isAdminUser() || (!isContractExpired(contract) && user.getId().compareTo(contract.getUser().getId()) == 0)) {
return true;
}
throw new ForbiddenUserException();
}
use of org.asqatasun.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 = contractDataService.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());
}
use of org.asqatasun.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 = auditDataService.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.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ManualAuditController method dispatchSubmitManualAuditValues.
/**
* TO DO : replace this method with an call to the orchestrator
* to delegate the writes to the engine.
*
* @param webresourceId
* @param manualAuditCommand
* @param result
* @param model
* @param request
* @param isValidating
* @return
*/
private String dispatchSubmitManualAuditValues(String webresourceId, ManualAuditCommand manualAuditCommand, BindingResult result, Model model, HttpServletRequest request, boolean isValidating) {
WebResource webResource;
try {
webResource = webResourceDataService.ligthRead(Long.valueOf(webresourceId));
} catch (NumberFormatException nfe) {
throw new ForbiddenPageException();
}
if (webResource instanceof Site) {
throw new ForbiddenPageException();
}
Audit audit = getAuditFromWebResource(webResource);
if (isUserAllowedToDisplayResult(audit)) {
model.addAttribute(TgolKeyStore.IS_MANUAL_AUDIT_KEY, true);
List<ProcessResult> processResultList = testResultFactory.getProcessResultListFromTestsResult(manualAuditCommand.getModifiedManualResultMap(), webResource);
processResultDataService.saveOrUpdate(processResultList);
/**
* if save the manual audit for the first time save we set the
* manual audit start time and status to MANUAL_INITIALIZING
*/
if (audit.getManualAuditDateOfCreation() == null) {
audit.setManualAuditDateOfCreation(Calendar.getInstance().getTime());
audit.setStatus(AuditStatus.MANUAL_INITIALIZING);
auditDataService.update(audit);
}
List<ProcessResult> allProcessResultList = testResultFactory.getAllProcessResultListFromTestsResult(manualAuditCommand.getModifiedManualResultMap(), webResource);
manualAuditCommand.setProcessResultList(allProcessResultList);
if (isValidating) {
manualAuditValidator.validate(manualAuditCommand, result);
if (result.hasErrors()) {
// ajout message d'erreur.
model.addAttribute(TgolKeyStore.MANUAL_AUDIT_COMMAND_KEY, manualAuditCommand);
return dispatchDisplayResultRequest(webResource.getId(), null, model, request, true, manualAuditCommand);
} else {
// mettre à jour le statut
audit.setStatus(AuditStatus.MANUAL_COMPLETED);
auditDataService.update(audit);
webResourceStatisticsDataService.createWebResourceStatisticsForManualAudit(audit, webResource, allProcessResultList);
Contract contract = retrieveContractFromAudit(audit);
model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
return TgolKeyStore.CONTRACT_VIEW_NAME_REDIRECT;
}
}
webResourceStatisticsDataService.createWebResourceStatisticsForManualAudit(audit, webResource, allProcessResultList);
return dispatchDisplayResultRequest(webResource.getId(), null, model, request, true, manualAuditCommand);
} else {
throw new ForbiddenPageException();
}
}
Aggregations