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);
}
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;
}
}
Aggregations