Skip to content

Commit

Permalink
Merge pull request #6 from eroispaziali/ft/flows
Browse files Browse the repository at this point in the history
Support for flow deactivation and deletion
  • Loading branch information
Lorenzo Frattini authored Oct 25, 2016
2 parents 4cdf614 + 3f53359 commit deb9ad7
Show file tree
Hide file tree
Showing 28 changed files with 1,909 additions and 25 deletions.
13 changes: 11 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ target/classes/*
*.class
test-report*.xml
/target/
.idea*
.DS_Store
package.xml
7 changes: 4 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?xml version="1.0" encoding="UTF-8"?>
<project name="forceflow-sample" xmlns:forceflow="antlib:com.spaceheroes">
<project name="forceflow-sample" xmlns:ff="antlib:com.spaceheroes">

<!--
This assumes forceflow.jar is copied
Expand All @@ -35,57 +36,87 @@ If you are not familiar with Ant and you need a template for your script you can
### Execute Apex code
You can execute an Apex script as follows.
```XML
<forceflow:apex username="..." password="..." serverurl="...">
<ff:apex username="..." password="..." serverurl="...">
<![CDATA[
List<Contact> cts = [SELECT id,Email FROM Contact WHERE (Email<>null AND (NOT Email LIKE '%.nospam'))];
for (Contact ct : cts) {
ct.Email = ct.Email + '.nospam';
}
update cts;
]]>
</forceflow:apex>
</ff:apex>
```

### Remote Site Settings
Use this to create or update remote site settings.
```XML
<forceflow:remotesite name="Google_APIs" url="https://www.googleapis.com" disableProtocolSecurity="true" username="..." password="..." serverurl="...">
<ff:remotesite name="Google_APIs" url="https://www.googleapis.com" disableProtocolSecurity="true" username="..." password="..." serverurl="...">
Allows queries to the Google Maps API
</forceflow:remotesite>
</ff:remotesite>
```

### Clear scheduled jobs
Use this tag to abort all the jobs that are currently scheduled.
```XML
<forceflow:clearschedule username="..." password="..." serverurl="..." />
<ff:clearschedule username="..." password="..." serverurl="..." />
```

### Schedule an Apex job
You can use this task to schedule the execution of a batch class.
```XML
<forceflow:scheduleapex username="..." password="..." serverurl="..." className="MySchedulableClass" cron="0 0 12 1/1 * ? *" />
<ff:scheduleapex username="..." password="..." serverurl="..." className="MySchedulableClass" cron="0 0 12 1/1 * ? *" />
```

### Insert a record
Works with both objects and custom settings.
```XML
<forceflow:insert object="Contact" username="..." password="..." serverurl="...">
<ff:insert object="Contact" username="..." password="..." serverurl="...">
<property name="FirstName" value="Some"/>
<property name="LastName" value="Dude"/>
<property name="Email" value="[email protected]"/>
</forceflow:insert>
</ff:insert>
```

### Delete all records
You can delete all the records from an object or a custom settings. It's bulkified, so it works also with very large tables.
```XML
<forceflow:deleteall object="Contact" username="..." password="..." serverurl="..."/>
<ff:deleteall object="Contact" username="..." password="..." serverurl="..."/>
```

### Run all tests (with XML test report)
Generates a full test report in the JUnit XML format (output file: _test-report.xml_). This report can be read by Atlassian Bamboo to [display test results of a build](https://confluence.atlassian.com/bamboo/viewing-test-results-for-a-build-289276936.html).
```XML
<forceflow:runtests username="..." password="..." serverurl="..." />
<ff:runtests username="..." password="..." serverurl="..." />
```

### Deactivate flows

```XML
<target name="deactivateFlows">

<delete dir="temp"/>

<!-- retrieve existing flows -->
<ff:createFlowRetrieveAllManifest destinationPath="temp/existing" />
<sf:retrieve
username="${sf.username}"
password="${sf.password}"
serverurl="${sf.serverurl}"
retrieveTarget="temp/existing"
unpackaged="temp/existing/package.xml"/>

<!-- create a manifest to inactivate all the flows, then deploy it -->
<ff:createFlowInactivateManifest
sourcePath="temp/existing"
destinationPath="temp/inactivation" />
<sf:deploy
username="${sf.username}"
password="${sf.password}"
serverurl="${sf.serverurl}"
deployRoot="temp/inactivation" />

<delete dir="temp"/>
</target>
```

## License
Expand Down
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine:
java:
version: openjdk8
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.spaceheroes</groupId>
<artifactId>forceflow</artifactId>
<version>0.0.9</version>
<version>0.0.10</version>
<name>ForceFlow</name>
<dependencies>
<dependency>
Expand Down Expand Up @@ -51,6 +51,11 @@
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<resources>
Expand All @@ -67,8 +72,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down
5 changes: 5 additions & 0 deletions src/antlib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<typedef name="apex" classname="com.spaceheroes.task.RunApexTask"/>
<typedef name="runtests" classname="com.spaceheroes.task.RunTestsTask"/>

<!-- Flows -->
<typedef name="createFlowRetrieveManifest" classname="com.spaceheroes.task.local.CreateFlowRetrieveManifestTask"/>
<typedef name="createFlowInactivateManifest" classname="com.spaceheroes.task.local.CreateFlowInactivateManifestTask"/>
<typedef name="createFlowDeleteManifest" classname="com.spaceheroes.task.local.CreateFlowDeleteManifestTask"/>

</antlib>
66 changes: 66 additions & 0 deletions src/main/java/com/spaceheroes/model/FlowFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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 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);
}

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;
}

public File getFile() {
return file;
}

}
6 changes: 3 additions & 3 deletions src/main/java/com/spaceheroes/task/RunTestsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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 CreateFlowDeleteManifestTask 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;
}

public String getSourcePath() {
return sourcePath;
}

public void setSourcePath(String sourcePath) {
this.sourcePath = sourcePath;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 CreateFlowInactivateManifestTask extends Task {

private String sourcePath;
private String destinationPath;
private Boolean destructiveChanges = Boolean.FALSE;

@Override
public void execute() throws BuildException {
try {
FlowUtils.createFlowInactivation(sourcePath, destinationPath, destructiveChanges);
} 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;
}

public Boolean getDestructiveChanges() {
return destructiveChanges;
}

public void setDestructiveChanges(Boolean destructiveChanges) {
this.destructiveChanges = destructiveChanges;
}

}
Loading

0 comments on commit deb9ad7

Please sign in to comment.