Search in sources :

Example 11 with Network

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();
}
Also used : Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) NetworkState(org.obiba.mica.network.domain.NetworkState) PublishedNetworkService(org.obiba.mica.network.service.PublishedNetworkService) LoggerFactory(org.slf4j.LoggerFactory) Network(org.obiba.mica.network.domain.Network) NetworkService(org.obiba.mica.network.service.NetworkService) NotNull(javax.validation.constraints.NotNull) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NetworkState(org.obiba.mica.network.domain.NetworkState) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NotNull(javax.validation.constraints.NotNull)

Example 12 with Network

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();
}
Also used : Network(org.obiba.mica.network.domain.Network)

Example 13 with Network

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();
}
Also used : Network(org.obiba.mica.network.domain.Network)

Example 14 with Network

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;
}
Also used : Network(org.obiba.mica.network.domain.Network) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment)

Example 15 with Network

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();
}
Also used : Network(org.obiba.mica.network.domain.Network) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Network (org.obiba.mica.network.domain.Network)19 NetworkState (org.obiba.mica.network.domain.NetworkState)6 Map (java.util.Map)5 Inject (javax.inject.Inject)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Maps (com.google.common.collect.Maps)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Strings (com.google.common.base.Strings)3 Sets (com.google.common.collect.Sets)3 Set (java.util.Set)3 NotNull (javax.validation.constraints.NotNull)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 LocalizedString (org.obiba.mica.core.domain.LocalizedString)3 Attachment (org.obiba.mica.file.Attachment)3 NetworkService (org.obiba.mica.network.service.NetworkService)3 SubjectAclService (org.obiba.mica.security.service.SubjectAclService)3 BaseStudy (org.obiba.mica.study.domain.BaseStudy)3 Component (org.springframework.stereotype.Component)3