use of org.obiba.mica.network.domain.Network 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();
}
use of org.obiba.mica.network.domain.Network in project mica2 by obiba.
the class PersonDtos method asNetworkMembershipDto.
private Mica.PersonDto.MembershipDto asNetworkMembershipDto(Person.Membership membership, boolean asDraft) {
Mica.PersonDto.MembershipDto.Builder builder = Mica.PersonDto.MembershipDto.newBuilder();
builder.setRole(membership.getRole());
builder.setParentId(membership.getParentId());
if (membership.getParentId() != null) {
Network network = asDraft ? networkService.findById(membership.getParentId()) : publishedNetworkService.findById(membership.getParentId());
if (network != null) {
builder.addAllParentAcronym(localizedStringDtos.asDto(network.getAcronym()));
builder.addAllParentName(localizedStringDtos.asDto(network.getName()));
}
}
return builder.build();
}
use of org.obiba.mica.network.domain.Network in project mica2 by obiba.
the class DraftNetworkResource method update.
@PUT
public Response update(@SuppressWarnings("TypeMayBeWeakened") Mica.NetworkDto networkDto, @Nullable @QueryParam("comment") String comment) {
checkPermission("/draft/network", "EDIT");
// ensure network exists
networkService.findById(id);
Network network = dtos.fromDto(networkDto);
networkService.save(network, comment);
return Response.noContent().build();
}
use of org.obiba.mica.network.domain.Network in project mica2 by obiba.
the class DraftNetworkResource method file.
@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
checkPermission("/draft/network", "VIEW", key);
FileResource fileResource = applicationContext.getBean(FileResource.class);
Network network = networkService.findById(id);
if (network.getLogo() == null)
throw NoSuchEntityException.withId(Attachment.class, fileId);
fileResource.setAttachment(network.getLogo());
return fileResource;
}
use of org.obiba.mica.network.domain.Network in project mica2 by obiba.
the class DraftNetworksResource method create.
@POST
@Path("/networks")
@Timed
@RequiresPermissions("/draft/network:ADD")
public Response create(Mica.NetworkDto networkDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
Network network = dtos.fromDto(networkDto);
networkService.save(network, comment);
return Response.created(uriInfo.getBaseUriBuilder().segment("draft", "network", network.getId()).build()).build();
}
Aggregations