cancel
Showing results for 
Search instead for 
Did you mean: 

How to run the activiti source code?

balaji1
Champ in-the-making
Champ in-the-making
Hi,

1. We have checked out the source code from SVN and installed in SVN.
Can you please tell us how to build this source code?

ALso what will be the outcome of this process?

2. We have proposed to use activiti plugin for our porject. We need to customise the palette shapes and XML tags. Can you please tell us the process to perform.


Please help us to resolve to above issues. We are badly stuck up here.
294 REPLIES 294

tiesebarrell
Champ in-the-making
Champ in-the-making
Depends. If you want to use an existing extension point and you have a subclass in your project, just point to your own implementation in the extension definition. But there are no extension points for the classes you mentioned, so that's probably not the case. For other cases, where you instantiate the class, just instantiate your own type (basic OO).

You shouldn't subclass BpmnXMLExport for two reasons:
* The next release of Activiti Designer won't contain this class anymore.
* This is an internal class of Activiti Designer. If you want to write an ExportMarshaller, use the extension point as described in the userguide. If you want to use some of the code, just copy it.

balaji1
Champ in-the-making
Champ in-the-making
HI,

Could you please tell what all are the changes are expected to BPMNExport class and where
it will be available?

Also, We could see lot of changes is expected in Jan/Feb release. Is it advisable to proceed with the current source now. Because later on it would be much difficult to accomodate our
changes?

Thanks

tiesebarrell
Champ in-the-making
Champ in-the-making
Balaji,

As I mentioned before, this class will no longer be in the source from the January release. It has been completely replaced by the bpmn 2.0 Export Marshaller code, which is in the .export.bpmn20 bundle. Also, I personally don't see a reason to amend / subclass this particular class, so I would advise against it anyway. Whether you should customize the source at all at this point is difficult to answer without knowing which customizations you plan to make. If possible, I would suggest you try to stick to the extension points or write surrounding functionality is separate bundles. Until we have a 1.0 release, any piece of code may change of course (though some are more likely than others).

balaji1
Champ in-the-making
Champ in-the-making
Hi,
Basically we are doing following customisations
1. Replacing the existing XML structure into our own set of tags and attributes.
2. Adding palettes of our own shape.

Out of these two,Currently we started with First part. But somehow we badly stuck up and not
able to proceed further.

And also, We ran the source in debug mode to understand the flow and we found BPMN XML export class is called in GUI project rather .export.bpmn20 bundle. Can we understand that
in Jan release this will be changed and control flows to .export.bpmn20 bundle and other one will be deprecated.

As you advise we will go by extension points.  But we are struggling to implement the same. I hope the extension points implementation will be mentioned in user guide.

tiesebarrell
Champ in-the-making
Champ in-the-making
Balaji,

first things first: yes, you are right. bpmn20 bundle will be the one used, the other will be removed (not even deprecated).

With regard to your features: you should be able to do all of that without customizing our code. The extension points are all you need.

Point 1 is done by creating an ExportMarshaller. The userguide is intentionally vague on this, because we mainly offer access to the entire diagram, independent of any format and allow you to do whatever you wish with it. If you have a direct question about how to use it, please ask. Otherwise, for general guidance, look at how the .bpmn20 bundle is coded; it uses the extension point itself.

Point 2 is explained in the userguide, in detail I might add, here: http://activiti.org/userguide/index.html#N1149F

balaji1
Champ in-the-making
Champ in-the-making
HI Tiesse,

I find it difficult to understand the extension points. IF possible , Can you please tell the sequence of
steps to be followed to implement the extension points from marshaller class ?

I hope this will hugely help us. Please dont mistake us.

Thanks

tiesebarrell
Champ in-the-making
Champ in-the-making
Balaji,

I wrote up a quick overview of the steps you need to take to help you get going.


1. Create a new plugin project in Eclipse
2. Declare dependencies as shown here http://activiti.org/userguide/index.html#N11639 and make sure all of them can be found (i.e. no errors for this project in Eclipse)
3. In plugin.xml, declare an extension to the org.activiti.designer.eclipse.extension.export.ExportMarshaller extension point like this:
<extension
         point="org.activiti.designer.eclipse.extension.export.ExportMarshaller">
      <ExportMarshaller
            class="org.acme.export.AcmeExportMarshaller">
      </ExportMarshaller>
   </extension>
4. Click the warning icon in plugin.xml to create the AcmeExportMarshaller class or create it yourself. Remove the "implements" part and instead make sure the class extends the AbstractExportMarshaller base class instead:
public class AcmeExportMarshaller extends AbstractExportMarshaller {
}

5. Implement the required methods (getFilenamePattern will probably be removed later):
@Override
  public String getMarshallerName() {
    return "Acme Export Marshaller";
  }

  @Override
  public String getFormatName() {
    return "Acme Format 1.15";
  }

6. Now, for the real work, implement the marshallDiagram method:
@Override
  public void marshallDiagram(Diagram diagram, IProgressMonitor monitor) {
}

7. First, clear any problems previously associated with this marshaller:
clearMarkers(getResource(diagram.eResource().getURI()));

8. If you have a related validator, you can invoke it from your marshaller to make sure you don't attempt to marshall content that's not valid like this (MY_VALIDATOR_ID is assumed a static member referring to the ID of the validator):

boolean validDiagram = invokeValidator(MY_VALIDATOR_ID, diagram, monitor);

        if (!validDiagram) {
//create problem
} else {
//perform marshalling
}

9. Create problems, info and warnings if you encounter any during marshalling by invoking the appropriate methods in the base class (January release only):
addProblemToDiagram(diagram, "Could not find the Acme element we require", null);
addWarningToDiagram(diagram, "You really should not use the Acme brand name in the node name", null);

10. Depending on preference, you can produce output in a variety of ways. One way is to use XSLT, the other is to use APIs such as XMLStreamWriter to create content. The base class provides methods to get a hold of streams for the diagrams instead of the object if you need it (e.g. for XSLT you could use a StreamSource). Create the object in memory and fill it by extracting information from the diagram (for instance by looping through process constructs). The most interesting information is probably in the EObject content list:

final EList<EObject> contents = diagram.eResource().getContents();

You can iterate those contents to find the familiar BPMN constructs you most likely want to use:

      Process process = null;

      for (final EObject eObject : contents) {
        if (eObject instanceof Process) {
          process = (Process) eObject;
          break;
        }
      }

After casting, you can access construct-specific attributes to write to your output.

11. Once you're finished, create a resource by invoking the saveResource method with an InputStream to your content:
saveResource(getRelativeURIForDiagram(diagram, "my-output-filename.xml"), inputStream, this.monitor);

balaji1
Champ in-the-making
Champ in-the-making
Hi.
As mentioned in the above steps I have created acme export class.

//Attached code


package org.acme.export;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

import org.activiti.designer.eclipse.common.ActivitiBPMNDiagramConstants;
import org.activiti.designer.eclipse.extension.export.AbstractExportMarshaller;
import org.activiti.designer.eclipse.extension.export.ExportMarshaller;
import org.eclipse.bpmn2.EndEvent;
import org.eclipse.bpmn2.Process;
import org.eclipse.bpmn2.StartEvent;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.mm.pictograms.Diagram;

public class AcmeExportMarshaller extends AbstractExportMarshaller {

private static final String FILENAME_PATTERN = ExportMarshaller.PLACEHOLDER_ORIGINAL_FILENAME + ".bpmn20_new.xml";

   private static final String BPMN2_NAMESPACE = "http://www.omg.org/spec/BPMN/20100524/MODEL";
   private static final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
   private static final String SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
   private static final String XPATH_NAMESPACE = "http://www.w3.org/1999/XPath";
   private static final String PROCESS_NAMESPACE = "http://www.activiti.org/test";
   private static final String ACTIVITI_EXTENSIONS_NAMESPACE = "http://activiti.org/bpmn";
   private static final String ACTIVITI_EXTENSIONS_PREFIX = "activiti";

   private IProgressMonitor monitor;
   private Diagram diagram;


public AcmeExportMarshaller() {
  // TODO Auto-generated constructor stub
}

@Override
public String getMarshallerName() {
  // TODO Auto-generated method stub
  return "Acme Export Marshaller";
}

@Override
public String getFormatName() {
  // TODO Auto-generated method stub

  return "Acme Format 1.15";
}

@Override
public String getFilenamePattern() {
  // TODO Auto-generated method stub
  return null;
}

@Override
public void marshallDiagram(Diagram diagram, IProgressMonitor monitor) {
  
  boolean performMarshalling = true;
 
  clearProblems(getResource(diagram.eResource().getURI()));

boolean validDiagram = invokeValidator(ActivitiBPMNDiagramConstants.MY_VALIDATOR_ID, diagram, monitor);

if (!validDiagram) {
 
  addProblemToDiagram(diagram, "Could not find the Acme element we require", null);
 
} else {
  //perform marshalling
  performMarshalling = false;
  }
 


}

  private void marshallBPMNDiagram()
  {

    try {

      XMLOutputFactory xof = XMLOutputFactory.newInstance();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      OutputStreamWriter out = new OutputStreamWriter(baos, "UTF-8");

      XMLStreamWriter xtw = xof.createXMLStreamWriter(out);

      final EList<EObject> contents = diagram.eResource().getContents();

      Process process = null;

      for (final EObject eObject : contents) {
        if (eObject instanceof Process) {
          process = (Process) eObject;
          break;
        }
      }

      if (process == null) {
        addProblemToDiagram(diagram, "Process cannot be null", null);
      }

      xtw.writeStartDocument("UTF-8", "1.0");

      // start definitions root element
      xtw.writeStartElement("definitions");
      xtw.setDefaultNamespace(BPMN2_NAMESPACE);
      xtw.writeDefaultNamespace(BPMN2_NAMESPACE);
      xtw.writeNamespace("xsi", XSI_NAMESPACE);
      xtw.writeNamespace(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE);
      xtw.writeAttribute("typeLanguage", SCHEMA_NAMESPACE);
      xtw.writeAttribute("expressionLanguage", XPATH_NAMESPACE);
      xtw.writeAttribute("targetNamespace", PROCESS_NAMESPACE);

      // start process element
      xtw.writeStartElement("process");
      xtw.writeAttribute("id", process.getId());
      xtw.writeAttribute("name", process.getName());
      if (process.getDocumentation() != null && process.getDocumentation().size() > 0 && process.getDocumentation().get(0) != null
              && process.getDocumentation().get(0).getText() != null && process.getDocumentation().get(0).getText().length() > 0) {

        xtw.writeStartElement("documentation");
        xtw.writeCharacters(process.getDocumentation().get(0).getText());
        xtw.writeEndElement();
      }

      // start StartEvent element
      xtw.writeStartElement("startEvent");
      StartEvent startEvent = getStartEvent(contents);

      if (startEvent == null)
        addProblemToDiagram(diagram, "start event cannot be null", null);
      xtw.writeAttribute("id", startEvent.getId());
      xtw.writeAttribute("name", startEvent.getName());

      // end StartEvent element
      xtw.writeEndElement();

      for (EObject object : contents) {
        createXML(object, xtw, "");
      }

      // start EndEvent element
      xtw.writeStartElement("endEvent");
      EndEvent endEvent = getEndEvent(contents);

      if (endEvent == null)
        addProblemToDiagram(diagram, "end event cannot be null", null);
      xtw.writeAttribute("id", endEvent.getId());
      xtw.writeAttribute("name", endEvent.getName());

      // end EndEvent element
      xtw.writeEndElement();

      // end process element
      xtw.writeEndElement();

      // end definitions root element
      xtw.writeEndElement();
      xtw.writeEndDocument();

      xtw.flush();

      final byte[] bytes = baos.toByteArray();
      final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      saveResource(getRelativeURIForDiagram(diagram, getFilenamePattern()), bais, this.monitor);

      xtw.close();
    } catch (Exception e) {
      addProblemToDiagram(diagram, "An exception occurred while creating the BPMN 2.0 XML: " + e.getMessage(), null);
    }
 
}

But still I am facing the below error like this.
1. The method getStartEvent(EList<EObject>) is undefined for the type AcmeExportMarshaller
2. The method createXML(EObject, XMLStreamWriter, String) is undefined for the type AcmeExportMarshaller

Can you please confirm am I going the right approach as told by you,

tiesebarrell
Champ in-the-making
Champ in-the-making
Yes, you're doing fine. From the code, it looks like you copy pasted a bunch of code from the BPMN marshaller. The errors you have are probably because you forgot to copy a couple of helper methods from the same class.

balaji1
Champ in-the-making
Champ in-the-making
Hi,
First we are trying to simulate your functionality in our acme project.

Say, If we are trying to build the projects and how can we confirm that the acme marshall class is called
rather than BPMNExport class from GUI project  to create XML structure?

THanks