Search in sources :

Example 1 with SortaJobExecution

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution)

Example 2 with 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);
}
Also used : User(org.molgenis.data.security.auth.User) SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution)

Example 3 with SortaJobExecution

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);
}
Also used : User(org.molgenis.data.security.auth.User) SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution) IOException(java.io.IOException)

Example 4 with SortaJobExecution

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();
}
Also used : SortaJobImpl(org.molgenis.ontology.sorta.job.SortaJobImpl) SortaCsvRepository(org.molgenis.ontology.sorta.repo.SortaCsvRepository) SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 5 with SortaJobExecution

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);
    }
}
Also used : SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution)

Aggregations

SortaJobExecution (org.molgenis.ontology.sorta.job.SortaJobExecution)9 EntityType (org.molgenis.data.meta.model.EntityType)4 File (java.io.File)3 IOException (java.io.IOException)3 CsvWriter (org.molgenis.data.csv.CsvWriter)3 Attribute (org.molgenis.data.meta.model.Attribute)3 DynamicEntity (org.molgenis.data.support.DynamicEntity)3 QueryImpl (org.molgenis.data.support.QueryImpl)3 SortaJobImpl (org.molgenis.ontology.sorta.job.SortaJobImpl)3 SortaCsvRepository (org.molgenis.ontology.sorta.repo.SortaCsvRepository)3 SortaServiceResponse (org.molgenis.ontology.sorta.request.SortaServiceResponse)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 NumberFormat (java.text.NumberFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2