use of org.hisp.dhis.common.SubscribableObject in project dhis2-core by dhis2.
the class DefaultInterpretationService method notifySubscribers.
private void notifySubscribers(Interpretation interpretation, InterpretationComment comment, NotificationType notificationType) {
IdentifiableObject interpretableObject = interpretation.getObject();
Schema interpretableObjectSchema = schemaService.getDynamicSchema(HibernateProxyUtils.getRealClass(interpretableObject));
if (interpretableObjectSchema.isSubscribable()) {
SubscribableObject object = (SubscribableObject) interpretableObject;
Set<User> subscribers = new HashSet<>(userService.getUsers(object.getSubscribers()));
subscribers.remove(currentUserService.getCurrentUser());
if (!subscribers.isEmpty()) {
sendNotificationMessage(subscribers, interpretation, comment, notificationType);
}
}
}
use of org.hisp.dhis.common.SubscribableObject in project dhis2-core by dhis2.
the class AbstractCrudController method subscribe.
@PostMapping(value = "/{uid}/subscriber")
@ResponseBody
public WebMessage subscribe(@PathVariable("uid") String pvUid, @CurrentUser User currentUser) {
if (!getSchema().isSubscribable()) {
return conflict("Objects of this class cannot be subscribed to");
}
@SuppressWarnings("unchecked") List<SubscribableObject> entity = (List<SubscribableObject>) getEntity(pvUid);
if (entity.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
SubscribableObject object = entity.get(0);
object.subscribe(currentUser);
manager.updateNoAcl(object);
return ok(String.format("User '%s' subscribed to object '%s'", currentUser.getUsername(), pvUid));
}
use of org.hisp.dhis.common.SubscribableObject in project dhis2-core by dhis2.
the class AbstractCrudController method unsubscribe.
@DeleteMapping(value = "/{uid}/subscriber")
@ResponseBody
@SuppressWarnings("unchecked")
public WebMessage unsubscribe(@PathVariable("uid") String pvUid, @CurrentUser User currentUser) {
if (!getSchema().isSubscribable()) {
return conflict("Objects of this class cannot be subscribed to");
}
List<SubscribableObject> entity = (List<SubscribableObject>) getEntity(pvUid);
if (entity.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
SubscribableObject object = entity.get(0);
object.unsubscribe(currentUser);
manager.updateNoAcl(object);
return ok(String.format("User '%s' removed as subscriber of object '%s'", currentUser.getUsername(), pvUid));
}
Aggregations