提交 0a4f4f34 编写于 作者: T Tijs Rademakers

Remove standalone tasks from REST and add custom form types to REST webapp

上级 806b5143
/* 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();
}
}
/* 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();
}
}
/* 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;
}
}
......@@ -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<User> users = identityService.createUserQuery().list();
List<Group> 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();
......
......@@ -41,6 +41,13 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/t
<property name="mailServerHost" value="localhost" />
<property name="mailServerPort" value="5025" />
<property name="jobExecutorActivate" value="false" />
<property name="customFormTypes">
<list>
<bean class="org.activiti.rest.form.UserFormType"/>
<bean class="org.activiti.rest.form.ProcessDefinitionFormType"/>
<bean class="org.activiti.rest.form.MonthFormType"/>
</list>
</property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册