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