use of org.asqatasun.webapp.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.webapp.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.webapp.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 = getContractDataService().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();
break;
}
}
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.webapp.entity.scenario.Scenario 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 = getContractDataService().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());
} else {
throw new ForbiddenPageException(getCurrentUser());
}
}
use of org.asqatasun.webapp.entity.scenario.Scenario in project Asqatasun by Asqatasun.
the class AuditScenarioController method saveScenario.
/**
* Persist a scenario
*
* @param addScenarioCommand
* @param contract
*/
private void saveScenario(AddScenarioCommand addScenarioCommand, Contract contract) {
Scenario scenario = scenarioDataService.create();
scenario.setLabel(addScenarioCommand.getScenarioLabel());
scenario.setContent(addScenarioCommand.getScenarioContent());
scenario.setContract(contract);
scenario.setDateOfCreation(Calendar.getInstance().getTime());
scenarioDataService.saveOrUpdate(scenario);
}
Aggregations