Search in sources :

Example 11 with CommentInstance

use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.

the class CommentNotificationEventListener method buildAndPublishNotification.

protected void buildAndPublishNotification(CaseCommentEvent event) {
    if (publishers.isEmpty()) {
        logger.debug("No publishers available, skipping comment notifications");
        return;
    }
    CommentInstance comment = event.getComment();
    List<String> mentionedRoles = extractMentionedRoles(comment.getComment());
    if (mentionedRoles.isEmpty()) {
        logger.debug("No one has been mentioned in the comment, skipping comment notification");
        return;
    }
    logger.debug("Found mentions {} in comment {}", mentionedRoles, comment.getId());
    StringBuilder commentContent = new StringBuilder(comment.getComment());
    Set<OrganizationalEntity> recipients = collectOrgEntitiesByRole(mentionedRoles, event, commentContent);
    String notificationSubject = MessageFormat.format(subject, event.getCaseId());
    Map<String, Object> parameters = buildParams(event, commentContent);
    for (NotificationPublisher publisher : publishers) {
        if (!publisher.isActive()) {
            logger.debug("Publisher {} is not active, skipping it", publisher);
            continue;
        }
        try {
            publisher.publish(sender, notificationSubject, recipients, template, parameters);
        } catch (IllegalArgumentException e) {
            publisher.publish(sender, notificationSubject, recipients, commentContent.toString());
        }
    }
}
Also used : NotificationPublisher(org.kie.internal.utils.NotificationPublisher) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity)

Example 12 with CommentInstance

use of org.jbpm.casemgmt.api.model.instance.CommentInstance in project jbpm by kiegroup.

the class CaseFileInstanceMarshallingStrategy method unmarshal.

@SuppressWarnings("unchecked")
@Override
public Object unmarshal(Context context, ObjectInputStream is, byte[] object, ClassLoader classloader) throws IOException, ClassNotFoundException {
    logger.debug("About to read {} bytes to unmarshal CaseFileInstance", (object == null ? 0 : object.length));
    Map<String, Object> caseFileContent = (Map<String, Object>) caseFileMarshaller.unmarshal(context, is, object, classloader);
    CaseFileInstanceImpl caseFileInstance = new CaseFileInstanceImpl();
    caseFileInstance.setCaseId((String) caseFileContent.get(CASE_ID_KEY));
    caseFileInstance.setDefinitionId((String) caseFileContent.get(CASE_DEF_ID_KEY));
    caseFileInstance.setCaseStartDate((Date) caseFileContent.get(CASE_START_KEY));
    caseFileInstance.setCaseEndDate((Date) caseFileContent.get(CASE_END_KEY));
    caseFileInstance.setCaseReopenDate((Date) caseFileContent.get(CASE_REOPEN_KEY));
    caseFileInstance.setRolesAssignments((Map<String, CaseRoleInstance>) caseFileContent.get(CASE_ROLE_ASSIGNMENTS_KEY));
    caseFileInstance.setComments((List<CommentInstance>) caseFileContent.get(CASE_COMMENTS_KEY));
    logger.debug("CaseFileInstance meta data unmarshalled properly into {}", caseFileInstance);
    List<SerializedContent> caseDataContent = (List<SerializedContent>) caseFileContent.get(CASE_DATA_KEY);
    logger.debug("About to read serialized content {}", caseDataContent);
    for (SerializedContent serializedContent : caseDataContent) {
        ObjectMarshallingStrategy marshaller = marshallersByName.get(serializedContent.getMarshaller());
        logger.debug("Marshaller for {} is of type {}", serializedContent, marshaller);
        Object value = marshaller.unmarshal(context, is, serializedContent.getContent(), classloader);
        caseFileInstance.add(serializedContent.getName(), value);
        logger.debug("Data unmarshalled into {} and put into case file under '{}' name", value, serializedContent.getName());
    }
    caseFileInstance.setAccessRestrictions((Map<String, List<String>>) caseFileContent.get(CASE_DATA_RESTRICTIONS_KEY));
    caseFileInstance.setParentInstanceId((Long) caseFileContent.get(CASE_PARENT_INSTANCE_ID_KEY));
    caseFileInstance.setParentWorkItemId((Long) caseFileContent.get(CASE_PARENT_WORK_ITEM_ID_KEY));
    logger.debug("Unmarshal of CaseFileInstance completed - result {}", caseFileInstance);
    return caseFileInstance;
}
Also used : CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ArrayList(java.util.ArrayList) List(java.util.List) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

CommentInstance (org.jbpm.casemgmt.api.model.instance.CommentInstance)12 HashMap (java.util.HashMap)9 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)9 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)5 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)5 UserImpl (org.jbpm.services.task.impl.model.UserImpl)5 Test (org.junit.Test)5 QueryContext (org.kie.api.runtime.query.QueryContext)5 Collection (java.util.Collection)4 Map (java.util.Map)4 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)4 CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)4 MessageFormat (java.text.MessageFormat)3 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)3 AuthorizationManager (org.jbpm.casemgmt.api.auth.AuthorizationManager)3 CommentInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl)3 IdentityProvider (org.kie.internal.identity.IdentityProvider)3