use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class ContractDAO method read.
@Override
public Contract read(Long id) {
try {
Query query = entityManager.createQuery("SELECT c FROM " + getEntityClass().getName() + " c" + " LEFT JOIN FETCH c.optionElementSet o" + " LEFT JOIN FETCH c.functionalitySet f" + " LEFT JOIN FETCH c.referentialSet r" + " LEFT JOIN FETCH c.scenarioSet s" + " WHERE c.id = :id");
query.setParameter("id", id);
Contract contract = (Contract) query.getSingleResult();
// to ensure the options associated with the contract is
// retrieved
contract.getOptionElementSet().size();
contract.getFunctionalitySet().size();
contract.getScenarioSet().size();
contract.getReferentialSet().size();
return contract;
} catch (NoResultException nre) {
return null;
}
}
use of org.asqatasun.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 = contractDataService.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 = contractDataService.getUrlFromContractOption(contract);
if (scope.equals(ScopeEnum.DOMAIN)) {
asqatasunOrchestrator.auditSite(contract, url, getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
model.addAttribute(TgolKeyStore.TESTED_URL_KEY, url);
} else if (scope.equals(ScopeEnum.SCENARIO)) {
asqatasunOrchestrator.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.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditScenarioController method getScenarioFile.
@RequestMapping(value = TgolKeyStore.DOWNLOAD_SCENARIO_URL_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public void getScenarioFile(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletResponse response) {
Contract contract = contractDataService.read(Long.valueOf(contractId));
if (contract.getUser().getId().equals(getCurrentUser().getId())) {
try {
for (Scenario scenario : contract.getScenarioSet()) {
if (scenario.getId().equals(Long.valueOf(scenarioId))) {
InputStream is = IOUtils.toInputStream(scenario.getContent());
IOUtils.copy(is, response.getOutputStream());
response.setContentType(TgolKeyStore.CONTENT_TYPE);
StringBuilder strb = new StringBuilder(TgolKeyStore.ATTACHMENT);
strb.append(scenario.getLabel());
strb.append(TgolKeyStore.JSON_EXTENSION);
response.setHeader(TgolKeyStore.CONTENT_DISPOSITION, strb.toString());
response.flushBuffer();
return;
}
}
throw new ForbiddenPageException(getCurrentUser());
} catch (IOException ex) {
throw new RuntimeException("IOError writing file to output stream");
}
} else {
throw new ForbiddenPageException(getCurrentUser());
}
}
use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditScenarioController method submitForm.
@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_SET_UP_CONTRACT_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitForm(@ModelAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
Contract contract = contractDataService.read(auditSetUpCommand.getContractId());
Map<String, List<AuditSetUpFormField>> formFielMap = getFreshAuditSetUpFormFieldMap(contract, scenarioOptionFormFieldBuilderMap);
return submitForm(contract, auditSetUpCommand, formFielMap, auditSiteSetUpFormValidator, model, result, request);
}
use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.
the class AuditScenarioController method addScenario.
@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_MANAGEMENT_CONTRACT_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String addScenario(@ModelAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY) AddScenarioCommand addScenarioCommand, BindingResult result, Model model, HttpServletRequest request) {
Contract contract = contractDataService.read(addScenarioCommand.getContractId());
addScenarioFormValidator.validate(addScenarioCommand, result);
// and the same page with updated data is displayed again
if (!result.hasErrors()) {
saveScenario(addScenarioCommand, contract);
model.addAttribute(TgolKeyStore.NEW_SCENARIO_NAME_KEY, addScenarioCommand.getScenarioLabel());
prepareScenarioManagementData(model, addScenarioCommand.getContractId().toString());
return TgolKeyStore.SCENARIO_MANAGEMENT_VIEW_NAME;
}
addScenarioListToModel(contract, model);
model.addAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY, addScenarioCommand);
model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
return TgolKeyStore.SCENARIO_MANAGEMENT_VIEW_NAME;
}
Aggregations