Skip to content

Commit

Permalink
BPMSPL-119 - Add taskService.addContent() for Remote API
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Rietveld committed Aug 3, 2015
1 parent 64d3a26 commit e639f8e
Show file tree
Hide file tree
Showing 28 changed files with 623 additions and 36 deletions.
Expand Up @@ -63,14 +63,14 @@ public Long execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt; TaskContext context = (TaskContext) cntxt;


if (params != null) { if (params != null) {
return context.getTaskContentService().addContent(taskId, params); return context.getTaskContentService().addOutputContent(taskId, params);
} else { } else {
Content comentImpl = content; Content comentImpl = content;
if (comentImpl == null) { if (comentImpl == null) {
comentImpl = jaxbContent; comentImpl = jaxbContent;
} }


return context.getTaskContentService().addContent(taskId, comentImpl); return context.getTaskContentService().setDocumentContent(taskId, comentImpl);
} }
} }


Expand All @@ -80,11 +80,6 @@ public Content getContent() {


public void setContent(Content content) { public void setContent(Content content) {
this.content = content; this.content = content;
// if (content instanceof JaxbContent) {
// this.jaxbContent = (JaxbContent) content;
// } else {
// this.jaxbContent = new JaxbContent(content);
// }
} }


public JaxbContent getJaxbContent() { public JaxbContent getJaxbContent() {
Expand Down
@@ -0,0 +1,91 @@
/*
* Copyright 2012 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jbpm.services.task.commands;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.drools.core.xml.jaxb.util.JaxbMapAdapter;
import org.kie.internal.command.Context;
import org.kie.internal.jaxb.StringKeyObjectValueMapXmlAdapter;

@XmlRootElement(name = "add-content-from-user-command")
@XmlAccessorType(XmlAccessType.NONE)
public class AddContentFromUserCommand extends UserGroupCallbackTaskCommand<Long> {

private static final long serialVersionUID = -1295175858745522756L;

@XmlElement(name="document-content-bytes")
@XmlSchemaType(name = "base64Binary")
private byte[] documentContentBytes = null;


@XmlJavaTypeAdapter(JaxbMapAdapter.class)
@XmlElement(name="output-content-map")
private Map<String, Object> outputContentMap = null;

public AddContentFromUserCommand() {
// default JAXB constructor
}

public AddContentFromUserCommand(long taskId, String userId) {
setTaskId(taskId);
setUserId(userId);
}

public byte[] getDocumentContentBytes() {
return documentContentBytes;
}

public void setDocumentContentBytes( byte[] documentContentBytes ) {
this.documentContentBytes = documentContentBytes;
}

public Map<String, Object> getOutputContentMap() {
if( this.outputContentMap == null ) {
this.outputContentMap = new HashMap<String, Object>();
}
return outputContentMap;
}

public void setOutputContentMap( Map<String, Object> outputContentMap ) {
this.outputContentMap = outputContentMap;
}

public Long execute( Context cntxt ) {
TaskContext context = (TaskContext) cntxt;
doCallbackUserOperation(userId, context);
groupIds = doUserGroupCallbackOperation(userId, null, context);
context.set("local:groups", groupIds);

if( outputContentMap != null ) {
return context.getTaskInstanceService().addOutputContentFromUser(taskId, userId, outputContentMap);
} else if( documentContentBytes != null ) {
// TODO!
// return context.getTaskInstanceService().setDocumentContentFromUser(taskId, userId, documentContentBytes);
}
return -1l;
}

}
Expand Up @@ -37,6 +37,7 @@ public class CompositeCommand<T> extends TaskCommand<T> {
@XmlElement(name="add-attachment", type=AddAttachmentCommand.class), @XmlElement(name="add-attachment", type=AddAttachmentCommand.class),
@XmlElement(name="add-comment", type=AddCommentCommand.class), @XmlElement(name="add-comment", type=AddCommentCommand.class),
@XmlElement(name="add-content", type=AddContentCommand.class), @XmlElement(name="add-content", type=AddContentCommand.class),
@XmlElement(name="add-content-from-user", type=AddContentFromUserCommand.class),
@XmlElement(name="add-group", type=AddGroupCommand.class), @XmlElement(name="add-group", type=AddGroupCommand.class),
@XmlElement(name="add-task", type=AddTaskCommand.class), @XmlElement(name="add-task", type=AddTaskCommand.class),
@XmlElement(name="add-user", type=AddUserCommand.class), @XmlElement(name="add-user", type=AddUserCommand.class),
Expand Down Expand Up @@ -68,7 +69,9 @@ public class CompositeCommand<T> extends TaskCommand<T> {
@XmlElement(name="get-comment", type=GetCommentCommand.class), @XmlElement(name="get-comment", type=GetCommentCommand.class),
@XmlElement(name="get-completed-tasks-by-user", type=GetCompletedTasksByUserCommand.class), @XmlElement(name="get-completed-tasks-by-user", type=GetCompletedTasksByUserCommand.class),
@XmlElement(name="get-completed-tasks", type=GetCompletedTasksCommand.class), @XmlElement(name="get-completed-tasks", type=GetCompletedTasksCommand.class),
@XmlElement(name="get-content", type=GetContentCommand.class), @XmlElement(name="get-content", type=GetContentByIdCommand.class),
@XmlElement(name="get-content-by-id-for-user", type=GetContentByIdForUserCommand.class),
@XmlElement(name="get-content-map-for-user", type=GetContentMapForUserCommand.class),
@XmlElement(name="get-group", type=GetGroupCommand.class), @XmlElement(name="get-group", type=GetGroupCommand.class),
@XmlElement(name="get-groups", type=GetGroupsCommand.class), @XmlElement(name="get-groups", type=GetGroupsCommand.class),
@XmlElement(name="get-org-entity", type=GetOrgEntityCommand.class), @XmlElement(name="get-org-entity", type=GetOrgEntityCommand.class),
Expand Down
Expand Up @@ -42,7 +42,7 @@ public DeleteContentCommand(long taskId, Long contentId) {


public Void execute(Context cntxt) { public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt; TaskContext context = (TaskContext) cntxt;
context.getTaskContentService().deleteContent(taskId, contentId); context.getTaskContentService().deleteDocumentContent(taskId, contentId);
return null; return null;


} }
Expand Down
Expand Up @@ -24,20 +24,20 @@
import org.kie.api.task.model.Content; import org.kie.api.task.model.Content;
import org.kie.internal.command.Context; import org.kie.internal.command.Context;


@XmlRootElement(name="get-content-command") @XmlRootElement(name="get-content-by-id-command")
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
public class GetContentCommand extends TaskCommand<Content> { public class GetContentByIdCommand extends TaskCommand<Content> {


private static final long serialVersionUID = 5911387213149078240L; private static final long serialVersionUID = 5911387213149078240L;


@XmlElement @XmlElement
@XmlSchemaType(name="long") @XmlSchemaType(name="long")
private Long contentId; private Long contentId;


public GetContentCommand() { public GetContentByIdCommand() {
} }


public GetContentCommand(Long contentId) { public GetContentByIdCommand(Long contentId) {
this.contentId = contentId; this.contentId = contentId;
} }


Expand Down
@@ -0,0 +1,61 @@
/*
* Copyright 2015 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.services.task.commands;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;

import org.kie.api.task.model.Content;
import org.kie.internal.command.Context;

@XmlRootElement(name="get-content-by-id-for-user-command")
@XmlAccessorType(XmlAccessType.NONE)
public class GetContentByIdForUserCommand extends UserGroupCallbackTaskCommand<Content> {

private static final long serialVersionUID = 5911387213149078240L;

@XmlElement
@XmlSchemaType(name="long")
private Long contentId;

public GetContentByIdForUserCommand() {
}

public GetContentByIdForUserCommand(Long contentId) {
this.contentId = contentId;
}

public Long getContentId() {
return contentId;
}

public void setContentId(Long contentId) {
this.contentId = contentId;
}

public Content execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
doCallbackUserOperation(userId, context);
groupIds = doUserGroupCallbackOperation(userId, null, context);
context.set("local:groups", groupIds);

return context.getTaskInstanceService().getContentByIdForUser(contentId, userId);
}

}
@@ -0,0 +1,49 @@
/*
* Copyright 2015 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.services.task.commands;

import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.kie.internal.command.Context;

@XmlRootElement(name="get-content-map-for-user-command")
@XmlAccessorType(XmlAccessType.NONE)
public class GetContentMapForUserCommand extends UserGroupCallbackTaskCommand<Map<String,Object>> {

private static final long serialVersionUID = 5911387213149078240L;

public GetContentMapForUserCommand() {
}

public GetContentMapForUserCommand(Long taskId, String userId) {
this.taskId = taskId;
this.userId = userId;
}

public Map<String, Object> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
doCallbackUserOperation(userId, context);
groupIds = doUserGroupCallbackOperation(userId, null, context);
context.set("local:groups", groupIds);

return context.getTaskInstanceService().getContentMapForUser(taskId, userId);
}

}
Expand Up @@ -25,6 +25,7 @@
import org.jbpm.services.task.impl.TaskIdentityServiceImpl; import org.jbpm.services.task.impl.TaskIdentityServiceImpl;
import org.jbpm.services.task.impl.TaskInstanceServiceImpl; import org.jbpm.services.task.impl.TaskInstanceServiceImpl;
import org.jbpm.services.task.impl.TaskQueryServiceImpl; import org.jbpm.services.task.impl.TaskQueryServiceImpl;
import org.jbpm.services.task.internals.lifecycle.LifeCycleManager;
import org.jbpm.services.task.internals.lifecycle.MVELLifeCycleManager; import org.jbpm.services.task.internals.lifecycle.MVELLifeCycleManager;
import org.jbpm.services.task.rule.TaskRuleService; import org.jbpm.services.task.rule.TaskRuleService;
import org.jbpm.services.task.rule.impl.RuleContextProviderImpl; import org.jbpm.services.task.rule.impl.RuleContextProviderImpl;
Expand Down Expand Up @@ -69,9 +70,7 @@ public TaskContext(Context context, Environment environment, TaskEventSupport ta
} }


public TaskInstanceService getTaskInstanceService() { public TaskInstanceService getTaskInstanceService() {
return new TaskInstanceServiceImpl(this, persistenceContext, return new TaskInstanceServiceImpl(this, persistenceContext, getMvelLifeCycleManager(), taskEventSupport, environment);
new MVELLifeCycleManager(this, persistenceContext, getTaskContentService(), taskEventSupport),
taskEventSupport, environment);
} }


public TaskDefService getTaskDefService() { public TaskDefService getTaskDefService() {
Expand Down Expand Up @@ -145,7 +144,10 @@ public void set(String string, Object o) {
public UserGroupCallback getUserGroupCallback() { public UserGroupCallback getUserGroupCallback() {
return (UserGroupCallback) get(EnvironmentName.TASK_USER_GROUP_CALLBACK); return (UserGroupCallback) get(EnvironmentName.TASK_USER_GROUP_CALLBACK);
} }


private LifeCycleManager getMvelLifeCycleManager() {
return new MVELLifeCycleManager(this, persistenceContext, getTaskContentService(), taskEventSupport);
}
/* /*
* currently not used methods * currently not used methods
*/ */
Expand Down
Expand Up @@ -49,7 +49,7 @@ public void setPersistenceContext(TaskPersistenceContext persistenceContext) {
} }


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public long addContent(long taskId, Map<String, Object> params) { public long addOutputContent(long taskId, Map<String, Object> params) {
Task task = persistenceContext.findTask(taskId); Task task = persistenceContext.findTask(taskId);
long outputContentId = task.getTaskData().getOutputContentId(); long outputContentId = task.getTaskData().getOutputContentId();
Content outputContent = persistenceContext.findContent(outputContentId); Content outputContent = persistenceContext.findContent(outputContentId);
Expand Down Expand Up @@ -79,14 +79,15 @@ public long addContent(long taskId, Map<String, Object> params) {
return contentId; return contentId;
} }


public long addContent(long taskId, Content content) { // TODO: if there's an existing document content entity, we lose all link to that through this!
public long setDocumentContent(long taskId, Content content) {
Task task = persistenceContext.findTask(taskId); Task task = persistenceContext.findTask(taskId);
persistenceContext.persistContent(content); persistenceContext.persistContent(content);
((InternalTaskData) task.getTaskData()).setDocumentContentId(content.getId()); ((InternalTaskData) task.getTaskData()).setDocumentContentId(content.getId());
return content.getId(); return content.getId();
} }


public void deleteContent(long taskId, long contentId) { public void deleteDocumentContent(long taskId, long contentId) {
Task task = persistenceContext.findTask(taskId); Task task = persistenceContext.findTask(taskId);
((InternalTaskData) task.getTaskData()).setDocumentContentId(-1); ((InternalTaskData) task.getTaskData()).setDocumentContentId(-1);
Content content = persistenceContext.findContent(contentId); Content content = persistenceContext.findContent(contentId);
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.kie.api.task.model.Task; import org.kie.api.task.model.Task;
import org.kie.api.task.model.TaskSummary; import org.kie.api.task.model.TaskSummary;
import org.kie.api.task.model.User; import org.kie.api.task.model.User;
import org.kie.internal.task.api.ContentMarshallerContext;
import org.kie.internal.task.api.TaskInstanceService; import org.kie.internal.task.api.TaskInstanceService;
import org.kie.internal.task.api.TaskModelProvider; import org.kie.internal.task.api.TaskModelProvider;
import org.kie.internal.task.api.TaskPersistenceContext; import org.kie.internal.task.api.TaskPersistenceContext;
Expand Down Expand Up @@ -394,6 +395,39 @@ public void setSubject(long taskId, String subject) {
Task task = persistenceContext.findTask(taskId); Task task = persistenceContext.findTask(taskId);
((InternalTask) task).setSubject(subject); ((InternalTask) task).setSubject(subject);
} }

@Override
public long addOutputContentFromUser( long taskId, String userId, Map<String, Object> params ) {
// check permissions
this.lifeCycleManager.taskOperation(Operation.Modify, taskId, userId, null, null, toGroups(null));
return new TaskContentServiceImpl(this.persistenceContext).addOutputContent(taskId, params);
}

@Override
public Content getContentByIdForUser( long contentId, String userId ) {
long taskId = persistenceContext.findTaskIdByContentId(contentId);
// check permissions
this.lifeCycleManager.taskOperation(Operation.View, taskId, userId, null, null, toGroups(null));
return this.persistenceContext.findContent(contentId);
}

@Override
public Map<String, Object> getContentMapForUser( Long taskId, String userId ) {
// check permissions
this.lifeCycleManager.taskOperation(Operation.View, taskId, userId, null, null, toGroups(null));
Task task = this.persistenceContext.findTask(taskId);
if( task.getTaskData() != null && task.getTaskData().getOutputContentId() != null ) {
Content content = this.persistenceContext.findContent(task.getTaskData().getOutputContentId());
ContentMarshallerContext mContext = TaskContentRegistry.get().getMarshallerContext(task);
Object outputContent = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if( outputContent instanceof Map ) {
return (Map<String, Object>) outputContent;
} else {
throw new IllegalStateException("Output content for task " + taskId + " is not a Map<String, Object>!");
}
}
return null;
}


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected List<String> toGroups(List<String> groups) { protected List<String> toGroups(List<String> groups) {
Expand Down Expand Up @@ -447,4 +481,7 @@ protected void resolveTaskDetailsForTaskProperties(Task task) {
((InternalTask)task).setSubject((String) replacements.get("subject")); ((InternalTask)task).setSubject((String) replacements.get("subject"));
((InternalTask)task).setFormName((String) replacements.get("formName")); ((InternalTask)task).setFormName((String) replacements.get("formName"));
} }



} }

0 comments on commit e639f8e

Please sign in to comment.