@SuppressWarnings("unchecked") public void initialize(Content content) { if( content == null || content.getId() == -1) { return; } this.id = content.getId(); this.content = content.getContent(); if( content instanceof JaxbContent ) { this.contentMap = ((JaxbContent) content).getContentMap(); } else { try { Object unmarshalledContent = ContentMarshallerHelper.unmarshall(content.getContent(), null); if( unmarshalledContent != null && unmarshalledContent instanceof Map ) { contentMap = (Map<String, Object>) unmarshalledContent; } } catch (Exception e) { // don't fail in case of unmarshalling problem as it might be content not handled via jaxb // Ļe.g. custom classes, non map based etc } } }
/** * Sets the content for this attachment, i.e. the <field>size</field> and the <field>attachmentContentId</field>. * @param content attachment content */ public void setContent(Content content) { setSize(content.getContent().length); setAttachmentContentId(content.getId()); }
@SuppressWarnings("unchecked") protected Map<String, Object> loadContentData(Long contentId, Task task) { if (contentId != null) { Map<String, Object> data = null; Content contentById = getContentById(contentId); if (contentById != null) { ContentMarshallerContext mContext = getMarshallerContext(task); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), mContext.getEnvironment(), mContext.getClassloader()); if (!(unmarshalledObject instanceof Map)) { data = new HashMap<String, Object>(); data.put("Content", unmarshalledObject); } else { data = (Map<String, Object>) unmarshalledObject; } return data; } } return null; } }
@SuppressWarnings("unchecked") private Map<String, Object> getVariables(TaskContext ctx, TaskPersistenceContext persistenceContext, Task task, TaskData taskData) { Map<String, Object> variables; Content content = persistenceContext.findContent(taskData.getDocumentContentId()); if (content != null) { ContentMarshallerContext mContext = ctx.getTaskContentService().getMarshallerContext(task); Object objectFromBytes = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader()); if (objectFromBytes instanceof Map) { variables = (Map<String, Object>) objectFromBytes; } else { variables = new HashMap<String, Object>(); variables.put("content", objectFromBytes); } } else { variables = Collections.emptyMap(); } return variables; }
@SuppressWarnings("unchecked") public Map<String, Object> execute(Context cntxt ) { TaskContext context = (TaskContext) cntxt; Task taskById = context.getTaskQueryService().getTaskInstanceById(taskId); if (taskById == null) { throw new IllegalStateException("Unable to find task with id " + taskId); } TaskContentService contentService = context.getTaskContentService(); Content contentById = contentService.getContentById(taskById.getTaskData().getDocumentContentId()); ContentMarshallerContext mContext = contentService.getMarshallerContext(taskById); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), mContext.getEnvironment(), mContext.getClassloader()); if (!(unmarshalledObject instanceof Map)) { logger.debug(" The Task Content is not of type Map, it was: {} so packaging it into new map under Content key ", unmarshalledObject.getClass()); Map<String, Object> content = new HashMap<String, Object>(); content.put("Content", unmarshalledObject); return content; } Map<String, Object> content = (Map<String, Object>) unmarshalledObject; return content; }
Content content = taskService.getContentById(contentId); Object result = ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment(), ksession.getClass().getClassLoader()); results.put("Result", result); if (result instanceof Map) {
protected Map<String, Object> getTaskOutput(Task task) { long documentContentId = task.getTaskData().getOutputContentId(); if (documentContentId > 0) { Content contentById = taskService.getContentById(documentContentId); if (contentById == null) { return new HashMap<String, Object>(); } Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), null); return (Map<String, Object>) unmarshall; } return new HashMap<String, Object>(); } }
Object orig = ContentMarshallerHelper.unmarshall(content.getContent(), null); assertNotNull( "Round tripped JaxbContent is null!", xmlCopy ); Object roundTrip = ContentMarshallerHelper.unmarshall(xmlCopy.getContent(), null);
public void deleteOutput(long taskId, String userId) { Task task = persistenceContext.findTask(taskId); long contentId = task.getTaskData().getOutputContentId(); Content content = persistenceContext.findContent(contentId); Map<String, Object> initialContent = new HashMap<>(); ContentMarshallerContext context = TaskContentRegistry.get().getMarshallerContext(task); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), context.getEnvironment(), context.getClassloader()); if(unmarshalledObject != null && unmarshalledObject instanceof Map){ // set initial content before updating with this params initialContent.putAll((Map<String, Object>)unmarshalledObject); } taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, this.context, initialContent); ContentData data = TaskModelProvider.getFactory().newContentData(); persistenceContext.removeContent(content); persistenceContext.setOutputToTask(null, data, task); taskEventSupport.fireAfterTaskOutputVariablesChanged(task, this.context, null); }
@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; }
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null); if(!(unmarshalledObject instanceof Map)){ fail("The variables should be a Map");
public Long execute(Context cntxt) { TaskContext context = (TaskContext) cntxt; Attachment attachmentImpl = attachment; if (attachmentImpl == null) { attachmentImpl = jaxbAttachment; } Content contentImpl = content; if (contentImpl == null) { contentImpl = jaxbContent; } if (rawContent != null && contentImpl == null) { Task task = context.getPersistenceContext().findTask(taskId); contentImpl = TaskModelProvider.getFactory().newContent(); ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getTaskData().getDeploymentId()); ((InternalContent)contentImpl).setContent(ContentMarshallerHelper.marshallContent(task, rawContent, ctx.getEnvironment())); ((InternalAttachment)attachmentImpl).setSize(contentImpl.getContent().length); } doCallbackOperationForAttachment(attachmentImpl, context); return context.getTaskAttachmentService().addAttachment(taskId, attachmentImpl, contentImpl); }
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), context.getEnvironment(), context.getClassloader()); if(unmarshalledObject != null && unmarshalledObject instanceof Map){
Map<String, Object> unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null); assertEquals("content", unmarshalledObject.get("content")); String updated = new String(content.getContent()); unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null); assertEquals("updated content", unmarshalledObject.get("content"));
@Test public void testCompleteWithResults() { // One potential owner, should go straight to state Reserved String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),"; str += "name = 'This is my task name' })"; Task task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, new HashMap<String, Object>()); long taskId = task.getId(); // Go straight from Ready to Inprogress taskService.start(taskId, "Darth Vader"); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.InProgress, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); Map<String, Object> params = new HashMap<String, Object>(); params.put("content", "content"); taskService.complete(taskId, "Darth Vader", params); Task task2 = taskService.getTaskById(taskId); assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getOutputAccessType()); assertEquals("java.util.HashMap", task2.getTaskData().getOutputType()); long contentId = task2.getTaskData().getOutputContentId(); assertTrue(contentId != -1); Content content = taskService.getContentById(contentId); Map<String, Object> unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null); assertEquals("content", unmarshalledObject.get("content")); }
@Test public void testNewTaskWithContent() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),"; str += "name = 'This is my task name' })"; ContentData data = ContentMarshallerHelper.marshal(null, "content", null); Task task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, data); long taskId = task.getId(); // Task should be assigned to the single potential owner and state set to Reserved Task task1 = taskService.getTaskById(taskId); assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType()); assertEquals("java.lang.String", task1.getTaskData().getDocumentType()); long contentId = task1.getTaskData().getDocumentContentId(); assertTrue(contentId != -1); Content content = taskService.getContentById(contentId); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null); assertEquals("content", unmarshalledObject.toString()); xmlRoundTripContent(content); }
long firstAttachContentId = firstAttach.getAttachmentContentId(); Content firstAttachContent = taskService.getContentById(firstAttachContentId); String firstDocString = (String)ContentMarshallerHelper.unmarshall(firstAttachContent.getContent(), null); assertEquals("This is my first inline document", firstDocString); long secondAttachContentId = secondAttach.getAttachmentContentId(); Content secondAttachContent = taskService.getContentById(secondAttachContentId); String secondDocString = (String)ContentMarshallerHelper.unmarshall(secondAttachContent.getContent(), null); assertEquals("This is my second inline document", secondDocString);
@Test public void testNewTaskWithLargeContent() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),"; str += "name = 'This is my task name' })"; String largeContent = ""; for (int i = 0; i < 1000; i++) { largeContent += i + "xxxxxxxxx"; } ContentData data = ContentMarshallerHelper.marshal(null, largeContent, null); Task task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, data); long taskId = task.getId(); // Task should be assigned to the single potential owner and state set to Reserved Task task1 = taskService.getTaskById(taskId); assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType()); assertEquals("java.lang.String", task1.getTaskData().getDocumentType()); long contentId = task1.getTaskData().getDocumentContentId(); assertTrue(contentId != -1); Content content = taskService.getContentById(contentId); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null); assertEquals(largeContent, unmarshalledObject.toString()); xmlRoundTripContent(content); }
taskService.getContentById(contentId).getContent(), ksession.getEnvironment());
taskService.getContentById(contentId).getContent(), ksession.getEnvironment()); assertEquals("This is the content", data);