use of io.lumeer.engine.api.event.ResourceVariableEvent in project engine by Lumeer.
the class PusherFacade method createOrUpdateResourceVariableNotification.
public void createOrUpdateResourceVariableNotification(final ResourceVariableEvent resourceVariableEvent, final String suffix) {
if (isEnabled()) {
try {
ResourceVariable resourceVariable = resourceVariableAdapter.mapVariable(resourceVariableEvent.getVariable());
Organization organization = organizationDao.getOrganizationById(resourceVariable.getOrganizationId());
Set<String> users;
ObjectWithParent object;
ResourceId backup;
if (resourceVariable.getResourceType() == ResourceType.ORGANIZATION) {
object = new ObjectWithParent(getAppId(), resourceVariable, organization.getId());
backup = new ResourceId(getAppId(), resourceVariable.getId(), organization.getId());
users = permissionAdapter.getOrganizationUsersByRole(organization, RoleType.TechConfig);
} else {
Project project = projectDao.getProjectById(resourceVariable.getProjectId());
object = new ObjectWithParent(getAppId(), resourceVariable, organization.getId(), project.getId());
backup = new ResourceId(getAppId(), resourceVariable.getId(), organization.getId(), project.getId());
users = permissionAdapter.getProjectUsersByRole(organization, project, RoleType.TechConfig);
}
List<Event> events = users.stream().map(userId -> pusherAdapter.createEventForObjectWithParent(object, backup, suffix, userId)).collect(Collectors.toList());
sendNotificationsBatch(events);
} catch (Exception e) {
log.log(Level.WARNING, "Unable to send push notification: ", e);
}
}
}
Aggregations