Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Activiti app component part of the Activiti project
* Copyright 2005-2015 Alfresco Software, Ltd. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.activiti.service.runtime;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.impl.HistoricVariableInstanceQueryImpl;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.Task;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.activiti.domain.idm.Group;
import com.activiti.domain.idm.User;
import com.activiti.domain.runtime.Form;
import com.activiti.domain.runtime.RelatedContent;
import com.activiti.domain.runtime.RuntimeAppDeployment;
import com.activiti.domain.runtime.SubmittedForm;
import com.activiti.exception.FormValidationException;
import com.activiti.model.component.SimpleContentTypeMapper;
import com.activiti.model.editor.form.FormDefinitionRepresentation;
import com.activiti.model.editor.form.FormFieldRepresentation;
import com.activiti.model.editor.form.FormFieldTypes;
import com.activiti.model.idm.LightGroupRepresentation;
import com.activiti.model.idm.LightUserRepresentation;
import com.activiti.model.runtime.ProcessInstanceVariableRepresentation;
import com.activiti.model.runtime.RelatedContentRepresentation;
import com.activiti.repository.runtime.FormRepository;
import com.activiti.repository.runtime.RuntimeAppDeploymentRepository;
import com.activiti.repository.runtime.SubmittedFormRepository;
import com.activiti.security.SecurityUtils;
import com.activiti.service.api.GroupHierarchyCache;
import com.activiti.service.api.UserCache;
import com.activiti.service.api.UserCache.CachedUser;
import com.activiti.service.exception.InternalServerErrorException;
import com.activiti.service.exception.NotFoundException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.util.ISO8601Utils;
/**
* @author Joram Barrez
*/
@Service
@Transactional
public class FormProcessingServiceImpl implements FormProcessingService {
private static final Logger logger = LoggerFactory.getLogger(FormProcessingServiceImpl.class);
private static final int CONTENT_FETCH_PAGE_SIZE = 50;
@Autowired
protected TaskService taskService;
@Autowired
protected FormService formService;
@Autowired
protected RuntimeService runtimeService;
@Autowired
protected HistoryService historyService;
@Autowired
protected FormStoreService formStoreService;
@Autowired
protected RelatedContentService relatedContentService;
@Autowired
protected PermissionService permissionService;
@Autowired
protected RepositoryService repositoryService;
@Autowired
protected SubmittedFormRepository submittedFormRepository;
@Autowired
protected FormRepository formRepository;
@Autowired
protected RuntimeAppDeploymentRepository runtimeAppDeploymentRepository;
@Autowired
protected ObjectMapper objectMapper;
@Autowired
protected SimpleContentTypeMapper contentTypeMapper;
@Autowired
protected UserCache userCache;
@Autowired
protected GroupHierarchyCache groupCache;
@Override
public Form getTaskForm(String taskId) {
// TODO: this could be optimized, but needs an Activiti change:
// better would be if the formkey is directly stored on the Task in the db
// and returned with the query.
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) {
return null;
}
String formKey = formService.getTaskFormKey(task.getProcessDefinitionId(), task.getTaskDefinitionKey());
if (formKey == null) {
return null;
}
return formStoreService.getForm(formKey);
}
@Override
public Form getStartForm(String processDefinitionId) {
Form result = null;
String formKey = formService.getStartFormKey(processDefinitionId);
if (formKey != null) {
result = formStoreService.getForm(formKey);
}
return result;
}
@Override
public SubmittedFormVariables getVariablesFromFormSubmission(Form form, FormDefinitionRepresentation definition,
Map values, String outcome, ObjectNode submittedFormValuesJson) {
SubmittedFormVariables result = new SubmittedFormVariables();
// When no values are given, use an empty map to ensure validation is performed
// (eg. for required fields)
if (values == null) {
values = Collections.emptyMap();
}
// Loop over all form fields and see if a value was provided
Map fieldMap = definition.allFieldsAsMap();
Map variables = new HashMap();
ObjectNode valuesNode = objectMapper.createObjectNode();
submittedFormValuesJson.put("values", valuesNode);
for (String fieldId : fieldMap.keySet()) {
Object variableValue = null;
FormFieldRepresentation formField = fieldMap.get(fieldId);
if (FormFieldTypes.READONLY_TEXT.equals(formField.getType()) || FormFieldTypes.CONTAINER.equals(formField.getType()) || FormFieldTypes.GROUP.equals(formField.getType())) {
continue;
}
if (FormFieldTypes.READONLY.equals(formField.getType())) {
boolean displayEditableField = false;
Object tableEditable = formField.getParam("tableEditable");
Object documentsEditable = formField.getParam("documentsEditable");
if (tableEditable != null && Boolean.valueOf(tableEditable.toString())) {
displayEditableField = true;
}
if (documentsEditable != null && Boolean.valueOf(documentsEditable.toString())) {
displayEditableField = true;
}
if (displayEditableField == false) {
continue;
}
}
if (values.containsKey(fieldId)) {
variableValue = transformFormFieldValueToVariableValue(formField, values.get(fieldId), result, valuesNode);
variables.put(formField.getId(), variableValue);
}
if (formField.isRequired() && variableValue == null && !FormFieldTypes.UPLOAD.equals(formField.getType())) {
throw new FormValidationException("Form field " + formField.getId() + " is required, but no value was found");
}
}
// Handle outcomes
if (outcome != null) {
String targetVariable = "form" + form.getId() + "outcome";
if (definition.getOutcomeTarget() != null) {
targetVariable = definition.getOutcomeTarget();
}
variables.put(targetVariable, outcome);
submittedFormValuesJson.put("outcome", outcome);
}
result.setVariables(variables);
return result;
}
@Override
public List