use of com.odysseusinc.arachne.portal.model.Analysis in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method setIsExecutable.
/**
* Updates isExecutable flag in a file with the given uuid and sets entry point
*
* @param uuid analysis file uuid
*/
@Override
public void setIsExecutable(String uuid) {
AnalysisFile analysisFile = analysisFileRepository.findByUuid(uuid);
Analysis analysis = analysisFile.getAnalysis();
throwAccessDeniedExceptionIfLocked(analysis);
setExecutableFileInAnalysis(analysis, uuid);
}
use of com.odysseusinc.arachne.portal.model.Analysis in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method sendAnalysisUnlockRequest.
@Override
public AnalysisUnlockRequest sendAnalysisUnlockRequest(Long analysisId, AnalysisUnlockRequest analysisUnlockRequest) throws NotExistException, AlreadyExistException {
final Optional<A> analysisOptional = analysisRepository.findByIdAndAndLockedTrue(analysisId);
final Analysis analysis = analysisOptional.orElseThrow(() -> new NotExistException(ANALYSIS_NOT_FOUND_EXCEPTION, Analysis.class));
IUser user = analysisUnlockRequest.getUser();
final AnalysisUnlockRequest existUnlockRequest = analysisUnlockRequestRepository.findByAnalysisAndStatus(analysis, AnalysisUnlockRequestStatus.PENDING);
if (existUnlockRequest != null) {
String message = String.format(UNLOCK_REQUEST_ALREADY_EXISTS_EXCEPTION, analysis.getId(), user.getId());
throw new AlreadyExistException(message);
}
analysisUnlockRequest.setAnalysis(analysis);
final AnalysisUnlockRequest savedUnlockRequest = analysisUnlockRequestRepository.save(analysisUnlockRequest);
studyService.findLeads((S) savedUnlockRequest.getAnalysis().getStudy()).forEach(lead -> mailSender.send(new UnlockAnalysisRequestMailMessage(WebSecurityConfig.getDefaultPortalURI(), lead, savedUnlockRequest)));
return savedUnlockRequest;
}
use of com.odysseusinc.arachne.portal.model.Analysis in project ArachneCentralAPI by OHDSI.
the class BaseArachneSecureServiceImpl method getRolesBySubmission.
@Override
public List<ParticipantRole> getRolesBySubmission(ArachneUser user, Submission submission) {
List<ParticipantRole> result = new LinkedList<>();
if (submission != null) {
Analysis analysis = submission.getSubmissionGroup().getAnalysis();
result = getRolesByAnalysis(user, analysis);
final DataNode dataNode = submission.getDataSource().getDataNode();
if (!DataNodeUtils.isDataNodeOwner(dataNode, user.getId())) {
// There can be many DATA_SET_OWNER-s in a single study, owning different data sources
// But in case of Submission, we are interested, whether current user is owner of the submission's DS
result.removeIf(ParticipantRole.DATA_SET_OWNER::equals);
}
}
return result;
}
use of com.odysseusinc.arachne.portal.model.Analysis in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method doAddCommonEntityToAnalysis.
protected void doAddCommonEntityToAnalysis(T analysis, DataReference dataReference, IUser user, CommonAnalysisType analysisType, List<MultipartFile> files) throws IOException {
files.stream().filter(f -> !CommonAnalysisType.COHORT.equals(analysisType) || !f.getName().endsWith(CommonFileUtils.OHDSI_JSON_EXT)).forEach(f -> {
try {
analysisService.saveFile(f, user, analysis, f.getName(), detectExecutable(analysisType, f), dataReference);
} catch (IOException e) {
LOGGER.error("Failed to save file", e);
}
});
if (analysisType.equals(CommonAnalysisType.COHORT)) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
class StringContainer {
String value = CommonAnalysisType.COHORT.getTitle();
}
final StringContainer generatedFileName = new StringContainer();
try (final ZipOutputStream zos = new ZipOutputStream(out)) {
files.forEach(file -> {
try {
if (file.getName().endsWith(CommonFileUtils.OHDSI_SQL_EXT)) {
String statement = org.apache.commons.io.IOUtils.toString(file.getInputStream(), "UTF-8");
String renderedSql = SqlRender.renderSql(statement, null, null);
DBMSType[] dbTypes = new DBMSType[] { DBMSType.POSTGRESQL, DBMSType.ORACLE, DBMSType.MS_SQL_SERVER, DBMSType.REDSHIFT, DBMSType.PDW };
String baseName = FilenameUtils.getBaseName(file.getOriginalFilename());
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
for (final DBMSType dialect : dbTypes) {
final String sql = SqlTranslate.translateSql(renderedSql, DBMSType.MS_SQL_SERVER.getOhdsiDB(), dialect.getOhdsiDB());
final String fileName = baseName + "." + dialect.getLabel().replaceAll(" ", "-") + "." + extension;
ZipUtil.addZipEntry(zos, fileName, new ByteArrayInputStream(sql.getBytes("UTF-8")));
}
final String shortBaseName = baseName.replaceAll("\\.ohdsi", "");
if (!generatedFileName.value.contains(shortBaseName)) {
generatedFileName.value += "_" + shortBaseName;
}
} else {
String fileName = file.getName();
ZipUtil.addZipEntry(zos, fileName, file.getInputStream());
}
} catch (IOException e) {
LOGGER.error("Failed to add file to archive", e);
throw new RuntimeIOException(e.getMessage(), e);
}
});
}
String fileName = generatedFileName.value + ".zip";
final MultipartFile sqlArchive = new MockMultipartFile(fileName, fileName, "application/zip", out.toByteArray());
analysisService.saveFile(sqlArchive, user, analysis, fileName, false, dataReference);
}
}
use of com.odysseusinc.arachne.portal.model.Analysis in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method list.
@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
JsonResult<List<D>> result;
IUser user = userService.getByEmail(principal.getName());
if (user == null) {
result = new JsonResult<>(PERMISSION_DENIED);
return result;
}
Iterable<T> analyses = analysisService.list(user, studyId);
result = new JsonResult<>(NO_ERROR);
List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
result.setResult(analysisDTOs);
return result;
}
Aggregations