Alessandro Dionisi [
https://community.jboss.org/people/cecchisandrone] created the
discussion
"Re: Link between org.drools.definition.process.Process and asset in Guvnor"
To view the discussion, visit:
https://community.jboss.org/message/761044#761044
--------------------------------------------------------------
I've written this function that using the REST API retrieves the process UUID. It
returns the first asset (BPMN file) that has a matching process ID in the definition.
Do you think it's a right solution?
public String getProcessUUID(Process p) {
try {
URL restUrl = new URL(url + "rest/packages/");
HttpURLConnection connection = (HttpURLConnection)
restUrl.openConnection();
connection.setRequestProperty("Authorization",
"Basic " + new Base64().encodeToString(((username + ":" +
password).getBytes())));
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept",
MediaType.APPLICATION_ATOM_XML);
connection.connect();
assertEquals(200, connection.getResponseCode());
assertEquals(MediaType.APPLICATION_ATOM_XML,
connection.getContentType());
// Parse response
InputStream in = connection.getInputStream();
Document<Feed> doc = abdera.getParser().parse(in);
Feed feed = doc.getRoot();
List<Entry> entries = feed.getEntries();
Iterator<Entry> it = entries.iterator();
while (it.hasNext()) {
Entry entry = it.next();
// Match package
if (p.getPackageName().equals(entry.getTitle()))
{
// Get the assets
restUrl = new URL(url +
"rest/packages/" + p.getPackageName() + "/assets");
HttpURLConnection assetConnection =
(HttpURLConnection) restUrl.openConnection();
assetConnection.setRequestProperty("Authorization",
"Basic " + new Base64().encodeToString(((username + ":" +
password).getBytes())));
assetConnection.setRequestMethod("GET");
assetConnection.setRequestProperty("Accept",
MediaType.APPLICATION_ATOM_XML);
assetConnection.connect();
assertEquals(200,
assetConnection.getResponseCode());
assertEquals(MediaType.APPLICATION_ATOM_XML,
assetConnection.getContentType());
// Parse response
InputStream in2 =
assetConnection.getInputStream();
Document<Feed> assets =
abdera.getParser().parse(in2);
Feed assetFeed = assets.getRoot();
List<Entry> assetsEntries =
assetFeed.getEntries();
for (Entry atomEntry : assetsEntries) {
ExtensibleElement
metadataExtension = atomEntry.getExtension(Translator.METADATA);
ExtensibleElement
formatExtension = metadataExtension.getExtension(Translator.FORMAT);
ExtensibleElement
uuidExtension = metadataExtension.getExtension(Translator.UUID);
String uuid =
uuidExtension.getSimpleExtension(Translator.VALUE);
if
(formatExtension.getSimpleExtension(Translator.VALUE).contains("bpmn")) {
// Check if the bpmn
file contains the specified process ID
SemanticModules
modules = new SemanticModules();
modules.addSemanticModule(new BPMNSemanticModule());
modules.addSemanticModule(new BPMNDISemanticModule());
XmlProcessReader
processReader = new XmlProcessReader(modules, getClass().getClassLoader());
processReader.read(atomEntry.getContentStream());
// The bpmn file
matches the process ID, return the UUID of the asset
if
(processReader.getProcess().get(0).getId().equals(p.getId()))
return
uuid;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/761044#761044]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]