use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorImpl method generateAllForms.
@Override
public void generateAllForms(Diagram diagram) {
try {
LOGGER.finest("Generating all forms");
final Path path = diagram.getMetadata().getPath();
final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path);
ioService.startBatch(ioService.getFileSystem(nioPath.toUri()));
final Definitions definitions = toDefinitions(diagram);
final BusinessProcessFormModel processFormModel = bpmnFormModelGenerator.generateProcessFormModel(definitions, path);
createFormForModel(processFormModel, nioPath);
List<TaskFormModel> taskFormModels = bpmnFormModelGenerator.generateTaskFormModels(definitions, path);
for (TaskFormModel taskFormModel : taskFormModels) {
createFormForModel(taskFormModel, nioPath);
}
} catch (Exception ex) {
LOGGER.severe("Error generating all diagram forms");
throw new RuntimeException(ex);
} finally {
ioService.endBatch();
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorImplTest method init.
@Before
public void init() throws Exception {
SimpleFileSystemProvider simpleFileSystemProvider = new SimpleFileSystemProvider();
simpleFileSystemProvider.forceAsDefault();
Definitions processDefinitions = BPMN2Utils.getDefinitions(FormDefinitionGeneratorImplTest.class.getResourceAsStream(PROCESS_PATH));
// Prepare BPMNFormModelGenerator
when(kieModuleService.resolveModule(any())).thenReturn(module);
when(module.getRootPath()).thenReturn(path);
when(moduleClassLoaderHelper.getModuleClassLoader(module)).thenReturn(moduleClassLoader);
when(moduleClassLoader.loadClass(anyString())).thenAnswer(invocation -> Object.class);
BPMNFormModelGenerator bpmnFormModelGenerator = spy(new BPMNFormModelGeneratorImpl(kieModuleService, moduleClassLoaderHelper));
FormModelHandlerManager formModelHandlerManager = new TestFormModelHandlerManager(kieModuleService, moduleClassLoaderHelper, new TestFieldManager());
BPMNFormGeneratorService<Path> bpmnFormGeneratorService = new BPMNVFSFormDefinitionGeneratorService(new TestFieldManager(), formModelHandlerManager, formFinderService, formDefinitionSerializer, ioService, commentedOptionFactory, synchronizationUtil);
generator = spy(new TestFormDefinitionGeneratorImpl(formGenerationModelProviders, ioService, bpmnFormModelGenerator, formDefinitionSerializer, bpmnFormGeneratorService, processDefinitions));
when(diagram.getMetadata()).thenReturn(metadata);
when(metadata.getPath()).thenReturn(diagramPath);
when(diagram.getGraph()).thenReturn(graph);
when(diagramPath.toURI()).thenReturn("default:///src/main/resources" + PROCESS_PATH);
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshaller method marshall.
@Override
@SuppressWarnings("unchecked")
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
LOG.debug("Starting diagram marshalling...");
Bpmn2Resource resource = createBpmn2Resource();
// we start converting from the root, then pull out the result
DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
Definitions definitions = definitionsConverter.toDefinitions();
resource.getContents().add(definitions);
LOG.debug("Diagram marshalling completed successfully.");
String outputString = renderToString(resource);
LOG.trace(outputString);
return outputString;
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshaller method parseDefinitions.
private static Definitions parseDefinitions(final InputStream inputStream) throws IOException {
DroolsPackageImpl.init();
BpsimPackageImpl.init();
final ResourceSet resourceSet = new ResourceSetImpl();
Resource.Factory.Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
resourceFactoryRegistry.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactoryImpl());
EPackage.Registry packageRegistry = resourceSet.getPackageRegistry();
packageRegistry.put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
packageRegistry.put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE);
final JBPMBpmn2ResourceImpl resource = (JBPMBpmn2ResourceImpl) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
resource.setEncoding("UTF-8");
final Map<String, Object> options = new HashMap<String, Object>();
options.put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
options.put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true);
options.put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true);
options.put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD);
resource.load(inputStream, options);
final DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
return root.getDefinitions();
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BaseDiagramMarshaller method unmarshall.
@Override
public Graph unmarshall(final Metadata metadata, final InputStream inputStream) throws IOException {
LOG.debug("Starting diagram unmarshalling...");
// No rule checking for marshalling/unmarshalling, current jbpm designer marshallers should do it for us.
final Bpmn2UnMarshaller parser = new Bpmn2UnMarshaller(bpmnGraphBuilderFactory, definitionManager, factoryManager, rulesManager, oryxManager, graphCommandManager, commandFactory, indexBuilder, getDiagramDefinitionSetClass(), getDiagramDefinitionClass());
Graph result = null;
try {
// Unmarshall the diagram definition
final Definitions definitions = parseDefinitions(inputStream);
parser.setProfile(new DefaultProfileImpl());
result = parser.unmarshall(definitions, getPreProcessingData(metadata));
// Update diagram's settings.
updateRootUUID(metadata, result);
} catch (IOException e) {
LOG.error("Error unmarshalling file.", e);
}
LOG.debug("Diagram unmarshalling finished successfully.");
return result;
}
Aggregations