com.visualparadigm.app
com.visualparadigm.app.lib.openapi
@@ -173,6 +204,14 @@
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 3.2.0
+
+ ${java.home}/bin/javadoc
+
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -271,6 +310,11 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java b/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java
index 1eb9eb50..e8472a7b 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java
@@ -16,7 +16,7 @@
*/
public class OntoUMLPlugin implements VPPlugin {
- public static final String PLUGIN_VERSION_RELEASE = "0.4.0";
+ public static final String PLUGIN_VERSION_RELEASE = "0.5.0";
public static final String PLUGIN_ID = "it.unibz.inf.ontouml.vp";
public static final String PLUGIN_NAME = "OntoUML Plugin";
public static final String PLUGIN_REPO = "https://github.com/OntoUML/ontouml-vp-plugin/";
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java
index 452f2a89..d8e46288 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java
@@ -4,11 +4,7 @@
import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPContext;
import com.vp.plugin.action.VPContextActionController;
-import com.vp.plugin.model.IAssociation;
-import com.vp.plugin.model.IAssociationEnd;
-import com.vp.plugin.model.IClass;
-import com.vp.plugin.model.IModelElement;
-import com.vp.plugin.model.ITaggedValue;
+import com.vp.plugin.model.*;
import com.vp.plugin.model.factory.IModelElementFactory;
import it.unibz.inf.ontouml.vp.model.Configurations;
import it.unibz.inf.ontouml.vp.model.uml.Association;
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java
index b6ee4cc9..ffb5da0a 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java
@@ -11,11 +11,7 @@
import it.unibz.inf.ontouml.vp.model.uml.Association;
import it.unibz.inf.ontouml.vp.model.uml.Class;
import it.unibz.inf.ontouml.vp.model.uml.ModelElement;
-import it.unibz.inf.ontouml.vp.utils.ActionIdManager;
-import it.unibz.inf.ontouml.vp.utils.OntoUMLConstraintsManager;
-import it.unibz.inf.ontouml.vp.utils.Stereotype;
-import it.unibz.inf.ontouml.vp.utils.StereotypesManager;
-import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
+import it.unibz.inf.ontouml.vp.utils.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationController.java
deleted file mode 100644
index 025b4fb2..00000000
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationController.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package it.unibz.inf.ontouml.vp.controllers;
-
-import com.vp.plugin.ApplicationManager;
-import com.vp.plugin.action.VPAction;
-import com.vp.plugin.action.VPActionController;
-import com.vp.plugin.diagram.IClassDiagramUIModel;
-import com.vp.plugin.diagram.IDiagramUIModel;
-import com.vp.plugin.view.IDialog;
-import com.vp.plugin.view.IDialogHandler;
-import it.unibz.inf.ontouml.vp.model.ServerRequest;
-import it.unibz.inf.ontouml.vp.model.uml.ModelElement;
-import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
-import it.unibz.inf.ontouml.vp.views.ProgressPanel;
-import java.awt.Component;
-
-/** Implementation of toolbar button action responsible for performing diagram verification. */
-public class DiagramVerificationController implements VPActionController {
-
- private ProgressPanel progressPanel;
- private ProgressDialog loading;
- private IDialog mainDialog;
- DiagramVerificationRequest request;
- Thread thread;
-
- /**
- * Performs OntoUML diagram verification.
- *
- * @param action
- */
- @Override
- public void performAction(VPAction action) {
-
- if (!hasOpenedClassDiagram()) {
- ViewManagerUtils.simpleDialog(
- "Diagram Verification", "Please open a diagram before running this command.");
- return;
- }
-
- request = new DiagramVerificationRequest();
-
- loading = new ProgressDialog();
- ApplicationManager.instance().getViewManager().showDialog(loading);
-
- Thread thread = new Thread(request);
- thread.start();
- }
-
- /**
- * Called when the menu containing the button is accessed allowing for action manipulation, such
- * as enable/disable or selecting the button.
- *
- * OBS: DOES NOT apply to this class.
- */
- @Override
- public void update(VPAction action) {}
-
- private static boolean hasOpenedClassDiagram() {
- final IDiagramUIModel[] diagramArray =
- ApplicationManager.instance().getProjectManager().getProject().toDiagramArray();
-
- if (diagramArray == null) return false;
-
- for (IDiagramUIModel diagram : diagramArray)
- if (diagram instanceof IClassDiagramUIModel && diagram.isOpened()) return true;
-
- return false;
- }
-
- protected class ProgressDialog implements IDialogHandler {
-
- @Override
- public Component getComponent() {
- progressPanel = new ProgressPanel(request);
- return progressPanel;
- }
-
- @Override
- public void prepare(IDialog dialog) {
- mainDialog = dialog;
- mainDialog.setTitle("Verification Service");
- mainDialog.setModal(false);
- mainDialog.setResizable(false);
- dialog.setSize(progressPanel.getWidth(), progressPanel.getHeight() + 20);
- progressPanel.setContainerDialog(mainDialog);
- }
-
- @Override
- public void shown() {}
-
- @Override
- public boolean canClosed() {
- mainDialog.close();
- return true;
- }
- }
-
- protected class DiagramVerificationRequest extends ServerRequest {
-
- @Override
- public void run() {
- while (keepRunning()) {
- try {
- final String response =
- OntoUMLServerAccessController.requestModelVerification(
- ModelElement.generateModel(true), loading);
-
- if (keepRunning()) {
- if (response != null) {
- mainDialog.close();
- request.doStop();
- ViewManagerUtils.logDiagramVerificationResponse(response);
- } else {
- loading.canClosed();
- request.doStop();
- }
- } else {
- loading.canClosed();
- request.doStop();
- ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user.");
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GUFOExportController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GUFOExportController.java
deleted file mode 100644
index 7406e08f..00000000
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GUFOExportController.java
+++ /dev/null
@@ -1,231 +0,0 @@
-package it.unibz.inf.ontouml.vp.controllers;
-
-import com.vp.plugin.ApplicationManager;
-import com.vp.plugin.action.VPAction;
-import com.vp.plugin.action.VPActionController;
-import com.vp.plugin.view.IDialog;
-import com.vp.plugin.view.IDialogHandler;
-import it.unibz.inf.ontouml.vp.OntoUMLPlugin;
-import it.unibz.inf.ontouml.vp.model.Configurations;
-import it.unibz.inf.ontouml.vp.model.ProjectConfigurations;
-import it.unibz.inf.ontouml.vp.model.ServerRequest;
-import it.unibz.inf.ontouml.vp.model.uml.ModelElement;
-import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
-import it.unibz.inf.ontouml.vp.views.GUFOExportView;
-import it.unibz.inf.ontouml.vp.views.ProgressPanel;
-import java.awt.Component;
-import java.awt.FileDialog;
-import java.awt.Frame;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.stream.Collectors;
-
-/**
- * Implementation of toolbar button Export to gUFO.
- *
- * @author Victor Viola
- * @author Claudenir Fonseca
- */
-public class GUFOExportController implements VPActionController {
-
- private ProgressPanel progressPanel;
- private ProgressDialog loading;
- private IDialog mainDialog;
-
- private ExportDialog menu;
- private GUFOExportView _exportMenuView;
- private IDialog _dialog;
- MenuExport requestMenu;
-
- @Override
- public void performAction(VPAction action) {
-
- requestMenu = new MenuExport();
- menu = new ExportDialog();
-
- if (OntoUMLPlugin.getExportToGUFOWindowOpen() == true) return;
- else OntoUMLPlugin.setExportToGUFOWindowOpen(true);
-
- ApplicationManager.instance().getViewManager().showDialog(menu);
- }
-
- /**
- * Called when the menu containing the button is accessed allowing for action manipulation, such
- * as enable/disable or selecting the button.
- *
- *
OBS: DOES NOT apply to this class.
- */
- @Override
- public void update(VPAction action) {}
-
- private void saveFile(BufferedReader buffer, String exportFormat) throws IOException {
- final Configurations configs = Configurations.getInstance();
- final ProjectConfigurations projectConfigurations = configs.getProjectConfigurations();
- final FileDialog fd =
- new FileDialog(
- (Frame) ApplicationManager.instance().getViewManager().getRootFrame(),
- "Choose destination",
- FileDialog.SAVE);
-
- String suggestedFolderPath = projectConfigurations.getExportGUFOFolderPath();
- String suggestedFileName = projectConfigurations.getExportGUFOFilename();
- String exportFormatExtension = exportFormat != "Turtle" ? ".nt" : ".ttl";
-
- if (suggestedFileName.isEmpty()) {
- String projectName = ApplicationManager.instance().getProjectManager().getProject().getName();
- suggestedFileName = projectName + exportFormatExtension;
- }
-
- fd.setDirectory(suggestedFolderPath);
- fd.setFile(suggestedFileName);
- fd.setVisible(true);
-
- if (fd.getDirectory() != null && fd.getFile() != null) {
- final String fileDirectory = fd.getDirectory();
- final String fileName =
- !fd.getFile().endsWith(exportFormatExtension)
- ? fd.getFile() + exportFormatExtension
- : fd.getFile();
- final String output = buffer.lines().collect(Collectors.joining("\n"));
-
- Files.write(Paths.get(fileDirectory, fileName), output.getBytes());
- projectConfigurations.setExportGUFOFolderPath(fileDirectory);
- projectConfigurations.setExportGUFOFilename(fileName);
- configs.save();
- }
- }
-
- public class ProgressDialog implements IDialogHandler {
-
- @Override
- public Component getComponent() {
- progressPanel = new ProgressPanel(requestMenu);
- return progressPanel;
- }
-
- @Override
- public void prepare(IDialog dialog) {
- mainDialog = dialog;
- mainDialog.setTitle("Export to GUFO");
- mainDialog.setModal(false);
- mainDialog.setResizable(false);
- dialog.setSize(progressPanel.getWidth(), progressPanel.getHeight() + 20);
- progressPanel.setContainerDialog(mainDialog);
- }
-
- @Override
- public void shown() {}
-
- @Override
- public boolean canClosed() {
- mainDialog.close();
- return true;
- }
- }
-
- protected class ExportDialog implements IDialogHandler {
-
- /**
- * Called once before the dialog is shown. Developer should return the content of the dialog
- * (similar to the content pane).
- */
- @Override
- public Component getComponent() {
- _exportMenuView =
- new GUFOExportView(Configurations.getInstance().getProjectConfigurations(), requestMenu);
- return _exportMenuView;
- }
-
- /**
- * Called after the getComponent(). A dialog is created on Visual Paradigm internally (it still
- * not shown out). Developer can set the outlook of the dialog on prepare().
- */
- @Override
- public void prepare(IDialog dialog) {
- _dialog = dialog;
- _dialog.setTitle(OntoUMLPlugin.PLUGIN_NAME + " Configurations");
- _dialog.setModal(false);
- _dialog.setResizable(false);
- _dialog.setSize(_exportMenuView.getWidth(), _exportMenuView.getHeight() + 20);
- _exportMenuView.setContainerDialog(_dialog);
- }
-
- /** Called when the dialog is shown. */
- @Override
- public void shown() {}
-
- /** Called when the dialog is closed by the user clicking on the close button of the frame. */
- @Override
- public boolean canClosed() {
- requestMenu.doStop();
- OntoUMLPlugin.setExportToGUFOWindowOpen(false);
- ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user.");
- return true;
- }
- }
-
- public class MenuExport extends ServerRequest {
-
- final Configurations configs = Configurations.getInstance();
- final ProjectConfigurations projectConfigurations = configs.getProjectConfigurations();
-
- @Override
- public void run() {
- while (keepRunning()) {
- try {
-
- if (keepRunning()) {
- if (!_exportMenuView.getIsOpen()) {
-
- if (_exportMenuView.getIsToExport()) {
-
- loading = new ProgressDialog();
- ApplicationManager.instance().getViewManager().showDialog(loading);
-
- final BufferedReader gufo =
- OntoUMLServerAccessController.transformToGUFO(
- ModelElement.generateModel(_exportMenuView.getSavedElements(), true),
- projectConfigurations.getExportGUFOIRI(),
- projectConfigurations.getExportGUFOFormat(),
- projectConfigurations.getExportGUFOURIFormat(),
- projectConfigurations.getExportGUFOInverseBox(),
- projectConfigurations.getExportGUFOObjectBox(),
- projectConfigurations.getExportGUFOAnalysisBox(),
- projectConfigurations.getExportGUFOPackagesBox(),
- projectConfigurations.getExportGUFOElementMapping(),
- projectConfigurations.getExportGUFOPackageMapping(),
- loading);
-
- if (gufo != null) {
- saveFile(gufo, projectConfigurations.getExportGUFOFormat());
- ViewManagerUtils.cleanAndShowMessage("Model exported successfully.");
- requestMenu.doStop();
- } else {
- menu.canClosed();
- requestMenu.doStop();
- ViewManagerUtils.cleanAndShowMessage(
- "Unable to transform to GUFO. Please check your model.");
- }
- } else {
- menu.canClosed();
- requestMenu.doStop();
- ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user.");
- }
-
- OntoUMLPlugin.setExportToGUFOWindowOpen(false);
- }
- } else {
- OntoUMLPlugin.setExportToGUFOWindowOpen(false);
- menu.canClosed();
- requestMenu.doStop();
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java
index 74f16251..3d6eb75c 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java
@@ -6,11 +6,7 @@
import it.unibz.inf.ontouml.vp.model.Configurations;
import it.unibz.inf.ontouml.vp.model.GitHubRelease;
import it.unibz.inf.ontouml.vp.model.GitHubReleaseAsset;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
+import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GufoExportController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GufoExportController.java
new file mode 100644
index 00000000..e7b07d4e
--- /dev/null
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GufoExportController.java
@@ -0,0 +1,136 @@
+package it.unibz.inf.ontouml.vp.controllers;
+
+import com.vp.plugin.ApplicationManager;
+import com.vp.plugin.action.VPAction;
+import com.vp.plugin.action.VPActionController;
+import it.unibz.inf.ontouml.vp.model.Configurations;
+import it.unibz.inf.ontouml.vp.model.GufoExportOptions;
+import it.unibz.inf.ontouml.vp.model.GufoTransformationServiceResult;
+import it.unibz.inf.ontouml.vp.model.ProjectConfigurations;
+import it.unibz.inf.ontouml.vp.model.vp2ontouml.Uml2OntoumlTransformer;
+import it.unibz.inf.ontouml.vp.utils.SimpleServiceWorker;
+import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
+import java.awt.FileDialog;
+import java.awt.Frame;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+/**
+ * Implementation of toolbar button Export to gUFO.
+ *
+ * @author Victor Viola
+ * @author Claudenir Fonseca
+ */
+public class GufoExportController implements VPActionController {
+
+ private static final String MESSAGE_MODEL_EXPORTED = "Model exported successfully.";
+
+ private Configurations configurations;
+ private ProjectConfigurations projectConfigurations;
+ private String fileFormat = ".ttl";
+ private Path filePath;
+
+ @Override
+ public void performAction(VPAction action) {
+ configurations = Configurations.getInstance();
+ projectConfigurations = configurations.getProjectConfigurations();
+ GufoExportDialogHandler exportDialog = new GufoExportDialogHandler(projectConfigurations);
+ exportDialog.showDialog();
+
+ if (exportDialog.wasCancelled()) {
+ ViewManagerUtils.log("Request cancelled by the user.");
+ return;
+ }
+
+ fileFormat = !"Turtle".equals(projectConfigurations.getExportGUFOFormat()) ? ".nt" : ".ttl";
+ filePath = getFilePath();
+
+ new SimpleServiceWorker(this::task).execute();
+ }
+
+ private List task(SimpleServiceWorker context) {
+ try {
+ if (filePath == null) {
+ context.cancel(true);
+ return List.of();
+ }
+
+ final String project = Uml2OntoumlTransformer.transformAndSerialize();
+ final String options = new GufoExportOptions(projectConfigurations).toJson();
+ final GufoTransformationServiceResult result =
+ OntoUMLServerAccessController.requestModelTransformationToGufo(project, options);
+ final String gufoFile = result != null ? result.getResult() : "";
+
+ if (!context.isCancelled()) {
+ Files.write(filePath, gufoFile.getBytes());
+ saveFilePath();
+ ViewManagerUtils.log(MESSAGE_MODEL_EXPORTED);
+ return List.of(MESSAGE_MODEL_EXPORTED);
+ }
+
+ return List.of();
+ } catch (IOException e) {
+ if (!context.isCancelled()) {
+ ViewManagerUtils.log(e.getMessage());
+ }
+
+ e.printStackTrace();
+ return List.of(e.getMessage());
+ }
+ }
+
+ private Path getFilePath() {
+ final FileDialog fileDialog;
+ final Frame rootFrame = (Frame) ApplicationManager.instance().getViewManager().getRootFrame();
+ final String suggestedFolderPath = projectConfigurations.getExportGUFOFolderPath();
+ String suggestedFileName = projectConfigurations.getExportGUFOFilename();
+
+ if (suggestedFileName.isEmpty()) {
+ final String projectName =
+ ApplicationManager.instance().getProjectManager().getProject().getName();
+ suggestedFileName = projectName + fileFormat;
+ }
+
+ final String title = "Choose export file destination";
+ fileDialog = new FileDialog(rootFrame, title, FileDialog.SAVE);
+
+ fileDialog.setFile(suggestedFileName);
+ fileDialog.setDirectory(suggestedFolderPath);
+ fileDialog.setMultipleMode(false);
+ fileDialog.setFilenameFilter((dir, name) -> name != null && name.endsWith(fileFormat));
+ fileDialog.setVisible(true);
+
+ final String fileDirectory = fileDialog.getDirectory();
+ final String fileName = fileDialog.getFile();
+
+ if (fileDirectory != null && fileName != null) {
+ return fileName.endsWith(fileFormat)
+ ? Paths.get(fileDirectory, fileName)
+ : Paths.get(fileDirectory, fileName + fileFormat);
+ }
+
+ return null;
+ }
+
+ private void saveFilePath() {
+ final Path directoryPath = filePath.getParent();
+ final String directoryPathName = directoryPath.toAbsolutePath().getFileName().toString();
+ final String filePathName = filePath.getFileName().toString();
+
+ projectConfigurations.setExportGUFOFolderPath(directoryPathName);
+ projectConfigurations.setExportGUFOFilename(filePathName);
+ configurations.save();
+ }
+
+ /**
+ * Called when the menu containing the button is accessed allowing for action manipulation, such
+ * as enable/disable or selecting the button.
+ *
+ * OBS: DOES NOT apply to this class.
+ */
+ @Override
+ public void update(VPAction action) {}
+}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GufoExportDialogHandler.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GufoExportDialogHandler.java
new file mode 100644
index 00000000..0c82c997
--- /dev/null
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GufoExportDialogHandler.java
@@ -0,0 +1,96 @@
+package it.unibz.inf.ontouml.vp.controllers;
+
+import com.vp.plugin.ApplicationManager;
+import com.vp.plugin.ViewManager;
+import com.vp.plugin.view.IDialog;
+import com.vp.plugin.view.IDialogHandler;
+import it.unibz.inf.ontouml.vp.OntoUMLPlugin;
+import it.unibz.inf.ontouml.vp.model.Configurations;
+import it.unibz.inf.ontouml.vp.model.ProjectConfigurations;
+import it.unibz.inf.ontouml.vp.views.GufoExportView;
+import java.awt.Component;
+
+class GufoExportDialogHandler implements IDialogHandler {
+
+ private IDialog dialog;
+ private final GufoExportView view;
+ private final ViewManager viewManager;
+ private boolean wasShown = false;
+ private boolean wasClosed = false;
+ private boolean wasCancelled = false;
+
+ public GufoExportDialogHandler(ProjectConfigurations projectConfigurations) {
+ view = new GufoExportView(projectConfigurations);
+ viewManager = ApplicationManager.instance().getViewManager();
+
+ view.onExport(
+ e -> {
+ view.updateConfigurationsValues(projectConfigurations);
+ Configurations.getInstance().save();
+ closeDialog();
+ });
+ view.onCancel(
+ e -> {
+ wasCancelled = true;
+ closeDialog();
+ });
+ }
+
+ /**
+ * Called once before the dialog is shown. Developer should return the content of the dialog
+ * (similar to the content pane).
+ */
+ @Override
+ public Component getComponent() {
+ return view;
+ }
+
+ /**
+ * Called after the getComponent(). A dialog is created on Visual Paradigm internally (it still
+ * not shown out). Developer can set the outlook of the dialog on prepare().
+ */
+ @Override
+ public void prepare(IDialog dialog) {
+ this.dialog = dialog;
+ dialog.setTitle(OntoUMLPlugin.PLUGIN_NAME);
+ dialog.setModal(true);
+ dialog.setResizable(true);
+ dialog.setSize(view.getWidth(), view.getHeight() + 20);
+ dialog.pack();
+ }
+
+ /** Called when the dialog is shown. */
+ @Override
+ public void shown() {}
+
+ /** Called when the dialog is closed by the user clicking on the close button of the frame. */
+ @Override
+ public boolean canClosed() {
+ wasCancelled = true;
+ wasClosed = true;
+ return true;
+ }
+
+ public void showDialog() {
+ if (!wasClosed) {
+ wasShown = true;
+ viewManager.showDialog(this);
+ }
+ }
+
+ public void closeDialog() {
+ if (wasClosed) {
+ System.out.println("Export dialog was already closed.");
+ } else if (!wasShown) {
+ System.out.println("Export dialog was never shown. Setting wasClosed to \"true\"");
+ } else {
+ System.out.println("Closing export dialog.");
+ dialog.close();
+ }
+ wasClosed = true;
+ }
+
+ public boolean wasCancelled() {
+ return wasCancelled;
+ }
+}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonExportController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonExportController.java
deleted file mode 100644
index 5d9a1405..00000000
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonExportController.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package it.unibz.inf.ontouml.vp.controllers;
-
-import com.vp.plugin.ApplicationManager;
-import com.vp.plugin.action.VPAction;
-import com.vp.plugin.action.VPActionController;
-import com.vp.plugin.view.IDialog;
-import com.vp.plugin.view.IDialogHandler;
-import it.unibz.inf.ontouml.vp.model.Configurations;
-import it.unibz.inf.ontouml.vp.model.ProjectConfigurations;
-import it.unibz.inf.ontouml.vp.model.uml.ModelElement;
-import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
-import it.unibz.inf.ontouml.vp.views.ProgressPanel;
-import java.awt.*;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-/**
- * Implementation toolbar button action responsible for exporting OntoUML model in JSON (according
- * to OntoUML Schema).
- *
- * @author Claudenir Fonseca
- */
-public class JsonExportController implements VPActionController {
-
- private ProgressPanel progressPanel;
- private ProgressDialog loading;
- private IDialog mainDialog;
-
- Thread thread;
-
- /**
- * Performs model export in JSON format.
- *
- * @param action
- */
- @Override
- public void performAction(VPAction action) {
- final Configurations configs = Configurations.getInstance();
- final ProjectConfigurations projectConfigurations = configs.getProjectConfigurations();
-
- FileDialog fd =
- new FileDialog(
- (Frame) ApplicationManager.instance().getViewManager().getRootFrame(),
- "Choose destination",
- FileDialog.SAVE);
-
- String suggestedFolderPath = projectConfigurations.getExportFolderPath();
- String suggestedFileName = projectConfigurations.getExportFilename();
-
- if (suggestedFileName.isEmpty()) {
- String projectName = ApplicationManager.instance().getProjectManager().getProject().getName();
- suggestedFileName = projectName + ".json";
- }
-
- fd.setDirectory(suggestedFolderPath);
- fd.setFile(suggestedFileName);
- fd.setVisible(true);
-
- String fileDirectory = fd.getDirectory();
-
- if (fileDirectory != null) {
-
- loading = new ProgressDialog();
- ApplicationManager.instance().getViewManager().showDialog(loading);
-
- try {
- String fileName = fd.getFile();
-
- if (!fileName.endsWith(".json")) fileName += ".json";
-
- final String jsonModel = ModelElement.generateModel(true);
- Files.write(Paths.get(fileDirectory, fileName), jsonModel.getBytes());
- projectConfigurations.setExportFolderPath(fileDirectory);
- projectConfigurations.setExportFilename(fileName);
- configs.save();
- ViewManagerUtils.cleanAndShowMessage("Model exported successfully.");
- } catch (IOException e) {
- ViewManagerUtils.cleanAndShowMessage("Model export failed.");
- e.printStackTrace();
- }
-
- mainDialog.close();
- }
- }
-
- /**
- * Called when the menu containing the button is accessed allowing for action manipulation, such
- * as enable/disable or selecting the button.
- *
- *
OBS: DOES NOT apply to this class.
- */
- @Override
- public void update(VPAction action) {}
-
- protected class ProgressDialog implements IDialogHandler {
-
- @Override
- public Component getComponent() {
- progressPanel = new ProgressPanel("Building model...");
- return progressPanel;
- }
-
- @Override
- public void prepare(IDialog dialog) {
- mainDialog = dialog;
- mainDialog.setTitle("Export to JSON");
- mainDialog.setModal(false);
- mainDialog.setResizable(false);
- dialog.setSize(progressPanel.getWidth(), progressPanel.getHeight() + 20);
- progressPanel.setContainerDialog(mainDialog);
- }
-
- @Override
- public void shown() {}
-
- @Override
- public boolean canClosed() {
- return false;
- }
- }
-}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonImportAndExportController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonImportAndExportController.java
new file mode 100644
index 00000000..0defa523
--- /dev/null
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonImportAndExportController.java
@@ -0,0 +1,200 @@
+package it.unibz.inf.ontouml.vp.controllers;
+
+import com.vp.plugin.ApplicationManager;
+import com.vp.plugin.action.VPAction;
+import com.vp.plugin.action.VPActionController;
+import it.unibz.inf.ontouml.vp.model.Configurations;
+import it.unibz.inf.ontouml.vp.model.ProjectConfigurations;
+import it.unibz.inf.ontouml.vp.model.ontouml2vp.Ontouml2UmlLoader;
+import it.unibz.inf.ontouml.vp.model.vp2ontouml.Uml2OntoumlTransformer;
+import it.unibz.inf.ontouml.vp.utils.SimpleServiceWorker;
+import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
+import java.awt.*;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+/**
+ * Implementation toolbar button action responsible for exporting OntoUML model in JSON (according
+ * to OntoUML Schema).
+ *
+ * @author Claudenir Fonseca
+ */
+public class JsonImportAndExportController implements VPActionController {
+
+ private static final String IMPORT_ACTION_ID = "it.unibz.inf.ontouml.vp.actions.JsonImportAction";
+ private static final String PROJECT_IMPORT_ACTION_ID = "project.import.JsonImportAction";
+ private static final String EXPORT_ACTION_ID = "it.unibz.inf.ontouml.vp.actions.JsonExportAction";
+ private static final String PROJECT_EXPORT_ACTION_ID = "project.export.JsonExportAction";
+
+ private static final String FILE_FORMAT = ".json";
+
+ private static final String MESSAGE_IMPORT_WARNING =
+ "Warning: this action may override elements in your project. Do you wish to continue?";
+ private static final String MESSAGE_MODEL_EXPORTED = "Model exported successfully.";
+ private static final String MESSAGE_MODEL_IMPORTED = "Model imported successfully.";
+ private static final String MESSAGE_MODEL_EXPORT_INVALID_FILE_ERROR =
+ "Unable to export: invalid file.";
+ private static final String MESSAGE_MODEL_IMPORT_INVALID_FILE_ERROR =
+ "Unable to import: invalid file.";
+ private static final String MESSAGE_MODEL_EXPORT_UNEXPECTED_ERROR =
+ "Unable to export: unexpected error.";
+ private static final String MESSAGE_MODEL_IMPORT_UNEXPECTED_ERROR =
+ "Unable to import: unexpected error.";
+
+ private Configurations configs;
+ private ProjectConfigurations projectConfigurations;
+ private VPAction action;
+ private Path filePath;
+
+ /** Called when a button is clicked. */
+ @Override
+ public void performAction(VPAction action) {
+ this.action = action;
+ configs = Configurations.getInstance();
+ projectConfigurations = configs.getProjectConfigurations();
+
+ if (shouldImport()) {
+ boolean shouldProceed = ViewManagerUtils.warningDialog(MESSAGE_IMPORT_WARNING);
+ if (!shouldProceed) return;
+ }
+
+ filePath = getFilePath();
+
+ if (shouldImport()) {
+ new SimpleServiceWorker(this::importTask).execute();
+ } else if (shouldExport()) {
+ new SimpleServiceWorker(this::exportTask).execute();
+ }
+ }
+
+ /**
+ * Called when the menu containing the button is accessed allowing for action manipulation, such
+ * as enable/disable or selecting the button.
+ *
+ *
OBS: DOES NOT apply to this class.
+ */
+ @Override
+ public void update(VPAction action) {}
+
+ private boolean shouldExport() {
+ return EXPORT_ACTION_ID.equals(action.getActionId())
+ || PROJECT_EXPORT_ACTION_ID.equals(action.getActionId());
+ }
+
+ private boolean shouldImport() {
+ return IMPORT_ACTION_ID.equals(action.getActionId())
+ || PROJECT_IMPORT_ACTION_ID.equals(action.getActionId());
+ }
+
+ private Path getFilePath() {
+ final FileDialog fileDialog;
+ final Frame rootFrame = (Frame) ApplicationManager.instance().getViewManager().getRootFrame();
+ final String suggestedFolderPath = projectConfigurations.getExportFolderPath();
+ String suggestedFileName = projectConfigurations.getExportFilename();
+
+ if (suggestedFileName.isEmpty()) {
+ final String projectName =
+ ApplicationManager.instance().getProjectManager().getProject().getName();
+ suggestedFileName = projectName + ".json";
+ }
+
+ if (shouldExport()) {
+ final String title = "Choose export file destination";
+ fileDialog = new FileDialog(rootFrame, title, FileDialog.SAVE);
+ } else if (shouldImport()) {
+ final String title = "Select import file ";
+ fileDialog = new FileDialog(rootFrame, title, FileDialog.LOAD);
+ } else {
+ throw new RuntimeException("Unexpected action: " + action.getActionId());
+ }
+
+ fileDialog.setFile(suggestedFileName);
+ fileDialog.setDirectory(suggestedFolderPath);
+ fileDialog.setMultipleMode(false);
+ fileDialog.setFilenameFilter((dir, name) -> name != null && name.endsWith(FILE_FORMAT));
+
+ fileDialog.setVisible(true);
+
+ final String fileDirectory = fileDialog.getDirectory();
+ final String fileName = fileDialog.getFile();
+
+ if (fileDirectory != null && fileName != null) {
+ return fileName.endsWith(FILE_FORMAT)
+ ? Paths.get(fileDirectory, fileName)
+ : Paths.get(fileDirectory, fileName + FILE_FORMAT);
+ }
+
+ return null;
+ }
+
+ private void saveFilePath() {
+ final Path directoryPath = filePath.getParent();
+ final String directoryPathName = directoryPath.toAbsolutePath().getFileName().toString();
+ final String filePathName = filePath.getFileName().toString();
+
+ projectConfigurations.setExportFolderPath(directoryPathName);
+ projectConfigurations.setExportFilename(filePathName);
+ configs.save();
+ }
+
+ private List importTask(SimpleServiceWorker context) {
+ try {
+ if (filePath == null) {
+ context.cancel(true);
+ return List.of();
+ }
+
+ final String importFileContents = Files.readString(filePath);
+
+ if (!context.isCancelled()) {
+ Ontouml2UmlLoader.deserializeAndLoad(importFileContents, false, false);
+ saveFilePath();
+ ViewManagerUtils.log(MESSAGE_MODEL_IMPORTED);
+ return List.of(MESSAGE_MODEL_IMPORTED);
+ }
+
+ return List.of();
+ } catch (IOException e) {
+ e.printStackTrace();
+ ViewManagerUtils.log(MESSAGE_MODEL_IMPORT_INVALID_FILE_ERROR);
+ return List.of(MESSAGE_MODEL_IMPORT_INVALID_FILE_ERROR);
+ } catch (Exception e) {
+ e.printStackTrace();
+ ViewManagerUtils.log(MESSAGE_MODEL_IMPORT_UNEXPECTED_ERROR);
+ return List.of(MESSAGE_MODEL_IMPORT_UNEXPECTED_ERROR);
+ }
+ }
+
+ private List exportTask(SimpleServiceWorker context) {
+ try {
+ if (filePath == null) {
+ context.cancel(true);
+ return List.of();
+ }
+
+ final String exportFileContents = Uml2OntoumlTransformer.transformAndSerialize();
+
+ if (!context.isCancelled()) {
+ Files.write(filePath, exportFileContents.getBytes());
+ saveFilePath();
+ ViewManagerUtils.log(MESSAGE_MODEL_EXPORTED);
+ return List.of(MESSAGE_MODEL_EXPORTED);
+ }
+
+ return List.of();
+ } catch (IOException e) {
+ e.printStackTrace();
+ ViewManagerUtils.log(MESSAGE_MODEL_EXPORT_INVALID_FILE_ERROR);
+
+ return List.of(MESSAGE_MODEL_EXPORT_INVALID_FILE_ERROR);
+ } catch (Exception e) {
+ e.printStackTrace();
+ ViewManagerUtils.log(MESSAGE_MODEL_EXPORT_UNEXPECTED_ERROR);
+
+ return List.of(MESSAGE_MODEL_EXPORT_UNEXPECTED_ERROR);
+ }
+ }
+}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java
index 2536543e..25fb839f 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java
@@ -3,13 +3,19 @@
import com.vp.plugin.ApplicationManager;
import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPActionController;
-import com.vp.plugin.view.IDialog;
-import com.vp.plugin.view.IDialogHandler;
-import it.unibz.inf.ontouml.vp.model.ServerRequest;
-import it.unibz.inf.ontouml.vp.model.uml.ModelElement;
+import com.vp.plugin.diagram.IBaseDiagramElement;
+import com.vp.plugin.diagram.IDiagramElement;
+import com.vp.plugin.diagram.IDiagramUIModel;
+import it.unibz.inf.ontouml.vp.model.ServiceIssue;
+import it.unibz.inf.ontouml.vp.model.VerificationServiceResult;
+import it.unibz.inf.ontouml.vp.model.vp2ontouml.Uml2OntoumlTransformer;
+import it.unibz.inf.ontouml.vp.utils.SimpleServiceWorker;
import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
-import it.unibz.inf.ontouml.vp.views.ProgressPanel;
-import java.awt.Component;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
/**
* Implementation of toolbar button action responsible for performing model verification.
@@ -19,27 +25,12 @@
*/
public class ModelVerificationController implements VPActionController {
- private ProgressPanel progressPanel;
- private ProgressDialog loading;
- private IDialog mainDialog;
- ModelVerificationRequest request;
+ private static final String MODEL_VERIFICATION_ACTION =
+ "it.unibz.inf.ontouml.vp.actions.ModelVerificationAction";
+ private static final String DIAGRAM_VERIFICATION_ACTION =
+ "it.unibz.inf.ontouml.vp.actions.DiagramVerificationAction";
- /**
- * Performs OntoUML model verification.
- *
- * @param action
- */
- @Override
- public void performAction(VPAction action) {
-
- request = new ModelVerificationRequest();
-
- loading = new ProgressDialog();
- ApplicationManager.instance().getViewManager().showDialog(loading);
-
- Thread thread = new Thread(request);
- thread.start();
- }
+ private VPAction action;
/**
* Called when the menu containing the button is accessed allowing for action manipulation, such
@@ -50,63 +41,67 @@ public void performAction(VPAction action) {
@Override
public void update(VPAction action) {}
- protected class ProgressDialog implements IDialogHandler {
+ /** Performs OntoUML model verification. */
+ @Override
+ public void performAction(VPAction action) {
+ this.action = action;
+ final SimpleServiceWorker worker = new SimpleServiceWorker(this::task);
+ worker.execute();
+ }
- @Override
- public Component getComponent() {
- progressPanel = new ProgressPanel(request);
- return progressPanel;
- }
+ private List task(SimpleServiceWorker context) {
+ try {
+ final String project = Uml2OntoumlTransformer.transformAndSerialize();
+ final VerificationServiceResult result =
+ OntoUMLServerAccessController.requestModelVerification(project);
- @Override
- public void prepare(IDialog dialog) {
- mainDialog = dialog;
- mainDialog.setTitle("Verification Service");
- mainDialog.setModal(false);
- mainDialog.setResizable(false);
- dialog.setSize(progressPanel.getWidth(), progressPanel.getHeight() + 20);
- progressPanel.setContainerDialog(mainDialog);
- }
+ if (DIAGRAM_VERIFICATION_ACTION.equals(action.getActionId())) {
+ retainDiagramIssues(result);
+ }
- @Override
- public void shown() {}
+ if (!context.isCancelled()) {
+ ViewManagerUtils.log(result);
+ }
+
+ return List.of(result.getMessage());
+ } catch (IOException e) {
+ if (!context.isCancelled()) {
+ ViewManagerUtils.log(e.getMessage());
+ }
- @Override
- public boolean canClosed() {
- mainDialog.close();
- return true;
+ e.printStackTrace();
+ return List.of(e.getMessage());
}
}
- public class ModelVerificationRequest extends ServerRequest {
-
- @Override
- public void run() {
- while (keepRunning()) {
- try {
- final String response =
- OntoUMLServerAccessController.requestModelVerification(
- ModelElement.generateModel(true), loading);
-
- if (keepRunning()) {
- if (response != null) {
- loading.canClosed();
- request.doStop();
- ViewManagerUtils.logVerificationResponse(response);
- } else {
- loading.canClosed();
- request.doStop();
- }
- } else {
- loading.canClosed();
- request.doStop();
- ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user.");
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ private void retainDiagramIssues(VerificationServiceResult result) {
+ if (result == null) {
+ return;
}
+
+ final IDiagramUIModel activeDiagram =
+ ApplicationManager.instance().getDiagramManager().getActiveDiagram();
+ final IDiagramElement[] diagramElements = activeDiagram.toDiagramElementArray();
+
+ if (diagramElements == null) {
+ result.setResult(null);
+ return;
+ }
+
+ final List verificationIssues = result.getResult();
+ final Set presentModelElementsIds =
+ Arrays.stream(diagramElements)
+ .map(IBaseDiagramElement::getModelElement)
+ .map(modelElement -> modelElement != null ? modelElement.getId() : null)
+ .collect(Collectors.toSet());
+ final List filteredVerificationIssues =
+ verificationIssues.stream()
+ .filter(
+ issue ->
+ issue.getSource() != null
+ && presentModelElementsIds.contains(issue.getSource().getId()))
+ .collect(Collectors.toList());
+
+ result.setResult(filteredVerificationIssues);
}
}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModularizationController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModularizationController.java
new file mode 100644
index 00000000..3dc2b882
--- /dev/null
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModularizationController.java
@@ -0,0 +1,60 @@
+package it.unibz.inf.ontouml.vp.controllers;
+
+import com.vp.plugin.action.VPAction;
+import com.vp.plugin.action.VPActionController;
+import it.unibz.inf.ontouml.vp.model.ModularizationServiceResult;
+import it.unibz.inf.ontouml.vp.model.ontouml.Project;
+import it.unibz.inf.ontouml.vp.model.ontouml2vp.IProjectLoader;
+import it.unibz.inf.ontouml.vp.model.vp2ontouml.Uml2OntoumlTransformer;
+import it.unibz.inf.ontouml.vp.utils.SimpleServiceWorker;
+import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
+import java.io.IOException;
+import java.util.List;
+
+public class ModularizationController implements VPActionController {
+
+ @Override
+ public void performAction(VPAction vpAction) {
+ final SimpleServiceWorker worker = new SimpleServiceWorker(this::task);
+ worker.execute();
+ }
+
+ @Override
+ public void update(VPAction vpAction) {}
+
+ private List task(SimpleServiceWorker context) {
+ try {
+ System.out.println("Starting modularization service...");
+ System.out.println("Serializing project...");
+ final String serializedProject = Uml2OntoumlTransformer.transformAndSerialize();
+ System.out.println(serializedProject);
+ System.out.println("Project serialized!");
+
+ System.out.println("Requesting diagrams from the modularization service...");
+ final ModularizationServiceResult serviceResult =
+ OntoUMLServerAccessController.requestProjectModularization(serializedProject);
+ System.out.println("Request answered by modularization service!");
+
+ System.out.println(serviceResult.getIssues());
+
+ // Load project
+ System.out.println("Processing modularization service response...");
+ Project modularizedProject = serviceResult.getResult();
+ if (!context.isCancelled() && modularizedProject != null) {
+ IProjectLoader.load(modularizedProject, false, true);
+ ViewManagerUtils.log(serviceResult.getMessage());
+ }
+ System.out.println("Modularization service response processed!");
+ System.out.println("Modularization service concluded.");
+
+ return List.of(serviceResult.getMessage());
+ } catch (IOException e) {
+ if (!context.isCancelled()) {
+ ViewManagerUtils.log(e.getMessage());
+ }
+
+ e.printStackTrace();
+ return List.of(e.getMessage());
+ }
+ }
+}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java
index c69f06e7..6de3ca12 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java
@@ -1,19 +1,17 @@
package it.unibz.inf.ontouml.vp.controllers;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.vp.plugin.view.IDialogHandler;
+import com.fasterxml.jackson.databind.ObjectMapper;
import it.unibz.inf.ontouml.vp.model.Configurations;
+import it.unibz.inf.ontouml.vp.model.GufoTransformationServiceResult;
+import it.unibz.inf.ontouml.vp.model.ModularizationServiceResult;
import it.unibz.inf.ontouml.vp.model.ProjectConfigurations;
-import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
+import it.unibz.inf.ontouml.vp.model.ServiceResult;
+import it.unibz.inf.ontouml.vp.model.VerificationServiceResult;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.URL;
import java.util.stream.Collectors;
@@ -29,244 +27,152 @@ public class OntoUMLServerAccessController {
private static final String TRANSFORM_GUFO_SERVICE_ENDPOINT = "/v1/transform/gufo";
private static final String VERIFICATION_SERVICE_ENDPOINT = "/v1/verify";
+ private static final String MODULARIZATION_SERVICE_ENDPOINT = "/v1/modularize";
private static final String USER_MESSAGE_BAD_REQUEST =
- "There was a internal plugin error and the verification could not be completed.";
- private static final String USER_MESSAGE_NOT_FOUND = "Unable to reach the server.";
+ "There was a internal plugin error and the service could not be completed.";
+ private static final String USER_MESSAGE_REQUEST_WITH_SYNTACTICAL_ERRORS =
+ "Unable to execute request on a project containing syntactical errors.";
+ private static final String USER_MESSAGE_NOT_FOUND = "Server not found.";
+ private static final String USER_MESSAGE_CONNECTION_ERROR = "Unable to reach the server.";
private static final String USER_MESSAGE_INTERNAL_ERROR = "Internal server error.";
- private static final String USER_MESSAGE_UNKNOWN_ERROR_REQUEST =
- "Error sending model verification to the server.";
private static final String USER_MESSAGE_UNKNOWN_ERROR_RESPONSE =
- "Error receiving model verification response.";
+ "Error receiving service response.";
- public static BufferedReader transformToGUFO(
- String model,
- String baseIRI,
- String format,
- String uriFormatBy,
- String inverse,
- String object,
- String analysis,
- String packages,
- String elementMapping,
- String packageMapping,
- IDialogHandler loading)
- throws Exception {
- final JsonObject optionsObj = new JsonObject();
-
- boolean createObjectProperty = !Boolean.parseBoolean(object);
- boolean createInverses = Boolean.parseBoolean(inverse);
- boolean preAnalysis = Boolean.parseBoolean(analysis);
- boolean prefixPackages = Boolean.parseBoolean(packages);
+ private static String getServiceRequestBody(String project) {
+ return "{\"options\": null, \"project\": " + project + "}";
+ }
- optionsObj.addProperty("baseIRI", baseIRI);
- optionsObj.addProperty("format", format);
- optionsObj.addProperty("uriFormatBy", uriFormatBy);
- optionsObj.addProperty("createInverses", createInverses);
- optionsObj.addProperty("createObjectProperty", createObjectProperty);
- optionsObj.addProperty("preAnalysis", preAnalysis);
- optionsObj.addProperty("prefixPackages", prefixPackages);
- optionsObj.add("customElementMapping", new Gson().fromJson(elementMapping, JsonObject.class));
- optionsObj.add("customPackageMapping", new Gson().fromJson(packageMapping, JsonObject.class));
+ private static String getServiceRequestBody(String project, String options) {
+ return "{\"options\": " + options + ", \"project\": " + project + "}";
+ }
- final JsonObject bodyObj = new JsonObject();
- bodyObj.add("options", optionsObj);
- bodyObj.add("model", new JsonParser().parse(model).getAsJsonObject());
+ private static String getModularizationRequestUrl() {
+ final ProjectConfigurations config = Configurations.getInstance().getProjectConfigurations();
+ return config.isCustomServerEnabled()
+ ? config.getServerURL() + MODULARIZATION_SERVICE_ENDPOINT
+ : ProjectConfigurations.DEFAULT_SERVER_URL + MODULARIZATION_SERVICE_ENDPOINT;
+ }
- final GsonBuilder builder = new GsonBuilder();
- final Gson gson = builder.serializeNulls().setPrettyPrinting().create();
- final String body = gson.toJson(bodyObj);
+ private static String getVerificationRequestUrl() {
+ final ProjectConfigurations config = Configurations.getInstance().getProjectConfigurations();
+ return config.isCustomServerEnabled()
+ ? config.getServerURL() + VERIFICATION_SERVICE_ENDPOINT
+ : ProjectConfigurations.DEFAULT_SERVER_URL + VERIFICATION_SERVICE_ENDPOINT;
+ }
- final ProjectConfigurations configurations =
- Configurations.getInstance().getProjectConfigurations();
- final String url;
+ private static String getTransformationToGufoRequestUrl() {
+ final ProjectConfigurations config = Configurations.getInstance().getProjectConfigurations();
+ return config.isCustomServerEnabled()
+ ? config.getServerURL() + TRANSFORM_GUFO_SERVICE_ENDPOINT
+ : ProjectConfigurations.DEFAULT_SERVER_URL + TRANSFORM_GUFO_SERVICE_ENDPOINT;
+ }
- if (configurations.isCustomServerEnabled()) {
- url = configurations.getServerURL() + TRANSFORM_GUFO_SERVICE_ENDPOINT;
- } else {
- url = ProjectConfigurations.DEFAULT_SERVER_URL + TRANSFORM_GUFO_SERVICE_ENDPOINT;
+ private static > T parseResponse(
+ HttpURLConnection connection, Class _class) throws IOException {
+ if (connection.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ return null;
}
- loading.shown();
-
- try {
- final HttpURLConnection request = request(url, body);
- final BufferedReader responseReader =
- request.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST
- ? new BufferedReader(new InputStreamReader(request.getInputStream()))
- : new BufferedReader(new InputStreamReader(request.getErrorStream()));
-
- loading.canClosed();
-
- switch (request.getResponseCode()) {
- case HttpURLConnection.HTTP_OK:
- if (!request.getContentType().equals("text/html")) {
- return responseReader;
- } else {
- if (ViewManagerUtils.exportToGUFOIssueDialogWithOption(
- "Server not found.", HttpURLConnection.HTTP_NOT_FOUND))
- return transformToGUFO(
- model,
- baseIRI,
- format,
- uriFormatBy,
- inverse,
- object,
- analysis,
- packages,
- elementMapping,
- packageMapping,
- loading);
-
- System.out.println(responseReader.lines().collect(Collectors.joining()));
- new Exception("Server not found.").printStackTrace();
- return null;
- }
- case HttpURLConnection.HTTP_BAD_REQUEST:
- ViewManagerUtils.exportToGUFOIssueDialog(
- "Unable to transform the model due to an unexpected error.\n"
- + "Please check the model for any syntactical errors.\n\n"
- + "Warning: partially exporting models to gUFO may introduce syntactical"
- + " errors.");
- System.out.println(responseReader.lines().collect(Collectors.joining()));
- new Exception(
- "Unable to transform the model due to an unexpected error.\n"
- + "Please check the model for any syntactical errors.\n\n"
- + "Warning: partially exporting models to gUFO may introduce syntactical"
- + " errors.")
- .printStackTrace();
- return null;
- case HttpURLConnection.HTTP_NOT_FOUND:
- if (ViewManagerUtils.exportToGUFOIssueDialogWithOption(
- "Server not found.", HttpURLConnection.HTTP_NOT_FOUND))
- return transformToGUFO(
- model,
- baseIRI,
- format,
- uriFormatBy,
- inverse,
- object,
- analysis,
- packages,
- elementMapping,
- packageMapping,
- loading);
-
- System.out.println(responseReader.lines().collect(Collectors.joining()));
- new Exception("Server not found.").printStackTrace();
- return null;
- case HttpURLConnection.HTTP_INTERNAL_ERROR:
- if (ViewManagerUtils.exportToGUFOIssueDialogWithOption(
- "Server error.", HttpURLConnection.HTTP_INTERNAL_ERROR))
- return transformToGUFO(
- model,
- baseIRI,
- format,
- uriFormatBy,
- inverse,
- object,
- analysis,
- packages,
- elementMapping,
- packageMapping,
- loading);
-
- System.out.println(responseReader.lines().collect(Collectors.joining()));
- new Exception("Server error.").printStackTrace();
- return null;
- default:
- ViewManagerUtils.exportToGUFOIssueDialog("Unexpected error.");
- throw new Exception("Unknown error");
- }
- } catch (MalformedURLException e) {
- ViewManagerUtils.exportToGUFOIssueDialog("Server error.");
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ if (!hasJsonContentType(connection)) {
+ throw new IOException(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE);
}
- return null;
+ final BufferedReader reader =
+ new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ final String json = reader.lines().parallel().collect(Collectors.joining("\n"));
+ return new ObjectMapper().readValue(json, _class);
}
- public static String requestModelVerification(String serializedModel, IDialogHandler loading) {
- final ProjectConfigurations configurations =
- Configurations.getInstance().getProjectConfigurations();
- final String url;
-
- if (configurations.isCustomServerEnabled()) {
- url = configurations.getServerURL() + VERIFICATION_SERVICE_ENDPOINT;
- } else {
- url = ProjectConfigurations.DEFAULT_SERVER_URL + VERIFICATION_SERVICE_ENDPOINT;
- }
+ private static boolean hasJsonContentType(HttpURLConnection connection) {
+ return connection.getContentType().contains("application/json");
+ }
- loading.shown();
+ public static ModularizationServiceResult requestProjectModularization(String project)
+ throws IOException {
+ final String body = getServiceRequestBody(project);
+ final String url = getModularizationRequestUrl();
+ final HttpURLConnection connection = request(url, body);
- try {
+ return parseResponse(connection, ModularizationServiceResult.class);
+ }
- final HttpURLConnection request = request(url, serializedModel);
- final StringBuilder response = new StringBuilder();
- final BufferedReader reader =
- request.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST
- ? new BufferedReader(new InputStreamReader(request.getInputStream()))
- : new BufferedReader(new InputStreamReader(request.getErrorStream()));
+ public static VerificationServiceResult requestModelVerification(String project)
+ throws IOException {
+ final String url = getVerificationRequestUrl();
+ final String body = getServiceRequestBody(project);
+ final HttpURLConnection connection = request(url, body);
- String line = null;
+ return parseResponse(connection, VerificationServiceResult.class);
+ }
- while ((line = reader.readLine()) != null) {
- response.append(line.trim());
- }
+ public static GufoTransformationServiceResult requestModelTransformationToGufo(
+ String project, String options) throws IOException {
+ final String url = getTransformationToGufoRequestUrl();
+ final String body = getServiceRequestBody(project, options);
+ final HttpURLConnection connection = request(url, body);
- reader.close();
+ return parseResponse(connection, GufoTransformationServiceResult.class);
+ }
- loading.canClosed();
+ private static HttpURLConnection request(String url, String body) throws IOException {
+ try {
+ final HttpURLConnection connection = performRequest(url, body);
- switch (request.getResponseCode()) {
+ switch (connection.getResponseCode()) {
case HttpURLConnection.HTTP_OK:
- if (!request.getContentType().equals("text/html")) {
- return response.toString();
+ return connection;
+ case HttpURLConnection.HTTP_BAD_REQUEST:
+ if (!url.contains("verify")) {
+ // failed because the project contains syntactical errors
+ throw new IOException(USER_MESSAGE_REQUEST_WITH_SYNTACTICAL_ERRORS);
} else {
- if (ViewManagerUtils.verificationFailedDialogWithOption(
- USER_MESSAGE_NOT_FOUND, HttpURLConnection.HTTP_NOT_FOUND))
- return requestModelVerification(serializedModel, loading);
+ throw new IOException(USER_MESSAGE_BAD_REQUEST);
}
- case HttpURLConnection.HTTP_BAD_REQUEST:
- ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_BAD_REQUEST);
- return null;
case HttpURLConnection.HTTP_NOT_FOUND:
- if (ViewManagerUtils.verificationFailedDialogWithOption(
- USER_MESSAGE_NOT_FOUND, HttpURLConnection.HTTP_NOT_FOUND))
- return requestModelVerification(serializedModel, loading);
-
- return null;
+ throw new IOException(USER_MESSAGE_NOT_FOUND);
case HttpURLConnection.HTTP_INTERNAL_ERROR:
- if (ViewManagerUtils.verificationFailedDialogWithOption(
- USER_MESSAGE_INTERNAL_ERROR, HttpURLConnection.HTTP_INTERNAL_ERROR))
- return requestModelVerification(serializedModel, loading);
-
- return null;
+ throw new IOException(USER_MESSAGE_INTERNAL_ERROR);
default:
- ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE);
- return null;
+ throw new IOException(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE);
}
-
} catch (SocketException e) {
- loading.canClosed();
- ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_NOT_FOUND);
- e.printStackTrace();
+ throw new IOException(USER_MESSAGE_CONNECTION_ERROR);
} catch (IOException e) {
- loading.canClosed();
- ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE);
- e.printStackTrace();
+ throw e;
} catch (Exception e) {
- loading.canClosed();
- ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_REQUEST);
- e.printStackTrace();
+ throw new IOException(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE);
}
-
- return null;
}
- private static HttpURLConnection request(String urlString, String body)
- throws MalformedURLException, IOException {
+ // public static GufoTransformationServiceResult requestProjectTransformationToGufo(
+ // String project, String options) {
+ // final String body = getServiceRequestBody(project, options);
+ // final String url = getTransformationToGufoRequestUrl();
+ //
+ // try {
+ // final HttpURLConnection connection = performRequest(url, body);
+ //
+ // switch (connection.getResponseCode()) {
+ // case HttpURLConnection.HTTP_OK:
+ // if (hasJsonContentType(connection)) {
+ // return parseResponse(connection, GufoTransformationServiceResult.class);
+ // }
+ // case HttpURLConnection.HTTP_BAD_REQUEST:
+ // case HttpURLConnection.HTTP_NOT_FOUND:
+ // case HttpURLConnection.HTTP_INTERNAL_ERROR:
+ // default:
+ // System.err.println("Attention! Transformation request was not processed correctly");
+ // System.err.println("Status Code: " + connection.getResponseCode());
+ // }
+ // } catch (IOException ioException) {
+ // ioException.printStackTrace();
+ // }
+ //
+ // return null;
+ // }
+
+ private static HttpURLConnection performRequest(String urlString, String body)
+ throws IOException {
final URL url = new URL(urlString);
final HttpURLConnection request = (HttpURLConnection) url.openConnection();
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java
index c21dc404..def74bbd 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java
@@ -1,123 +1,27 @@
package it.unibz.inf.ontouml.vp.controllers;
import com.vp.plugin.ApplicationManager;
-import com.vp.plugin.DiagramManager;
import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPActionController;
-import com.vp.plugin.diagram.IDiagramUIModel;
-import com.vp.plugin.model.IPackage;
-import com.vp.plugin.model.factory.IModelElementFactory;
import it.unibz.inf.ontouml.vp.OntoUMLPlugin;
-import it.unibz.inf.ontouml.vp.utils.Stereotype;
-import java.util.List;
+import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
public class ReloadClassesController implements VPActionController {
@Override
public void performAction(VPAction action) {
- // OntoUMLPlugin.reload();
- // generateModel();
- reverseDirection(action);
+ reloadPlugin();
}
@Override
public void update(VPAction action) {}
- private void reverseDirection(VPAction action) {
+ private void reloadPlugin() {
+ System.out.println("----------------------------------------");
+ System.out.println("Reloading OntoUML Plugin...");
ApplicationManager app = ApplicationManager.instance();
app.reloadPluginClasses(OntoUMLPlugin.PLUGIN_ID);
-
- // DiagramManager dm = app.getDiagramManager();
- // IDiagramElement[] selectedElements = dm.getSelectedDiagramElements();
- //
- // for (int i = 0; selectedElements != null && i < selectedElements.length; i++) {
- // IDiagramElement diagramElement = selectedElements[i];
- // IModelElement element = diagramElement.getModelElement();
- //
- // if (element == null ||
- // !IModelElementFactory.MODEL_TYPE_ASSOCIATION.equals(element.getModelType())) {
- // continue;
- // }
- //
- // IAssociation association = (IAssociation) element;
- // Association.invertAssociation(association);
- // IAssociationUIModel originalAssociationView = (IAssociationUIModel) diagramElement;
- // IClass originalFrom = (IClass) association.getFrom();
- // IClass originalTo = (IClass) association.getTo();
- // IAssociationEnd originalFromEnd = (IAssociationEnd) association.getFromEnd();
- // IAssociationEnd originalToEnd = (IAssociationEnd) association.getToEnd();
- //
- // association.setFrom(originalTo);
- // association.setTo(originalFrom);
- //
- // Point[] points = originalAssociationView.getPoints();
- // IDiagramUIModel diagram = diagramElement.getDiagramUIModel();
- // IAssociationUIModel reverseAssociationView = (IAssociationUIModel)
- // dm.createConnector(diagram, association, originalAssociationView.getToShape(),
- // originalAssociationView.getFromShape(), null);
- // diagramElement.deleteViewOnly();
- //
- // if(points != null) {
- // for (int j = points.length - 1; j >= 0; j--) {
- // reverseAssociationView.addPoint(points[j]);
- // }
- // }
- // reverseAssociationView.resetCaption();
- // IConnectorUIModel reverseAssociationView = (IConnectorUIModel)
- // dm.createDiagramElement(diagram, association);
- // reverseAssociationView.set
- // }
- }
-
- @SuppressWarnings("unused")
- private void generateModel() {
- final ApplicationManager app = ApplicationManager.instance();
- final DiagramManager dm = app.getDiagramManager();
- final IDiagramUIModel diagram = dm.getActiveDiagram();
- final IPackage pkg = (IPackage) diagram.getParentModel();
- final IModelElementFactory factory = IModelElementFactory.instance();
-
- if (diagram == null || pkg == null) {
- return;
- }
-
- final List stereotypes = Stereotype.getOntoUMLClassStereotypeNames();
-
- for (String sourceStereotype : stereotypes) {
- final IPackage sourcePkg = factory.createPackage();
- sourcePkg.setName(sourceStereotype);
- pkg.addChild(sourcePkg);
-
- for (String targetStereotype : stereotypes) {
- // // Method getAllowedAssociations() was removed
- // final List allowedAssociations =
- // OntoUMLConstraintsManager.getAllowedAssociations(sourceStereotype,
- // targetStereotype);
-
- // if(!allowedAssociations.isEmpty()) {
- // final IClass source = factory.createClass();
- // final IClass target = factory.createClass();
- //
- // source.setName(sourceStereotype + " as Source");
- // target.setName(targetStereotype + " as Target");
- //
- // source.addStereotype(sourceStereotype);
- // target.addStereotype(targetStereotype);
- //
- // sourcePkg.addChild(source);
- // sourcePkg.addChild(target);
- //
- // for (String associationStereotype : allowedAssociations) {
- // final IAssociation association = factory.createAssociation();
- //
- // association.addStereotype(associationStereotype);
- // association.setFrom(source);
- // association.setTo(target);
- //
- // sourcePkg.addChild(association);
- // }
- // }
- }
- }
+ System.out.println("Plugin reloaded!");
+ ViewManagerUtils.simpleDialog("Plugin reloaded!");
}
}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java
index fb639ba6..951b589d 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java
@@ -3,7 +3,7 @@
import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPActionController;
import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
-import java.awt.Desktop;
+import java.awt.*;
import java.net.URI;
public class ReportErrorController implements VPActionController {
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java
index a9f97256..180e642c 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java
@@ -7,11 +7,7 @@
import it.unibz.inf.ontouml.vp.model.GitHubRelease;
import it.unibz.inf.ontouml.vp.model.GitHubReleaseAsset;
import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java b/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java
index 39b14a06..9adb1ea0 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java
@@ -46,8 +46,7 @@ public void diagramUIModelPropertyChanged(
public void diagramUIModelRenamed(IDiagramUIModel diagram) {}
private void smartPaint(IDiagramElement diagramElement) {
- if (diagramElement != null
- && diagramElement instanceof IClassUIModel
+ if (diagramElement instanceof IClassUIModel
&& Configurations.getInstance().getProjectConfigurations().isAutomaticColoringEnabled()) {
SmartColoringUtils.paint((IClassUIModel) diagramElement);
}
diff --git a/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java b/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java
index 2915533a..839dc98a 100644
--- a/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java
+++ b/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java
@@ -5,14 +5,14 @@
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.util.ArrayList;
+import java.util.List;
import javax.swing.*;
public final class IssueLogMenuListener extends MouseAdapter {
- private ArrayList idModelElementList;
+ private List idModelElementList;
private JList