Search in sources :

Example 1 with NetworkUpdatedEvent

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);
}
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 2 with NetworkUpdatedEvent

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));
}
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)2 NetworkState (org.obiba.mica.network.domain.NetworkState)2 NetworkUpdatedEvent (org.obiba.mica.network.event.NetworkUpdatedEvent)2 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 NetworkPublishedEvent (org.obiba.mica.network.event.NetworkPublishedEvent)1 NetworkUnpublishedEvent (org.obiba.mica.network.event.NetworkUnpublishedEvent)1