use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class ImportUploadReceiver method deployUploadedFile.
protected void deployUploadedFile() {
try {
try {
if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
validFile = true;
XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()), "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 {
String processName = null;
if (StringUtils.isNotEmpty(bpmnModel.getMainProcess().getName())) {
processName = bpmnModel.getMainProcess().getName();
} else {
processName = bpmnModel.getMainProcess().getId();
}
modelData = repositoryService.newModel();
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
modelObjectNode.put(MODEL_NAME, processName);
modelObjectNode.put(MODEL_REVISION, 1);
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName(processName);
repositoryService.saveModel(modelData);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
ObjectNode editorNode = jsonConverter.convertToJson(bpmnModel);
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
}
}
} else {
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_FILE, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_FILE_EXPLANATION));
}
} catch (Exception e) {
String errorMsg = e.getMessage().replace(System.getProperty("line.separator"), "<br/>");
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, errorMsg);
}
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
notificationManager.showErrorNotification("Server-side error", e.getMessage());
}
}
}
}
use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class EditorProcessDefinitionDetailPanel method deployModelerModel.
protected void deployModelerModel(final ObjectNode modelNode) {
BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
String processName = modelData.getName() + ".bpmn20.xml";
Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
ExplorerApp.get().getViewManager().showDeploymentPage(deployment.getId());
}
use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class AbstractConverterTest method readJsonFile.
protected BpmnModel readJsonFile() throws Exception {
InputStream jsonStream = this.getClass().getClassLoader().getResourceAsStream(getResource());
JsonNode modelNode = new ObjectMapper().readTree(jsonStream);
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
return bpmnModel;
}
use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class EditModelClickListener method showSelectEditorPopupWindow.
protected void showSelectEditorPopupWindow() {
final PopupWindow selectEditorPopupWindow = new PopupWindow();
selectEditorPopupWindow.setModal(true);
selectEditorPopupWindow.setResizable(false);
selectEditorPopupWindow.setWidth("350px");
selectEditorPopupWindow.setHeight("250px");
selectEditorPopupWindow.addStyleName(Reindeer.PANEL_LIGHT);
selectEditorPopupWindow.center();
final SelectEditorComponent selectEditorComponent = new SelectEditorComponent(false);
selectEditorComponent.getModelerDescriptionLabel().setValue(ExplorerApp.get().getI18nManager().getMessage(Messages.PROCESS_EDITOR_CONVERSION_WARNING_MODELER));
selectEditorComponent.getModelerDescriptionLabel().addStyleName(ExplorerLayout.STYLE_LABEL_RED);
selectEditorComponent.preferTableDrivenEditor();
selectEditorPopupWindow.getContent().addComponent(selectEditorComponent);
selectEditorComponent.setEditorSelectedListener(new EditorSelectedListener() {
public void editorSelectionChanged() {
try {
WorkflowDefinition workflowDefinition = loadWorkflowDefinition();
// When using the modeler, the format must first be converted to the modeler json format
if (selectEditorComponent.isModelerPreferred()) {
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
model.setCategory(null);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode metaInfoJson = objectMapper.createObjectNode();
metaInfoJson.put("name", model.getName());
model.setMetaInfo(metaInfoJson.toString());
repositoryService.saveModel(model);
BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
ObjectNode json = bpmnJsonConverter.convertToJson(conversion.getBpmnModel());
repositoryService.addModelEditorSource(model.getId(), json.toString().getBytes("utf-8"));
// Show modeler
showModeler();
} else {
// Load and show table editor
ExplorerApp.get().getViewManager().showSimpleTableProcessEditor(model.getId(), workflowDefinition);
}
} catch (Exception e) {
LOGGER.error("Error showing editor", e);
ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_EDITOR_LOADING_ERROR, e);
} finally {
ExplorerApp.get().getMainWindow().removeWindow(selectEditorPopupWindow);
}
}
});
ExplorerApp.get().getViewManager().showPopupWindow(selectEditorPopupWindow);
}
use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.
the class AbstractConverterTest method convertToJsonAndBack.
protected BpmnModel convertToJsonAndBack(BpmnModel bpmnModel) {
ObjectNode modelNode = new BpmnJsonConverter().convertToJson(bpmnModel);
bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
return bpmnModel;
}
Aggregations