Search in sources :

Example 1 with NoSuchNetworkException

use of org.obiba.mica.network.NoSuchNetworkException 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 NoSuchNetworkException

use of org.obiba.mica.network.NoSuchNetworkException in project mica2 by obiba.

the class NetworkService method getNextId.

private String getNextId(LocalizedString suggested) {
    if (suggested == null)
        return null;
    String prefix = suggested.asUrlSafeString().toLowerCase();
    if (Strings.isNullOrEmpty(prefix))
        return null;
    String next = prefix;
    try {
        findById(next);
        for (int i = 1; i <= 1000; i++) {
            next = prefix + "-" + i;
            findById(next);
        }
        return null;
    } catch (NoSuchNetworkException e) {
        return next;
    }
}
Also used : NoSuchNetworkException(org.obiba.mica.network.NoSuchNetworkException) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Aggregations

LocalizedString (org.obiba.mica.core.domain.LocalizedString)2 NoSuchNetworkException (org.obiba.mica.network.NoSuchNetworkException)2 Charsets (com.google.common.base.Charsets)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Hashing (com.google.common.hash.Hashing)1 ByteSource (com.google.common.io.ByteSource)1 ByteStreams (com.google.common.io.ByteStreams)1 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 JsonFormat (com.googlecode.protobuf.format.JsonFormat)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1