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.editor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
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.bpmn.model.BpmnModel;
import org.activiti.editor.language.json.converter.util.JsonConverterUtil;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.activiti.domain.editor.AbstractModel;
import com.activiti.domain.editor.AppDefinition;
import com.activiti.domain.editor.AppModelDefinition;
import com.activiti.domain.editor.Model;
import com.activiti.domain.editor.ModelHistory;
import com.activiti.domain.editor.ModelRelation;
import com.activiti.domain.editor.ModelRelationTypes;
import com.activiti.domain.idm.User;
import com.activiti.domain.runtime.AppRelation;
import com.activiti.domain.runtime.RuntimeAppDefinition;
import com.activiti.domain.runtime.RuntimeAppDeployment;
import com.activiti.repository.editor.ModelHistoryRepository;
import com.activiti.repository.editor.ModelRelationRepository;
import com.activiti.repository.runtime.AppRelationRepository;
import com.activiti.repository.runtime.RuntimeAppDefinitionRepository;
import com.activiti.repository.runtime.RuntimeAppDeploymentRepository;
import com.activiti.security.SecurityUtils;
import com.activiti.service.api.AppDefinitionService;
import com.activiti.service.api.DeploymentResult;
import com.activiti.service.api.DeploymentService;
import com.activiti.service.api.ModelService;
import com.activiti.service.exception.BadRequestException;
import com.activiti.service.exception.ConflictingRequestException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* Can't merge this with {@link AppDefinitionService}, as it doesn't have visibility of
* domain models needed to do the publication.
*
* @author jbarrez
*/
@Service
@Transactional
public class AppDefinitionPublishService {
private static final Logger logger = LoggerFactory.getLogger(AppDefinitionPublishService.class);
@Autowired
protected ModelInternalService modelInternalService;
@Autowired
protected ModelService modelService;
@Autowired
protected ModelHistoryRepository modelHistoryRepository;
@Autowired
protected ModelRelationRepository modelRelationRepository;
@Autowired
protected DeploymentService deploymentService;
@Autowired
protected AppRelationRepository appRelationRepository;
@Autowired
protected RepositoryService repositoryService;
@Autowired
protected RuntimeAppDeploymentRepository runtimeAppDeploymentRepository;
@Autowired
protected RuntimeAppDefinitionRepository runtimeAppDefinitionRepository;
@Autowired
protected ObjectMapper objectMapper;
public void publishAppDefinition(Long modelId, String comment, Model appDefinitionModel,
Long appDefinitionId, String appDefinitionName, String appDefinitionDescription, String appDefinitionJson,
User user, Boolean force) {
// First we have to check if the model we have can be deployed
validateAppModel(modelId, appDefinitionModel, appDefinitionId, appDefinitionJson, user, force);
// Create new version of the app model
modelInternalService.createNewModelVersion(appDefinitionModel, comment, user);
// Deploy the app model to be executable
DeploymentResult deploymentResult = deploymentService.updateAppDefinition(
appDefinitionId, appDefinitionName, appDefinitionDescription, appDefinitionJson, user);
// Create model history version of all related models
handleAppRelations(deploymentResult, appDefinitionId, appDefinitionDescription, appDefinitionJson);
}
protected void validateAppModel(Long appModelId, Model appDefinitionModel, Long appDefinitionId, String appDefinitionJson, User user,Boolean force) {
List modelRelations = modelRelationRepository.findByParentModelId(appModelId);
validateProcessDefinitionKeys(user, modelRelations);
// Force == true -> user has confirmed it's ok
if (force == null || force.equals(Boolean.FALSE)) {
validateModelUsage(appModelId, modelRelations);
}
}
private void validateProcessDefinitionKeys(User user, List modelRelations) {
Map allProcessDefinitionKeys = new HashMap();
List