use of org.molgenis.ontology.sorta.job.SortaJobExecution in project molgenis by molgenis.
the class SortaController method createJobExecution.
private SortaJobExecution createJobExecution(Repository<Entity> inputData, String jobName, String ontologyIri) {
String resultEntityName = idGenerator.generateId();
SortaJobExecution sortaJobExecution = sortaJobExecutionFactory.create();
sortaJobExecution.setIdentifier(resultEntityName);
sortaJobExecution.setName(jobName);
sortaJobExecution.setUser(userAccountService.getCurrentUser());
sortaJobExecution.setSourceEntityName(inputData.getName());
sortaJobExecution.setDeleteUrl(getSortaServiceMenuUrl() + "/delete/" + resultEntityName);
sortaJobExecution.setResultEntityName(resultEntityName);
sortaJobExecution.setThreshold(DEFAULT_THRESHOLD);
sortaJobExecution.setOntologyIri(ontologyIri);
RunAsSystemAspect.runAsSystem(() -> {
createInputRepository(inputData);
createEmptyResultRepository(jobName, resultEntityName, inputData.getEntityType());
dataService.add(SORTA_JOB_EXECUTION, sortaJobExecution);
});
EntityType resultEntityType = entityTypeFactory.create(resultEntityName);
permissionSystemService.giveUserWriteMetaPermissions(asList(inputData.getEntityType(), resultEntityType));
return sortaJobExecution;
}
use of org.molgenis.ontology.sorta.job.SortaJobExecution in project molgenis by molgenis.
the class SortaController method deleteResult.
@PostMapping("/delete/{sortaJobExecutionId}")
@ResponseStatus(value = HttpStatus.OK)
public String deleteResult(@PathVariable("sortaJobExecutionId") String sortaJobExecutionId, Model model) {
SortaJobExecution sortaJobExecution = findSortaJobExecution(sortaJobExecutionId);
if (sortaJobExecution != null) {
User currentUser = userAccountService.getCurrentUser();
if (currentUser.isSuperuser() || sortaJobExecution.getUser().equals(currentUser.getUsername())) {
RunAsSystemAspect.runAsSystem(() -> dataService.deleteById(SORTA_JOB_EXECUTION, sortaJobExecution.getIdentifier()));
tryDeleteRepository(sortaJobExecution.getResultEntityName());
tryDeleteRepository(sortaJobExecution.getSourceEntityName());
}
}
return init(model);
}
use of org.molgenis.ontology.sorta.job.SortaJobExecution in project molgenis by molgenis.
the class SortaController method updateThreshold.
@PostMapping("/threshold/{sortaJobExecutionId}")
public String updateThreshold(@RequestParam(value = "threshold") String threshold, @PathVariable String sortaJobExecutionId, Model model) {
if (!StringUtils.isEmpty(threshold)) {
SortaJobExecution sortaJobExecution = findSortaJobExecution(sortaJobExecutionId);
try {
User currentUser = userAccountService.getCurrentUser();
if (currentUser.isSuperuser() || sortaJobExecution.getUser().equals(currentUser.getUsername())) {
RunAsSystemAspect.runAsSystem(() -> {
Double thresholdValue = Double.parseDouble(threshold);
sortaJobExecution.setThreshold(thresholdValue);
dataService.update(SORTA_JOB_EXECUTION, sortaJobExecution);
});
}
} catch (NumberFormatException e) {
model.addAttribute(MODEL_KEY_MESSAGE, threshold + " is illegal threshold value!");
} catch (Exception other) {
model.addAttribute(MODEL_KEY_MESSAGE, "Error updating threshold: " + other.getMessage());
}
}
return matchResult(sortaJobExecutionId, model);
}
use of org.molgenis.ontology.sorta.job.SortaJobExecution in project molgenis by molgenis.
the class SortaController method startMatchJob.
private String startMatchJob(String jobName, String ontologyIri, Model model, HttpServletRequest httpServletRequest, InputStream inputStream) throws IOException {
String sessionId = httpServletRequest.getSession().getId();
File uploadFile = fileStore.store(inputStream, sessionId + // TODO determine whether multiple match jobs during the same session results in wrong file usage
".csv");
String inputRepositoryName = idGenerator.generateId();
SortaCsvRepository inputRepository = new SortaCsvRepository(inputRepositoryName, jobName + " input", uploadFile, entityTypeFactory, attrMetaFactory);
if (!validateFileHeader(inputRepository)) {
model.addAttribute(MODEL_KEY_MESSAGE, "The Name header is missing!");
return matchTask(model);
}
if (!validateEmptyFileHeader(inputRepository)) {
model.addAttribute(MODEL_KEY_MESSAGE, "The empty header is not allowed!");
return matchTask(model);
}
if (!validateInputFileContent(inputRepository)) {
model.addAttribute(MODEL_KEY_MESSAGE, "The content of input is empty!");
return matchTask(model);
}
SortaJobExecution jobExecution = createJobExecution(inputRepository, jobName, ontologyIri);
SortaJobImpl sortaMatchJob = sortaMatchJobFactory.create(jobExecution);
taskExecutor.submit(sortaMatchJob);
return "redirect:" + getSortaServiceMenuUrl();
}
use of org.molgenis.ontology.sorta.job.SortaJobExecution in project molgenis by molgenis.
the class SortaController method matchResult.
@GetMapping("/result/{sortaJobExecutionId}")
public String matchResult(@PathVariable("sortaJobExecutionId") String sortaJobExecutionId, Model model) {
SortaJobExecution sortaJobExecution = findSortaJobExecution(sortaJobExecutionId);
if (sortaJobExecution != null) {
model.addAttribute("sortaJobExecutionId", sortaJobExecution.getIdentifier());
model.addAttribute("threshold", sortaJobExecution.getThreshold());
model.addAttribute("ontologyIri", sortaJobExecution.getOntologyIri());
model.addAttribute("numberOfMatched", countMatchedEntities(sortaJobExecution, true));
model.addAttribute("numberOfUnmatched", countMatchedEntities(sortaJobExecution, false));
return MATCH_VIEW_NAME;
} else {
LOG.info("Job execution with id {} not found.", sortaJobExecutionId);
model.addAttribute(MODEL_KEY_MESSAGE, "Job execution not found.");
return init(model);
}
}
Aggregations