Skip to content

Commit

Permalink
Merge pull request #234 from valb3r/bugfix/FBP-233-documentation-elem…
Browse files Browse the repository at this point in the history
…ent-formatting

Bugfix/fbp 233 documentation element formatting
  • Loading branch information
valb3r authored Jul 17, 2021
2 parents 90cabe8 + cfedaef commit 939a3fd
Show file tree
Hide file tree
Showing 13 changed files with 462 additions and 27 deletions.
14 changes: 7 additions & 7 deletions activiti-intellij-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Activiti BPMN visualizer</name>

<!-- Plugin version -->
<version>0.4.6</version>
<version>0.4.6.1</version>

<!-- Unique identifier of the plugin. Cannot be changed between the plugin versions.
If not specified, assumed to be equal to <name>. -->
Expand Down Expand Up @@ -36,6 +36,12 @@
<!-- Description of changes in the latest version of the plugin. Displayed in the "Plugins" settings dialog and
in the plugin repository Web interface. -->
<change-notes><![CDATA[
<p>0.4.6.1:</p>
<ul>
<li>
Preserve &lt;documentation&gt; element formatting
</li>
</ul>
<p>0.4.6:</p>
<ul>
<li>
Expand Down Expand Up @@ -64,12 +70,6 @@
Jump through properties in table with TAB
</li>
</ul>
<p>0.4.4.1:</p>
<ul>
<li>
Hotfix for 'Template not found: Activiti BPMN 2.0 diagram' that prevents plugin to start
</li>
</ul>
]]></change-notes>

<!-- The vendor of the plugin. The optional "url" attribute specifies the URL of the vendor homepage.
Expand Down
1 change: 1 addition & 0 deletions activiti-xml-parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ apply plugin: 'kotlin-kapt'

dependencies {
api project(":xml-parser-api")
implementation project(":xml-parser-core")

implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.10.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import com.valb3r.bpmn.intellij.plugin.bpmn.api.events.*
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyValueType
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyValueType.*
import com.valb3r.bpmn.intellij.plugin.bpmn.parser.core.CustomizedXmlWriter
import org.dom4j.*
import org.dom4j.io.OutputFormat
import org.dom4j.io.SAXReader
import org.dom4j.io.XMLWriter
import java.awt.geom.Point2D
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -169,7 +169,7 @@ class ActivitiParser : BpmnParser {
val format = OutputFormat.createPrettyPrint()
format.isPadText = false
format.isNewLineAfterDeclaration = false
val writer = XMLWriter(os, format)
val writer = CustomizedXmlWriter(os, format)
writer.write(doc)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.valb3r.bpmn.intellij.plugin.activiti.parser

import com.valb3r.bpmn.intellij.plugin.activiti.parser.testevents.BpmnElementRemovedEvent
import com.valb3r.bpmn.intellij.plugin.activiti.parser.testevents.BpmnShapeObjectAddedEvent
import com.valb3r.bpmn.intellij.plugin.bpmn.api.BpmnProcessObject
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.WithParentId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.tasks.BpmnServiceTask
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.DiagramElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.BoundsElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.ShapeElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.events.EventPropagatableToXml
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBeNull
import org.junit.jupiter.api.Test

class XmlUpdateEventDocumentationFormatTest {

private val startEventId = "startevent1"
private val parentProcess = BpmnElementId("m40191.SBWS-CallActivity-PdfGenerator-MapParameter")
private val documentationProcessName = "documentation-element-formatting.bpmn20.xml"

private val parser = ActivitiParser()

@Test
fun `Parsing respects newline formatting`() {
val originalProcess = documentationProcessName.asResource()!!
val updated = parser.update(documentationProcessName.asResource()!!, listOf())
updated.count { it == '\n' }.shouldBeEqualTo(originalProcess.count { it == '\n' } + 1)
}

@Test
fun `New element is added with new line`() {
val originalProcess = documentationProcessName.asResource()!!
val testId = BpmnElementId("test")
val updated = parser.update(
documentationProcessName.asResource()!!, listOf(
BpmnShapeObjectAddedEvent(
WithParentId(
parentProcess,
BpmnServiceTask(
testId,
"test",
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
)
),
ShapeElement(DiagramElementId("id"), testId, BoundsElement(0.0f, 0.0f, 0.0f, 0.0f)),
emptyMap()
)
)
)

updated.count { it == '\n' }.shouldBeEqualTo(originalProcess.count { it == '\n' } + 5) // Shape + Diagram \n
}

@Test
fun `Removing element does not break 'documentation' element formatting`() {
val originalProcess = readProcess()
val updatedProcess = readAndUpdateProcess(BpmnElementRemovedEvent(BpmnElementId(startEventId)))
updatedProcess.process.body!!.scriptTask!![0].documentation
.shouldBeEqualTo(originalProcess.process.body!!.scriptTask!![0].documentation)
}

private fun readProcess(): BpmnProcessObject {
val process = parser.parse(documentationProcessName.asResource()!!)
process.shouldNotBeNull()
return process
}

private fun readAndUpdateProcess(event: EventPropagatableToXml): BpmnProcessObject {
val updated = parser.update(
documentationProcessName.asResource()!!,
listOf(event)
)

updated.shouldNotBeNull()

return parser.parse(updated)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="ELEKTRONISCHER_ANTRAG">
<process id="m40191.SBWS-CallActivity-PdfGenerator-MapParameter" name="SBWS-CallActivity-PdfGenerator-Map-Parameter" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<scriptTask id="sid-0152746A-45A2-485C-B831-B05EF4B71BC8" name="Evaluate Map" scriptFormat="groovy" activiti:autoStoreVariables="false">
<documentation>Subprocess to evaluate an incoming map.

In:
testMap - to be passed in by caller</documentation>
<script><![CDATA[log = org.slf4j.LoggerFactory.getLogger("com.example.EvaluateMap");
def map= execution.getVariable("testMap")
log.info(map)
log.info("${testMap}")]]></script>
</scriptTask>
<sequenceFlow id="sid-76A2706A-8FF4-4CF4-8EFE-15494A17A256" sourceRef="startevent1" targetRef="sid-0152746A-45A2-485C-B831-B05EF4B71BC8"></sequenceFlow>
<endEvent id="sid-85B92D35-1ACD-49D3-83F0-F5C63CD1ECA9"></endEvent>
<sequenceFlow id="sid-6F09B97C-576A-4157-B5C7-97F870886832" sourceRef="sid-0152746A-45A2-485C-B831-B05EF4B71BC8" targetRef="sid-85B92D35-1ACD-49D3-83F0-F5C63CD1ECA9"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_m40191.SBWS-CallActivity-PdfGenerator-MapParameter">
<bpmndi:BPMNPlane bpmnElement="m40191.SBWS-CallActivity-PdfGenerator-MapParameter" id="BPMNPlane_m40191.SBWS-CallActivity-PdfGenerator-MapParameter">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="30.0" width="30.0" x="142.0" y="85.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-0152746A-45A2-485C-B831-B05EF4B71BC8" id="BPMNShape_sid-0152746A-45A2-485C-B831-B05EF4B71BC8">
<omgdc:Bounds height="80.0" width="100.0" x="255.0" y="60.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-85B92D35-1ACD-49D3-83F0-F5C63CD1ECA9" id="BPMNShape_sid-85B92D35-1ACD-49D3-83F0-F5C63CD1ECA9">
<omgdc:Bounds height="28.0" width="28.0" x="400.0" y="86.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-6F09B97C-576A-4157-B5C7-97F870886832" id="BPMNEdge_sid-6F09B97C-576A-4157-B5C7-97F870886832">
<omgdi:waypoint x="355.0" y="100.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="100.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-76A2706A-8FF4-4CF4-8EFE-15494A17A256" id="BPMNEdge_sid-76A2706A-8FF4-4CF4-8EFE-15494A17A256">
<omgdi:waypoint x="172.0" y="100.0"></omgdi:waypoint>
<omgdi:waypoint x="255.0" y="100.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
23 changes: 7 additions & 16 deletions flowable-intellij-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Flowable BPMN visualizer</name>

<!-- Plugin version -->
<version>0.4.6</version>
<version>0.4.6.1</version>

<!-- Unique identifier of the plugin. Cannot be changed between the plugin versions.
If not specified, assumed to be equal to <name>. -->
Expand Down Expand Up @@ -36,6 +36,12 @@
<!-- Description of changes in the latest version of the plugin. Displayed in the "Plugins" settings dialog and
in the plugin repository Web interface. -->
<change-notes><![CDATA[
<p>0.4.6.1:</p>
<ul>
<li>
Preserve &lt;documentation&gt; element formatting
</li>
</ul>
<p>0.4.6:</p>
<ul>
<li>
Expand Down Expand Up @@ -64,21 +70,6 @@
Jump through properties in table with TAB
</li>
</ul>
<p>0.4.4.1:</p>
<ul>
<li>
Hotfix for 'Template not found: Flowable BPMN 2.0 diagram' that prevents plugin to start
</li>
</ul>
<p>0.4.4:</p>
<ul>
<li>
Fixed bug that boundary events and alike couldn't have attached sequence flow element
</li>
<li>
Fixed MismatchedInputException when parsing failedJobRetryTimeCycle
</li>
</ul>
]]></change-notes>

<!-- The vendor of the plugin. The optional "url" attribute specifies the URL of the vendor homepage.
Expand Down
1 change: 1 addition & 0 deletions flowable-xml-parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ apply plugin: 'kotlin-kapt'

dependencies {
api project(":xml-parser-api")
implementation project(":xml-parser-core")

implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.10.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import com.valb3r.bpmn.intellij.plugin.bpmn.api.events.*
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyValueType
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyValueType.*
import com.valb3r.bpmn.intellij.plugin.bpmn.parser.core.CustomizedXmlWriter
import com.valb3r.bpmn.intellij.plugin.flowable.parser.nodes.BpmnFile
import com.valb3r.bpmn.intellij.plugin.flowable.parser.nodes.DiagramNode
import com.valb3r.bpmn.intellij.plugin.flowable.parser.nodes.ProcessNode
import org.dom4j.*
import org.dom4j.io.OutputFormat
import org.dom4j.io.SAXReader
import org.dom4j.io.XMLWriter
import java.awt.geom.Point2D
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -177,7 +177,7 @@ class FlowableParser : BpmnParser {
val format = OutputFormat.createPrettyPrint()
format.isPadText = false
format.isNewLineAfterDeclaration = false
val writer = XMLWriter(os, format)
val writer = CustomizedXmlWriter(os, format)
writer.write(doc)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.valb3r.bpmn.intellij.plugin.flowable.parser

import com.valb3r.bpmn.intellij.plugin.bpmn.api.BpmnProcessObject
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.WithParentId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.tasks.BpmnServiceTask
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.DiagramElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.BoundsElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.ShapeElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.events.EventPropagatableToXml
import com.valb3r.bpmn.intellij.plugin.flowable.parser.testevents.BpmnElementRemovedEvent
import com.valb3r.bpmn.intellij.plugin.flowable.parser.testevents.BpmnShapeObjectAddedEvent
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBeNull
import org.junit.jupiter.api.Test

class XmlUpdateEventDocumentationFormatTest {

private val startEventId = "startevent1"
private val parentProcess = BpmnElementId("m40191.SBWS-CallActivity-PdfGenerator-MapParameter")
private val documentationProcessName = "documentation-element-formatting.bpmn20.xml"

private val parser = FlowableParser()

@Test
fun `Parsing respects newline formatting`() {
val originalProcess = documentationProcessName.asResource()!!
val updated = parser.update(documentationProcessName.asResource()!!, listOf())
updated.count { it == '\n' }.shouldBeEqualTo(originalProcess.count { it == '\n' } + 1)
}

@Test
fun `New element is added with new line`() {
val originalProcess = documentationProcessName.asResource()!!
val testId = BpmnElementId("test")
val updated = parser.update(
documentationProcessName.asResource()!!, listOf(
BpmnShapeObjectAddedEvent(
WithParentId(
parentProcess,
BpmnServiceTask(
testId,
"test",
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
)
),
ShapeElement(DiagramElementId("id"), testId, BoundsElement(0.0f, 0.0f, 0.0f, 0.0f)),
emptyMap()
)
)
)

updated.count { it == '\n' }.shouldBeEqualTo(originalProcess.count { it == '\n' } + 5) // Shape + Diagram \n
}

@Test
fun `Removing element does not break 'documentation' element formatting`() {
val originalProcess = readProcess()
val updatedProcess = readAndUpdateProcess(BpmnElementRemovedEvent(BpmnElementId(startEventId)))
updatedProcess.process.body!!.scriptTask!![0].documentation
.shouldBeEqualTo(originalProcess.process.body!!.scriptTask!![0].documentation)
}

private fun readProcess(): BpmnProcessObject {
val process = parser.parse(documentationProcessName.asResource()!!)
process.shouldNotBeNull()
return process
}

private fun readAndUpdateProcess(event: EventPropagatableToXml): BpmnProcessObject {
val updated = parser.update(
documentationProcessName.asResource()!!,
listOf(event)
)

updated.shouldNotBeNull()

return parser.parse(updated)
}
}
Loading

0 comments on commit 939a3fd

Please sign in to comment.