use of org.asqatasun.entity.scenario.Scenario 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.scenario.Scenario in project Asqatasun by Asqatasun.
the class AuditSetUpCommandFactory method getScenarioAuditSetUpCommand.
/**
* @param contract
* @param scenarioId
* @param levelFormFieldList
* @param optionalFormFieldMap
* @return
*/
public AuditSetUpCommand getScenarioAuditSetUpCommand(Contract contract, String scenarioId, List<SelectFormField> levelFormFieldList, Map<String, List<AuditSetUpFormField>> optionalFormFieldMap) {
AuditSetUpCommand scenarioAuditSetUpCommand = new AuditSetUpCommand();
scenarioAuditSetUpCommand.setScope(ScopeEnum.SCENARIO);
Scenario scenario = scenarioDataService.read(Long.valueOf(scenarioId));
scenarioAuditSetUpCommand.setScenarioName(scenario.getLabel());
scenarioAuditSetUpCommand.setScenarioId(scenario.getId());
setUpAuditSetUpCommand(scenarioAuditSetUpCommand, contract, levelFormFieldList, optionalFormFieldMap, ScopeEnum.SCENARIO);
return scenarioAuditSetUpCommand;
}
use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.
the class AddScenarioFormValidator method checkScenarioLabel.
/**
* @param addScenarioCommand
* @param errors
* @return whether the scenario handled by the current AddScenarioCommand
* has a well-formed label
*/
public boolean checkScenarioLabel(AddScenarioCommand addScenarioCommand, Errors errors) {
if (StringUtils.isEmpty(addScenarioCommand.getScenarioLabel())) {
// if no label set
LOGGER.debug("empty Scenario Label");
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
errors.rejectValue(SCENARIO_LABEL_KEY, NO_SCENARIO_LABEL_MSG_BUNDLE_KEY);
return false;
}
Contract contract = contractDataService.read(addScenarioCommand.getContractId());
Set<String> scenarioLabelSet = new HashSet();
for (Scenario scenario : contract.getScenarioSet()) {
scenarioLabelSet.add(scenario.getLabel());
}
if (scenarioLabelSet.contains(addScenarioCommand.getScenarioLabel())) {
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
errors.rejectValue(SCENARIO_LABEL_KEY, SCENARIO_LABEL_EXISTS_MSG_BUNDLE_KEY);
return false;
}
return true;
}
use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.
the class AsqatasunOrchestrator method auditScenario.
public void auditScenario(Contract contract, Long idScenario, String clientIp, Set<Parameter> parameterSet, Locale locale) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Scenarion audit on scenario with id" + idScenario);
for (Parameter param : parameterSet) {
LOGGER.debug("param " + param.getValue() + " " + param.getParameterElement().getParameterElementCode());
}
}
Act act = createAct(contract, ScopeEnum.SCENARIO, clientIp);
Scenario scenario = scenarioDataService.read(idScenario);
AuditThread auditScenarioThread = new AuditScenarioThread(scenario.getLabel(), scenario.getContent(), auditService, act, parameterSet, locale);
threadPoolTaskExecutor.submit(auditScenarioThread);
}
use of org.asqatasun.entity.scenario.Scenario in project Asqatasun by Asqatasun.
the class AuditScenarioController method displayScenarioSetUp.
@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_SET_UP_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayScenarioSetUp(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletRequest request, HttpServletResponse response, Model model) {
Scenario scenario = scenarioDataService.read(Long.valueOf(scenarioId));
model.addAttribute(TgolKeyStore.SCENARIO_KEY, scenario);
return displayAuditSetUpView(TgolKeyStore.AUDIT_SCENARIO_SET_UP_VIEW_NAME, contractId, scenarioId, scenarioOptionFormFieldBuilderMap, ScopeEnum.SCENARIO, model);
}
Aggregations