Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.6.0alpha1 #101

Open
wants to merge 14 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ repo/
ontouml-vp-plugin.zip

.java-version

.metadata/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.unibz.inf.ontouml</groupId>
<artifactId>ontouml-vp-plugin</artifactId>
<version>0.5.0</version>
<version>0.5.1</version>

<name>OntoUML 2 Plugin for Visual Paradigm</name>

Expand Down
22 changes: 21 additions & 1 deletion src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
*/
public class OntoUMLPlugin implements VPPlugin {

public static final String PLUGIN_VERSION_RELEASE = "0.5.0";
public static final String PLUGIN_VERSION_RELEASE = "0.5.1";
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/";
public static final String PLUGIN_REPO_OWNER = "OntoUML";
public static final String PLUGIN_REPO_NAME = "ontouml-vp-plugin";

private static boolean isExportToGUFOWindowOpen;
private static boolean isDBExportWindowOpen;
private static boolean isOBDAExportWindowOpen;
private static boolean isConfigWindowOpen;
private static ProjectListener projectListener;

/** OntoUMLPlugin constructor. Declared to make explicit Open API requirements. */
public OntoUMLPlugin() {
// The constructor of a VPPlugin MUST NOT have parameters.
isExportToGUFOWindowOpen = false;
isDBExportWindowOpen = false;
isOBDAExportWindowOpen = false;
isConfigWindowOpen = false;
System.out.println("OntoUML Plugin (v" + PLUGIN_VERSION_RELEASE + ") loaded successfully.");
}
Expand Down Expand Up @@ -71,4 +75,20 @@ public static void setConfigWindowOpen(boolean open) {
public static boolean getConfigWindowOpen() {
return isConfigWindowOpen;
}

public static boolean getDBExportWindowOpen() {
return isDBExportWindowOpen;
}

public static void setDBExportWindowOpen(boolean open) {
isDBExportWindowOpen = open;
}

public static boolean getOBDAExportWindowOpen() {
return isOBDAExportWindowOpen;
}

public static void setOBDAExportWindowOpen(boolean open) {
isOBDAExportWindowOpen = open;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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.DbMappingOptions;
import it.unibz.inf.ontouml.vp.model.Ontouml2DbServiceResult;
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;

public class DbMappingController implements VPActionController {

private static final String MESSAGE_MODEL_EXPORTED = "Model exported successfully.";

private Configurations configurations;
private ProjectConfigurations projectConfigurations;
private String schemaFormat = ".sql";
private String obdaFormat = ".obda";
private String propertiesFormat = ".properties";
private Path schemaFilePath;
private Path obdaFilePath;
private Path propertiesFilePath;

@Override
public void performAction(VPAction action) {
schemaFilePath = null;
obdaFilePath = null;
propertiesFilePath = null;
configurations = Configurations.getInstance();
projectConfigurations = configurations.getProjectConfigurations();
DbMappingDialogHandler mappingDialog = new DbMappingDialogHandler(projectConfigurations);
mappingDialog.showDialog();

if (mappingDialog.wasCancelled()) {
ViewManagerUtils.log("Request cancelled by the user.");
return;
}
putFilePath();
new SimpleServiceWorker(this::task).execute();
}

private List<String> task(SimpleServiceWorker context) {
try {
if (schemaFilePath == null) {
context.cancel(true);
return List.of();
}

saveFilePath();

final String project = Uml2OntoumlTransformer.transformAndSerialize();
final String options = new DbMappingOptions(projectConfigurations).toJson();
final Ontouml2DbServiceResult serviceResult =
OntoUMLServerAccessController.requestModelTransformationToDb(project, options);

if (!context.isCancelled()) {
if (projectConfigurations.isGenerateSchema()) {
Files.write(schemaFilePath, serviceResult.getResult().getSchema().getBytes());
}
if (projectConfigurations.isGenerateObda()) {
Files.write(obdaFilePath, serviceResult.getResult().getObda().getBytes());
}
if (projectConfigurations.isGenerateConnection()) {
Files.write(propertiesFilePath, serviceResult.getResult().getConnection().getBytes());
}
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 boolean putFilePath() {
final FileDialog fileDialog;
final Frame rootFrame = (Frame) ApplicationManager.instance().getViewManager().getRootFrame();
final String suggestedFolderPath = projectConfigurations.getDbMappingFolderPath();
String suggestedFileName = projectConfigurations.getDbMappingFileName();

if (suggestedFileName.isEmpty()) {
suggestedFileName = ApplicationManager.instance().getProjectManager().getProject().getName();
}

final String title = "Choose file destination";
fileDialog = new FileDialog(rootFrame, title, FileDialog.SAVE);

fileDialog.setFile(suggestedFileName);
fileDialog.setDirectory(suggestedFolderPath);
fileDialog.setMultipleMode(false);
fileDialog.setVisible(true);

final String fileDirectory = fileDialog.getDirectory();
final String fileName = removeFileExtension(fileDialog.getFile());

if (fileDirectory != null && fileName != null) {
schemaFilePath = Paths.get(fileDirectory, fileName + schemaFormat);
obdaFilePath = Paths.get(fileDirectory, fileName + obdaFormat);
propertiesFilePath = Paths.get(fileDirectory, fileName + propertiesFormat);
return true;
} else {
return false;
}
}

private void saveFilePath() {
final Path directoryPath = schemaFilePath.getParent();
final String directoryPathName = directoryPath.toAbsolutePath().getFileName().toString();
final String filePathName = removeFileExtension(schemaFilePath.getFileName().toString());

projectConfigurations.setDbMappingFolderPath(directoryPathName);
projectConfigurations.setDbMappingFileName(filePathName);
configurations.save();
}

/**
* Called when the menu containing the button is accessed allowing for action manipulation, such
* as enable/disable or selecting the button.
*
* <p>OBS: DOES NOT apply to this class.
*/
@Override
public void update(VPAction action) {}

private String removeFileExtension(String fileName) {
if (fileName.lastIndexOf('.') > 0) return fileName.substring(0, fileName.lastIndexOf('.'));
else return fileName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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.DbMappingView;
import java.awt.Component;

public class DbMappingDialogHandler implements IDialogHandler {

private IDialog dialog;
private final DbMappingView view;
private final ViewManager viewManager;
private boolean wasShown = false;
private boolean wasClosed = false;
private boolean wasCancelled = false;

public DbMappingDialogHandler(ProjectConfigurations projectConfigurations) {
view = new DbMappingView(projectConfigurations);
viewManager = ApplicationManager.instance().getViewManager();

view.onExport(
e -> {
if (view.checkValidParamters()) {
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(false); // 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("Mapping to ER dialog was already closed.");
} else if (!wasShown) {
System.out.println("Mapping to ER dialog was never shown. Setting wasClosed to \"true\"");
} else {
System.out.println("Closing mapping do ER dialog.");
dialog.close();
}
wasClosed = true;
}

public boolean wasCancelled() {
return wasCancelled;
}
}
Loading