Skip to content

Commit

Permalink
Merge branch 'master' into github
Browse files Browse the repository at this point in the history
  • Loading branch information
dofs197 committed Mar 29, 2021
2 parents 8544518 + 1a45160 commit f187f4b
Show file tree
Hide file tree
Showing 41 changed files with 776 additions and 271 deletions.
16 changes: 16 additions & 0 deletions wfe-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<!--spring.version>4.3.17.RELEASE</spring.version-->
<!--spring.version>5.0.6.RELEASE</spring.version-->
<querydsl.version>4.2.1</querydsl.version>
<jackson.version>2.5.5</jackson.version>
<project.build.cactus>false</project.build.cactus>
<maven.profile.jndi.name>java:global/runawfe/${jar.name}-${project.version}/${bean.name}!${interface.class.name}</maven.profile.jndi.name>
<maven.profile.hibernate.datasource>java:jboss/datasources/ExampleDS</maven.profile.hibernate.datasource>
Expand Down Expand Up @@ -298,6 +299,21 @@
<type>jar</type>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
*/
package ru.runa.wfe;

import javax.ejb.ApplicationException;

/**
* Signals about inappropriate application usage.
*
* @author Dofs
*/
@ApplicationException(rollback = true)
public class InternalApplicationException extends RuntimeException {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ public static boolean isDefinitionDeploymentWithEmptyCommentsAllowed() {
return RESOURCES.getBooleanProperty("definition.comments.empty.allowed", true);
}

public static boolean isDefinitionCompatibilityCheckEnabled() {
return RESOURCES.getBooleanProperty("definition.compatibility.check.enabled", true);
}

public static boolean isCheckProcessStartPermissions() {
return RESOURCES.getBooleanProperty("check.process.start.permissions", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ private void readTransitions(ProcessDefinition processDefinition, Element proces
}
Transition transition = new Transition();
transition.setNodeId(id);
GraphElement sourceElement = processDefinition.getGraphElementNotNull(from);
Node source = (Node) sourceElement;
Node source = processDefinition.getNodeNotNull(from);
transition.setFrom(source);
Node target = processDefinition.getNodeNotNull(to);
transition.setTo(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import ru.runa.wfe.InternalApplicationException;
import ru.runa.wfe.audit.AdminActionLog;
import ru.runa.wfe.audit.ProcessDefinitionDeleteLog;
Expand All @@ -42,6 +43,7 @@
import ru.runa.wfe.definition.ProcessDefinitionChange;
import ru.runa.wfe.definition.dto.WfDefinition;
import ru.runa.wfe.definition.par.ProcessArchive;
import ru.runa.wfe.definition.validation.DefinitionUpdateValidatorManager;
import ru.runa.wfe.execution.ParentProcessExistsException;
import ru.runa.wfe.execution.Process;
import ru.runa.wfe.execution.ProcessFilter;
Expand All @@ -66,6 +68,8 @@
* Created on 15.03.2005
*/
public class DefinitionLogic extends WfCommonLogic {
@Autowired
DefinitionUpdateValidatorManager definitionVersionValidatorManager;

public WfDefinition deployProcessDefinition(User user, byte[] processArchiveBytes, List<String> categories) {
permissionDao.checkAllowed(user, Permission.CREATE_DEFINITION, SecuredSingleton.SYSTEM);
Expand Down Expand Up @@ -171,6 +175,7 @@ public WfDefinition updateProcessDefinition(User user, Long definitionId, byte[]
+ " comments. Most likely you try to upload an old version of definition (page update is recommended). ");
}
}
definitionVersionValidatorManager.validate(getDefinition(deployment.getId()), uploadedDefinition);
deployment.setContent(uploadedDefinition.getDeployment().getContent());
deployment.setUpdateDate(new Date());
deployment.setUpdateActor(user.getActor());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package ru.runa.wfe.definition.par;

import com.google.common.base.Throwables;
import java.util.List;

import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;

import com.google.common.base.Throwables;

import ru.runa.wfe.commons.xml.XmlUtils;
import ru.runa.wfe.definition.FileDataProvider;
import ru.runa.wfe.definition.InvalidDefinitionException;
Expand All @@ -16,7 +13,6 @@
import ru.runa.wfe.lang.Node;
import ru.runa.wfe.lang.ProcessDefinition;
import ru.runa.wfe.lang.SubprocessDefinition;
import ru.runa.wfe.lang.SwimlaneDefinition;
import ru.runa.wfe.lang.Transition;

public class GraphXmlParser implements ProcessArchiveParser {
Expand Down Expand Up @@ -48,21 +44,25 @@ public void readFromArchive(ProcessArchive archive, ProcessDefinition processDef
List<Element> nodeElements = root.elements(NODE_ELEMENT);
for (Element nodeElement : nodeElements) {
String nodeId = nodeElement.attributeValue("name");
GraphElement graphElement = processDefinition.getGraphElementNotNull(nodeId);
graphElement.setGraphConstraints(Integer.parseInt(nodeElement.attributeValue("x")) - xOffset,
Integer.parseInt(nodeElement.attributeValue("y")) - yOffset, Integer.parseInt(nodeElement.attributeValue("width")),
Integer.parseInt(nodeElement.attributeValue("height")));
Node transitionSource;
if (graphElement instanceof Node) {
boolean minimizedView = Boolean.parseBoolean(nodeElement.attributeValue("minimizedView", "false"));
((Node) graphElement).setGraphMinimizedView(minimizedView);
transitionSource = (Node) graphElement;
GraphElement graphElement;
Node transitionSource = processDefinition.getNode(nodeId);
if (transitionSource != null) {
graphElement = transitionSource;
} else {
if (!(graphElement instanceof SwimlaneDefinition)) {
graphElement = processDefinition.getSwimlaneById(nodeId);
if (graphElement == null) {
LogFactory.getLog(getClass()).warn("Ignored graph element " + graphElement + " in " + processDefinition);
continue;
}
}
graphElement.setGraphConstraints(Integer.parseInt(nodeElement.attributeValue("x")) - xOffset,
Integer.parseInt(nodeElement.attributeValue("y")) - yOffset, Integer.parseInt(nodeElement.attributeValue("width")),
Integer.parseInt(nodeElement.attributeValue("height")));
if (transitionSource == null) {
continue;
}
boolean minimizedView = Boolean.parseBoolean(nodeElement.attributeValue("minimizedView", "false"));
transitionSource.setGraphMinimizedView(minimizedView);
List<Element> transitionElements = nodeElement.elements(TRANSITION_ELEMENT);
for (Element transitionElement : transitionElements) {
String transitionName = transitionElement.attributeValue("name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
package ru.runa.wfe.definition.par;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -30,18 +33,13 @@
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import ru.runa.wfe.commons.ApplicationContextFactory;
import ru.runa.wfe.definition.DefinitionArchiveFormatException;
import ru.runa.wfe.definition.Deployment;
import ru.runa.wfe.definition.FileDataProvider;
import ru.runa.wfe.lang.ProcessDefinition;
import ru.runa.wfe.lang.SubprocessDefinition;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams;

public class ProcessArchive {
private final Deployment deployment;
public static final List<String> UNSECURED_FILE_NAMES = Lists.newArrayList();
Expand All @@ -61,8 +59,8 @@ public class ProcessArchive {
processArchiveParsers.add(ApplicationContextFactory.autowireBean(new GraphXmlParser()));
processArchiveParsers.add(ApplicationContextFactory.autowireBean(new CommentsParser()));
}
private static final Pattern SUBPROCESS_DEFINITION_PATTERN = Pattern.compile(FileDataProvider.SUBPROCESS_DEFINITION_PREFIX + "(\\d*)."
+ FileDataProvider.PROCESSDEFINITION_XML_FILE_NAME);
private static final Pattern SUBPROCESS_DEFINITION_PATTERN = Pattern
.compile(FileDataProvider.SUBPROCESS_DEFINITION_PREFIX + "(\\d*)." + FileDataProvider.PROCESSDEFINITION_XML_FILE_NAME);

private final Map<String, byte[]> fileData = Maps.newHashMap();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.runa.wfe.definition.validation;

/**
* @author azyablin
*/
public interface DefinitionUpdateValidator {

void validate(DeploymentUpdateData deploymentUpdateData);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ru.runa.wfe.definition.validation;

import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.runa.wfe.commons.SystemProperties;
import ru.runa.wfe.commons.TimeMeasurer;
import ru.runa.wfe.execution.Process;
import ru.runa.wfe.execution.ProcessFilter;
import ru.runa.wfe.execution.dao.ProcessDao;
import ru.runa.wfe.lang.ProcessDefinition;

/**
* @author azyablin
*/
@Component
public class DefinitionUpdateValidatorManager {
private static final Log log = LogFactory.getLog(DefinitionUpdateValidatorManager.class);
@Autowired
private List<DefinitionUpdateValidator> validators;
@Autowired
private ProcessDao processDao;

public void validate(ProcessDefinition oldDefinition, ProcessDefinition newDefinition) {
if (!SystemProperties.isDefinitionCompatibilityCheckEnabled()) {
return;
}
TimeMeasurer timeMeasurer = new TimeMeasurer(log);
timeMeasurer.jobStarted();
ProcessFilter filter = new ProcessFilter();
filter.setDefinitionName(oldDefinition.getName());
filter.setDefinitionVersion(oldDefinition.getDeployment().getVersion());
filter.setFinished(false);
List<Process> processes = processDao.getProcesses(filter);
timeMeasurer.jobEnded("Loading " + processes.size() + " active processes");
timeMeasurer.jobStarted();
validate(oldDefinition, newDefinition, processes);
timeMeasurer.jobEnded("Validation of " + oldDefinition);
}

public void validate(ProcessDefinition oldDefinition, ProcessDefinition newDefinition, Process process) {
if (!SystemProperties.isDefinitionCompatibilityCheckEnabled()) {
return;
}
validate(oldDefinition, newDefinition, Collections.singletonList(process));
}

private void validate(ProcessDefinition oldDefinition, ProcessDefinition newDefinition, List<Process> processes) {
DeploymentUpdateData deploymentUpdateData = new DeploymentUpdateData(oldDefinition, newDefinition, processes);
for (DefinitionUpdateValidator validator : validators) {
validator.validate(deploymentUpdateData);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.runa.wfe.definition.validation;

import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import ru.runa.wfe.execution.Process;
import ru.runa.wfe.lang.ProcessDefinition;

/**
* Contains information about old and new definition for process definition compatibility check.
*
* @author azyablin
*/
@RequiredArgsConstructor
@Getter
@Setter
public class DeploymentUpdateData {
private final ProcessDefinition oldDefinition;
private final ProcessDefinition newDefinition;
private final List<Process> processes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.runa.wfe.definition.validation;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import ru.runa.wfe.InternalApplicationException;

/**
* @author azyablin
*/
@RequiredArgsConstructor
@Getter
@ToString
public class ProcessDefinitionNotCompatibleException extends InternalApplicationException {
public static final String NODE_EXISTENCE = "node.existence";
public static final String PARALLEL_GATEWAY_MISTYPED = "parallel.gateway.mistyped";
public static final String PARALLEL_GATEWAY_TRANSITIONS = "parallel.gateway.transitions";
private static final long serialVersionUID = 1L;
private final String type;
private final String[] args;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.runa.wfe.definition.validation.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.runa.wfe.definition.validation.DefinitionUpdateValidator;
import ru.runa.wfe.definition.validation.DeploymentUpdateData;
import ru.runa.wfe.definition.validation.ProcessDefinitionNotCompatibleException;
import ru.runa.wfe.execution.Token;
import ru.runa.wfe.execution.dao.TokenDao;

/**
* Checks that all nodes with tokens in active processes exist in new process definition.
*
* @author azyablin
*/
@Component
public class NodeExistenceDefinitionUpdateValidator implements DefinitionUpdateValidator {
@Autowired
TokenDao tokenDao;

@Override
public void validate(DeploymentUpdateData deploymentUpdateData) {
for (ru.runa.wfe.execution.Process process : deploymentUpdateData.getProcesses()) {
for (Token token : tokenDao.findByProcessAndExecutionStatusIsNotEnded(process)) {
String nodeId = token.getNodeId();
if (deploymentUpdateData.getNewDefinition().getNode(nodeId) == null) {
throw new ProcessDefinitionNotCompatibleException(ProcessDefinitionNotCompatibleException.NODE_EXISTENCE,
new String[] { nodeId, token.getProcess().getId().toString() });
}
}
}
}

}
Loading

0 comments on commit f187f4b

Please sign in to comment.