From 0a4f4f346ccc31b793060c9630b1c1554bb7501c Mon Sep 17 00:00:00 2001 From: Tijs Rademakers Date: Fri, 29 Nov 2013 10:37:56 +0100 Subject: [PATCH] Remove standalone tasks from REST and add custom form types to REST webapp --- .../org/activiti/rest/form/MonthFormType.java | 43 +++++++++++++ .../rest/form/ProcessDefinitionFormType.java | 63 +++++++++++++++++++ .../org/activiti/rest/form/UserFormType.java | 57 +++++++++++++++++ .../rest/service/demo/DemoDataGenerator.java | 33 ---------- .../src/main/resources/activiti-context.xml | 7 +++ 5 files changed, 170 insertions(+), 33 deletions(-) create mode 100644 modules/activiti-rest/src/main/java/org/activiti/rest/form/MonthFormType.java create mode 100644 modules/activiti-rest/src/main/java/org/activiti/rest/form/ProcessDefinitionFormType.java create mode 100644 modules/activiti-rest/src/main/java/org/activiti/rest/form/UserFormType.java diff --git a/modules/activiti-rest/src/main/java/org/activiti/rest/form/MonthFormType.java b/modules/activiti-rest/src/main/java/org/activiti/rest/form/MonthFormType.java new file mode 100644 index 0000000000..1c4b489ef0 --- /dev/null +++ b/modules/activiti-rest/src/main/java/org/activiti/rest/form/MonthFormType.java @@ -0,0 +1,43 @@ +/* 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.activiti.rest.form; + +import org.activiti.engine.form.AbstractFormType; + + +/** + * @author Joram Barrez + */ +public class MonthFormType extends AbstractFormType { + + public static final String TYPE_NAME = "month"; + + public String getName() { + return TYPE_NAME; + } + + @Override + public Object convertFormValueToModelValue(String propertyValue) { + Integer month = Integer.valueOf(propertyValue); + return month; + } + + @Override + public String convertModelValueToFormValue(Object modelValue) { + if (modelValue == null) { + return null; + } + return modelValue.toString(); + } +} diff --git a/modules/activiti-rest/src/main/java/org/activiti/rest/form/ProcessDefinitionFormType.java b/modules/activiti-rest/src/main/java/org/activiti/rest/form/ProcessDefinitionFormType.java new file mode 100644 index 0000000000..179a2975fe --- /dev/null +++ b/modules/activiti-rest/src/main/java/org/activiti/rest/form/ProcessDefinitionFormType.java @@ -0,0 +1,63 @@ +/* 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.activiti.rest.form; + +import org.activiti.engine.ActivitiIllegalArgumentException; +import org.activiti.engine.ActivitiObjectNotFoundException; +import org.activiti.engine.ProcessEngines; +import org.activiti.engine.form.AbstractFormType; +import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity; +import org.activiti.engine.repository.ProcessDefinition; + + +/** + * @author Joram Barrez + */ +public class ProcessDefinitionFormType extends AbstractFormType { + + public static final String TYPE_NAME = "processDefinition"; + + public String getName() { + return TYPE_NAME; + } + + @Override + public Object convertFormValueToModelValue(String propertyValue) { + if(propertyValue != null) { + ProcessDefinition processDefinition = ProcessEngines.getDefaultProcessEngine() + .getRepositoryService() + .createProcessDefinitionQuery() + .processDefinitionId(propertyValue) + .singleResult(); + + if(processDefinition == null) { + throw new ActivitiObjectNotFoundException("Process definition with id " + propertyValue + " does not exist", ProcessDefinitionEntity.class); + } + + return processDefinition; + } + return null; + } + + @Override + public String convertModelValueToFormValue(Object modelValue) { + if (modelValue == null) { + return null; + } + if (!(modelValue instanceof ProcessDefinition)) { + throw new ActivitiIllegalArgumentException("This form type only support process definitions, but is " + modelValue.getClass()); + } + return ((ProcessDefinition) modelValue).getId(); + } +} diff --git a/modules/activiti-rest/src/main/java/org/activiti/rest/form/UserFormType.java b/modules/activiti-rest/src/main/java/org/activiti/rest/form/UserFormType.java new file mode 100644 index 0000000000..82fdc5ee14 --- /dev/null +++ b/modules/activiti-rest/src/main/java/org/activiti/rest/form/UserFormType.java @@ -0,0 +1,57 @@ +/* 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.activiti.rest.form; + +import org.activiti.engine.ActivitiObjectNotFoundException; +import org.activiti.engine.ProcessEngines; +import org.activiti.engine.form.AbstractFormType; +import org.activiti.engine.identity.User; + + +/** + * Form type that holds an ID of a user. + * + * @author 'Frederik Heremans' + */ +public class UserFormType extends AbstractFormType { + + public static final String TYPE_NAME = "user"; + + public String getName() { + return TYPE_NAME; + } + + @Override + public Object convertFormValueToModelValue(String propertyValue) { + // Check if user exists + if(propertyValue != null) { + // TODO: perhaps better wiring mechanism for service + long count = ProcessEngines.getDefaultProcessEngine() + .getIdentityService() + .createUserQuery() + .userId(propertyValue).count(); + + if(count == 0) { + throw new ActivitiObjectNotFoundException("User " + propertyValue + " does not exist", User.class); + } + return propertyValue; + } + return null; + } + + @Override + public String convertModelValueToFormValue(Object modelValue) { + return (String) modelValue; + } +} diff --git a/modules/activiti-rest/src/main/java/org/activiti/rest/service/demo/DemoDataGenerator.java b/modules/activiti-rest/src/main/java/org/activiti/rest/service/demo/DemoDataGenerator.java index ed86dfae5e..0e58486564 100644 --- a/modules/activiti-rest/src/main/java/org/activiti/rest/service/demo/DemoDataGenerator.java +++ b/modules/activiti-rest/src/main/java/org/activiti/rest/service/demo/DemoDataGenerator.java @@ -29,7 +29,6 @@ import org.activiti.engine.identity.User; import org.activiti.engine.impl.util.IoUtil; import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.Model; -import org.activiti.engine.task.Task; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.node.ObjectNode; @@ -74,9 +73,6 @@ public class DemoDataGenerator implements ModelDataJsonConstants { LOGGER.info("Initializing demo models"); initDemoModelData(); } - - initDemoStandaloneTasks(); - } public void setProcessEngine(ProcessEngine processEngine) { @@ -228,35 +224,6 @@ protected void initDemoProcessDefinitions() { } } - protected void initDemoStandaloneTasks() { - - List users = identityService.createUserQuery().list(); - List groups = identityService.createGroupQuery().groupType("assignment").list(); - Random random = new Random(); - - String loremIpsum = "Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et " + - "dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat" + - " Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat " + - "cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum"; - String[] words = loremIpsum.split(" "); - - for (int i=0; i<100; i++) { - - Task task = taskService.newTask(); - task.setName(randomSentence(words, 6)); - task.setDescription(randomSentence(words, 15)); - taskService.saveTask(task); - - if (random.nextBoolean()) { - taskService.setAssignee(task.getId(), users.get(random.nextInt(users.size())).getId()); - } else { - taskService.addCandidateGroup(task.getId(), groups.get(random.nextInt(groups.size())).getId()); - } - - } - - } - protected String randomSentence(String[] words, int length) { Random random = new Random(); StringBuilder strb = new StringBuilder(); diff --git a/modules/activiti-webapp-rest2/src/main/resources/activiti-context.xml b/modules/activiti-webapp-rest2/src/main/resources/activiti-context.xml index f2e2bbe0b6..266664fc00 100644 --- a/modules/activiti-webapp-rest2/src/main/resources/activiti-context.xml +++ b/modules/activiti-webapp-rest2/src/main/resources/activiti-context.xml @@ -41,6 +41,13 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/t + + + + + + + -- GitLab