use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project Activiti by Activiti.
the class CachingAndArtifactsManager method updateCachingAndArtifacts.
/**
* Ensures that the process definition is cached in the appropriate places, including the
* deployment's collection of deployed artifacts and the deployment manager's cache, as well
* as caching any ProcessDefinitionInfos.
*/
public void updateCachingAndArtifacts(ParsedDeployment parsedDeployment) {
CommandContext commandContext = Context.getCommandContext();
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = processEngineConfiguration.getDeploymentManager().getProcessDefinitionCache();
DeploymentEntity deployment = parsedDeployment.getDeployment();
for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
BpmnModel bpmnModel = parsedDeployment.getBpmnModelForProcessDefinition(processDefinition);
Process process = parsedDeployment.getProcessModelForProcessDefinition(processDefinition);
ProcessDefinitionCacheEntry cacheEntry = new ProcessDefinitionCacheEntry(processDefinition, bpmnModel, process);
processDefinitionCache.add(processDefinition.getId(), cacheEntry);
addDefinitionInfoToCache(processDefinition, processEngineConfiguration, commandContext);
// Add to deployment for further usage
deployment.addDeployedArtifact(processDefinition);
}
}
use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project Activiti by Activiti.
the class TimerStartEventJobHandler method execute.
public void execute(JobEntity job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
ProcessDefinitionEntity processDefinitionEntity = ProcessDefinitionUtil.getProcessDefinitionFromDatabase(// From DB -> need to get latest suspended state
job.getProcessDefinitionId());
if (processDefinitionEntity == null) {
throw new ActivitiException("Could not find process definition needed for timer start event");
}
try {
if (!processDefinitionEntity.isSuspended()) {
if (commandContext.getEventDispatcher().isEnabled()) {
commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_FIRED, job));
}
// Find initial flow element matching the signal start event
org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(job.getProcessDefinitionId());
String activityId = TimerEventHandler.getActivityIdFromConfiguration(configuration);
if (activityId != null) {
FlowElement flowElement = process.getFlowElement(activityId, true);
if (flowElement == null) {
throw new ActivitiException("Could not find matching FlowElement for activityId " + activityId);
}
ProcessInstanceHelper processInstanceHelper = commandContext.getProcessEngineConfiguration().getProcessInstanceHelper();
processInstanceHelper.createAndStartProcessInstanceWithInitialFlowElement(processDefinitionEntity, null, null, flowElement, process, null, null, true);
} else {
new StartProcessInstanceCmd(processDefinitionEntity.getKey(), null, null, null, job.getTenantId()).execute(commandContext);
}
} else {
log.debug("ignoring timer of suspended process definition {}", processDefinitionEntity.getName());
}
} catch (RuntimeException e) {
log.error("exception during timer execution", e);
throw e;
} catch (Exception e) {
log.error("exception during timer execution", e);
throw new ActivitiException("exception during timer execution: " + e.getMessage(), e);
}
}
use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method getProcessDefinitions.
@Override
public CollectionWithPagingInfo<ProcessDefinition> getProcessDefinitions(Parameters parameters) {
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionCategoryNotEquals(WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL);
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(PROCESS_DEFINITION_COLLECTION_EQUALS_QUERY_PROPERTIES, PROCESS_DEFINITION_COLLECTION_MATCHES_QUERY_PROPERTIES);
boolean keyQueryIncluded = false;
if (parameters.getQuery() != null) {
QueryHelper.walk(parameters.getQuery(), propertyWalker);
// Property equals
String categoryProperty = propertyWalker.getProperty("category", WhereClauseParser.EQUALS);
if (categoryProperty != null) {
query.processDefinitionCategory(categoryProperty);
}
String keyProperty = propertyWalker.getProperty("key", WhereClauseParser.EQUALS);
if (keyProperty != null) {
query.processDefinitionKey(getProcessDefinitionKey(keyProperty));
keyQueryIncluded = true;
}
String nameProperty = propertyWalker.getProperty("name", WhereClauseParser.EQUALS);
if (nameProperty != null) {
query.processDefinitionName(nameProperty);
}
Integer versionProperty = propertyWalker.getProperty("version", WhereClauseParser.EQUALS, Integer.class);
if (versionProperty != null) {
query.processDefinitionVersion(versionProperty);
}
String deploymentProperty = propertyWalker.getProperty("deploymentId", WhereClauseParser.EQUALS);
if (deploymentProperty != null) {
query.deploymentId(deploymentProperty);
}
// Property matches
String categoryMatchesProperty = propertyWalker.getProperty("category", WhereClauseParser.MATCHES);
if (categoryMatchesProperty != null) {
query.processDefinitionCategoryLike(categoryMatchesProperty);
}
String keyMatchesProperty = propertyWalker.getProperty("key", WhereClauseParser.MATCHES);
if (keyMatchesProperty != null) {
query.processDefinitionKeyLike(getProcessDefinitionKey(keyMatchesProperty));
keyQueryIncluded = true;
}
String nameLikeProperty = propertyWalker.getProperty("name", WhereClauseParser.MATCHES);
if (nameLikeProperty != null) {
query.processDefinitionNameLike(nameLikeProperty);
}
}
// Filter based on tenant, if required
if (keyQueryIncluded == false && tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one orderBy parameter is supported");
}
sortColumn = sortList.get(0);
switch(sortColumn.column) {
case "id":
query.orderByProcessDefinitionId();
break;
case "deploymentId":
query.orderByDeploymentId();
break;
case "key":
query.orderByProcessDefinitionKey();
break;
case "category":
query.orderByProcessDefinitionCategory();
break;
case "version":
query.orderByProcessDefinitionVersion();
break;
case "name":
query.orderByProcessDefinitionName();
break;
default:
throw new InvalidArgumentException("OrderBy " + sortColumn.column + " is not supported, supported items are " + PROCESS_DEFINITION_COLLECTION_SORT_PROPERTIES);
}
if (sortColumn.asc) {
query.asc();
} else {
query.desc();
}
} else {
query.orderByProcessDefinitionId().asc();
}
List<org.activiti.engine.repository.ProcessDefinition> processDefinitions = query.listPage(parameters.getPaging().getSkipCount(), parameters.getPaging().getMaxItems());
int totalCount = (int) query.count();
List<ProcessDefinition> page = new ArrayList<ProcessDefinition>(processDefinitions.size());
for (org.activiti.engine.repository.ProcessDefinition processDefinition : processDefinitions) {
page.add(createProcessDefinitionRest((ProcessDefinitionEntity) processDefinition));
}
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), page, (page.size() + parameters.getPaging().getSkipCount()) < totalCount, totalCount);
}
use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project Activiti by Activiti.
the class ProcessInstanceDetailPanel method addProcessImage.
protected void addProcessImage() {
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
// Only show when graphical notation is defined
if (processDefinitionEntity != null) {
boolean didDrawImage = false;
if (ExplorerApp.get().isUseJavascriptDiagram()) {
try {
final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
if (!bpmnModel.getFlowLocationMap().isEmpty()) {
int maxX = 0;
int maxY = 0;
for (String key : bpmnModel.getLocationMap().keySet()) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
double elementX = graphicInfo.getX() + graphicInfo.getWidth();
if (maxX < elementX) {
maxX = (int) elementX;
}
double elementY = graphicInfo.getY() + graphicInfo.getHeight();
if (maxY < elementY) {
maxY = (int) elementY;
}
}
// using panel for scrollbars
Panel imagePanel = new Panel();
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight(100, UNITS_PERCENTAGE);
URL explorerURL = ExplorerApp.get().getURL();
URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId() + "&processInstanceId=" + processInstance.getId());
Embedded browserPanel = new Embedded("", new ExternalResource(url));
browserPanel.setType(Embedded.TYPE_BROWSER);
browserPanel.setWidth(maxX + 350 + "px");
browserPanel.setHeight(maxY + 220 + "px");
HorizontalLayout panelLayoutT = new HorizontalLayout();
panelLayoutT.setSizeUndefined();
imagePanel.setContent(panelLayoutT);
imagePanel.addComponent(browserPanel);
panelLayout.addComponent(imagePanel);
didDrawImage = true;
}
} catch (Exception e) {
LOGGER.error("Error loading process diagram component", e);
}
}
if (!didDrawImage && processDefinitionEntity.isGraphicalNotationDefined()) {
ProcessEngineConfiguration processEngineConfiguration = ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processInstance, repositoryService, runtimeService, diagramGenerator, processEngineConfiguration);
if (diagram != null) {
Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
header.addStyleName(ExplorerLayout.STYLE_H3);
header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
panelLayout.addComponent(header);
Embedded embedded = new Embedded(null, diagram);
embedded.setType(Embedded.TYPE_IMAGE);
embedded.setSizeUndefined();
// using panel for scrollbars
Panel imagePanel = new Panel();
imagePanel.setScrollable(true);
imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
imagePanel.setWidth(100, UNITS_PERCENTAGE);
imagePanel.setHeight(100, UNITS_PERCENTAGE);
HorizontalLayout panelLayoutT = new HorizontalLayout();
panelLayoutT.setSizeUndefined();
imagePanel.setContent(panelLayoutT);
imagePanel.addComponent(embedded);
panelLayout.addComponent(imagePanel);
}
}
}
}
use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project Activiti by Activiti.
the class ProcessInstanceHighlightsResource method getHighlighted.
@RequestMapping(value = "/process-instance/{processInstanceId}/highlights", method = RequestMethod.GET, produces = "application/json")
public ObjectNode getHighlighted(@PathVariable String processInstanceId) {
ObjectNode responseJSON = objectMapper.createObjectNode();
responseJSON.put("processInstanceId", processInstanceId);
ArrayNode activitiesArray = objectMapper.createArrayNode();
ArrayNode flowsArray = objectMapper.createArrayNode();
try {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
responseJSON.put("processDefinitionId", processInstance.getProcessDefinitionId());
List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
List<String> highLightedFlows = getHighLightedFlows(processDefinition, processInstanceId);
for (String activityId : highLightedActivities) {
activitiesArray.add(activityId);
}
for (String flow : highLightedFlows) {
flowsArray.add(flow);
}
} catch (Exception e) {
e.printStackTrace();
}
responseJSON.put("activities", activitiesArray);
responseJSON.put("flows", flowsArray);
return responseJSON;
}
Aggregations