Search in sources :

Example 26 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionInsightServiceImpl method createSubmissionInsight.

@Override
@PreAuthorize("hasPermission(#submissionId,  'Submission', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public SubmissionInsight createSubmissionInsight(Long submissionId, SubmissionInsight insight) throws AlreadyExistException, NotExistException {
    LOGGER.info(CREATING_INSIGHT_LOG, submissionId);
    final SubmissionInsight submissionInsight = submissionInsightRepository.findOneBySubmissionId(submissionId);
    if (submissionInsight != null) {
        final String message = String.format(INSIGHT_ALREADY_EXISTS_EXCEPTION, submissionId);
        throw new AlreadyExistException(message);
    }
    final List<SubmissionStatus> allowedStatuses = Arrays.asList(EXECUTED_PUBLISHED, FAILED_PUBLISHED);
    final Submission submission = submissionService.getSubmissionByIdAndStatus(submissionId, allowedStatuses);
    throwNotExistExceptionIfNull(submission, submissionId);
    insight.setId(null);
    insight.setCreated(new Date());
    insight.setSubmission(submission);
    final SubmissionInsight savedInsight = submissionInsightRepository.save(insight);
    final List<SubmissionInsightSubmissionFile> submissionInsightSubmissionFiles = submission.getSubmissionGroup().getFiles().stream().map(sf -> new SubmissionInsightSubmissionFile(savedInsight, sf, new CommentTopic())).collect(Collectors.toList());
    submissionInsightSubmissionFileRepository.save(submissionInsightSubmissionFiles);
    final List<ResultFile> resultFiles = submission.getResultFiles();
    resultFiles.forEach(resultFile -> resultFile.setCommentTopic(new CommentTopic()));
    submissionResultFileRepository.save(resultFiles);
    return savedInsight;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) EntityGraphUtils(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EXECUTED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_PUBLISHED) Submission(com.odysseusinc.arachne.portal.model.Submission) FAILED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_PUBLISHED) Map(java.util.Map) BigInteger(java.math.BigInteger) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) LinkedList(java.util.LinkedList) CommentService(com.odysseusinc.arachne.portal.service.CommentService) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) SubmissionResultFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionResultFileRepository) Set(java.util.Set) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) SubmissionInsightSubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionInsightSubmissionFile) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) SubmissionInsightRepository(com.odysseusinc.arachne.portal.repository.SubmissionInsightRepository) SubmissionService(com.odysseusinc.arachne.portal.service.submission.SubmissionService) List(java.util.List) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) EntityUtils(com.odysseusinc.arachne.portal.util.EntityUtils) Stream(java.util.stream.Stream) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) SubmissionInsightSubmissionFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionInsightSubmissionFileRepository) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) Submission(com.odysseusinc.arachne.portal.model.Submission) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Date(java.util.Date) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) SubmissionInsightSubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionInsightSubmissionFile) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 27 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionServiceImpl method deleteSubmissionResultFile.

@Override
public boolean deleteSubmissionResultFile(Long submissionId, ResultFile resultFile) throws NotExistException, ValidationException {
    final T submission = submissionRepository.findByIdAndStatusIn(submissionId, Collections.singletonList(IN_PROGRESS.name()));
    throwNotExistExceptionIfNull(submission, submissionId);
    Optional.ofNullable(resultFile).orElseThrow(() -> new NotExistException(String.format(RESULT_FILE_NOT_EXISTS_EXCEPTION, resultFile.getId(), submission.getId()), ResultFile.class));
    ArachneFileMeta fileMeta = contentStorageService.getFileByPath(resultFile.getPath());
    if (fileMeta.getCreatedBy() == null) {
        // not manually uploaded
        throw new ValidationException(String.format(FILE_NOT_UPLOADED_MANUALLY_EXCEPTION, resultFile.getId()));
    }
    deleteSubmissionResultFile(resultFile);
    submission.getResultFiles().remove(resultFile);
    submission.setUpdated(new Date());
    saveSubmission(submission);
    return true;
}
Also used : ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) Date(java.util.Date)

Example 28 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class BaseAchillesController method getFile.

@ApiOperation("Get file contents")
@RequestMapping(value = { "datasource/{id}/files/{filename:.*}", "datasource/{id}/files/{filepath:.*}/{filename:.*}" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JsonResult<JsonNode> getFile(@PathVariable("id") Long datasourceId, @RequestParam(name = "char", required = false) Long characterizationId, @PathVariable(value = "filepath", required = false) String path, @PathVariable("filename") String filename) throws NotExistException, IOException {
    final String filepath = StringUtils.isBlank(path) ? filename : path + File.separator + filename;
    DS dataSource = checkDataSource(datasourceId);
    if (characterizationId == null) {
        characterizationId = achillesService.getLatestCharacterizationId(dataSource);
    }
    AchillesFile file = achillesService.getAchillesFile(characterizationId, filepath).orElseThrow(() -> new NotExistException(String.format("File %s not found", filepath), AchillesFile.class));
    JsonObject jsonObject = file.getData();
    JsonNode node = objectMapper.readTree(new Gson().toJson(jsonObject));
    return new JsonResult<>(NO_ERROR, node);
}
Also used : JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) AchillesFile(com.odysseusinc.arachne.portal.model.achilles.AchillesFile) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with NotExistException

use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.

the class BaseAchillesController method getLatestCharacterization.

@ApiOperation("List latest characterization for given datasource")
@RequestMapping(value = "datasource/{id}", method = RequestMethod.GET)
public JsonResult<CharacterizationDTO> getLatestCharacterization(@PathVariable("id") Long datasourceId) throws NotExistException {
    DS dataSource = checkDataSource(datasourceId);
    Characterization characterization = achillesService.getLatestCharacterization(dataSource).orElseThrow(() -> new NotExistException(String.format("Characterization doesn't exist for dataSource: %s", datasourceId), Characterization.class));
    JsonResult<CharacterizationDTO> result = new JsonResult<>();
    result.setErrorCode(NO_ERROR.getCode());
    CharacterizationDTO dto = conversionService.convert(characterization, CharacterizationDTO.class);
    result.setResult(dto);
    return result;
}
Also used : Characterization(com.odysseusinc.arachne.portal.model.achilles.Characterization) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) CharacterizationDTO(com.odysseusinc.arachne.portal.api.v1.dto.CharacterizationDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)29 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 IUser (com.odysseusinc.arachne.portal.model.IUser)8 Date (java.util.Date)7 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)6 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 Study (com.odysseusinc.arachne.portal.model.Study)5 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)4 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)4 ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 User (com.odysseusinc.arachne.portal.model.User)3 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)2 Analysis (com.odysseusinc.arachne.portal.model.Analysis)2 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)2