New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JBPM-7913 - Create pastebin workitem #76
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/target | ||
/local | ||
/bin | ||
|
||
# Eclipse, Netbeans and IntelliJ files | ||
/.* | ||
!.gitignore | ||
/nbproject | ||
/*.ipr | ||
/*.iws | ||
/*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> | ||
<id>bin</id> | ||
<formats> | ||
<format>dir</format> | ||
<format>zip</format> | ||
</formats> | ||
<includeBaseDirectory>false</includeBaseDirectory> | ||
|
||
<fileSets> | ||
<fileSet> | ||
<directory>target</directory> | ||
<outputDirectory></outputDirectory> | ||
<includes> | ||
<include>*.jar</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>target/generated-sources/annotations</directory> | ||
<outputDirectory></outputDirectory> | ||
<includes> | ||
<include>*.wid</include> | ||
<include>index.html</include> | ||
<include>*.json</include> | ||
<include>*.xml</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>target/classes</directory> | ||
<outputDirectory></outputDirectory> | ||
<includes> | ||
<include>repoconf.part</include> | ||
<include>repoindex.html</include> | ||
<include>icon.png</include> | ||
</includes> | ||
</fileSet> | ||
</fileSets> | ||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
<?xml version="1.0"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jbpm.contrib</groupId> | ||
<artifactId>workitems</artifactId> | ||
<version>7.15.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pastebin-workitem</artifactId> | ||
<name>Pastebin</name> | ||
<description>Create new or get existing pastes from Pastebin</description> | ||
<organization> | ||
<name>jBPM dev team</name> | ||
</organization> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org</groupId> | ||
<artifactId>jpastebin</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kie-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jbpm</groupId> | ||
<artifactId>jbpm-workitems-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jbpm</groupId> | ||
<artifactId>jbpm-document</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jbpm</groupId> | ||
<artifactId>jbpm-workitems-core</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.powermock</groupId> | ||
<artifactId>powermock-api-mockito</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.powermock</groupId> | ||
<artifactId>powermock-module-junit4</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jbpm</groupId> | ||
<artifactId>jbpm-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jbpm</groupId> | ||
<artifactId>jbpm-test-util</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>template-resources</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>${project.build.directory}/generated-sources/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>false</filtering> | ||
<includes> | ||
<include>*.png</include> | ||
</includes> | ||
</resource> | ||
<resource> | ||
<directory>${project.build.directory}/maven-shared-archive-resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>*.part</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>templating-maven-plugin</artifactId> | ||
<version>1.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>filter-src</id> | ||
<goals> | ||
<goal>filter-sources</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory> | ||
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-remote-resources-plugin</artifactId> | ||
<version>1.5</version> | ||
<configuration> | ||
<resourceBundles> | ||
<resourceBundle>${project.groupId}:template-resources:${project.version}</resourceBundle> | ||
</resourceBundles> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>process</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-repository-resources</id> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
<resources> | ||
<resource> | ||
<directory>target/generated-sources/annotations</directory> | ||
<includes> | ||
<include>repoindex.html</include> | ||
</includes> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<outputDirectory>target/classes</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Pastebin Workitems - prerequisite | ||
|
||
* To use these workitems first create an account on https://pastebin.com/. | ||
Once you create an account go to | ||
https://pastebin.com/api to get your developer API key. This key | ||
needs to be passed to the handlers in your deployment descriptor configuration. | ||
|
||
* To use the GetExistingPastebin workitem handler it's necessary to have | ||
your IP white-listed. See more info on this on https://pastebin.com/api_scraping_faq. |
146 changes: 146 additions & 0 deletions
146
...kitem/src/main/java/org/jbpm/process/workitem/pastebin/CreatePastebinWorkitemHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jbpm.process.workitem.pastebin; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.jbpm.document.Document; | ||
import org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler; | ||
import org.jbpm.process.workitem.core.util.RequiredParameterValidator; | ||
import org.jbpm.process.workitem.core.util.Wid; | ||
import org.jbpm.process.workitem.core.util.WidMavenDepends; | ||
import org.jbpm.process.workitem.core.util.WidParameter; | ||
import org.jbpm.process.workitem.core.util.WidResult; | ||
import org.jbpm.process.workitem.core.util.service.WidAction; | ||
import org.jbpm.process.workitem.core.util.service.WidService; | ||
import org.jpastebin.pastebin.PastebinLink; | ||
import org.jpastebin.pastebin.PastebinPaste; | ||
import org.kie.api.runtime.process.WorkItem; | ||
import org.kie.api.runtime.process.WorkItemManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Wid(widfile = "CreatePastebin.wid", name = "CreatePastebin", | ||
displayName = "CreatePastebin", | ||
defaultHandler = "mvel: new org.jbpm.process.workitem.pastebin.CreatePastebinWorkitemHandler()", | ||
documentation = "${artifactId}/index.html", | ||
parameters = { | ||
@WidParameter(name = "Title"), | ||
@WidParameter(name = "Content", required = true), | ||
@WidParameter(name = "Format"), | ||
@WidParameter(name = "Visibility"), | ||
@WidParameter(name = "Author") | ||
}, | ||
results = { | ||
@WidResult(name = "PasteURL") | ||
}, | ||
mavenDepends = { | ||
@WidMavenDepends(group = "${groupId}", artifact = "${artifactId}", version = "${version}") | ||
}, | ||
serviceInfo = @WidService(category = "${name}", description = "${description}", | ||
keywords = "paste,pastebin,create", | ||
action = @WidAction(title = "Create a paste on Pastebin") | ||
)) | ||
public class CreatePastebinWorkitemHandler extends AbstractLogOrThrowWorkItemHandler { | ||
|
||
private String develKey; | ||
|
||
private static final Logger logger = LoggerFactory | ||
.getLogger(CreatePastebinWorkitemHandler.class); | ||
private static final String RESULTS_VALUE = "PasteURL"; | ||
|
||
public CreatePastebinWorkitemHandler(String develKey) { | ||
this.develKey = develKey; | ||
} | ||
|
||
public void executeWorkItem(WorkItem workItem, | ||
WorkItemManager workItemManager) { | ||
try { | ||
RequiredParameterValidator.validate(this.getClass(), | ||
workItem); | ||
|
||
Map<String, Object> results = new HashMap<String, Object>(); | ||
String title = (String) workItem.getParameter("Title"); | ||
Object content = workItem.getParameter("Content"); | ||
String format = (String) workItem.getParameter("Format"); | ||
String visibility = (String) workItem.getParameter("Visibility"); | ||
String author = (String) workItem.getParameter("Author"); | ||
|
||
PastebinPaste pastebin = (PastebinPaste) workItem.getParameter("Pastebin"); | ||
if (pastebin == null) { | ||
pastebin = new PastebinPaste(); | ||
} | ||
|
||
pastebin.setDeveloperKey(develKey); | ||
|
||
if (content instanceof Document) { | ||
pastebin.setContents(new String(((Document) content).getContent(), | ||
StandardCharsets.UTF_8)); | ||
} else if (content instanceof String) { | ||
pastebin.setContents((String) content); | ||
} else { | ||
throw new IllegalArgumentException("Invalid type for " + content + ". Should be Document or String type"); | ||
} | ||
|
||
if (title != null && title.trim().length() > 0) { | ||
pastebin.setPasteTitle(title); | ||
} | ||
|
||
if (format != null && format.trim().length() > 0) { | ||
pastebin.setPasteFormat(format); | ||
} | ||
|
||
if (visibility != null && visibility.trim().length() > 0 && visibility.matches("-?\\d+")) { | ||
int visibilityInt = Integer.parseInt(visibility); | ||
|
||
switch (visibilityInt) { | ||
case 0: | ||
pastebin.setVisibility(PastebinPaste.VISIBILITY_PUBLIC); | ||
break; | ||
case 1: | ||
pastebin.setVisibility(PastebinPaste.VISIBILITY_UNLISTED); | ||
break; | ||
case 2: | ||
pastebin.setVisibility(PastebinPaste.VISIBILITY_PRIVATE); | ||
break; | ||
default: | ||
pastebin.setVisibility(PastebinPaste.VISIBILITY_PUBLIC); | ||
break; | ||
} | ||
} else { | ||
pastebin.setVisibility(PastebinPaste.VISIBILITY_PUBLIC); | ||
} | ||
|
||
if (author != null) { | ||
pastebin.setPasteAuthor(author); | ||
} | ||
|
||
PastebinLink pastebinLink = pastebin.paste(); | ||
results.put(RESULTS_VALUE, | ||
pastebinLink.getLink()); | ||
workItemManager.completeWorkItem(workItem.getId(), | ||
results); | ||
} catch (Exception e) { | ||
handleException(e); | ||
} | ||
} | ||
|
||
public void abortWorkItem(WorkItem wi, | ||
WorkItemManager wim) { | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find the work item handler to get existing pastes... is this still planned to be implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to and would be easy but for scraping existing padtebin makes you buy the pro version which costs money, so i deferred it for now.can add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added