From 3ae0f65baeebd49d65cf028af7a31ceb1c968c19 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 15:21:30 +0100 Subject: [PATCH 01/22] flows --- .gitignore | 2 ++ pom.xml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 068ccfe..ea50b79 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ target/classes/* *.class test-report*.xml /target/ +.idea* +.DS_Store diff --git a/pom.xml b/pom.xml index 559b301..9f87fc5 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ commons-io 2.5 + + junit + junit + 4.12 + From 8821fa6ce2c9ded5284b6cd8ab88c150c96322d9 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 17:06:17 +0100 Subject: [PATCH 02/22] updates --- .classpath | 1 + .gitignore | 1 + .settings/org.eclipse.jdt.core.prefs | 7 +- pom.xml | 4 +- .../spaceheroes/task/DeactivateFlowsTask.java | 5 ++ .../com/spaceheroes/task/RunTestsTask.java | 6 +- .../java/com/spaceheroes/util/FlowUtils.java | 77 +++++++++++++++++++ .../spaceheroes/{ => xml}/junit/TestCase.java | 2 +- .../{ => xml}/junit/TestFailure.java | 2 +- .../{ => xml}/junit/TestSuite.java | 2 +- .../spaceheroes/xml/sfdc/FlowDefinition.java | 17 ++++ .../com/spaceheroes/xml/sfdc/Manifest.java | 47 +++++++++++ .../spaceheroes/xml/sfdc/ManifestType.java | 49 ++++++++++++ src/main/main.iml | 11 +++ src/test/java/TestRun.java | 26 +++++++ src/test/test.iml | 12 +++ 16 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java create mode 100644 src/main/java/com/spaceheroes/util/FlowUtils.java rename src/main/java/com/spaceheroes/{ => xml}/junit/TestCase.java (96%) rename src/main/java/com/spaceheroes/{ => xml}/junit/TestFailure.java (94%) rename src/main/java/com/spaceheroes/{ => xml}/junit/TestSuite.java (97%) create mode 100644 src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java create mode 100644 src/main/java/com/spaceheroes/xml/sfdc/Manifest.java create mode 100644 src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java create mode 100644 src/main/main.iml create mode 100644 src/test/java/TestRun.java create mode 100644 src/test/test.iml diff --git a/.classpath b/.classpath index 3686ca4..333eeaf 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + diff --git a/.gitignore b/.gitignore index ea50b79..9084317 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ test-report*.xml /target/ .idea* .DS_Store +package.xml diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 8e4055a..6b5aebc 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,13 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/pom.xml b/pom.xml index 9f87fc5..b217ea9 100644 --- a/pom.xml +++ b/pom.xml @@ -74,8 +74,8 @@ maven-compiler-plugin 3.0 - 1.5 - 1.5 + 1.7 + 1.7 diff --git a/src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java b/src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java new file mode 100644 index 0000000..a06b173 --- /dev/null +++ b/src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java @@ -0,0 +1,5 @@ +package com.spaceheroes.task; + +public class DeactivateFlowsTask extends SalesforceTask { + +} diff --git a/src/main/java/com/spaceheroes/task/RunTestsTask.java b/src/main/java/com/spaceheroes/task/RunTestsTask.java index 0c0371a..59394c0 100644 --- a/src/main/java/com/spaceheroes/task/RunTestsTask.java +++ b/src/main/java/com/spaceheroes/task/RunTestsTask.java @@ -16,10 +16,10 @@ import com.sforce.soap.apex.RunTestsResult; import com.sforce.soap.apex.SoapConnection; import com.sforce.ws.ConnectionException; -import com.spaceheroes.junit.TestCase; -import com.spaceheroes.junit.TestFailure; -import com.spaceheroes.junit.TestSuite; import com.spaceheroes.util.ConnectionFactory; +import com.spaceheroes.xml.junit.TestCase; +import com.spaceheroes.xml.junit.TestFailure; +import com.spaceheroes.xml.junit.TestSuite; public class RunTestsTask extends SalesforceTask { diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java new file mode 100644 index 0000000..0b6013a --- /dev/null +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -0,0 +1,77 @@ +package com.spaceheroes.util; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.simpleframework.xml.Serializer; +import org.simpleframework.xml.core.Persister; + +import com.spaceheroes.xml.sfdc.FlowDefinition; +import com.spaceheroes.xml.sfdc.Manifest; +import com.spaceheroes.xml.sfdc.ManifestType; + +public class FlowUtils { + + public static void createFlowInactivationPack(List flowNames) throws IOException { + createFlowDefinitionManifest(flowNames); + for (String flowName : flowNames) { + createInactiveDefinition(flowName); + } + } + + public static File createFlowDefinitionManifest(List flowNames) throws IOException { + Serializer serializer = new Persister(); + File source = new File("package.xml"); + FileUtils.forceMkdirParent(source); + Manifest m = new Manifest(); + ManifestType mt = new ManifestType("FlowDefinition"); + for (String name : flowNames) { + mt.addMember(name); + } + m.addType(mt); + try { + serializer.write(m, source); + return source; + } catch (Exception e) { + e.printStackTrace(); + throw new IOException("Unable to create package manifest"); + } + } + + public static File createFlowManifest(String filename, List flowNames) throws IOException { + Serializer serializer = new Persister(); + File source = new File("package.xml"); + FileUtils.forceMkdirParent(source); + Manifest m = new Manifest(); + ManifestType mt = new ManifestType("Flow"); + for (String name : flowNames) { + mt.addMember(name); + } + m.addType(mt); + try { + serializer.write(m, source); + return source; + } catch (Exception e) { + e.printStackTrace(); + throw new IOException("Unable to create package manifest"); + } + } + + public static File createInactiveDefinition(String flowName) throws IOException { + String filename = "flowDefinitions/" + flowName + ".flowDefinition"; + Serializer serializer = new Persister(); + File source = new File(filename); + FileUtils.forceMkdirParent(source); + FlowDefinition fd = new FlowDefinition(); + try { + serializer.write(fd, source); + return source; + } catch (Exception e) { + e.printStackTrace(); + throw new IOException("Unable to create flow definition"); + } + } + +} diff --git a/src/main/java/com/spaceheroes/junit/TestCase.java b/src/main/java/com/spaceheroes/xml/junit/TestCase.java similarity index 96% rename from src/main/java/com/spaceheroes/junit/TestCase.java rename to src/main/java/com/spaceheroes/xml/junit/TestCase.java index 11a3eb0..2ff8cfc 100644 --- a/src/main/java/com/spaceheroes/junit/TestCase.java +++ b/src/main/java/com/spaceheroes/xml/junit/TestCase.java @@ -1,4 +1,4 @@ -package com.spaceheroes.junit; +package com.spaceheroes.xml.junit; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/spaceheroes/junit/TestFailure.java b/src/main/java/com/spaceheroes/xml/junit/TestFailure.java similarity index 94% rename from src/main/java/com/spaceheroes/junit/TestFailure.java rename to src/main/java/com/spaceheroes/xml/junit/TestFailure.java index ebec7ef..de76f79 100644 --- a/src/main/java/com/spaceheroes/junit/TestFailure.java +++ b/src/main/java/com/spaceheroes/xml/junit/TestFailure.java @@ -1,4 +1,4 @@ -package com.spaceheroes.junit; +package com.spaceheroes.xml.junit; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Root; diff --git a/src/main/java/com/spaceheroes/junit/TestSuite.java b/src/main/java/com/spaceheroes/xml/junit/TestSuite.java similarity index 97% rename from src/main/java/com/spaceheroes/junit/TestSuite.java rename to src/main/java/com/spaceheroes/xml/junit/TestSuite.java index 9196e83..c66e6d8 100644 --- a/src/main/java/com/spaceheroes/junit/TestSuite.java +++ b/src/main/java/com/spaceheroes/xml/junit/TestSuite.java @@ -1,4 +1,4 @@ -package com.spaceheroes.junit; +package com.spaceheroes.xml.junit; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java b/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java new file mode 100644 index 0000000..34b4145 --- /dev/null +++ b/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java @@ -0,0 +1,17 @@ +package com.spaceheroes.xml.sfdc; + +import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; + +@Root(name="FlowDefinition") +public class FlowDefinition { + + @Attribute + private String xmlns="http://soap.sforce.com/2006/04/metadata"; + + @Element + private String activeVersionNumber = "0"; + + +} diff --git a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java new file mode 100644 index 0000000..ef3cd12 --- /dev/null +++ b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java @@ -0,0 +1,47 @@ +package com.spaceheroes.xml.sfdc; + +import java.util.ArrayList; +import java.util.List; + +import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; + +@Root(name="Package") +public class Manifest { + + @Attribute + private String xmlns="http://soap.sforce.com/2006/04/metadata"; + + @ElementList(inline=true, name="types", required=false) + private List types = new ArrayList(); + + @Element + private String version = "37.0"; + + public Manifest() { + super(); + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public List getTypes() { + return types; + } + + public void setTypes(List types) { + this.types = types; + } + + public void addType(ManifestType type) { + this.types.add(type); + } + +} diff --git a/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java b/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java new file mode 100644 index 0000000..7f6ae70 --- /dev/null +++ b/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java @@ -0,0 +1,49 @@ +package com.spaceheroes.xml.sfdc; + +import java.util.ArrayList; +import java.util.List; + +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; + +@Root(name="types") +public class ManifestType { + + public ManifestType() { + super(); + } + + public ManifestType(String name) { + super(); + this.name = name; + } + + @ElementList(inline=true, name="members", required=false, entry="members") + private List members = new ArrayList(); + + @Element + private String name = "Flow"; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getMembers() { + return members; + } + + public void setMembers(List members) { + this.members = members; + } + + public void addMember(String member) { + this.members.add(member); + } + + +} diff --git a/src/main/main.iml b/src/main/main.iml new file mode 100644 index 0000000..908ad4f --- /dev/null +++ b/src/main/main.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java new file mode 100644 index 0000000..78d1f99 --- /dev/null +++ b/src/test/java/TestRun.java @@ -0,0 +1,26 @@ + + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.spaceheroes.util.FlowUtils; + +public class TestRun { + + + @Test + public void testPackage() throws Exception { + + List flowNames = new ArrayList(); + flowNames.add("Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated"); + flowNames.add("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); + //FlowUtils.createFlowManifest("package.xml", flowNames); + //FlowUtils.createInactiveDefinition("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); + FlowUtils.createFlowInactivationPack(flowNames); + + } + + +} diff --git a/src/test/test.iml b/src/test/test.iml new file mode 100644 index 0000000..5ebc6f4 --- /dev/null +++ b/src/test/test.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file From 324e5bfd305aee4f5df83cc0cf79226cc8f9c35f Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 17:12:58 +0100 Subject: [PATCH 03/22] updates --- .../java/com/spaceheroes/util/FlowUtils.java | 26 ++++++++++++------- src/test/java/TestRun.java | 4 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 0b6013a..4da26f8 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -14,16 +14,23 @@ public class FlowUtils { - public static void createFlowInactivationPack(List flowNames) throws IOException { - createFlowDefinitionManifest(flowNames); + public static void createFlowInactivationPack(String path, List flowNames) throws IOException { + File root = new File(path); + createFlowDefinitionManifest(root, flowNames); for (String flowName : flowNames) { - createInactiveDefinition(flowName); + createInactiveDefinition(root, flowName); } } - public static File createFlowDefinitionManifest(List flowNames) throws IOException { + public static void createFlowDeletionPack(String path, List flowNames) throws IOException { + File root = new File(path); + createFlowManifest(root, flowNames); + } + + private static File createFlowDefinitionManifest(File root, List flowNames) throws IOException { Serializer serializer = new Persister(); - File source = new File("package.xml"); + String filename = root.getPath() + "/" + "package.xml"; + File source = new File(filename); FileUtils.forceMkdirParent(source); Manifest m = new Manifest(); ManifestType mt = new ManifestType("FlowDefinition"); @@ -40,9 +47,10 @@ public static File createFlowDefinitionManifest(List flowNames) throws I } } - public static File createFlowManifest(String filename, List flowNames) throws IOException { + private static File createFlowManifest(File root, List flowNames) throws IOException { Serializer serializer = new Persister(); - File source = new File("package.xml"); + String filename = root.getPath() + "/" + "package.xml"; + File source = new File(filename); FileUtils.forceMkdirParent(source); Manifest m = new Manifest(); ManifestType mt = new ManifestType("Flow"); @@ -59,8 +67,8 @@ public static File createFlowManifest(String filename, List flowNames) t } } - public static File createInactiveDefinition(String flowName) throws IOException { - String filename = "flowDefinitions/" + flowName + ".flowDefinition"; + public static File createInactiveDefinition(File root, String flowName) throws IOException { + String filename = root.getPath() + "/flowDefinitions/" + flowName + ".flowDefinition"; Serializer serializer = new Persister(); File source = new File(filename); FileUtils.forceMkdirParent(source); diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index 78d1f99..68953e9 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -18,7 +18,9 @@ public void testPackage() throws Exception { flowNames.add("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); //FlowUtils.createFlowManifest("package.xml", flowNames); //FlowUtils.createInactiveDefinition("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); - FlowUtils.createFlowInactivationPack(flowNames); + + FlowUtils.createFlowInactivationPack("flow-inactivations", flowNames); + FlowUtils.createFlowDeletionPack("flow-deletions", flowNames); } From 63cc4969d08081b7a758a4df4e0443c74c4540b8 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 17:16:02 +0100 Subject: [PATCH 04/22] updates --- .../spaceheroes/xml/sfdc/FlowDefinition.java | 17 ++++++++++++++++- .../java/com/spaceheroes/xml/sfdc/Manifest.java | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java b/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java index 34b4145..4f0aaa3 100644 --- a/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java +++ b/src/main/java/com/spaceheroes/xml/sfdc/FlowDefinition.java @@ -12,6 +12,21 @@ public class FlowDefinition { @Element private String activeVersionNumber = "0"; - + + public String getXmlns() { + return xmlns; + } + + public void setXmlns(String xmlns) { + this.xmlns = xmlns; + } + + public String getActiveVersionNumber() { + return activeVersionNumber; + } + + public void setActiveVersionNumber(String activeVersionNumber) { + this.activeVersionNumber = activeVersionNumber; + } } diff --git a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java index ef3cd12..3ee74c6 100644 --- a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java +++ b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java @@ -43,5 +43,13 @@ public void setTypes(List types) { public void addType(ManifestType type) { this.types.add(type); } + + public String getXmlns() { + return xmlns; + } + + public void setXmlns(String xmlns) { + this.xmlns = xmlns; + } } From 79c2de59068371baa6db743c473e299a459dc690 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 17:22:28 +0100 Subject: [PATCH 05/22] updates --- src/main/java/com/spaceheroes/util/FlowUtils.java | 12 ++++++++++++ src/test/java/TestRun.java | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 4da26f8..ccf2f0b 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; @@ -22,6 +23,11 @@ public static void createFlowInactivationPack(String path, List flowName } } + public static void createFlowDownloadAllPack(String path) throws IOException { + File root = new File(path); + createFlowManifest(root); + } + public static void createFlowDeletionPack(String path, List flowNames) throws IOException { File root = new File(path); createFlowManifest(root, flowNames); @@ -47,6 +53,12 @@ private static File createFlowDefinitionManifest(File root, List flowNam } } + private static File createFlowManifest(File root) throws IOException { + List names = new ArrayList(); + names.add("*"); + return createFlowManifest(root, names); + } + private static File createFlowManifest(File root, List flowNames) throws IOException { Serializer serializer = new Persister(); String filename = root.getPath() + "/" + "package.xml"; diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index 68953e9..714a058 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -16,11 +16,10 @@ public void testPackage() throws Exception { List flowNames = new ArrayList(); flowNames.add("Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated"); flowNames.add("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); - //FlowUtils.createFlowManifest("package.xml", flowNames); - //FlowUtils.createInactiveDefinition("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); FlowUtils.createFlowInactivationPack("flow-inactivations", flowNames); FlowUtils.createFlowDeletionPack("flow-deletions", flowNames); + FlowUtils.createFlowDownloadAllPack("existing-flows"); } From 67208c22925e30129d194bc7723f57d2b2ef4f55 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 17:31:01 +0100 Subject: [PATCH 06/22] updates --- .../java/com/spaceheroes/util/FlowUtils.java | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index ccf2f0b..1985596 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -34,23 +34,14 @@ public static void createFlowDeletionPack(String path, List flowNames) t } private static File createFlowDefinitionManifest(File root, List flowNames) throws IOException { - Serializer serializer = new Persister(); String filename = root.getPath() + "/" + "package.xml"; - File source = new File(filename); - FileUtils.forceMkdirParent(source); Manifest m = new Manifest(); ManifestType mt = new ManifestType("FlowDefinition"); for (String name : flowNames) { mt.addMember(name); } m.addType(mt); - try { - serializer.write(m, source); - return source; - } catch (Exception e) { - e.printStackTrace(); - throw new IOException("Unable to create package manifest"); - } + return serializeXml(filename, m); } private static File createFlowManifest(File root) throws IOException { @@ -60,38 +51,34 @@ private static File createFlowManifest(File root) throws IOException { } private static File createFlowManifest(File root, List flowNames) throws IOException { - Serializer serializer = new Persister(); String filename = root.getPath() + "/" + "package.xml"; - File source = new File(filename); - FileUtils.forceMkdirParent(source); Manifest m = new Manifest(); ManifestType mt = new ManifestType("Flow"); for (String name : flowNames) { mt.addMember(name); } m.addType(mt); - try { - serializer.write(m, source); - return source; - } catch (Exception e) { - e.printStackTrace(); - throw new IOException("Unable to create package manifest"); - } + return serializeXml(filename, m); } public static File createInactiveDefinition(File root, String flowName) throws IOException { String filename = root.getPath() + "/flowDefinitions/" + flowName + ".flowDefinition"; - Serializer serializer = new Persister(); - File source = new File(filename); - FileUtils.forceMkdirParent(source); FlowDefinition fd = new FlowDefinition(); + return serializeXml(filename, fd); + } + + private static File serializeXml(String filename, Object object) throws IOException { + Serializer serializer = new Persister(); + File output = new File(filename); + FileUtils.forceMkdirParent(output); try { - serializer.write(fd, source); - return source; + serializer.write(object, output); + return output; } catch (Exception e) { e.printStackTrace(); - throw new IOException("Unable to create flow definition"); + throw new IOException("Unable to serialize"); } + } } From 5124e9ff09873a8533f105e41e9fba82d40dea12 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 21:22:21 +0100 Subject: [PATCH 07/22] updates --- .../java/com/spaceheroes/util/FlowUtils.java | 42 ++++++++++++++++--- src/test/java/TestRun.java | 2 + 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 1985596..33360e0 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -6,6 +6,7 @@ import java.util.List; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; @@ -15,6 +16,35 @@ public class FlowUtils { + public static void copyFlowsAndIncreaseVersion(String srcPath, String destPath) { + File dir = new File(srcPath); + File[] directoryFiles = dir.listFiles(); + if (directoryFiles != null) { + for (File srcFile : directoryFiles) { + String srcFilename = srcFile.getName(); + if (srcFilename.matches(".+(-([0-9]+))?.flow")) { + String srcFileNameNoExt = StringUtils.substringBeforeLast(srcFilename, "."); + String flowName = StringUtils.substringBeforeLast(srcFileNameNoExt, "-"); + String flowNumber = StringUtils.substringAfterLast(srcFileNameNoExt, "-"); + Integer flowVersion = StringUtils.isNumeric(flowNumber) ? Integer.valueOf(flowNumber) : 1; + String destFilename = + (flowVersion>0) + ? String.format("%s-%d.flow", flowName, flowVersion+1) + : String.format("%s.flow", flowName) ; + try { + File destFile = new File(destPath + "/" + destFilename); + FileUtils.forceMkdirParent(destFile); + FileUtils.copyFile(srcFile, destFile); + System.out.println(destFile.getAbsolutePath().toString()); + } catch (IOException e) { + // ignore + e.printStackTrace(); + } + } + } + } + } + public static void createFlowInactivationPack(String path, List flowNames) throws IOException { File root = new File(path); createFlowDefinitionManifest(root, flowNames); @@ -35,13 +65,13 @@ public static void createFlowDeletionPack(String path, List flowNames) t private static File createFlowDefinitionManifest(File root, List flowNames) throws IOException { String filename = root.getPath() + "/" + "package.xml"; - Manifest m = new Manifest(); - ManifestType mt = new ManifestType("FlowDefinition"); - for (String name : flowNames) { - mt.addMember(name); + Manifest manifest = new Manifest(); + ManifestType manifestType = new ManifestType("FlowDefinition"); + for (String flowName : flowNames) { + manifestType.addMember(flowName); } - m.addType(mt); - return serializeXml(filename, m); + manifest.addType(manifestType); + return serializeXml(filename, manifest); } private static File createFlowManifest(File root) throws IOException { diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index 714a058..b3b62ce 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -21,6 +21,8 @@ public void testPackage() throws Exception { FlowUtils.createFlowDeletionPack("flow-deletions", flowNames); FlowUtils.createFlowDownloadAllPack("existing-flows"); + FlowUtils.copyFlowsAndIncreaseVersion("data/src/flows", "data/src/flows-copy"); + } From acaa5dfcb4b6dc69fc6eb6b9dd4d8f88029e521c Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 21:38:01 +0100 Subject: [PATCH 08/22] updates --- .../java/com/spaceheroes/util/FlowUtils.java | 43 ++++++++++++++----- .../spaceheroes/xml/sfdc/ManifestType.java | 8 ++++ src/test/java/TestRun.java | 14 +++--- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 33360e0..7dd2896 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -45,6 +45,32 @@ public static void copyFlowsAndIncreaseVersion(String srcPath, String destPath) } } + public static List getFlowsNames(String srcPath) { + File dir = new File(srcPath); + File[] directoryFiles = dir.listFiles(); + List flowNames = new ArrayList(); + if (directoryFiles != null) { + for (File srcFile : directoryFiles) { + String srcFilename = srcFile.getName(); + if (srcFilename.matches(".+(-([0-9]+))?.flow")) { + String srcFileNameNoExt = StringUtils.substringBeforeLast(srcFilename, "."); + String flowName = StringUtils.substringBeforeLast(srcFileNameNoExt, "-"); + flowNames.add(flowName); + } + } + } + return flowNames; + } + + public static void createFlowInactivationPack(String flowPath, String outputPath) throws IOException { + List flowNames = getFlowsNames(flowPath); + File outputRoot = new File(outputPath); + createFlowDefinitionManifest(outputRoot, flowNames); + for (String flowName : flowNames) { + createInactiveDefinition(outputRoot, flowName); + } + } + public static void createFlowInactivationPack(String path, List flowNames) throws IOException { File root = new File(path); createFlowDefinitionManifest(root, flowNames); @@ -67,9 +93,7 @@ private static File createFlowDefinitionManifest(File root, List flowNam String filename = root.getPath() + "/" + "package.xml"; Manifest manifest = new Manifest(); ManifestType manifestType = new ManifestType("FlowDefinition"); - for (String flowName : flowNames) { - manifestType.addMember(flowName); - } + manifestType.addMembers(flowNames); manifest.addType(manifestType); return serializeXml(filename, manifest); } @@ -82,13 +106,11 @@ private static File createFlowManifest(File root) throws IOException { private static File createFlowManifest(File root, List flowNames) throws IOException { String filename = root.getPath() + "/" + "package.xml"; - Manifest m = new Manifest(); - ManifestType mt = new ManifestType("Flow"); - for (String name : flowNames) { - mt.addMember(name); - } - m.addType(mt); - return serializeXml(filename, m); + Manifest manifest = new Manifest(); + ManifestType manifestType = new ManifestType("Flow"); + manifestType.addMembers(flowNames); + manifest.addType(manifestType); + return serializeXml(filename, manifest); } public static File createInactiveDefinition(File root, String flowName) throws IOException { @@ -108,7 +130,6 @@ private static File serializeXml(String filename, Object object) throws IOExcept e.printStackTrace(); throw new IOException("Unable to serialize"); } - } } diff --git a/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java b/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java index 7f6ae70..7d9d28e 100644 --- a/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java +++ b/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java @@ -45,5 +45,13 @@ public void addMember(String member) { this.members.add(member); } + public void addMembers(List members) { + if (members!=null && !members.isEmpty()) { + for (String member: members) { + addMember(member); + } + } + } + } diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index b3b62ce..6ee49ef 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -1,6 +1,5 @@ -import java.util.ArrayList; import java.util.List; import org.junit.Test; @@ -13,13 +12,14 @@ public class TestRun { @Test public void testPackage() throws Exception { - List flowNames = new ArrayList(); - flowNames.add("Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated"); - flowNames.add("Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated"); + FlowUtils.createFlowDownloadAllPack("1-flows-download"); - FlowUtils.createFlowInactivationPack("flow-inactivations", flowNames); - FlowUtils.createFlowDeletionPack("flow-deletions", flowNames); - FlowUtils.createFlowDownloadAllPack("existing-flows"); + // download flows with metadata API + + List flowNames = FlowUtils.getFlowsNames("data/src/flows"); + + FlowUtils.createFlowInactivationPack("2-flows-deactivate", flowNames); + FlowUtils.createFlowDeletionPack("3-flow-deletions", flowNames); FlowUtils.copyFlowsAndIncreaseVersion("data/src/flows", "data/src/flows-copy"); From a5afe7d2ff1fe6b19f366db34412aff1035867af Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 21:49:37 +0100 Subject: [PATCH 09/22] updates --- .../java/com/spaceheroes/util/FlowUtils.java | 6 +++--- src/test/java/TestRun.java | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 7dd2896..9358913 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -92,9 +92,9 @@ public static void createFlowDeletionPack(String path, List flowNames) t private static File createFlowDefinitionManifest(File root, List flowNames) throws IOException { String filename = root.getPath() + "/" + "package.xml"; Manifest manifest = new Manifest(); - ManifestType manifestType = new ManifestType("FlowDefinition"); - manifestType.addMembers(flowNames); - manifest.addType(manifestType); + ManifestType flowDefinitions = new ManifestType("FlowDefinition"); + flowDefinitions.addMembers(flowNames); + manifest.addType(flowDefinitions); return serializeXml(filename, manifest); } diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index 6ee49ef..c952cc2 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -12,13 +12,26 @@ public class TestRun { @Test public void testPackage() throws Exception { + /* stage 1 */ FlowUtils.createFlowDownloadAllPack("1-flows-download"); + // download flows with migration tool + + /* stage 2 */ + String downloadPath = "data/src/flows"; + String tempPath = "2-flows-deactivate"; + + List flowNames = FlowUtils.getFlowsNames(downloadPath); + FlowUtils.copyFlowsAndIncreaseVersion(downloadPath, tempPath + "/flows"); + FlowUtils.createFlowInactivationPack(tempPath, flowNames); + + /* stage 3 */ + + + + // deploy deactivations with migration tool - // download flows with metadata API - List flowNames = FlowUtils.getFlowsNames("data/src/flows"); - FlowUtils.createFlowInactivationPack("2-flows-deactivate", flowNames); FlowUtils.createFlowDeletionPack("3-flow-deletions", flowNames); FlowUtils.copyFlowsAndIncreaseVersion("data/src/flows", "data/src/flows-copy"); From 711f62689523e756bfe7a491f536b08953f5169b Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 21:55:34 +0100 Subject: [PATCH 10/22] updates --- src/main/java/com/spaceheroes/util/FlowUtils.java | 1 - src/test/java/TestRun.java | 14 ++++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 9358913..4a603d1 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -35,7 +35,6 @@ public static void copyFlowsAndIncreaseVersion(String srcPath, String destPath) File destFile = new File(destPath + "/" + destFilename); FileUtils.forceMkdirParent(destFile); FileUtils.copyFile(srcFile, destFile); - System.out.println(destFile.getAbsolutePath().toString()); } catch (IOException e) { // ignore e.printStackTrace(); diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index c952cc2..edae14d 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -14,7 +14,7 @@ public void testPackage() throws Exception { /* stage 1 */ FlowUtils.createFlowDownloadAllPack("1-flows-download"); - // download flows with migration tool + // TODO: download flows with migration tool /* stage 2 */ String downloadPath = "data/src/flows"; @@ -25,16 +25,18 @@ public void testPackage() throws Exception { FlowUtils.createFlowInactivationPack(tempPath, flowNames); /* stage 3 */ + // TODO: deploy deactivations with migration tool + /* stage 4 */ - // deploy deactivations with migration tool - - - + // create deletion pack: + // TODO: should have version in names + // TODO: file should be named destructiveChanges.xml FlowUtils.createFlowDeletionPack("3-flow-deletions", flowNames); - FlowUtils.copyFlowsAndIncreaseVersion("data/src/flows", "data/src/flows-copy"); + /* stage 4 */ + // deploy with migration tool } From 1a2f04a8a5ad5c6a143503afdcfc786479804617 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Fri, 14 Oct 2016 22:05:49 +0100 Subject: [PATCH 11/22] updates --- .../java/com/spaceheroes/util/FlowUtils.java | 18 +++++++++++++++++- src/test/java/TestRun.java | 5 +---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 4a603d1..88dfec7 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -61,6 +61,22 @@ public static List getFlowsNames(String srcPath) { return flowNames; } + public static void createFlowDeletionPack(String flowPath, String outputPath) throws IOException { + File dir = new File(flowPath); + File[] directoryFiles = dir.listFiles(); + List flowNames = new ArrayList(); + if (directoryFiles != null) { + for (File srcFile : directoryFiles) { + String srcFilename = srcFile.getName(); + if (srcFilename.matches(".+(-([0-9]+))?.flow")) { + String flowNameWithVersion = StringUtils.substringBeforeLast(srcFilename, "."); + flowNames.add(flowNameWithVersion); + } + } + createFlowDeletionPack(outputPath + "/destructiveChanges.xml", flowNames); + } + } + public static void createFlowInactivationPack(String flowPath, String outputPath) throws IOException { List flowNames = getFlowsNames(flowPath); File outputRoot = new File(outputPath); @@ -104,7 +120,7 @@ private static File createFlowManifest(File root) throws IOException { } private static File createFlowManifest(File root, List flowNames) throws IOException { - String filename = root.getPath() + "/" + "package.xml"; + String filename = root.isDirectory() ? root.getPath() + "/" + "package.xml" : root.getPath(); Manifest manifest = new Manifest(); ManifestType manifestType = new ManifestType("Flow"); manifestType.addMembers(flowNames); diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index edae14d..177deb8 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -31,10 +31,7 @@ public void testPackage() throws Exception { /* stage 4 */ // create deletion pack: - // TODO: should have version in names - // TODO: file should be named destructiveChanges.xml - FlowUtils.createFlowDeletionPack("3-flow-deletions", flowNames); - + FlowUtils.createFlowDeletionPack(downloadPath, "3-flow-deletions"); /* stage 4 */ // deploy with migration tool From 50ddc6f22795e305e555e7900a017c7e9ec2ab0b Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Mon, 17 Oct 2016 14:43:35 +0100 Subject: [PATCH 12/22] updates --- .../java/com/spaceheroes/model/FlowFile.java | 50 ++++++ .../java/com/spaceheroes/util/FlowUtils.java | 152 +++++++++++------- .../com/spaceheroes/xml/sfdc/Manifest.java | 2 +- src/test/java/TestRun.java | 33 +--- 4 files changed, 148 insertions(+), 89 deletions(-) create mode 100644 src/main/java/com/spaceheroes/model/FlowFile.java diff --git a/src/main/java/com/spaceheroes/model/FlowFile.java b/src/main/java/com/spaceheroes/model/FlowFile.java new file mode 100644 index 0000000..4a77d4d --- /dev/null +++ b/src/main/java/com/spaceheroes/model/FlowFile.java @@ -0,0 +1,50 @@ +package com.spaceheroes.model; + +import java.io.File; +import java.util.Objects; + +import org.apache.commons.lang3.StringUtils; + +public class FlowFile { + + private File file; + private String name; + private Integer version; + + public FlowFile(File f) { + this.file = Objects.requireNonNull(f); + String srcFileNameNoExt = StringUtils.substringBeforeLast(f.getName(), "."); + this.name = StringUtils.substringBeforeLast(srcFileNameNoExt, "-"); + String flowNumber = StringUtils.substringAfterLast(srcFileNameNoExt, "-"); + this.version = StringUtils.isNumeric(flowNumber) ? Integer.valueOf(flowNumber) : 1; + } + + public String getName() { + return name; + } + + public String getFilename(Integer version) { + String destFilename = + (version>0) + ? String.format("%s-%d.flow", name, version) + : String.format("%s.flow", name) ; + return destFilename; + } + + public String getFilenameCurrentVersion() { + return getFilename(version); + } + + public String getFilenameNextVersion() { + return getFilename(version+1); + } + + public Integer getVersion() { + return version; + } + + public File getFile() { + return file; + } + +} diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 88dfec7..5ef5bf6 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -6,33 +6,28 @@ import java.util.List; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; +import com.spaceheroes.model.FlowFile; import com.spaceheroes.xml.sfdc.FlowDefinition; import com.spaceheroes.xml.sfdc.Manifest; import com.spaceheroes.xml.sfdc.ManifestType; public class FlowUtils { - public static void copyFlowsAndIncreaseVersion(String srcPath, String destPath) { + private static void copyFlowsAndIncreaseVersion(Manifest manifest, String srcPath, String destPath) { File dir = new File(srcPath); File[] directoryFiles = dir.listFiles(); + ManifestType manifestType = new ManifestType("Flows"); if (directoryFiles != null) { for (File srcFile : directoryFiles) { String srcFilename = srcFile.getName(); if (srcFilename.matches(".+(-([0-9]+))?.flow")) { - String srcFileNameNoExt = StringUtils.substringBeforeLast(srcFilename, "."); - String flowName = StringUtils.substringBeforeLast(srcFileNameNoExt, "-"); - String flowNumber = StringUtils.substringAfterLast(srcFileNameNoExt, "-"); - Integer flowVersion = StringUtils.isNumeric(flowNumber) ? Integer.valueOf(flowNumber) : 1; - String destFilename = - (flowVersion>0) - ? String.format("%s-%d.flow", flowName, flowVersion+1) - : String.format("%s.flow", flowName) ; + FlowFile ff = new FlowFile(srcFile); + manifestType.addMember(ff.getFilenameNextVersion()); try { - File destFile = new File(destPath + "/" + destFilename); + File destFile = new File(destPath + "/" + ff.getFilenameNextVersion()); FileUtils.forceMkdirParent(destFile); FileUtils.copyFile(srcFile, destFile); } catch (IOException e) { @@ -41,102 +36,126 @@ public static void copyFlowsAndIncreaseVersion(String srcPath, String destPath) } } } + manifest.addType(manifestType); } } - public static List getFlowsNames(String srcPath) { + public static List getFlowFiles(String srcPath) { File dir = new File(srcPath); File[] directoryFiles = dir.listFiles(); - List flowNames = new ArrayList(); + List flowFiles = new ArrayList(); if (directoryFiles != null) { for (File srcFile : directoryFiles) { String srcFilename = srcFile.getName(); if (srcFilename.matches(".+(-([0-9]+))?.flow")) { - String srcFileNameNoExt = StringUtils.substringBeforeLast(srcFilename, "."); - String flowName = StringUtils.substringBeforeLast(srcFileNameNoExt, "-"); - flowNames.add(flowName); + flowFiles.add(new FlowFile(srcFile)); } } } - return flowNames; + return flowFiles; } - public static void createFlowDeletionPack(String flowPath, String outputPath) throws IOException { - File dir = new File(flowPath); - File[] directoryFiles = dir.listFiles(); - List flowNames = new ArrayList(); - if (directoryFiles != null) { - for (File srcFile : directoryFiles) { - String srcFilename = srcFile.getName(); - if (srcFilename.matches(".+(-([0-9]+))?.flow")) { - String flowNameWithVersion = StringUtils.substringBeforeLast(srcFilename, "."); - flowNames.add(flowNameWithVersion); - } - } - createFlowDeletionPack(outputPath + "/destructiveChanges.xml", flowNames); - } + public static void createFlowDeletionPack(String sourcePath, String outputPath) throws IOException { + //String tempPath = "ff-output/3-flows-delete"; + List nextVersionFlows = FlowUtils.getFlowFiles(sourcePath + "/flows"); + FlowUtils.createFlowDeletionPack(outputPath, nextVersionFlows); } +// public static void createFlowDeletionPack(String flowPath, String outputPath) throws IOException { +// List flowFiles = getFlowFiles(flowPath); +// createFlowDeletionPack(outputPath + "/destructiveChanges.xml", flowFiles); +// } - public static void createFlowInactivationPack(String flowPath, String outputPath) throws IOException { - List flowNames = getFlowsNames(flowPath); + public static void createFlowInactivationPack(Manifest manifest, String flowPath, String outputPath) throws IOException { + List flowFiles = getFlowFiles(flowPath); File outputRoot = new File(outputPath); - createFlowDefinitionManifest(outputRoot, flowNames); - for (String flowName : flowNames) { + createFlowDefinitionManifest(manifest, flowFiles); + for (FlowFile flowName : flowFiles) { createInactiveDefinition(outputRoot, flowName); } } - public static void createFlowInactivationPack(String path, List flowNames) throws IOException { + private static void createFlowInactivationPack(Manifest manifest, String path, List flowFiles) throws IOException { File root = new File(path); - createFlowDefinitionManifest(root, flowNames); - for (String flowName : flowNames) { + createFlowDefinitionManifest(manifest , flowFiles); + for (FlowFile flowName : flowFiles) { createInactiveDefinition(root, flowName); } } + // public public static void createFlowDownloadAllPack(String path) throws IOException { File root = new File(path); - createFlowManifest(root); + createFlowManifest(root, "package.xml"); + } + + public static void createFlowInactivation(String sourcePath, String outputPath) throws IOException { + //String downloadPath = "data/src/flows"; + //String tempPath = "ff-output/2-flows-deactivate"; + String flowsDestinationPath = outputPath + "/flows"; + + + List flowFiles = FlowUtils.getFlowFiles(sourcePath); + String manifestFilePath = outputPath + "/package.xml"; + File manifestFile = new File(manifestFilePath); + Manifest manifest = FlowUtils.readOrCreateManifest(manifestFile); + copyFlowsAndIncreaseVersion(manifest, sourcePath, flowsDestinationPath); + createFlowInactivationPack(manifest, outputPath, flowFiles); + + serializeXml(manifestFile, manifest); } - public static void createFlowDeletionPack(String path, List flowNames) throws IOException { + public static void createFlowDeletionPack(String path, List flowFiles) throws IOException { File root = new File(path); - createFlowManifest(root, flowNames); + String filePath = root.getPath() + "/" + "destructiveChanges.xml"; + File manifestFile = new File(filePath); + Manifest manifest = readOrCreateManifest(manifestFile); + ManifestType manifestType = new ManifestType("Flow"); + if (flowFiles!=null && flowFiles.size()>0) { + for (FlowFile ff : flowFiles) { + manifestType.addMember(ff.getFilenameCurrentVersion()); + } + } + manifest.addType(manifestType); + serializeXml(manifestFile, manifest); } - private static File createFlowDefinitionManifest(File root, List flowNames) throws IOException { - String filename = root.getPath() + "/" + "package.xml"; - Manifest manifest = new Manifest(); + private static void createFlowDefinitionManifest(Manifest manifest, List flowFiles) throws IOException { ManifestType flowDefinitions = new ManifestType("FlowDefinition"); - flowDefinitions.addMembers(flowNames); + for (FlowFile ff : flowFiles) { + flowDefinitions.addMember(ff.getName()); + } manifest.addType(flowDefinitions); - return serializeXml(filename, manifest); } - private static File createFlowManifest(File root) throws IOException { - List names = new ArrayList(); - names.add("*"); - return createFlowManifest(root, names); + public static File createFlowManifest(File root, String filename) throws IOException { + return createFlowManifest(root, filename, null); } - private static File createFlowManifest(File root, List flowNames) throws IOException { - String filename = root.isDirectory() ? root.getPath() + "/" + "package.xml" : root.getPath(); - Manifest manifest = new Manifest(); + public static File createFlowManifest(File root, String filename, List flowFiles) throws IOException { + String filePath = root.getPath() + "/" + filename; + File file = new File(filePath); + Manifest manifest = readOrCreateManifest(file); ManifestType manifestType = new ManifestType("Flow"); - manifestType.addMembers(flowNames); + if (flowFiles!=null && flowFiles.size()>0) { + for (FlowFile ff : flowFiles) { + manifestType.addMember(ff.getName()); + } + } else { + manifestType.addMember("*"); + } manifest.addType(manifestType); - return serializeXml(filename, manifest); + return serializeXml(file, manifest); } - public static File createInactiveDefinition(File root, String flowName) throws IOException { - String filename = root.getPath() + "/flowDefinitions/" + flowName + ".flowDefinition"; + public static File createInactiveDefinition(File root, FlowFile ff) throws IOException { + String filename = root.getPath() + "/flowDefinitions/" + ff.getName() + ".flowDefinition"; + File f = new File(filename); FlowDefinition fd = new FlowDefinition(); - return serializeXml(filename, fd); + return serializeXml(f, fd); } - private static File serializeXml(String filename, Object object) throws IOException { + private static File serializeXml(File output, Object object) throws IOException { Serializer serializer = new Persister(); - File output = new File(filename); FileUtils.forceMkdirParent(output); try { serializer.write(object, output); @@ -146,5 +165,18 @@ private static File serializeXml(String filename, Object object) throws IOExcept throw new IOException("Unable to serialize"); } } + + public static Manifest readOrCreateManifest(File manifestFile) { + Manifest manifest = new Manifest(); + if (manifestFile.exists()) { + Serializer serializer = new Persister(); + try { + manifest = serializer.read(Manifest.class, manifestFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + return manifest; + } } diff --git a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java index 3ee74c6..54343b5 100644 --- a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java +++ b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java @@ -11,7 +11,7 @@ @Root(name="Package") public class Manifest { - @Attribute + @Attribute(required=false) private String xmlns="http://soap.sforce.com/2006/04/metadata"; @ElementList(inline=true, name="types", required=false) diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index 177deb8..159f1ee 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -1,41 +1,18 @@ -import java.util.List; - import org.junit.Test; import com.spaceheroes.util.FlowUtils; public class TestRun { - @Test - public void testPackage() throws Exception { - - /* stage 1 */ - FlowUtils.createFlowDownloadAllPack("1-flows-download"); - // TODO: download flows with migration tool - - /* stage 2 */ - String downloadPath = "data/src/flows"; - String tempPath = "2-flows-deactivate"; - - List flowNames = FlowUtils.getFlowsNames(downloadPath); - FlowUtils.copyFlowsAndIncreaseVersion(downloadPath, tempPath + "/flows"); - FlowUtils.createFlowInactivationPack(tempPath, flowNames); - - /* stage 3 */ + public void testCreateFlowDownloadAll() throws Exception { + FlowUtils.createFlowDownloadAllPack("ff-output/1-flows-download"); + FlowUtils.createFlowInactivation("data/src/flows", "ff-output/2-flows-inactivation"); // TODO: deploy deactivations with migration tool - - - /* stage 4 */ - - // create deletion pack: - FlowUtils.createFlowDeletionPack(downloadPath, "3-flow-deletions"); - /* stage 4 */ - // deploy with migration tool - + FlowUtils.createFlowDeletionPack("ff-output/2-flows-inactivation", "ff-output/3-flows-delete"); + // TODO: deploy with migration tool } - } From 53c188a6471416e36ff0cf1fc16b4c6dbb4b68f7 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Mon, 17 Oct 2016 15:17:17 +0100 Subject: [PATCH 13/22] tasks --- src/antlib.xml | 6 +++ .../task/local/CreateFlowDeletePackage.java | 34 +++++++++++++++ .../local/CreateFlowInactivationsPackage.java | 42 +++++++++++++++++++ .../local/CreateRetrieveAllFlowsPackage.java | 33 +++++++++++++++ .../java/com/spaceheroes/util/FlowUtils.java | 15 ++----- src/test/java/TestRun.java | 2 +- 6 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java create mode 100644 src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java create mode 100644 src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java diff --git a/src/antlib.xml b/src/antlib.xml index 224900d..f62789d 100644 --- a/src/antlib.xml +++ b/src/antlib.xml @@ -14,4 +14,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java new file mode 100644 index 0000000..18680aa --- /dev/null +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java @@ -0,0 +1,34 @@ +package com.spaceheroes.task.local; + +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +import com.spaceheroes.util.FlowUtils; + +public class CreateFlowDeletePackage extends Task { + + private String sourcePath; + private String destinationPath; + + @Override + public void execute() throws BuildException { + try { + FlowUtils.createFlowDeletionPack(sourcePath, destinationPath); + } catch (IOException e) { + e.printStackTrace(); + throw new BuildException(e); + } + super.execute(); + } + + public String getDestinationPath() { + return destinationPath; + } + + public void setDestinationPath(String destinationPath) { + this.destinationPath = destinationPath; + } + +} diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java new file mode 100644 index 0000000..8ac97ff --- /dev/null +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java @@ -0,0 +1,42 @@ +package com.spaceheroes.task.local; + +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +import com.spaceheroes.util.FlowUtils; + +public class CreateFlowInactivationsPackage extends Task { + + private String sourcePath; + private String destinationPath; + + @Override + public void execute() throws BuildException { + try { + FlowUtils.createFlowInactivation(sourcePath, destinationPath); + } catch (IOException e) { + e.printStackTrace(); + throw new BuildException(e); + } + super.execute(); + } + + public String getDestinationPath() { + return destinationPath; + } + + public void setDestinationPath(String destinationPath) { + this.destinationPath = destinationPath; + } + + public String getSourcePath() { + return sourcePath; + } + + public void setSourcePath(String sourcePath) { + this.sourcePath = sourcePath; + } + +} diff --git a/src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java b/src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java new file mode 100644 index 0000000..8fe0e6f --- /dev/null +++ b/src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java @@ -0,0 +1,33 @@ +package com.spaceheroes.task.local; + +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +import com.spaceheroes.util.FlowUtils; + +public class CreateRetrieveAllFlowsPackage extends Task { + + private String destinationPath; + + @Override + public void execute() throws BuildException { + try { + FlowUtils.createFlowDownloadAllPack(destinationPath); + } catch (IOException e) { + e.printStackTrace(); + throw new BuildException(e); + } + super.execute(); + } + + public String getDestinationPath() { + return destinationPath; + } + + public void setDestinationPath(String destinationPath) { + this.destinationPath = destinationPath; + } + +} diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 5ef5bf6..0352972 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -56,7 +56,6 @@ public static List getFlowFiles(String srcPath) { } public static void createFlowDeletionPack(String sourcePath, String outputPath) throws IOException { - //String tempPath = "ff-output/3-flows-delete"; List nextVersionFlows = FlowUtils.getFlowFiles(sourcePath + "/flows"); FlowUtils.createFlowDeletionPack(outputPath, nextVersionFlows); } @@ -65,15 +64,6 @@ public static void createFlowDeletionPack(String sourcePath, String outputPath) // createFlowDeletionPack(outputPath + "/destructiveChanges.xml", flowFiles); // } - public static void createFlowInactivationPack(Manifest manifest, String flowPath, String outputPath) throws IOException { - List flowFiles = getFlowFiles(flowPath); - File outputRoot = new File(outputPath); - createFlowDefinitionManifest(manifest, flowFiles); - for (FlowFile flowName : flowFiles) { - createInactiveDefinition(outputRoot, flowName); - } - } - private static void createFlowInactivationPack(Manifest manifest, String path, List flowFiles) throws IOException { File root = new File(path); createFlowDefinitionManifest(manifest , flowFiles); @@ -88,9 +78,10 @@ public static void createFlowDownloadAllPack(String path) throws IOException { createFlowManifest(root, "package.xml"); } - public static void createFlowInactivation(String sourcePath, String outputPath) throws IOException { + public static void createFlowInactivation(String srcPath, String outputPath) throws IOException { //String downloadPath = "data/src/flows"; //String tempPath = "ff-output/2-flows-deactivate"; + String sourcePath = srcPath + "/flows"; String flowsDestinationPath = outputPath + "/flows"; @@ -104,7 +95,7 @@ public static void createFlowInactivation(String sourcePath, String outputPath) serializeXml(manifestFile, manifest); } - public static void createFlowDeletionPack(String path, List flowFiles) throws IOException { + private static void createFlowDeletionPack(String path, List flowFiles) throws IOException { File root = new File(path); String filePath = root.getPath() + "/" + "destructiveChanges.xml"; File manifestFile = new File(filePath); diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java index 159f1ee..736505f 100644 --- a/src/test/java/TestRun.java +++ b/src/test/java/TestRun.java @@ -9,7 +9,7 @@ public class TestRun { @Test public void testCreateFlowDownloadAll() throws Exception { FlowUtils.createFlowDownloadAllPack("ff-output/1-flows-download"); - FlowUtils.createFlowInactivation("data/src/flows", "ff-output/2-flows-inactivation"); + FlowUtils.createFlowInactivation("data/src", "ff-output/2-flows-inactivation"); // TODO: deploy deactivations with migration tool FlowUtils.createFlowDeletionPack("ff-output/2-flows-inactivation", "ff-output/3-flows-delete"); // TODO: deploy with migration tool From f47034e64d2eacc94f48ddfb44f8e37216e6c758 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Wed, 19 Oct 2016 11:04:23 +0100 Subject: [PATCH 14/22] updates --- .classpath | 4 +- src/main/java/Main.java | 11 ++++++ .../java/com/spaceheroes/model/FlowFile.java | 16 ++++++++ .../java/com/spaceheroes/util/FlowUtils.java | 37 ++++++++++++------- .../spaceheroes/xml/sfdc/ManifestType.java | 9 +++-- src/test/java/TestRun.java | 18 --------- 6 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 src/main/java/Main.java delete mode 100644 src/test/java/TestRun.java diff --git a/.classpath b/.classpath index 333eeaf..2cbc4db 100644 --- a/.classpath +++ b/.classpath @@ -1,8 +1,8 @@ - - + + diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..d1dc75e --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,11 @@ +import java.io.IOException; + +import com.spaceheroes.util.FlowUtils; + +public class Main { + + public static void main(String[] args) throws IOException { + FlowUtils.createFlowInactivation("data/tmp", "ff-output/2-flows-inactivation"); + } + +} diff --git a/src/main/java/com/spaceheroes/model/FlowFile.java b/src/main/java/com/spaceheroes/model/FlowFile.java index 4a77d4d..aaa8da9 100644 --- a/src/main/java/com/spaceheroes/model/FlowFile.java +++ b/src/main/java/com/spaceheroes/model/FlowFile.java @@ -31,6 +31,14 @@ public String getFilename(Integer version) { return destFilename; } + public String getFlowName(Integer version) { + String destFilename = + (version>0) + ? String.format("%s-%d", name, version) + : String.format("%s", name) ; + return destFilename; + } + public String getFilenameCurrentVersion() { return getFilename(version); } @@ -38,6 +46,14 @@ public String getFilenameCurrentVersion() { public String getFilenameNextVersion() { return getFilename(version+1); } + + public String getFlowNameCurrentVersion() { + return getFlowName(version); + } + + public String getFlowNameNextVersion() { + return getFlowName(version+1); + } public Integer getVersion() { return version; diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 0352972..651e988 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -3,7 +3,9 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.io.FileUtils; import org.simpleframework.xml.Serializer; @@ -19,25 +21,36 @@ public class FlowUtils { private static void copyFlowsAndIncreaseVersion(Manifest manifest, String srcPath, String destPath) { File dir = new File(srcPath); File[] directoryFiles = dir.listFiles(); - ManifestType manifestType = new ManifestType("Flows"); + ManifestType manifestType = new ManifestType("Flow"); + Map versionMap = new HashMap(); if (directoryFiles != null) { for (File srcFile : directoryFiles) { String srcFilename = srcFile.getName(); if (srcFilename.matches(".+(-([0-9]+))?.flow")) { FlowFile ff = new FlowFile(srcFile); - manifestType.addMember(ff.getFilenameNextVersion()); - try { - File destFile = new File(destPath + "/" + ff.getFilenameNextVersion()); - FileUtils.forceMkdirParent(destFile); - FileUtils.copyFile(srcFile, destFile); - } catch (IOException e) { - // ignore - e.printStackTrace(); + String key = ff.getName(); + FlowFile latestVersion = versionMap.getOrDefault(key, ff); + if (ff.getVersion() > latestVersion.getVersion()) { + versionMap.put(key, ff); + } else { + versionMap.put(key, latestVersion); } } } - manifest.addType(manifestType); } + + for (FlowFile ff : versionMap.values()) { + manifestType.addMember(ff.getFlowNameNextVersion()); + try { + File destFile = new File(destPath + "/" + ff.getFilenameNextVersion()); + FileUtils.forceMkdirParent(destFile); + FileUtils.copyFile(ff.getFile(), destFile); + } catch (IOException e) { + // ignore + e.printStackTrace(); + } + } + manifest.addType(manifestType); } public static List getFlowFiles(String srcPath) { @@ -79,8 +92,6 @@ public static void createFlowDownloadAllPack(String path) throws IOException { } public static void createFlowInactivation(String srcPath, String outputPath) throws IOException { - //String downloadPath = "data/src/flows"; - //String tempPath = "ff-output/2-flows-deactivate"; String sourcePath = srcPath + "/flows"; String flowsDestinationPath = outputPath + "/flows"; @@ -88,7 +99,7 @@ public static void createFlowInactivation(String srcPath, String outputPath) thr List flowFiles = FlowUtils.getFlowFiles(sourcePath); String manifestFilePath = outputPath + "/package.xml"; File manifestFile = new File(manifestFilePath); - Manifest manifest = FlowUtils.readOrCreateManifest(manifestFile); + Manifest manifest = new Manifest();//FlowUtils.readOrCreateManifest(manifestFile); copyFlowsAndIncreaseVersion(manifest, sourcePath, flowsDestinationPath); createFlowInactivationPack(manifest, outputPath, flowFiles); diff --git a/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java b/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java index 7d9d28e..18f22e9 100644 --- a/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java +++ b/src/main/java/com/spaceheroes/xml/sfdc/ManifestType.java @@ -1,7 +1,8 @@ package com.spaceheroes.xml.sfdc; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; @@ -20,7 +21,7 @@ public ManifestType(String name) { } @ElementList(inline=true, name="members", required=false, entry="members") - private List members = new ArrayList(); + private Set members = new HashSet(); @Element private String name = "Flow"; @@ -33,11 +34,11 @@ public void setName(String name) { this.name = name; } - public List getMembers() { + public Set getMembers() { return members; } - public void setMembers(List members) { + public void setMembers(Set members) { this.members = members; } diff --git a/src/test/java/TestRun.java b/src/test/java/TestRun.java deleted file mode 100644 index 736505f..0000000 --- a/src/test/java/TestRun.java +++ /dev/null @@ -1,18 +0,0 @@ - - -import org.junit.Test; - -import com.spaceheroes.util.FlowUtils; - -public class TestRun { - - @Test - public void testCreateFlowDownloadAll() throws Exception { - FlowUtils.createFlowDownloadAllPack("ff-output/1-flows-download"); - FlowUtils.createFlowInactivation("data/src", "ff-output/2-flows-inactivation"); - // TODO: deploy deactivations with migration tool - FlowUtils.createFlowDeletionPack("ff-output/2-flows-inactivation", "ff-output/3-flows-delete"); - // TODO: deploy with migration tool - } - -} From f2e5572d30fa28d5e2b6f5083cf1d7565e74fe3e Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Wed, 19 Oct 2016 17:15:40 +0100 Subject: [PATCH 15/22] updates --- src/main/java/Main.java | 3 +- .../task/local/CreateFlowDeletePackage.java | 8 +++++ .../local/CreateFlowInactivationsPackage.java | 11 +++++- .../java/com/spaceheroes/util/FlowUtils.java | 34 ++++++++++++++++--- .../com/spaceheroes/xml/sfdc/Manifest.java | 10 ++++++ 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index d1dc75e..d526d91 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,7 +5,8 @@ public class Main { public static void main(String[] args) throws IOException { - FlowUtils.createFlowInactivation("data/tmp", "ff-output/2-flows-inactivation"); + FlowUtils.createFlowInactivation("data/tmp", "ff-output/2-flows-inactivation", true); + FlowUtils.createFlowDeletionPack("data/tmp", "ff-output/3-flows-deletion"); } } diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java index 18680aa..ffcff6e 100644 --- a/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java @@ -30,5 +30,13 @@ public String getDestinationPath() { public void setDestinationPath(String destinationPath) { this.destinationPath = destinationPath; } + + public String getSourcePath() { + return sourcePath; + } + + public void setSourcePath(String sourcePath) { + this.sourcePath = sourcePath; + } } diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java index 8ac97ff..8dd3220 100644 --- a/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java @@ -11,11 +11,12 @@ public class CreateFlowInactivationsPackage extends Task { private String sourcePath; private String destinationPath; + private Boolean destructiveChanges = Boolean.FALSE; @Override public void execute() throws BuildException { try { - FlowUtils.createFlowInactivation(sourcePath, destinationPath); + FlowUtils.createFlowInactivation(sourcePath, destinationPath, destructiveChanges); } catch (IOException e) { e.printStackTrace(); throw new BuildException(e); @@ -38,5 +39,13 @@ public String getSourcePath() { public void setSourcePath(String sourcePath) { this.sourcePath = sourcePath; } + + public Boolean getDestructiveChanges() { + return destructiveChanges; + } + + public void setDestructiveChanges(Boolean destructiveChanges) { + this.destructiveChanges = destructiveChanges; + } } diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 651e988..23aba8f 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -91,19 +91,36 @@ public static void createFlowDownloadAllPack(String path) throws IOException { createFlowManifest(root, "package.xml"); } - public static void createFlowInactivation(String srcPath, String outputPath) throws IOException { + public static void createFlowInactivation(String srcPath, String outputPath, boolean createDestructiveChanges) throws IOException { String sourcePath = srcPath + "/flows"; String flowsDestinationPath = outputPath + "/flows"; - - List flowFiles = FlowUtils.getFlowFiles(sourcePath); String manifestFilePath = outputPath + "/package.xml"; File manifestFile = new File(manifestFilePath); Manifest manifest = new Manifest();//FlowUtils.readOrCreateManifest(manifestFile); copyFlowsAndIncreaseVersion(manifest, sourcePath, flowsDestinationPath); createFlowInactivationPack(manifest, outputPath, flowFiles); - serializeXml(manifestFile, manifest); + if (createDestructiveChanges) { + createFlowDeletionPack(manifest, outputPath); + } + } + + + + private static void createFlowDeletionPack(Manifest existingManifest, String path) throws IOException { + File root = new File(path); + String filePath = root.getPath() + "/" + "destructiveChangesPost.xml"; + File manifestFile = new File(filePath); + Manifest manifest = readOrCreateManifest(manifestFile); + ManifestType manifestType = existingManifest.getType("Flow"); + manifest.addType(manifestType); + serializeXml(manifestFile, manifest); + + File packageFile = new File(path + "/" + "package.xml"); + if (!packageFile.exists()) { + serializeXml(packageFile, new Manifest()); + } } private static void createFlowDeletionPack(String path, List flowFiles) throws IOException { @@ -114,11 +131,18 @@ private static void createFlowDeletionPack(String path, List flowFiles ManifestType manifestType = new ManifestType("Flow"); if (flowFiles!=null && flowFiles.size()>0) { for (FlowFile ff : flowFiles) { - manifestType.addMember(ff.getFilenameCurrentVersion()); + manifestType.addMember(ff.getFlowNameCurrentVersion()); } } manifest.addType(manifestType); serializeXml(manifestFile, manifest); + + + File packageFile = new File(path + "/" + "package.xml"); + if (!packageFile.exists()) { + serializeXml(packageFile, new Manifest()); + } + } private static void createFlowDefinitionManifest(Manifest manifest, List flowFiles) throws IOException { diff --git a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java index 54343b5..778a088 100644 --- a/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java +++ b/src/main/java/com/spaceheroes/xml/sfdc/Manifest.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; @@ -35,6 +36,15 @@ public void setVersion(String version) { public List getTypes() { return types; } + + public ManifestType getType(String name) { + for (ManifestType mt : types) { + if (StringUtils.equalsIgnoreCase(name, mt.getName())) { + return mt; + } + } + return null; + } public void setTypes(List types) { this.types = types; From 25cd522bd74537c129ce9a3754deb91413c4bfad Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 15:56:20 +0100 Subject: [PATCH 16/22] removed dead code --- src/main/java/com/spaceheroes/util/FlowUtils.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 23aba8f..00d7b1f 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -72,10 +72,6 @@ public static void createFlowDeletionPack(String sourcePath, String outputPath) List nextVersionFlows = FlowUtils.getFlowFiles(sourcePath + "/flows"); FlowUtils.createFlowDeletionPack(outputPath, nextVersionFlows); } -// public static void createFlowDeletionPack(String flowPath, String outputPath) throws IOException { -// List flowFiles = getFlowFiles(flowPath); -// createFlowDeletionPack(outputPath + "/destructiveChanges.xml", flowFiles); -// } private static void createFlowInactivationPack(Manifest manifest, String path, List flowFiles) throws IOException { File root = new File(path); @@ -106,8 +102,6 @@ public static void createFlowInactivation(String srcPath, String outputPath, boo } } - - private static void createFlowDeletionPack(Manifest existingManifest, String path) throws IOException { File root = new File(path); String filePath = root.getPath() + "/" + "destructiveChangesPost.xml"; From e37cd0d22382b189f0edaf7b468f58569e4d9ec5 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 16:13:15 +0100 Subject: [PATCH 17/22] task renamed --- .classpath | 12 ++++++------ src/antlib.xml | 7 +++---- ...ackage.java => CreateFlowDeleteManifestTask.java} | 2 +- ...ge.java => CreateFlowInactivateManifestTask.java} | 2 +- ...kage.java => CreateFlowRetrieveManifestTask.java} | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) rename src/main/java/com/spaceheroes/task/local/{CreateFlowDeletePackage.java => CreateFlowDeleteManifestTask.java} (93%) rename src/main/java/com/spaceheroes/task/local/{CreateFlowInactivationsPackage.java => CreateFlowInactivateManifestTask.java} (94%) rename src/main/java/com/spaceheroes/task/local/{CreateRetrieveAllFlowsPackage.java => CreateFlowRetrieveManifestTask.java} (91%) diff --git a/.classpath b/.classpath index cb18e1c..42f1bf5 100644 --- a/.classpath +++ b/.classpath @@ -1,21 +1,21 @@ -<<<<<<< HEAD - + + + + + + -======= - ->>>>>>> master - diff --git a/src/antlib.xml b/src/antlib.xml index f62789d..19181a8 100644 --- a/src/antlib.xml +++ b/src/antlib.xml @@ -15,9 +15,8 @@ - - - - + + + \ No newline at end of file diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowDeleteManifestTask.java similarity index 93% rename from src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java rename to src/main/java/com/spaceheroes/task/local/CreateFlowDeleteManifestTask.java index ffcff6e..0af7d25 100644 --- a/src/main/java/com/spaceheroes/task/local/CreateFlowDeletePackage.java +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowDeleteManifestTask.java @@ -7,7 +7,7 @@ import com.spaceheroes.util.FlowUtils; -public class CreateFlowDeletePackage extends Task { +public class CreateFlowDeleteManifestTask extends Task { private String sourcePath; private String destinationPath; diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowInactivateManifestTask.java similarity index 94% rename from src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java rename to src/main/java/com/spaceheroes/task/local/CreateFlowInactivateManifestTask.java index 8dd3220..3f4049b 100644 --- a/src/main/java/com/spaceheroes/task/local/CreateFlowInactivationsPackage.java +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowInactivateManifestTask.java @@ -7,7 +7,7 @@ import com.spaceheroes.util.FlowUtils; -public class CreateFlowInactivationsPackage extends Task { +public class CreateFlowInactivateManifestTask extends Task { private String sourcePath; private String destinationPath; diff --git a/src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java b/src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java similarity index 91% rename from src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java rename to src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java index 8fe0e6f..5060b1c 100644 --- a/src/main/java/com/spaceheroes/task/local/CreateRetrieveAllFlowsPackage.java +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java @@ -7,7 +7,7 @@ import com.spaceheroes.util.FlowUtils; -public class CreateRetrieveAllFlowsPackage extends Task { +public class CreateFlowRetrieveManifestTask extends Task { private String destinationPath; From fa77a2ac0791213ef4bd8672dedf357f7f67bdcc Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 17:09:26 +0100 Subject: [PATCH 18/22] upda --- src/main/java/Main.java | 12 - .../local/CreateFlowRetrieveManifestTask.java | 2 +- .../java/com/spaceheroes/util/FlowUtils.java | 8 +- .../com/spaceheroes/test/FlowUtilsTest.java | 33 ++ .../flowDefinitions/Pricebook.flowDefinition | 4 + ...mber_Sales_Owner_is_Updated.flowDefinition | 4 + ...mber_Sales_Owner_is_Updated.flowDefinition | 4 + src/test/resources/src/flows/Pricebook-1.flow | 175 ++++++ ...paign_Member_Sales_Owner_is_Updated-9.flow | 493 +++++++++++++++++ ...aign_Member_Sales_Owner_is_Updated-31.flow | 506 ++++++++++++++++++ 10 files changed, 1226 insertions(+), 15 deletions(-) delete mode 100644 src/main/java/Main.java create mode 100644 src/test/java/com/spaceheroes/test/FlowUtilsTest.java create mode 100644 src/test/resources/src/flowDefinitions/Pricebook.flowDefinition create mode 100644 src/test/resources/src/flowDefinitions/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition create mode 100644 src/test/resources/src/flowDefinitions/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition create mode 100644 src/test/resources/src/flows/Pricebook-1.flow create mode 100644 src/test/resources/src/flows/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated-9.flow create mode 100644 src/test/resources/src/flows/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated-31.flow diff --git a/src/main/java/Main.java b/src/main/java/Main.java deleted file mode 100644 index d526d91..0000000 --- a/src/main/java/Main.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.io.IOException; - -import com.spaceheroes.util.FlowUtils; - -public class Main { - - public static void main(String[] args) throws IOException { - FlowUtils.createFlowInactivation("data/tmp", "ff-output/2-flows-inactivation", true); - FlowUtils.createFlowDeletionPack("data/tmp", "ff-output/3-flows-deletion"); - } - -} diff --git a/src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java b/src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java index 5060b1c..239bfe3 100644 --- a/src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java +++ b/src/main/java/com/spaceheroes/task/local/CreateFlowRetrieveManifestTask.java @@ -14,7 +14,7 @@ public class CreateFlowRetrieveManifestTask extends Task { @Override public void execute() throws BuildException { try { - FlowUtils.createFlowDownloadAllPack(destinationPath); + FlowUtils.createRetrieveAllFlowsManifest(destinationPath); } catch (IOException e) { e.printStackTrace(); throw new BuildException(e); diff --git a/src/main/java/com/spaceheroes/util/FlowUtils.java b/src/main/java/com/spaceheroes/util/FlowUtils.java index 093d3b4..8a12f95 100644 --- a/src/main/java/com/spaceheroes/util/FlowUtils.java +++ b/src/main/java/com/spaceheroes/util/FlowUtils.java @@ -85,8 +85,12 @@ private static void createFlowInactivationPack(Manifest manifest, String path, L } } - // public - public static void createFlowDownloadAllPack(String path) throws IOException { + /** + * Creates a manifest file (package.xml) that can be used with the Force.com Migration Tool to retrieve all Flows from an org. + * @param path the relative path where the manifest file should be created + * @throws IOException if the manifest file cannot be created + */ + public static void createRetrieveAllFlowsManifest(String path) throws IOException { File root = new File(path); createFlowManifest(root, "package.xml"); } diff --git a/src/test/java/com/spaceheroes/test/FlowUtilsTest.java b/src/test/java/com/spaceheroes/test/FlowUtilsTest.java new file mode 100644 index 0000000..350cea3 --- /dev/null +++ b/src/test/java/com/spaceheroes/test/FlowUtilsTest.java @@ -0,0 +1,33 @@ +package com.spaceheroes.test; + +import java.io.File; + +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Test; + +import com.spaceheroes.util.FlowUtils; + +public class FlowUtilsTest { + + @Test + public void testFlowPackage() throws Exception { + FlowUtils.createRetrieveAllFlowsManifest("target/test-tmp/flow-retrieve"); + } + + @Test + public void testFlowInactivation() throws Exception { + FlowUtils.createFlowInactivation("src/test/resources/src", "target/test-tmp/flow-inactivation", true); + } + + @Test + public void testFlowDeletion() throws Exception { + FlowUtils.createFlowDeletionPack("src/test/resources/src", "target/test-tmp/flow-deletion"); + } + + @After + public void tearDown() { + FileUtils.deleteQuietly(new File("target/test-tmp")); + } + +} diff --git a/src/test/resources/src/flowDefinitions/Pricebook.flowDefinition b/src/test/resources/src/flowDefinitions/Pricebook.flowDefinition new file mode 100644 index 0000000..f520ee4 --- /dev/null +++ b/src/test/resources/src/flowDefinitions/Pricebook.flowDefinition @@ -0,0 +1,4 @@ + + + 1 + diff --git a/src/test/resources/src/flowDefinitions/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition b/src/test/resources/src/flowDefinitions/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition new file mode 100644 index 0000000..efbe661 --- /dev/null +++ b/src/test/resources/src/flowDefinitions/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition @@ -0,0 +1,4 @@ + + + 9 + diff --git a/src/test/resources/src/flowDefinitions/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition b/src/test/resources/src/flowDefinitions/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition new file mode 100644 index 0000000..c09e135 --- /dev/null +++ b/src/test/resources/src/flowDefinitions/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated.flowDefinition @@ -0,0 +1,4 @@ + + + 31 + diff --git a/src/test/resources/src/flows/Pricebook-1.flow b/src/test/resources/src/flows/Pricebook-1.flow new file mode 100644 index 0000000..f0d06be --- /dev/null +++ b/src/test/resources/src/flows/Pricebook-1.flow @@ -0,0 +1,175 @@ + + + + myVariable_waitStartTimeAssignment + + 0 + 0 + + myVariable_waitStartTimeVariable + Assign + + $Flow.CurrentDateTime + + + + myDecision + + + + + index + + 0.0 + + + myDecision + + 50 + 0 + default + + myRule_1 + and + + formula_myRule_1 + EqualTo + + true + + + + myRule_1_A1 + + + + + This process takes the price stage from the Pricebook and adds it to Opportunity Product + + formula_myRule_1 + Boolean + true + + Pricebook-1_OpportunityLineItem + + + ObjectType + + OpportunityLineItem + + + + ObjectVariable + + myVariable_current + + + + OldObjectVariable + + myVariable_old + + + + TriggerType + + onCreateOnly + + + Workflow + + + evaluationType + + always + + + + isChildRelationship + + false + + + + reference + + [OpportunityLineItem] + + + myRule_1_A1 + + 100 + 200 + + + implicit + + true + + + Id + EqualTo + + myVariable_current.Id + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Price Stage + + + + rightHandSideType + + Reference + + + Price_Stage__c + + myVariable_current.PricebookEntry.Pricebook2.Price_Stage__c + + + OpportunityLineItem + + myVariable_waitStartTimeAssignment + + myVariable_current + SObject + false + true + true + OpportunityLineItem + + + myVariable_old + SObject + false + true + false + OpportunityLineItem + + + myVariable_waitStartTimeVariable + DateTime + false + false + false + + $Flow.CurrentDateTime + + + diff --git a/src/test/resources/src/flows/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated-9.flow b/src/test/resources/src/flows/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated-9.flow new file mode 100644 index 0000000..492f689 --- /dev/null +++ b/src/test/resources/src/flows/Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated-9.flow @@ -0,0 +1,493 @@ + + + + myVariable_waitStartTimeAssignment + + 0 + 0 + + myVariable_waitStartTimeVariable + Assign + + $Flow.CurrentDateTime + + + + myDecision + + + + + index + + 0.0 + + + myDecision + + 50 + 0 + + myDecision4 + + default + + myRule_1 + and + + formula_myRule_1 + EqualTo + + true + + + + myRule_1_A1 + + + + + + + index + + 1.0 + + + myDecision4 + + 50 + 0 + default + + myRule_5 + and + + formula_myRule_5 + EqualTo + + true + + + + myRule_5_A1 + + + + + + + originalFormula + + TODAY() + 1 + + + formula_2_myRule_1_A2_ActivityDate + Date + TODAY() + 1 + + + + originalFormula + + [CampaignMember].Contact.Sales_Owners_ID__c & [CampaignMember].CampaignId & [CampaignMember].Sales_Owner__c + + + formula_3_myRule_1_A1_Sales_Owners_ID_c + String + {!myVariable_current.Contact.Sales_Owners_ID__c} & {!myVariable_current.CampaignId} & {!myVariable_current.Sales_Owner__c} + + + + originalFormula + + SUBSTITUTE( [CampaignMember].Contact.Sales_Owners_ID__c , + +( [CampaignMember].CampaignId & [CampaignMember].Sales_Owner__c ),"" +) + + + formula_6_myRule_5_A1_Sales_Owners_ID_c + String + SUBSTITUTE( {!myVariable_current.Contact.Sales_Owners_ID__c} , + +( {!myVariable_current.CampaignId} & {!myVariable_current.Sales_Owner__c} ),"" +) + + + + originalFormula + + AND( +OR +(ISNEW(), +ISCHANGED([CampaignMember].Sales_Owner__c ) +), +NOT(ISBLANK([CampaignMember].Sales_Owner__c)), +NOT(ISBLANK([CampaignMember].ContactId )) +) + + + + + + formula_myRule_1 + Boolean + AND( +OR +(ISNEW(), +ISCHANGED({!myVariable_current.Sales_Owner__c} ) +), +NOT(ISBLANK({!myVariable_current.Sales_Owner__c})), +NOT(ISBLANK({!myVariable_current.ContactId} )) +) + + + + originalFormula + + AND( +OR +(ISNEW(), +ISCHANGED([CampaignMember].Sales_Status2__c) +), +ISPICKVAL([CampaignMember].Sales_Status2__c,"Disqualified"), +NOT(ISBLANK([CampaignMember].ContactId )) +) + + + + + + formula_myRule_5 + Boolean + AND( +OR +(ISNEW(), +ISCHANGED({!myVariable_current.Sales_Status2__c}) +), +ISPICKVAL({!myVariable_current.Sales_Status2__c},"Disqualified"), +NOT(ISBLANK({!myVariable_current.ContactId} )) +) + + Update_Contact_when_Campaign_Member_Sales_Owner_is_Updated-9_CampaignMember + + + ObjectType + + CampaignMember + + + + ObjectVariable + + myVariable_current + + + + OldObjectVariable + + myVariable_old + + + + TriggerType + + onAllChanges + + + Workflow + + myRule_1_A2 + + 100 + 300 + + + dataType + + Date + + + + isRequired + + false + + + + leftHandSideLabel + + Due Date Only + + + + rightHandSideType + + Formula + + + ActivityDate + + formula_2_myRule_1_A2_ActivityDate + + + + + dataType + + ID + + + + isRequired + + false + + + + leftHandSideLabel + + Assigned To ID + + + + rightHandSideType + + Reference + + + OwnerId + + myVariable_current.Sales_Owner__c + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Subject + + + + rightHandSideType + + String + + + Subject + + New Prospect + + + + + dataType + + ID + + + + isRequired + + false + + + + leftHandSideLabel + + Name ID + + + + rightHandSideType + + Reference + + + WhoId + + myVariable_current.ContactId + + + Task + + + + evaluationType + + always + + + + isChildRelationship + + false + + + + reference + + [CampaignMember].Contact ID + + + myRule_1_A1 + + 100 + 200 + + myRule_1_A2 + + + + implicit + + true + + + Id + EqualTo + + myVariable_current.ContactId + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Sales Owners ID + + + + rightHandSideType + + Formula + + + Sales_Owners_ID__c + + formula_3_myRule_1_A1_Sales_Owners_ID_c + + + Contact + + + + evaluationType + + always + + + + isChildRelationship + + false + + + + reference + + [CampaignMember].Contact ID + + + myRule_5_A1 + + 500 + 200 + + + implicit + + true + + + Id + EqualTo + + myVariable_current.ContactId + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Sales Owners ID + + + + rightHandSideType + + Formula + + + Sales_Owners_ID__c + + formula_6_myRule_5_A1_Sales_Owners_ID_c + + + Contact + + myVariable_waitStartTimeAssignment + + myVariable_current + SObject + false + true + true + CampaignMember + + + myVariable_old + SObject + false + true + false + CampaignMember + + + myVariable_waitStartTimeVariable + DateTime + false + false + false + + $Flow.CurrentDateTime + + + diff --git a/src/test/resources/src/flows/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated-31.flow b/src/test/resources/src/flows/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated-31.flow new file mode 100644 index 0000000..21da50d --- /dev/null +++ b/src/test/resources/src/flows/Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated-31.flow @@ -0,0 +1,506 @@ + + + + myVariable_waitStartTimeAssignment + + 0 + 0 + + myVariable_waitStartTimeVariable + Assign + + $Flow.CurrentDateTime + + + + myDecision + + + + + index + + 0.0 + + + myDecision + + 50 + 0 + + myDecision4 + + default + + myRule_1 + and + + formula_myRule_1 + EqualTo + + true + + + + myRule_1_A1 + + + + + + + index + + 1.0 + + + myDecision4 + + 50 + 0 + default + + myRule_5 + and + + formula_myRule_5 + EqualTo + + true + + + + myRule_5_A1 + + + + + + + originalFormula + + TODAY() + 1 + + + formula_2_myRule_1_A2_ActivityDate + Date + TODAY() + 1 + + + + originalFormula + + [CampaignMember].Lead.Sales_Owner_Ids__c & ( [CampaignMember].CampaignId & [CampaignMember].Sales_Owner__c) + + + + formula_3_myRule_1_A1_Sales_Owner_Ids_c + String + {!myVariable_current.Lead.Sales_Owner_Ids__c} & ( {!myVariable_current.CampaignId} & {!myVariable_current.Sales_Owner__c}) + + + + originalFormula + + SUBSTITUTE( [CampaignMember].Lead.Sales_Owner_Ids__c , + +( [CampaignMember].CampaignId & [CampaignMember].Sales_Owner__c ),"" +) + + + formula_6_myRule_5_A1_Sales_Owner_Ids_c + String + SUBSTITUTE( {!myVariable_current.Lead.Sales_Owner_Ids__c} , + +( {!myVariable_current.CampaignId} & {!myVariable_current.Sales_Owner__c} ),"" +) + + + + originalFormula + + AND( +OR +(ISNEW(), +ISCHANGED([CampaignMember].Sales_Owner__c ) +), +NOT(ISBLANK([CampaignMember].Sales_Owner__c )), +NOT(ISBLANK([CampaignMember].LeadId )) +) + + + formula_myRule_1 + Boolean + AND( +OR +(ISNEW(), +ISCHANGED({!myVariable_current.Sales_Owner__c} ) +), +NOT(ISBLANK({!myVariable_current.Sales_Owner__c} )), +NOT(ISBLANK({!myVariable_current.LeadId} )) +) + + + + originalFormula + + AND( +OR +(ISNEW(), +ISCHANGED([CampaignMember].Sales_Status2__c) +), +ISPICKVAL([CampaignMember].Sales_Status2__c,"Disqualified"), +NOT(ISBLANK([CampaignMember].LeadId )) +) + + + + formula_myRule_5 + Boolean + AND( +OR +(ISNEW(), +ISCHANGED({!myVariable_current.Sales_Status2__c}) +), +ISPICKVAL({!myVariable_current.Sales_Status2__c},"Disqualified"), +NOT(ISBLANK({!myVariable_current.LeadId} )) +) + + Update_Lead_when_Campaign_Member_Sales_Owner_is_Updated-31_CampaignMember + + + ObjectType + + CampaignMember + + + + ObjectVariable + + myVariable_current + + + + OldObjectVariable + + myVariable_old + + + + RecursiveCountVariable + + RecursiveCountVariable + + + + TriggerType + + onAllChanges + + + Workflow + + myRule_1_A2 + + 100 + 300 + + myDecision4 + + + + dataType + + Date + + + + isRequired + + false + + + + leftHandSideLabel + + Due Date Only + + + + rightHandSideType + + Formula + + + ActivityDate + + formula_2_myRule_1_A2_ActivityDate + + + + + dataType + + ID + + + + isRequired + + false + + + + leftHandSideLabel + + Assigned To ID + + + + rightHandSideType + + Reference + + + OwnerId + + myVariable_current.Sales_Owner__c + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Subject + + + + rightHandSideType + + String + + + Subject + + New Prospect + + + + + dataType + + ID + + + + isRequired + + false + + + + leftHandSideLabel + + Name ID + + + + rightHandSideType + + Reference + + + WhoId + + myVariable_current.LeadId + + + Task + + + + evaluationType + + always + + + + isChildRelationship + + false + + + + reference + + [CampaignMember].Lead ID + + + myRule_1_A1 + + 100 + 200 + + myRule_1_A2 + + + + implicit + + true + + + Id + EqualTo + + myVariable_current.LeadId + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Sales Owner Ids + + + + rightHandSideType + + Formula + + + Sales_Owner_Ids__c + + formula_3_myRule_1_A1_Sales_Owner_Ids_c + + + Lead + + + + evaluationType + + always + + + + isChildRelationship + + false + + + + reference + + [CampaignMember].Lead ID + + + myRule_5_A1 + + 500 + 200 + + + implicit + + true + + + Id + EqualTo + + myVariable_current.LeadId + + + + + dataType + + String + + + + isRequired + + false + + + + leftHandSideLabel + + Sales Owner Ids + + + + rightHandSideType + + Formula + + + Sales_Owner_Ids__c + + formula_6_myRule_5_A1_Sales_Owner_Ids_c + + + Lead + + myVariable_waitStartTimeAssignment + + myVariable_current + SObject + false + true + true + CampaignMember + + + myVariable_old + SObject + false + true + false + CampaignMember + + + myVariable_waitStartTimeVariable + DateTime + false + false + false + + $Flow.CurrentDateTime + + + + RecursiveCountVariable + Number + false + true + false + 2 + + From c3a9b64fe8b5f7e6ff76984885ebf9d3655bbbd6 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 17:22:08 +0100 Subject: [PATCH 19/22] unit test updates --- .../com/spaceheroes/test/FlowUtilsTest.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/spaceheroes/test/FlowUtilsTest.java b/src/test/java/com/spaceheroes/test/FlowUtilsTest.java index 350cea3..bd641d1 100644 --- a/src/test/java/com/spaceheroes/test/FlowUtilsTest.java +++ b/src/test/java/com/spaceheroes/test/FlowUtilsTest.java @@ -4,25 +4,37 @@ import org.apache.commons.io.FileUtils; import org.junit.After; +import org.junit.Assert; import org.junit.Test; +import org.simpleframework.xml.Serializer; +import org.simpleframework.xml.core.Persister; import com.spaceheroes.util.FlowUtils; +import com.spaceheroes.xml.sfdc.Manifest; + public class FlowUtilsTest { @Test public void testFlowPackage() throws Exception { - FlowUtils.createRetrieveAllFlowsManifest("target/test-tmp/flow-retrieve"); + String destinationPath = "target/test-tmp/flow-retrieve"; + FlowUtils.createRetrieveAllFlowsManifest(destinationPath); + checkThatManifestExists(destinationPath, "package.xml"); } @Test public void testFlowInactivation() throws Exception { - FlowUtils.createFlowInactivation("src/test/resources/src", "target/test-tmp/flow-inactivation", true); + String destinationPath = "target/test-tmp/flow-inactivation"; + FlowUtils.createFlowInactivation("src/test/resources/src", destinationPath, true); + checkThatManifestExists(destinationPath, "package.xml"); + checkThatManifestExists(destinationPath, "destructiveChangesPost.xml"); } @Test public void testFlowDeletion() throws Exception { - FlowUtils.createFlowDeletionPack("src/test/resources/src", "target/test-tmp/flow-deletion"); + String destinationPath = "target/test-tmp/flow-deletion"; + FlowUtils.createFlowDeletionPack("src/test/resources/src", destinationPath); + checkThatManifestExists(destinationPath, "destructiveChanges.xml"); } @After @@ -30,4 +42,20 @@ public void tearDown() { FileUtils.deleteQuietly(new File("target/test-tmp")); } + private static void checkThatManifestExists(String path, String filename) { + + // Make sure that file exists, and it's not empty + File file = new File(path + "/" + filename); + Assert.assertTrue("Manifest must exist", file.exists()); + Assert.assertTrue("Manifest must not be empty", file.length()>0); + + // Make sure that file can be read correctly + try { + Serializer serializer = new Persister(); + serializer.read(Manifest.class, file); + } catch (Exception e) { + Assert.fail("Manifest must be valid and deserializable"); + } + } + } From 680fac68b38f7bd2fb2581a9cb9f503c9f3283df Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 17:23:00 +0100 Subject: [PATCH 20/22] removed empty task --- src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java diff --git a/src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java b/src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java deleted file mode 100644 index a06b173..0000000 --- a/src/main/java/com/spaceheroes/task/DeactivateFlowsTask.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.spaceheroes.task; - -public class DeactivateFlowsTask extends SalesforceTask { - -} From e3278ff490db8278de5ffcd0787ab7fa7236fbc7 Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 17:28:55 +0100 Subject: [PATCH 21/22] pom and README updates --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++----------- pom.xml | 2 +- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d13edb8..42ea04a 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,14 @@ It is built on top of [Apache Ant](http://ant.apache.org/), so it can be used in * Execute Apex code * Run Apex tests (with XML reports) * Insert and delete records +* Support for flow deactivation and deletion ## Usage ### Create a build file If you are not familiar with Ant and you need a template for your script you can copy the one below. ```XML - + + + + + + + + + + ``` ## License diff --git a/pom.xml b/pom.xml index 81eecc4..1feb95d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.spaceheroes forceflow - 0.0.9 + 0.0.10 ForceFlow From 3f533597fd162ef09034f0686fe85f290d5b0eee Mon Sep 17 00:00:00 2001 From: eroispaziali Date: Tue, 25 Oct 2016 17:32:01 +0100 Subject: [PATCH 22/22] added circle.yml --- circle.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..692e6aa --- /dev/null +++ b/circle.yml @@ -0,0 +1,3 @@ +machine: + java: + version: openjdk8 \ No newline at end of file