use of io.lumeer.engine.api.event.CreateOrUpdateGroup in project engine by Lumeer.
the class PusherFacade method createAddOrUpdateGroupNotification.
public void createAddOrUpdateGroupNotification(@Observes final CreateOrUpdateGroup createOrUpdateGroup) {
if (isEnabled()) {
try {
Organization organization = organizationDao.getOrganizationById(createOrUpdateGroup.getOrganizationId());
ObjectWithParent object = new ObjectWithParent(getAppId(), createOrUpdateGroup.getGroup(), organization.getId());
Set<String> users = resourceAdapter.getOrganizationReaders(organization);
List<Event> events = users.stream().map(userId -> createEventForObjectWithParent(object, UPDATE_EVENT_SUFFIX, userId)).collect(Collectors.toList());
sendNotificationsBatch(events);
} catch (Exception e) {
log.log(Level.WARNING, "Unable to send push notification: ", e);
}
}
}
use of io.lumeer.engine.api.event.CreateOrUpdateGroup in project engine by Lumeer.
the class MongoGroupDao method createGroup.
@Override
public Group createGroup(final Group group) {
try {
databaseCollection().insertOne(group);
if (createOrUpdateGroupEvent != null) {
group.setOrganizationId(getOrganization().get().getId());
createOrUpdateGroupEvent.fire(new CreateOrUpdateGroup(getOrganization().get().getId(), group));
}
return group;
} catch (MongoException ex) {
throw new StorageException("Cannot create group " + group, ex);
}
}
use of io.lumeer.engine.api.event.CreateOrUpdateGroup in project engine by Lumeer.
the class MongoGroupDao method updateGroup.
@Override
public Group updateGroup(final String id, final Group group) {
FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true);
try {
Group returnedGroup = databaseCollection().findOneAndReplace(idFilter(id), group, options);
if (returnedGroup == null) {
throw new StorageException("Group '" + id + "' has not been updated.");
}
if (createOrUpdateGroupEvent != null) {
returnedGroup.setOrganizationId(getOrganization().get().getId());
createOrUpdateGroupEvent.fire(new CreateOrUpdateGroup(getOrganization().get().getId(), returnedGroup));
}
return returnedGroup;
} catch (MongoException ex) {
throw new StorageException("Cannot update group " + group, ex);
}
}
Aggregations