use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class ConvertProcessDefinitionPopupWindow method addButtons.
protected void addButtons() {
// Cancel
Button cancelButton = new Button(i18nManager.getMessage(Messages.BUTTON_CANCEL));
cancelButton.addStyleName(Reindeer.BUTTON_SMALL);
cancelButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
close();
}
});
// Convert
Button convertButton = new Button(i18nManager.getMessage(Messages.PROCESS_CONVERT_POPUP_CONVERT_BUTTON));
convertButton.addStyleName(Reindeer.BUTTON_SMALL);
convertButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
try {
InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
if (bpmnModel.getMainProcess() == null || bpmnModel.getMainProcess().getId() == null) {
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMN_EXPLANATION));
} else {
if (bpmnModel.getLocationMap().isEmpty()) {
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_BPMNDI, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
} else {
BpmnJsonConverter converter = new BpmnJsonConverter();
ObjectNode modelNode = converter.convertToJson(bpmnModel);
Model modelData = repositoryService.newModel();
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
modelObjectNode.put(MODEL_NAME, processDefinition.getName());
modelObjectNode.put(MODEL_REVISION, 1);
modelObjectNode.put(MODEL_DESCRIPTION, processDefinition.getDescription());
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName(processDefinition.getName());
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
close();
ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());
URL explorerURL = ExplorerApp.get().getURL();
URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "modeler.html?modelId=" + modelData.getId());
ExplorerApp.get().getMainWindow().open(new ExternalResource(url));
}
}
} catch (Exception e) {
notificationManager.showErrorNotification("error", e);
}
}
});
// Alignment
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setSpacing(true);
buttonLayout.addComponent(cancelButton);
buttonLayout.addComponent(convertButton);
addComponent(buttonLayout);
windowLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
}
use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class EditorProcessDefinitionDetailPanel method exportModel.
protected void exportModel() {
final FileResource stream = new FileResource(new File(""), ExplorerApp.get()) {
private static final long serialVersionUID = 1L;
@Override
public DownloadStream getStream() {
DownloadStream ds = null;
try {
byte[] bpmnBytes = null;
String filename = null;
if (SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY.equals(modelData.getCategory())) {
WorkflowDefinition workflowDefinition = ExplorerApp.get().getSimpleWorkflowJsonConverter().readWorkflowDefinition(repositoryService.getModelEditorSource(modelData.getId()));
filename = workflowDefinition.getName();
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
bpmnBytes = conversion.getBpmn20Xml().getBytes("utf-8");
} else {
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
BpmnModel model = jsonConverter.convertToBpmnModel(editorNode);
filename = model.getMainProcess().getId() + ".bpmn20.xml";
bpmnBytes = new BpmnXMLConverter().convertToXML(model);
}
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
ds = new DownloadStream(in, "application/xml", filename);
// Need a file download POPUP
ds.setParameter("Content-Disposition", "attachment; filename=" + filename);
} catch (Exception e) {
LOGGER.error("failed to export model to BPMN XML", e);
ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_TOXML_FAILED, e);
}
return ds;
}
};
stream.setCacheTime(0);
ExplorerApp.get().getMainWindow().open(stream);
}
Aggregations