use of org.obiba.mica.NoSuchEntityException in project mica2 by obiba.
the class NetworkDtos method asDtoBuilderInternal.
private Mica.NetworkDto.Builder asDtoBuilderInternal(@NotNull Network network, boolean asDraft, boolean forListing) {
Mica.NetworkDto.Builder builder = Mica.NetworkDto.newBuilder();
if (network.hasModel())
builder.setContent(JSONUtils.toJSON(network.getModel()));
//
builder.setId(network.getId()).addAllName(//
localizedStringDtos.asDto(network.getName())).addAllDescription(//
localizedStringDtos.asDto(network.getDescription())).addAllAcronym(localizedStringDtos.asDto(network.getAcronym()));
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setPublished(networkState.isPublished());
if (asDraft) {
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
builder.setPermissions(permissionsDto);
}
if (network.getLogo() != null) {
builder.setLogo(attachmentDtos.asDto(network.getLogo()));
}
List<BaseStudy> publishedStudies = publishedStudyService.findByIds(network.getStudyIds());
Set<String> publishedStudyIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(Collectors.toSet());
Sets.SetView<String> unpublishedStudyIds = Sets.difference(ImmutableSet.copyOf(network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).collect(toList())), publishedStudyIds);
if (!publishedStudies.isEmpty()) {
Map<String, Long> datasetVariableCounts = asDraft ? null : datasetVariableService.getCountByStudyIds(Lists.newArrayList(publishedStudyIds));
publishedStudies.forEach(study -> {
builder.addStudyIds(study.getId());
if (!forListing) {
builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
}
});
}
unpublishedStudyIds.forEach(studyId -> {
try {
if (!forListing)
builder.addStudySummaries(studySummaryDtos.asDto(studyId));
builder.addStudyIds(studyId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), studyId);
// ignore
}
});
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
if (!forListing)
builder.addNetworkSummaries(networkSummaryDtos.asDtoBuilder(nId, asDraft));
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder;
}
use of org.obiba.mica.NoSuchEntityException in project mica2 by obiba.
the class NetworkDtos method asDtoBuilder.
@NotNull
Mica.NetworkDto.Builder asDtoBuilder(@NotNull Network network, boolean asDraft) {
Mica.NetworkDto.Builder builder = Mica.NetworkDto.newBuilder();
if (network.hasModel())
builder.setContent(JSONUtils.toJSON(network.getModel()));
//
builder.setId(network.getId()).addAllName(//
localizedStringDtos.asDto(network.getName())).addAllDescription(//
localizedStringDtos.asDto(network.getDescription())).addAllAcronym(localizedStringDtos.asDto(network.getAcronym()));
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setPublished(networkState.isPublished());
if (asDraft) {
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
List<String> roles = micaConfigService.getConfig().getRoles();
if (network.getMemberships() != null) {
List<Mica.MembershipsDto> memberships = network.getMemberships().entrySet().stream().filter(e -> roles.contains(e.getKey())).map(e -> Mica.MembershipsDto.newBuilder().setRole(e.getKey()).addAllMembers(e.getValue().stream().map(m -> personDtos.asDto(m.getPerson(), asDraft)).collect(toList())).build()).collect(toList());
builder.addAllMemberships(memberships);
}
List<BaseStudy> publishedStudies = publishedStudyService.findByIds(network.getStudyIds());
Set<String> publishedStudyIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(Collectors.toSet());
Sets.SetView<String> unpublishedStudyIds = Sets.difference(ImmutableSet.copyOf(network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).collect(toList())), publishedStudyIds);
if (!publishedStudies.isEmpty()) {
Map<String, Long> datasetVariableCounts = asDraft ? null : datasetVariableService.getCountByStudyIds(Lists.newArrayList(publishedStudyIds));
publishedStudies.forEach(study -> {
builder.addStudyIds(study.getId());
builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
});
}
unpublishedStudyIds.forEach(studyId -> {
try {
builder.addStudySummaries(studySummaryDtos.asDto(studyId));
builder.addStudyIds(studyId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), studyId);
// ignore
}
});
if (network.getLogo() != null) {
builder.setLogo(attachmentDtos.asDto(network.getLogo()));
}
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
builder.addNetworkSummaries(networkSummaryDtos.asDtoBuilder(nId, asDraft));
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder;
}
use of org.obiba.mica.NoSuchEntityException in project mica2 by obiba.
the class DraftFileSystemResource method downloadFile.
@GET
@Path("/file-dl/{path:.*}")
public Response downloadFile(@PathParam("path") String path, @QueryParam("version") String version, @QueryParam("inline") @DefaultValue("false") boolean inline, @QueryParam("key") String shareKey) {
try {
Attachment attachment = doGetAttachment(path, version, shareKey);
String filename = attachment.getName();
String uriEncodedFilename = UriUtils.encode(filename, "UTF-8");
if (inline) {
return Response.ok(fileStoreService.getFile(attachment.getFileReference())).header("Content-Disposition", "inline; filename=\"" + uriEncodedFilename + "\"").type(FileMediaType.type(Files.getFileExtension(filename))).build();
}
return Response.ok(fileStoreService.getFile(attachment.getFileReference())).header("Content-Disposition", "attachment; filename=" + uriEncodedFilename).build();
} catch (NoSuchEntityException | UnsupportedEncodingException e) {
String name = doZip(path);
return Response.ok(tempFileService.getInputStreamFromFile(name)).header("Content-Disposition", "attachment; filename=\"" + name + "\"").build();
}
}
use of org.obiba.mica.NoSuchEntityException in project mica2 by obiba.
the class PublishedFileSystemResource method downloadFile.
@GET
@Path("/file-dl/{path:.*}")
@Timed
public Response downloadFile(@PathParam("path") String path, @QueryParam("inline") @DefaultValue("false") boolean inline) {
try {
Attachment attachment = doGetAttachment(path);
String filename = attachment.getName();
String uriEncodedFilename = UriUtils.encode(filename, "UTF-8");
if (inline) {
return Response.ok(fileStoreService.getFile(attachment.getFileReference())).header("Content-Disposition", "inline; filename=\"" + uriEncodedFilename + "\"").type(FileMediaType.type(Files.getFileExtension(filename))).build();
}
return Response.ok(fileStoreService.getFile(attachment.getFileReference())).header("Content-Disposition", "attachment; filename*=" + uriEncodedFilename).build();
} catch (NoSuchEntityException | UnsupportedEncodingException e) {
String name = doZip(path);
return Response.ok(tempFileService.getInputStreamFromFile(name)).header("Content-Disposition", "attachment; filename=\"" + name + "\"").build();
}
}
use of org.obiba.mica.NoSuchEntityException in project mica2 by obiba.
the class NetworkSummaryDtos method asDto.
@NotNull
public Mica.NetworkSummaryDto asDto(@NotNull Network network, boolean asDraft) {
Mica.NetworkSummaryDto.Builder builder = Mica.NetworkSummaryDto.newBuilder();
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setId(network.getId()).addAllAcronym(localizedStringDtos.asDto(network.getAcronym())).addAllName(localizedStringDtos.asDto(network.getName())).setPublished(networkState.isPublished());
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
if (asDraft) {
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.networkSummaryState, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).forEach(sId -> {
try {
builder.addStudyIds(sId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), sId);
// ignore
}
});
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder.build();
}
Aggregations