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