use of org.obiba.mica.file.Attachment in project mica2 by obiba.
the class StudyPackageImportServiceImpl method importNetwork.
private void importNetwork(Network network, boolean publish, StudyPackage studyPackage) throws IOException {
Network updated;
try {
Network existing = networkService.findById(network.getId());
network.getStudyIds().stream().filter(sid -> !existing.getStudyIds().contains(sid)).forEach(sid -> existing.getStudyIds().add(sid));
updated = existing;
} catch (NoSuchNetworkException e) {
updated = network;
}
for (Map.Entry<String, ByteSource> e : studyPackage.attachments.entrySet()) {
Attachment attachment = network.getLogo();
if (attachment != null && attachment.getId().equals(e.getKey())) {
saveTempFile(attachment, e.getValue());
updated.setLogo(attachment);
}
}
networkService.save(updated);
if (publish)
networkService.publish(updated.getId(), true, PublishCascadingScope.ALL);
}
use of org.obiba.mica.file.Attachment in project mica2 by obiba.
the class StudyDtosTest method createAttachment.
private Attachment createAttachment() {
Attachment attachment = new Attachment();
attachment.setId("123");
attachment.setName("logo123");
return attachment;
}
use of org.obiba.mica.file.Attachment in project mica2 by obiba.
the class AbstractFileSystemResource method doGetAttachment.
protected Attachment doGetAttachment(String path, @Nullable String version, @Nullable String shareKey) {
String basePath = normalizePath(path);
if (isPublishedFileSystem())
subjectAclService.checkAccess("/file", basePath);
else
subjectAclService.checkPermission("/draft/file", "VIEW", basePath, shareKey);
if (path.endsWith("/"))
throw new IllegalArgumentException("Folder download is not supported");
Pair<String, String> pathName = FileSystemService.extractPathName(basePath);
AttachmentState state = fileSystemService.getAttachmentState(pathName.getKey(), pathName.getValue(), isPublishedFileSystem());
if (isPublishedFileSystem())
return state.getPublishedAttachment();
if (Strings.isNullOrEmpty(version))
return state.getAttachment();
List<Attachment> attachments = fileSystemService.getAttachmentRevisions(state).stream().filter(a -> a.getId().equals(version)).collect(Collectors.toList());
if (attachments.isEmpty())
throw new NoSuchElementException("No file version " + version + " found at path: " + basePath);
return attachments.get(0);
}
use of org.obiba.mica.file.Attachment in project mica2 by obiba.
the class DraftFileSystemResource method doReinstate.
private void doReinstate(String path, String versionId) {
Attachment attachment = doGetAttachment(path, versionId);
fileSystemService.reinstate(attachment);
}
use of org.obiba.mica.file.Attachment in project mica2 by obiba.
the class DraftHarmonizationStudyResource method file.
@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
checkPermission("/draft/harmonization-study", "VIEW", key);
FileResource fileResource = applicationContext.getBean(FileResource.class);
HarmonizationStudy study = studyService.findDraft(id);
if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
fileResource.setAttachment(study.getLogo());
} else {
List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/harmonization-study/%s", study.getId()), false).stream().filter(a -> a.getId().equals(fileId)).collect(Collectors.toList());
if (attachments.isEmpty())
throw NoSuchEntityException.withId(Attachment.class, fileId);
fileResource.setAttachment(attachments.get(0));
}
return fileResource;
}
Aggregations