Search in sources :

Example 1 with SubscribableObject

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);
        }
    }
}
Also used : User(org.hisp.dhis.user.User) Schema(org.hisp.dhis.schema.Schema) SubscribableObject(org.hisp.dhis.common.SubscribableObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) HashSet(java.util.HashSet)

Example 2 with SubscribableObject

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));
}
Also used : SubscribableObject(org.hisp.dhis.common.SubscribableObject) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with SubscribableObject

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));
}
Also used : SubscribableObject(org.hisp.dhis.common.SubscribableObject) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

SubscribableObject (org.hisp.dhis.common.SubscribableObject)3 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 HashSet (java.util.HashSet)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 Schema (org.hisp.dhis.schema.Schema)1 User (org.hisp.dhis.user.User)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1