use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.
the class ArachnePermissionEvaluator method addPermissions.
public boolean addPermissions(ArachneUser user, HasArachnePermissions hasPermissionsObj) {
Set<ArachnePermission> allPermissions = getAllPermissions(hasPermissionsObj, user);
hasPermissionsObj.setPermissions(allPermissions);
if (hasPermissionsObj instanceof Analysis) {
final Analysis analysis = (Analysis) hasPermissionsObj;
final List<SubmissionGroup> submissionGroups = analysis.getSubmissionGroups();
if (!CollectionUtils.isEmpty(submissionGroups)) {
submissionGroups.forEach(submissionGroup -> submissionGroup.getSubmissions().forEach(submission -> {
final Set<ArachnePermission> submissionPermissions = getAllPermissions(submission, user);
submission.setPermissions(submissionPermissions);
}));
}
final List<AnalysisFile> files = analysis.getFiles();
if (!CollectionUtils.isEmpty(files)) {
files.forEach(file -> {
final Set<ArachnePermission> filePermissions = getAllPermissions(file, user);
file.setPermissions(filePermissions);
});
}
}
return true;
}
use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.
the class AnalysisHelper method createSubmission.
public static List<Submission> createSubmission(BaseSubmissionService submissionService, List<Long> datasourceIds, IUser user, Analysis analysis) throws IOException, NotExistException, NoExecutableFileException, ValidationException {
final List<Submission> submissions = new LinkedList<>();
// removes datasourceId duplicates
Set<Long> datasourceIdSet = new HashSet<>(datasourceIds);
SubmissionGroup submissionGroup = submissionService.createSubmissionGroup(user, analysis);
for (Long datasourceId : datasourceIdSet) {
submissions.add(submissionService.createSubmission(user, analysis, datasourceId, submissionGroup));
}
return submissions;
}
use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method createSubmissionGroup.
@Override
public SubmissionGroup createSubmissionGroup(IUser user, Analysis analysis) throws IOException, NoExecutableFileException {
checkBeforeCreateSubmissionGroup(analysis);
List<SubmissionFile> files = new LinkedList<>();
SubmissionGroup submissionGroup = new SubmissionGroup();
submissionGroup.setAnalysis(analysis);
submissionGroup.setAnalysisType(analysis.getType());
submissionGroup.setAuthor(user);
Date now = new Date();
submissionGroup.setCreated(now);
submissionGroup.setUpdated(now);
submissionGroup.setFiles(files);
submissionGroup = submissionGroupRepository.save(submissionGroup);
Path submissionGroupFolder = analysisHelper.getSubmissionGroupFolder(submissionGroup);
if (Files.notExists(submissionGroupFolder)) {
Files.createDirectories(submissionGroupFolder);
}
for (AnalysisFile analysisFile : analysis.getFiles()) {
SubmissionFile submissionFile = new SubmissionFile();
String storeFilesPath = fileStorePath + File.separator + "content";
String uuid = UUID.randomUUID().toString();
submissionFile.setSubmissionGroup(submissionGroup);
submissionFile.setContentType(analysisFile.getContentType());
submissionFile.setCreated(analysisFile.getCreated());
submissionFile.setUpdated(analysisFile.getUpdated());
submissionFile.setLabel(analysisFile.getLabel());
submissionFile.setRealName(analysisFile.getRealName());
submissionFile.setEntryPoint(analysisFile.getEntryPoint());
submissionFile.setUuid(uuid);
submissionFile.setAuthor(analysisFile.getAuthor());
submissionFile.setVersion(analysisFile.getVersion());
submissionFile.setAntivirusStatus(analysisFile.getAntivirusStatus());
submissionFile.setAntivirusDescription(analysisFile.getAntivirusDescription());
Boolean isExecutable = analysisFile.getExecutable();
submissionFile.setExecutable(isExecutable != null && isExecutable);
Path analysisFileContent = Paths.get(storeFilesPath, analysis.getStudy().getId().toString(), analysis.getId().toString(), analysisFile.getUuid());
Path submissionFileContent = submissionGroupFolder.resolve(uuid);
Path target = Files.copy(analysisFileContent, submissionFileContent, StandardCopyOption.REPLACE_EXISTING);
try (InputStream in = Files.newInputStream(target)) {
String checksum = DigestUtils.md5DigestAsHex(in);
submissionFile.setChecksum(checksum);
}
files.add(submissionFile);
}
submissionFileRepository.save(files);
submissionGroup.setChecksum(calculateMD5Hash(submissionGroupFolder, files));
submissionGroupRepository.save(submissionGroup);
return submissionGroup;
}
use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method getSubmissionAllFiles.
@Override
public void getSubmissionAllFiles(Long submissionGroupId, String archiveName, OutputStream os) throws IOException {
SubmissionGroup submissionGroup = submissionGroupRepository.findOne(submissionGroupId);
Path storeFilesPath = analysisHelper.getSubmissionGroupFolder(submissionGroup);
try (ZipOutputStream zos = new ZipOutputStream(os)) {
for (SubmissionFile submissionFile : submissionGroup.getFiles()) {
String realName = submissionFile.getRealName();
Path file = storeFilesPath.resolve(submissionFile.getUuid());
if (Files.notExists(file)) {
file = legacyAnalysisHelper.getOldSubmissionFile(submissionFile).orElseThrow(FileNotFoundException::new);
}
if (Files.exists(file)) {
ZipUtil.addZipEntry(zos, realName, file);
}
}
}
}
use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method getSubmissionGroups.
@Override
@PreAuthorize("hasPermission(#submissoinGroupSearch.analysisId, 'Analysis', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).ACCESS_STUDY)")
@PostAuthorize("@ArachnePermissionEvaluator.addPermissionsToSubmissions(principal, returnObject )")
public Page<SubmissionGroup> getSubmissionGroups(SubmissionGroupSearch submissoinGroupSearch) {
final SubmissionGroupSpecification submissionGroupSpecification = new SubmissionGroupSpecification(submissoinGroupSearch);
final Integer page = submissoinGroupSearch.getPage();
final PageRequest pageRequest = new PageRequest(page == null ? 0 : page - 1, submissoinGroupSearch.getPageSize(), new Sort(Sort.Direction.DESC, "created"));
final Page<SubmissionGroup> submissionGroups = submissionGroupRepository.findAll(submissionGroupSpecification, pageRequest);
final List<SubmissionGroup> content = submissionGroups.getContent();
final Map<Long, SubmissionGroup> submissionGroupMap = content.stream().collect(Collectors.toMap(SubmissionGroup::getId, sg -> {
sg.setSubmissions(new ArrayList<>());
return sg;
}));
final Set<Long> submissionGroupIds = submissionGroupMap.keySet();
if (!CollectionUtils.isEmpty(submissionGroupIds)) {
final SubmissionSpecification<T> submissionSpecification = SubmissionSpecification.<T>builder(submissionGroupIds).withStatuses(submissoinGroupSearch.getSubmissionStatuses()).withDataSourceIds(submissoinGroupSearch.getDataSourceIds()).hasInsight(submissoinGroupSearch.getHasInsight()).showHidden(submissoinGroupSearch.getShowHidden()).build();
submissionRepository.findAll(submissionSpecification).forEach(s -> submissionGroupMap.get(s.getSubmissionGroup().getId()).getSubmissions().add(s));
}
return submissionGroups;
}
Aggregations