Search in sources :

Example 1 with Network

use of org.obiba.mica.network.domain.Network 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);
}
Also used : LocalizedString(org.obiba.mica.core.domain.LocalizedString) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LoggerFactory(org.slf4j.LoggerFactory) Hashing(com.google.common.hash.Hashing) AbstractProtobufProvider(org.obiba.jersey.protobuf.AbstractProtobufProvider) Inject(javax.inject.Inject) TempFile(org.obiba.mica.file.TempFile) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) PublishCascadingScope(org.obiba.mica.core.domain.PublishCascadingScope) Service(org.springframework.stereotype.Service) Map(java.util.Map) Mica(org.obiba.mica.web.model.Mica) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) TempFileService(org.obiba.mica.file.service.TempFileService) Network(org.obiba.mica.network.domain.Network) ByteSource(com.google.common.io.ByteSource) ZipEntry(java.util.zip.ZipEntry) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dtos(org.obiba.mica.web.model.Dtos) Charsets(com.google.common.base.Charsets) Attachment(org.obiba.mica.file.Attachment) Logger(org.slf4j.Logger) Pair(org.apache.commons.math3.util.Pair) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Set(java.util.Set) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) FileSystemService(org.obiba.mica.file.service.FileSystemService) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) Dataset(org.obiba.mica.dataset.domain.Dataset) NoSuchNetworkException(org.obiba.mica.network.NoSuchNetworkException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) Sets(com.google.common.collect.Sets) JsonFormat(com.googlecode.protobuf.format.JsonFormat) List(java.util.List) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) ObjectId(org.bson.types.ObjectId) NetworkService(org.obiba.mica.network.service.NetworkService) InputStream(java.io.InputStream) Network(org.obiba.mica.network.domain.Network) NoSuchNetworkException(org.obiba.mica.network.NoSuchNetworkException) ByteSource(com.google.common.io.ByteSource) Attachment(org.obiba.mica.file.Attachment) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Map(java.util.Map)

Example 2 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class IndividualStudyServiceTest method test_delete_study_conflict.

@Test
public void test_delete_study_conflict() {
    Study study = new Study();
    study.setName(en("name en").forFr("name fr"));
    individualStudyService.save(study);
    Network network = new Network();
    network.setId("test");
    network.setStudyIds(new ArrayList() {

        {
            add(study.getId());
        }
    });
    networkRepository.save(network);
    assertThat(studyStateRepository.findAll()).hasSize(1);
    exception.expect(ConstraintException.class);
    individualStudyService.delete(study.getId());
}
Also used : Study(org.obiba.mica.study.domain.Study) Network(org.obiba.mica.network.domain.Network) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class PublishedNetworkResource method study.

@Path("/file/{fileId}")
public FileResource study(@PathParam("id") String id, @PathParam("fileId") String fileId) {
    checkAccess(id);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    Network network = getNetwork(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) Path(javax.ws.rs.Path)

Example 4 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class NetworkService method saveInternal.

@SuppressWarnings("OverlyLongMethod")
private void saveInternal(@NotNull Network network, String comment, boolean cascade) {
    Network saved = network;
    if (network.isNew()) {
        generateId(saved);
    } else {
        saved = networkRepository.findOne(network.getId());
        if (saved != null) {
            BeanUtils.copyProperties(network, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate");
        } else {
            saved = network;
        }
    }
    if (saved.getLogo() != null && saved.getLogo().isJustUploaded()) {
        fileStoreService.save(saved.getLogo().getId());
        saved.getLogo().setJustUploaded(false);
    }
    ImmutableSet<String> invalidRoles = ImmutableSet.copyOf(Sets.difference(saved.membershipRoles(), Sets.newHashSet(micaConfigService.getConfig().getRoles())));
    for (String r : invalidRoles) {
        saved.removeRole(r);
    }
    NetworkState networkState = findEntityState(network, () -> {
        NetworkState defaultState = new NetworkState();
        defaultState.setName(network.getName());
        return defaultState;
    });
    if (!network.isNew())
        ensureGitRepository(networkState);
    networkState.incrementRevisionsAhead();
    networkStateRepository.save(networkState);
    saved.setLastModifiedDate(DateTime.now());
    if (cascade)
        networkRepository.saveWithReferences(saved);
    else
        networkRepository.save(saved);
    eventBus.post(new NetworkUpdatedEvent(saved));
    gitService.save(saved, comment);
}
Also used : Network(org.obiba.mica.network.domain.Network) NetworkUpdatedEvent(org.obiba.mica.network.event.NetworkUpdatedEvent) LocalizedString(org.obiba.mica.core.domain.LocalizedString) NetworkState(org.obiba.mica.network.domain.NetworkState)

Example 5 with Network

use of org.obiba.mica.network.domain.Network in project mica2 by obiba.

the class NetworkService method index.

/**
 * Index a specific {@link Network} without updating it.
 *
 * @param id
 * @throws NoSuchNetworkException
 */
public void index(@NotNull String id) throws NoSuchNetworkException {
    NetworkState networkState = getEntityState(id);
    Network network = findById(id);
    eventBus.post(new NetworkUpdatedEvent(network));
    processNetworkForPublishedNumberOfStudies(network);
    if (networkState.isPublished())
        eventBus.post(new NetworkPublishedEvent(network, getCurrentUsername()));
    else
        eventBus.post(new NetworkUnpublishedEvent(network));
}
Also used : NetworkUnpublishedEvent(org.obiba.mica.network.event.NetworkUnpublishedEvent) NetworkPublishedEvent(org.obiba.mica.network.event.NetworkPublishedEvent) Network(org.obiba.mica.network.domain.Network) NetworkUpdatedEvent(org.obiba.mica.network.event.NetworkUpdatedEvent) NetworkState(org.obiba.mica.network.domain.NetworkState)

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