diff --git a/sources/META-INF/MANIFEST.MF b/sources/META-INF/MANIFEST.MF index 66e27e06..d13c867d 100644 --- a/sources/META-INF/MANIFEST.MF +++ b/sources/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Database export / import plugin for Archimate Tool Bundle-SymbolicName: org.archicontribs.database;singleton:=true -Bundle-Version: 4.9.0.beta +Bundle-Version: 4.9.1 Bundle-Vendor: Herve Jouin Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/sources/src/org/archicontribs/database/DBPlugin.java b/sources/src/org/archicontribs/database/DBPlugin.java index e3e43a9b..05ffe702 100644 --- a/sources/src/org/archicontribs/database/DBPlugin.java +++ b/sources/src/org/archicontribs/database/DBPlugin.java @@ -49,10 +49,13 @@ * Fix folder when import individual component * Fix import and export windows default location * Fix import relationships in right folder + * Fix database upgrade for Oracle engine * Improve specializations management during export to database * Add Options tab in preference page to reduce window size * Add model metadata in compare to database process * + * v4.9.1 01/12/2021 Fix parent folder of imported components when merging models + * * ----------------------------------------------------------------------------------------- * * TO-DO list: diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java b/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java index 75e9f5aa..491bee18 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java @@ -210,13 +210,13 @@ public void widgetSelected(SelectionEvent e) { IDBImportCommand command = null; if ( importedComponent instanceof IArchimateElement ) - command = new DBImportElementFromIdCommand(importConnection, importedModel, null, parentFolder, id, version, DBImportMode.forceSharedMode, true); + command = new DBImportElementFromIdCommand(importConnection, importedModel, null, null, parentFolder, id, version, DBImportMode.forceSharedMode, true); else if ( importedComponent instanceof IArchimateRelationship ) - command = new DBImportRelationshipFromIdCommand(importConnection, importedModel, null, parentFolder, id, version, DBImportMode.forceSharedMode); + command = new DBImportRelationshipFromIdCommand(importConnection, importedModel, null, null, parentFolder, id, version, DBImportMode.forceSharedMode); else if ( importedComponent instanceof IFolder ) - command = new DBImportFolderFromIdCommand(importConnection, importedModel, parentFolder, id, version, DBImportMode.forceSharedMode); + command = new DBImportFolderFromIdCommand(importConnection, importedModel, null, parentFolder, id, version, DBImportMode.forceSharedMode); else if ( importedComponent instanceof IArchimateDiagramModel || importedComponent instanceof ICanvasModel || importedComponent instanceof ISketchModel ) - command = new DBImportViewFromIdCommand(importConnection, importedModel, parentFolder, id, version, DBImportMode.forceSharedMode, true); + command = new DBImportViewFromIdCommand(importConnection, importedModel, null, parentFolder, id, version, DBImportMode.forceSharedMode, true); else throw new Exception("Cannot import components of class "+importedComponent.getClass().getSimpleName()); diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java b/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java index 987c4bb2..5a9c29e9 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java @@ -2201,7 +2201,7 @@ protected void export() { DBMetadata versionToImport = this.exportConnection.getFoldersNotInModel().get(id); if ( versionToImport.getInitialVersion().getVersion() == 0 ) { if ( logger.isDebugEnabled() ) logger.debug("The folder id "+id+" has been created in the database. We import it from the database."); - undoableCommands.checkAndExecute(new DBImportFolderFromIdCommand(importConnection, this.exportedModel, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportFolderFromIdCommand(importConnection, this.exportedModel, null, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode)); incrementText(this.txtNewFoldersInDatabase); incrementText(this.txtTotalFolders); } else { @@ -2217,7 +2217,7 @@ protected void export() { IFolder folder = foldersIterator.next().getValue(); if ( this.exportedModel.getDBMetadata(folder).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { if ( logger.isDebugEnabled() ) logger.debug("The folder id "+folder.getId()+" has been updated in the database. We import the new version from the database."); - undoableCommands.checkAndExecute(new DBImportFolderFromIdCommand(importConnection, this.exportedModel, null, folder.getId(), 0, DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportFolderFromIdCommand(importConnection, this.exportedModel, null, null, folder.getId(), 0, DBImportMode.forceSharedMode)); incrementText(this.txtUpdatedFoldersInDatabase); } } @@ -2233,7 +2233,7 @@ protected void export() { DBMetadata versionToImport = this.exportConnection.getElementsNotInModel().get(id); if ( versionToImport.getInitialVersion().getVersion() == 0 ) { if ( logger.isDebugEnabled() ) logger.debug("The element id "+id+" has been created in the database. We import it from the database."); - undoableCommands.checkAndExecute(new DBImportElementFromIdCommand(importConnection, this.exportedModel, null, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode, false)); + undoableCommands.checkAndExecute(new DBImportElementFromIdCommand(importConnection, this.exportedModel, null, null, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode, false)); incrementText(this.txtNewElementsInDatabase); incrementText(this.txtTotalElements); } else { @@ -2249,7 +2249,7 @@ protected void export() { IArchimateElement element = elementsIterator.next().getValue(); if ( this.exportedModel.getDBMetadata(element).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { if ( logger.isDebugEnabled() ) logger.debug("The element id "+element.getId()+" has been updated in the database. We import the new version from the database."); - undoableCommands.checkAndExecute(new DBImportElementFromIdCommand(importConnection, this.exportedModel, null, null, element.getId(), 0, DBImportMode.forceSharedMode, false)); + undoableCommands.checkAndExecute(new DBImportElementFromIdCommand(importConnection, this.exportedModel, null, null, null, element.getId(), 0, DBImportMode.forceSharedMode, false)); incrementText(this.txtUpdatedElementsInDatabase); } } @@ -2264,7 +2264,7 @@ protected void export() { DBMetadata versionToImport = this.exportConnection.getRelationshipsNotInModel().get(id); if ( versionToImport.getInitialVersion().getVersion() == 0 ) { if ( logger.isDebugEnabled() ) logger.debug("The relationship id "+id+" has been created in the database. We import it from the database."); - undoableCommands.checkAndExecute(new DBImportRelationshipFromIdCommand(importConnection, this.exportedModel, null, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportRelationshipFromIdCommand(importConnection, this.exportedModel, null, null, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode)); incrementText(this.txtNewRelationshipsInDatabase); incrementText(this.txtTotalRelationships); } else { @@ -2280,7 +2280,7 @@ protected void export() { IArchimateRelationship relationship = relationshipsIterator.next().getValue(); if ( this.exportedModel.getDBMetadata(relationship).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { if ( logger.isDebugEnabled() ) logger.debug("The relationship id "+relationship.getId()+" has been updated in the database. We import the new version from the database."); - undoableCommands.checkAndExecute(new DBImportRelationshipFromIdCommand(importConnection, this.exportedModel, null, null, relationship.getId(), 0, DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportRelationshipFromIdCommand(importConnection, this.exportedModel, null, null, null, relationship.getId(), 0, DBImportMode.forceSharedMode)); incrementText(this.txtUpdatedRelationshipsInDatabase); } } @@ -2295,7 +2295,7 @@ protected void export() { DBMetadata versionToImport = this.exportConnection.getViewsNotInModel().get(id); if ( versionToImport.getInitialVersion().getVersion() == 0 ) { if ( logger.isDebugEnabled() ) logger.debug("The view id "+id+" has been created in the database. We import it in the model."); - undoableCommands.checkAndExecute(new DBImportViewFromIdCommand(importConnection, this.exportedModel, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode, false)); + undoableCommands.checkAndExecute(new DBImportViewFromIdCommand(importConnection, this.exportedModel, null, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode, false)); incrementText(this.txtNewViewsInDatabase); incrementText(this.txtTotalViews); } else { @@ -2311,7 +2311,7 @@ protected void export() { IDiagramModel view = viewsIterator.next().getValue(); if ( this.exportedModel.getDBMetadata(view).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { if ( logger.isDebugEnabled() ) logger.debug("The view id "+view.getId()+" has been updated in the database. We import the new version from the database."); - undoableCommands.checkAndExecute(new DBImportViewFromIdCommand(importConnection, this.exportedModel, null, view.getId(), 0, DBImportMode.forceSharedMode, false)); + undoableCommands.checkAndExecute(new DBImportViewFromIdCommand(importConnection, this.exportedModel, null, null, view.getId(), 0, DBImportMode.forceSharedMode, false)); incrementText(this.txtUpdatedViewsInDatabase); } } @@ -2326,7 +2326,7 @@ protected void export() { DBMetadata versionToImport = this.exportConnection.getViewObjectsNotInModel().get(id); if ( versionToImport.getInitialVersion().getVersion() == 0 ) { if ( logger.isDebugEnabled() ) logger.debug("The view object id "+id+" has been created in the database. We import it in the model."); - undoableCommands.checkAndExecute(new DBImportViewObjectFromIdCommand(importConnection, this.exportedModel, id, versionToImport.getLatestDatabaseVersion().getVersion(), false, DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportViewObjectFromIdCommand(importConnection, this.exportedModel, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), false, DBImportMode.forceSharedMode)); incrementText(this.txtNewViewObjectsInDatabase); incrementText(this.txtTotalViewObjects); } else { @@ -2342,7 +2342,7 @@ protected void export() { IDiagramModelObject viewObject = viewObjectsIterator.next().getValue(); if ( this.exportedModel.getDBMetadata(viewObject).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { if ( logger.isDebugEnabled() ) logger.debug("The view object id "+viewObject.getId()+" has been updated in the database. We import the new version from the database."); - undoableCommands.checkAndExecute(new DBImportViewObjectFromIdCommand(importConnection, this.exportedModel, viewObject.getId(), 0, false, DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportViewObjectFromIdCommand(importConnection, this.exportedModel, null, viewObject.getId(), 0, false, DBImportMode.forceSharedMode)); incrementText(this.txtUpdatedViewObjectsInDatabase); } } @@ -2357,7 +2357,7 @@ protected void export() { DBMetadata versionToImport = this.exportConnection.getViewConnectionsNotInModel().get(id); if ( versionToImport.getInitialVersion().getVersion() == 0 ) { if ( logger.isDebugEnabled() ) logger.debug("The view connection id "+id+" has been created in the database. We import it in the model."); - undoableCommands.checkAndExecute(new DBImportViewConnectionFromIdCommand(importConnection, this.exportedModel, id, versionToImport.getLatestDatabaseVersion().getVersion(), false, DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportViewConnectionFromIdCommand(importConnection, this.exportedModel, null, id, versionToImport.getLatestDatabaseVersion().getVersion(), false, DBImportMode.forceSharedMode)); incrementText(this.txtNewViewConnectionsInDatabase); incrementText(this.txtTotalViewConnections); } else { @@ -2373,7 +2373,7 @@ protected void export() { IDiagramModelConnection viewConnection = viewConnectionsIterator.next().getValue(); if ( this.exportedModel.getDBMetadata(viewConnection).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { if ( logger.isDebugEnabled() ) logger.debug("The view connection id "+viewConnection.getId()+" has been updated in the database. We import the new version from the database."); - undoableCommands.checkAndExecute(new DBImportViewConnectionFromIdCommand(importConnection, this.exportedModel, viewConnection.getId(), 0, false, DBImportMode.forceSharedMode)); + undoableCommands.checkAndExecute(new DBImportViewConnectionFromIdCommand(importConnection, this.exportedModel, null, viewConnection.getId(), 0, false, DBImportMode.forceSharedMode)); incrementText(this.txtUpdatedViewConnectionsInDatabase); } } @@ -2391,19 +2391,19 @@ protected void export() { int latestDatabaseVersion = metadata.getLatestDatabaseVersion().getVersion(); if ( componentToImport instanceof IArchimateElement ) { - command = new DBImportElementFromIdCommand(importConnection, this.exportedModel, null, null, id, latestDatabaseVersion, DBImportMode.forceSharedMode, false); + command = new DBImportElementFromIdCommand(importConnection, this.exportedModel, null, null, null, id, latestDatabaseVersion, DBImportMode.forceSharedMode, false); incrementText(this.txtUpdatedElementsInDatabase); } else if ( componentToImport instanceof IArchimateRelationship ) { - command = new DBImportRelationshipFromIdCommand(importConnection, this.exportedModel, null, null, id, latestDatabaseVersion, DBImportMode.forceSharedMode); + command = new DBImportRelationshipFromIdCommand(importConnection, this.exportedModel, null, null, null, id, latestDatabaseVersion, DBImportMode.forceSharedMode); incrementText(this.txtUpdatedRelationshipsInDatabase); } else if ( componentToImport instanceof IDiagramModel) { - command = new DBImportViewFromIdCommand(importConnection, this.exportedModel, null, id, latestDatabaseVersion, DBImportMode.forceSharedMode, false); + command = new DBImportViewFromIdCommand(importConnection, this.exportedModel, null, null, id, latestDatabaseVersion, DBImportMode.forceSharedMode, false); incrementText(this.txtUpdatedViewsInDatabase); } else if ( componentToImport instanceof IDiagramModelObject ) { - command = new DBImportViewObjectFromIdCommand(importConnection, this.exportedModel, id, latestDatabaseVersion, false, DBImportMode.forceSharedMode); + command = new DBImportViewObjectFromIdCommand(importConnection, this.exportedModel, null, id, latestDatabaseVersion, false, DBImportMode.forceSharedMode); incrementText(this.txtUpdatedViewObjectsInDatabase); } else if ( componentToImport instanceof IDiagramModelConnection ) { - command = new DBImportViewConnectionFromIdCommand(importConnection, this.exportedModel, id, latestDatabaseVersion, false, DBImportMode.forceSharedMode); + command = new DBImportViewConnectionFromIdCommand(importConnection, this.exportedModel, null, id, latestDatabaseVersion, false, DBImportMode.forceSharedMode); incrementText(this.txtUpdatedViewConnectionsInDatabase); } diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java b/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java index d306067c..9c68f86f 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java @@ -2199,19 +2199,19 @@ void doImport() throws Exception { int done = 0; try { for ( TableItem tableItem: this.tblComponents.getSelection() ) { - String id = (String)tableItem.getData("id"); - String name = tableItem.getText(0).trim(); + String mergedModelId = (String)tableItem.getData("id"); + String mergedModelName = tableItem.getText(0).trim(); if ( this.radioOptionModel.getSelection() ) { - setMessage("("+(++done)+"/"+this.tblComponents.getSelectionCount()+") Importing model \""+name+"\"."); + setMessage("("+(++done)+"/"+this.tblComponents.getSelectionCount()+") Importing model \""+mergedModelName+"\"."); // import folders - setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing folders from model \""+name+"\"."); + setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing folders from model \""+mergedModelName+"\"."); Map foldersConversionMap = new HashMap(); Map translatedFolders = new HashMap(); - try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT fim.folder_id, fim.folder_version, fim.parent_folder_id, f.type, f.root_type, f.name FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model fim JOIN "+this.selectedDatabase.getSchemaPrefix()+"folders f ON fim.folder_id = f.id and fim.folder_version = f.version WHERE fim.model_id = ? AND fim.model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model WHERE model_id = ?) ORDER BY fim.pos", id, id) ) { + try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT fim.folder_id, fim.folder_version, fim.parent_folder_id, f.type, f.root_type, f.name FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model fim JOIN "+this.selectedDatabase.getSchemaPrefix()+"folders f ON fim.folder_id = f.id and fim.folder_version = f.version WHERE fim.model_id = ? AND fim.model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model WHERE model_id = ?) ORDER BY fim.pos", mergedModelId, mergedModelId) ) { while ( result.next() ) { // we check if we already know how to convert this folder String convertedFolderId = translatedFolders.get(result.getString("folder_id")); @@ -2224,13 +2224,13 @@ void doImport() throws Exception { boolean isRootFolder = (folderType != 0); if ( isRootFolder ) - // for root folders, the path is directl the name of the folder + // for root folders, the path is directly the name of the folder folderPath = result.getString("name"); else { // for other folders, we recursively get the name of the parent folders until a root folder is found StringBuilder folderPathBuilder = new StringBuilder(); while ( !isRootFolder ) { - try (DBSelect subResult = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT fim.folder_id, fim.folder_version, fim.parent_folder_id, f.type, f.root_type, f.name FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model fim JOIN "+this.selectedDatabase.getSchemaPrefix()+"folders f ON fim.folder_id = f.id and fim.folder_version = f.version WHERE fim.model_id = ? AND fim.model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model WHERE model_id = ?) AND fim.folder_id = ?", id, id, folderId) ) { + try (DBSelect subResult = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT fim.folder_id, fim.folder_version, fim.parent_folder_id, f.type, f.root_type, f.name FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model fim JOIN "+this.selectedDatabase.getSchemaPrefix()+"folders f ON fim.folder_id = f.id and fim.folder_version = f.version WHERE fim.model_id = ? AND fim.model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model WHERE model_id = ?) AND fim.folder_id = ?", mergedModelId, mergedModelId, folderId) ) { subResult.next(); if ( folderPathBuilder.length() == 0 ) folderPathBuilder.append(subResult.getString("name")); @@ -2264,7 +2264,7 @@ void doImport() throws Exception { if ( folder == null ) { // if we're here, this means that we did not find the folder path in the model // so we import the folder - IDBImportCommand command = new DBImportFolderFromIdCommand(this.importConnection, this.importedModel, parentFolder, result.getString("folder_id"), result.getInt("folder_version"), DBImportMode.get(getOptionValue())); + IDBImportCommand command = new DBImportFolderFromIdCommand(this.importConnection, this.importedModel, mergedModelId, parentFolder, result.getString("folder_id"), result.getInt("folder_version"), DBImportMode.get(getOptionValue())); if ( command.getException() != null ) throw command.getException(); command.execute(); @@ -2289,8 +2289,8 @@ void doImport() throws Exception { } // import elements - setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing elements from model \""+name+"\"."); - try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT element_id, element_version, parent_folder_id FROM "+this.selectedDatabase.getSchemaPrefix()+"elements_in_model WHERE model_id = ? AND model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"elements_in_model WHERE model_id = ?) ORDER BY pos", id, id) ) { + setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing elements from model \""+mergedModelName+"\"."); + try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT element_id, element_version, parent_folder_id FROM "+this.selectedDatabase.getSchemaPrefix()+"elements_in_model WHERE model_id = ? AND model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"elements_in_model WHERE model_id = ?) ORDER BY pos", mergedModelId, mergedModelId) ) { while ( result.next() ) { // we check if the parent folder needs to be translated IFolder parentFolder = foldersConversionMap.get(result.getString("parent_folder_id")); @@ -2298,7 +2298,7 @@ void doImport() throws Exception { logger.debug(" Translating parent folder to \""+parentFolder.getName()+"\"("+parentFolder.getId()+")"); else parentFolder = this.importedModel.getAllFolders().get(result.getString("parent_folder_id")); - IDBImportCommand command = new DBImportElementFromIdCommand(this.importConnection, this.importedModel, null, parentFolder, result.getString("element_id"), result.getInt("element_version"), DBImportMode.get(getOptionValue()), false); + IDBImportCommand command = new DBImportElementFromIdCommand(this.importConnection, this.importedModel, mergedModelId, null, parentFolder, result.getString("element_id"), result.getInt("element_version"), DBImportMode.get(getOptionValue()), false); if ( command.getException() != null ) throw command.getException(); command.execute(); @@ -2309,8 +2309,8 @@ void doImport() throws Exception { } // import relationships - setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing relationships from model \""+name+"\"."); - try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT relationship_id, relationship_version, parent_folder_id FROM "+this.selectedDatabase.getSchemaPrefix()+"relationships_in_model WHERE model_id = ? AND model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"relationships_in_model WHERE model_id = ?) ORDER BY pos", id, id) ) { + setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing relationships from model \""+mergedModelName+"\"."); + try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT relationship_id, relationship_version, parent_folder_id FROM "+this.selectedDatabase.getSchemaPrefix()+"relationships_in_model WHERE model_id = ? AND model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"relationships_in_model WHERE model_id = ?) ORDER BY pos", mergedModelId, mergedModelId) ) { while ( result.next() ) { // we check if the parent folder needs to be translated IFolder parentFolder = foldersConversionMap.get(result.getString("parent_folder_id")); @@ -2318,7 +2318,7 @@ void doImport() throws Exception { logger.debug(" Translating parent folder to \""+parentFolder.getName()+"\"("+parentFolder.getId()+")"); else parentFolder = this.importedModel.getAllFolders().get(result.getString("parent_folder_id")); - IDBImportCommand command = new DBImportRelationshipFromIdCommand(this.importConnection, this.importedModel, null, parentFolder, result.getString("relationship_id"), result.getInt("relationship_version"), DBImportMode.get(getOptionValue())); + IDBImportCommand command = new DBImportRelationshipFromIdCommand(this.importConnection, this.importedModel, null, mergedModelId, parentFolder, result.getString("relationship_id"), result.getInt("relationship_version"), DBImportMode.get(getOptionValue())); if ( command.getException() != null ) throw command.getException(); command.execute(); @@ -2328,7 +2328,7 @@ void doImport() throws Exception { } } - setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Resolving relationships from model \""+name+"\"."); + setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Resolving relationships from model \""+mergedModelName+"\"."); if ( (this.importedModel.getAllSourceRelationshipsToResolve().size() != 0) || (this.importedModel.getAllTargetRelationshipsToResolve().size() != 0) ) { DBResolveRelationshipsCommand resolveRelationshipsCommand = new DBResolveRelationshipsCommand(this.importedModel); resolveRelationshipsCommand.execute(); @@ -2338,8 +2338,8 @@ void doImport() throws Exception { } // import views - setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing views from model \""+name+"\"."); - try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT view_id, view_version, parent_folder_id FROM "+this.selectedDatabase.getSchemaPrefix()+"views_in_model WHERE model_id = ? AND model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"views_in_model WHERE model_id = ?) ORDER BY pos", id, id) ) { + setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Importing views from model \""+mergedModelName+"\"."); + try ( DBSelect result = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT view_id, view_version, parent_folder_id FROM "+this.selectedDatabase.getSchemaPrefix()+"views_in_model WHERE model_id = ? AND model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"views_in_model WHERE model_id = ?) ORDER BY pos", mergedModelId, mergedModelId) ) { while ( result.next() ) { // we check if the parent folder needs to be translated IFolder parentFolder = foldersConversionMap.get(result.getString("parent_folder_id")); @@ -2347,7 +2347,7 @@ void doImport() throws Exception { logger.debug(" Translating parent folder to \""+parentFolder.getName()+"\"("+parentFolder.getId()+")"); else parentFolder = this.importedModel.getAllFolders().get(result.getString("parent_folder_id")); - IDBImportCommand command = new DBImportViewFromIdCommand(this.importConnection, this.importedModel, parentFolder, result.getString("view_id"), result.getInt("view_version"), DBImportMode.get(getOptionValue()), true); + IDBImportCommand command = new DBImportViewFromIdCommand(this.importConnection, this.importedModel, mergedModelId, parentFolder, result.getString("view_id"), result.getInt("view_version"), DBImportMode.get(getOptionValue()), true); if ( command.getException() != null ) throw command.getException(); command.execute(); @@ -2357,7 +2357,7 @@ void doImport() throws Exception { } } - setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Resolving connections from model \""+name+"\"."); + setMessage("("+done+"/"+this.tblComponents.getSelectionCount()+") Resolving connections from model \""+mergedModelName+"\"."); if ( (this.importedModel.getAllSourceConnectionsToResolve().size() != 0) || (this.importedModel.getAllTargetConnectionsToResolve().size() != 0) ) { DBResolveConnectionsCommand resolveConnectionsCommand = new DBResolveConnectionsCommand(this.importedModel); resolveConnectionsCommand.execute(); @@ -2366,8 +2366,8 @@ void doImport() throws Exception { undoRedoCommands.add(resolveConnectionsCommand); } } else if ( this.radioOptionElement.getSelection() ) { - setMessage("("+(++done)+"/"+this.tblComponents.getSelectionCount()+") Importing element \""+name+"\"."); - IDBImportCommand command = new DBImportElementFromIdCommand(this.importConnection, this.importedModel, this.selectedView, this.selectedFolder, id, 0, DBImportMode.get(getOptionValue()), true); + setMessage("("+(++done)+"/"+this.tblComponents.getSelectionCount()+") Importing element \""+mergedModelName+"\"."); + IDBImportCommand command = new DBImportElementFromIdCommand(this.importConnection, this.importedModel, mergedModelId, this.selectedView, this.selectedFolder, mergedModelId, 0, DBImportMode.get(getOptionValue()), true); if ( command.getException() != null ) throw command.getException(); command.execute(); @@ -2377,8 +2377,8 @@ void doImport() throws Exception { } else if ( this.radioOptionView.getSelection() ) { - setMessage("("+(++done)+"/"+this.tblComponents.getSelectionCount()+") Importing view \""+name+"\"."); - IDBImportCommand command = new DBImportViewFromIdCommand(this.importConnection, this.importedModel, this.selectedFolder, id, 0, DBImportMode.get(getOptionValue()), true); + setMessage("("+(++done)+"/"+this.tblComponents.getSelectionCount()+") Importing view \""+mergedModelName+"\"."); + IDBImportCommand command = new DBImportViewFromIdCommand(this.importConnection, this.importedModel, mergedModelId, this.selectedFolder, mergedModelId, 0, DBImportMode.get(getOptionValue()), true); if ( command.getException() != null ) throw command.getException(); command.execute(); diff --git a/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java b/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java index 68743550..f609e7a9 100644 --- a/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java +++ b/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java @@ -899,7 +899,7 @@ private void upgradeDatabase(int version) throws Exception { try ( DBSelect result = new DBSelect(this.databaseEntry.getName(), this.connection, "SELECT id, version FROM "+this.schemaPrefix+"views") ) { while ( result.next() ) { IDiagramModel view; - DBImportViewFromIdCommand command = new DBImportViewFromIdCommand(importConnection, tempModel, null, result.getString("id"), result.getInt("version"), DBImportMode.templateMode, false); + DBImportViewFromIdCommand command = new DBImportViewFromIdCommand(importConnection, tempModel, null, null, result.getString("id"), result.getInt("version"), DBImportMode.templateMode, false); if ( command.canExecute() ) command.execute(); if ( command.getException() != null ) @@ -1117,7 +1117,7 @@ private void upgradeDatabase(int version) throws Exception { while ( result.next() ) { IDiagramModel view; - DBImportViewFromIdCommand command = new DBImportViewFromIdCommand(importConnection, tempModel, null, result.getString("id"), result.getInt("version"), DBImportMode.forceSharedMode, false); + DBImportViewFromIdCommand command = new DBImportViewFromIdCommand(importConnection, tempModel, null, null, result.getString("id"), result.getInt("version"), DBImportMode.forceSharedMode, false); if ( command.canExecute() ) command.execute(); if ( command.getException() != null ) @@ -1280,8 +1280,8 @@ private void upgradeDatabase(int version) throws Exception { } // add profile column in elements and relationships tables - addColumn(this.schemaPrefix+"elements", "profile", objectIDColumn.getType()); - addColumn(this.schemaPrefix+"relationships", "profile", objectIDColumn.getType()); + addColumn(this.schemaPrefix+"elements", "profile", objectIDColumn.getFullType()); + addColumn(this.schemaPrefix+"relationships", "profile", objectIDColumn.getFullType()); dbVersion = 490; } diff --git a/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java b/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java index 7867475f..1434b33a 100644 --- a/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java +++ b/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java @@ -896,7 +896,7 @@ public boolean importViewsObjects(DBArchimateModel model, IDiagramModel view) th // we check that the element already exists. If not, we import it (this may be the case during an individual view import. IArchimateElement element = model.getAllElements().get(this.currentResultSetViewsObjects.getString("element_id")); if ( element == null ) { - DBImportElementFromIdCommand command = new DBImportElementFromIdCommand(this, model, null, null, this.currentResultSetViewsObjects.getString("element_id"), 0, DBImportMode.templateMode, true); + DBImportElementFromIdCommand command = new DBImportElementFromIdCommand(this, model, null, null, null, this.currentResultSetViewsObjects.getString("element_id"), 0, DBImportMode.templateMode, true); ((CommandStack)model.getAdapter(CommandStack.class)).execute(command); element = command.getImported(); @@ -1010,7 +1010,7 @@ public boolean importViewsConnections(DBArchimateModel model) throws Exception { // we check that the relationship already exists. If not, we import it (this may be the case during an individual view import. IArchimateRelationship relationship = model.getAllRelationships().get(this.currentResultSetViewsConnections.getString("relationship_id")); if ( relationship == null ) { - DBImportRelationshipFromIdCommand command = new DBImportRelationshipFromIdCommand(this, model, null, null, this.currentResultSetViewsConnections.getString("relationship_id"), 0, DBImportMode.templateMode); + DBImportRelationshipFromIdCommand command = new DBImportRelationshipFromIdCommand(this, model, null, null, null, this.currentResultSetViewsConnections.getString("relationship_id"), 0, DBImportMode.templateMode); ((CommandStack)model.getAdapter(CommandStack.class)).execute(command); relationship = command.getImported(); @@ -1371,14 +1371,18 @@ public void close() throws SQLException { /** * Gets the latest folder where the elementId was in the model - * @param model + * @param model + * @param mergedModelId * @param clazz * @param id * @return * @throws Exception */ - public IFolder getLastKnownFolder(DBArchimateModel model, String clazz, String id) throws Exception { + public IFolder getLastKnownFolder(DBArchimateModel model, String mergedModelId, String clazz, String id) throws Exception { IFolder parentFolder = null; + String searchedModelId = mergedModelId; + if ( searchedModelId == null ) + searchedModelId = model.getId(); if ( !model.isLatestVersionImported() ) { String table; @@ -1396,9 +1400,9 @@ public IFolder getLastKnownFolder(DBArchimateModel model, String clazz, String i try ( DBSelect result = new DBSelect(this.databaseEntry.getName(), this.connection,"SELECT parent_folder_id, model_version" +" FROM "+table +" WHERE model_id = ? AND "+column+" = ? AND model_version = (SELECT MAX(model_version) FROM "+table+" WHERE model_id = ? AND "+column+" = ?)" - , model.getId() + , searchedModelId , id - , model.getId() + , searchedModelId , id ) ) { if ( result.next() ) diff --git a/sources/src/org/archicontribs/database/data/DBImportMode.java b/sources/src/org/archicontribs/database/data/DBImportMode.java index 0dd7b3b8..9dd7bfb8 100644 --- a/sources/src/org/archicontribs/database/data/DBImportMode.java +++ b/sources/src/org/archicontribs/database/data/DBImportMode.java @@ -67,6 +67,10 @@ public static DBImportMode get(int value) { } } + /** + * @param properties Array with Archimate component properties + * @return true if import should be done in copy mode, false if import should be done in share mode + */ public boolean shouldCreateCopy(ArrayList properties) { switch ( this.value ) { case DBImportMode.forceSharedModeValue: @@ -81,12 +85,12 @@ public boolean shouldCreateCopy(ArrayList properties) { if ( properties != null ) { for ( DBProperty prop: properties) { if ( DBPlugin.areEqual(prop.getKey(), "template") && DBPlugin.areEqual(prop.getValue(), "copy") ) { - logger.debug(" Import in template mode : the \"template\" property requires the copy mode."); + logger.debug(" Import in copy mode (as specified by the \"template\" property)"); return true; } } } - logger.debug(" Import in template mode : the \"template\" property does not exist or does not require the copy mode."); + logger.debug(" Import in shared mode (no \"template\" property or value different from \"copy\")"); return false; default: diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java index 01b04a9a..4152f391 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java @@ -64,7 +64,7 @@ public class DBImportElementFromIdCommand extends Command implements IDBImportCo // new values that are retrieved from the database private HashMap newValues = null; - private IFolder newFolder = null; + private IFolder newParentFolder = null; // old values that need to be retain to allow undo private DBVersion oldInitialVersion; @@ -74,7 +74,7 @@ public class DBImportElementFromIdCommand extends Command implements IDBImportCo private String oldDocumentation = null; private String oldName = null; private String oldType = null; - private IFolder oldFolder = null; + private IFolder oldParentFolder = null; private ArrayList oldProperties = null; private ArrayList oldFeatures = null; @@ -83,14 +83,15 @@ public class DBImportElementFromIdCommand extends Command implements IDBImportCo * Imports an element into the model
* @param importConnection connection to the database * @param archimateModel model into which the element will be imported + * @param mergedModelId ID of the model merged in the actual model, to search for its parent folder * @param archimateDiagramModel if a view is provided, then an ArchimateObject will be automatically created - * @param folder if a folder is provided, the element will be created inside this folder. Else, we'll check in the database if the view has already been part of this model in order to import it in the same folder. + * @param parentFolder if a folder is provided, the element will be created inside this parent folder. Else, we'll check in the database if the element has already been part of this model in order to import it in the same parent folder. * @param idToImport id of the element to import * @param versionToImport version of the element to import (0 if the latest version should be imported) * @param importMode specifies if the element must be copied or shared * @param mustImportRelationships true if the relationships to and from the newly created element must be imported as well */ - public DBImportElementFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, IArchimateDiagramModel archimateDiagramModel, IFolder folder, String idToImport, int versionToImport, DBImportMode importMode, boolean mustImportRelationships) { + public DBImportElementFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String mergedModelId, IArchimateDiagramModel archimateDiagramModel, IFolder parentFolder, String idToImport, int versionToImport, DBImportMode importMode, boolean mustImportRelationships) { this.model = archimateModel; this.view = archimateDiagramModel; this.id = idToImport; @@ -112,10 +113,10 @@ public DBImportElementFromIdCommand(DBDatabaseImportConnection importConnection, this.newValues.put("name", (String)this.newValues.get("name") + DBPlugin.INSTANCE.getPreferenceStore().getString("copySuffix")); } - if ( (folder != null) && (archimateModel.getDBMetadata(folder).getRootFolderType().intValue() == DBMetadata.getDefaultFolderType((String)this.newValues.get("class"))) ) - this.newFolder = folder; + if ( (parentFolder != null) && (archimateModel.getDBMetadata(parentFolder).getRootFolderType().intValue() == DBMetadata.getDefaultFolderType((String)this.newValues.get("class"))) ) + this.newParentFolder = parentFolder; else - this.newFolder = importConnection.getLastKnownFolder(this.model, "IArchimateElement", this.id); + this.newParentFolder = importConnection.getLastKnownFolder(this.model, mergedModelId, "IArchimateElement", this.id); if ( this.mustImportTheRelationships ) { if ( logger.isDebugEnabled() ) logger.debug(" Checking if we must import relationships"); @@ -134,7 +135,7 @@ public DBImportElementFromIdCommand(DBDatabaseImportConnection importConnection, // we import only relationships that are not present in the model and, on the opposite, if the source and target do exist in the model if ( (relationship == null) && (DBPlugin.areEqual(resultRelationship.getString("source_id"), idToImport) || source != null) && (DBPlugin.areEqual(resultRelationship.getString("target_id"), idToImport) || target != null) ) { - IDBImportCommand command = new DBImportRelationshipFromIdCommand(importConnection, this.model, this.view, null, resultRelationship.getString("id"), 0, importMode); + IDBImportCommand command = new DBImportRelationshipFromIdCommand(importConnection, this.model, this.view, mergedModelId, null, resultRelationship.getString("id"), 0, importMode); if ( command.getException() == null ) this.importRelationshipCommands.add(command); else @@ -201,7 +202,7 @@ public void execute() { this.oldFeatures.add(new DBProperty(feature.getName(), feature.getValue())); } - this.oldFolder = metadata.getParentFolder(); + this.oldParentFolder = metadata.getParentFolder(); this.isNew = false; } @@ -232,12 +233,12 @@ public void execute() { } } - if ( this.newFolder == null ) { - if ( this.oldFolder == null) + if ( this.newParentFolder == null ) { + if ( this.oldParentFolder == null) metadata.setParentFolder(this.model.getDefaultFolderForObject(this.importedElement)); // else we keep the existing folder } else - metadata.setParentFolder(this.newFolder); + metadata.setParentFolder(this.newParentFolder); if ( this.view != null && metadata.findConnectables(this.view).isEmpty() ) { this.createdViewObject = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(this.importedElement); @@ -304,7 +305,7 @@ public void undo() { metadata.setDocumentation(this.oldDocumentation); metadata.setType(this.oldType); - metadata.setParentFolder(this.oldFolder); + metadata.setParentFolder(this.oldParentFolder); this.importedElement.getProperties().clear(); for ( DBProperty oldProperty: this.oldProperties ) { diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportFolderFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportFolderFromIdCommand.java index 448f43bf..b3ddf9a0 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportFolderFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportFolderFromIdCommand.java @@ -48,7 +48,7 @@ public class DBImportFolderFromIdCommand extends Command implements IDBImportCom // new values that are retrieved from the database private HashMap newValues = null; - private IFolder newFolder = null; + private IFolder newParentFolder = null; // old values that need to be retain to allow undo private DBVersion oldInitialVersion; @@ -59,7 +59,7 @@ public class DBImportFolderFromIdCommand extends Command implements IDBImportCom private String oldName = null; private FolderType oldFolderType = null; //private Integer oldRootFolderType = null; - private IFolder oldFolder = null; + private IFolder oldParentFolder = null; private ArrayList oldProperties = null; private ArrayList oldFeatures = null; @@ -67,12 +67,13 @@ public class DBImportFolderFromIdCommand extends Command implements IDBImportCom * Imports a folder into the model
* @param importConnection connection to the database * @param archimateModel model into which the folder will be imported - * @param folder if a folder is provided, the folder will be created inside this folder. Else, we'll check in the database if the view has already been part of this model in order to import it in the same folder. + * @param mergedModelId ID of the model merged in the actual model, to search for its parent folder + * @param parentFolder if a folder is provided, the folder will be created inside this parent folder. Else, we'll check in the database if the folder has already been part of this model in order to import it in the same parent folder. * @param idToImport id of the folder to import * @param versionToImport version of the folder to import * @param importMode specifies if the folder must be copied or shared */ - public DBImportFolderFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, IFolder folder, String idToImport, int versionToImport, DBImportMode importMode) { + public DBImportFolderFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String mergedModelId, IFolder parentFolder, String idToImport, int versionToImport, DBImportMode importMode) { this.model = archimateModel; this.id = idToImport; @@ -90,10 +91,10 @@ public DBImportFolderFromIdCommand(DBDatabaseImportConnection importConnection, this.newValues.put("name", (String)this.newValues.get("name") + DBPlugin.INSTANCE.getPreferenceStore().getString("copySuffix")); } - if ( (folder != null) && (archimateModel.getDBMetadata(folder).getRootFolderType() == (int)this.newValues.get("root_type")) ) - this.newFolder = folder; + if ( (parentFolder != null) && (archimateModel.getDBMetadata(parentFolder).getRootFolderType() == (int)this.newValues.get("root_type")) ) + this.newParentFolder = parentFolder; else - this.newFolder = importConnection.getLastKnownFolder(archimateModel, "IFolder", this.id); + this.newParentFolder = importConnection.getLastKnownFolder(archimateModel, mergedModelId, "IFolder", this.id); if ( DBPlugin.isEmpty((String)this.newValues.get("name")) ) { setLabel("import folder"); @@ -148,7 +149,7 @@ public void execute() { this.oldFeatures.add(new DBProperty(feature.getName(), feature.getValue())); } - this.oldFolder = dbMetadata.getParentFolder(); + this.oldParentFolder = dbMetadata.getParentFolder(); this.isNew = false; } @@ -180,10 +181,10 @@ public void execute() { } } - if ( this.newFolder == null ) + if ( this.newParentFolder == null ) dbMetadata.setParentFolder(this.model.getDefaultFolderForObject(this.importedFolder)); else - dbMetadata.setParentFolder(this.newFolder); + dbMetadata.setParentFolder(this.newParentFolder); if ( this.isNew ) this.model.countObject(this.importedFolder, false); @@ -222,7 +223,7 @@ public void undo() { dbMetadata.setFolderType(this.oldFolderType); //metadata.setRootFolderType(this.oldRootFolderType); - dbMetadata.setParentFolder(this.oldFolder); + dbMetadata.setParentFolder(this.oldParentFolder); this.importedFolder.getProperties().clear(); for ( DBProperty oldProperty: this.oldProperties ) { diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportRelationshipFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportRelationshipFromIdCommand.java index 681a793c..105630e4 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportRelationshipFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportRelationshipFromIdCommand.java @@ -58,7 +58,7 @@ public class DBImportRelationshipFromIdCommand extends Command implements IDBImp // new values that are retrieved from the database private HashMap newValues = null; - private IFolder newFolder = null; + private IFolder newParentFolder = null; // old values that need to be retain to allow undo private DBVersion oldInitialVersion; @@ -69,7 +69,7 @@ public class DBImportRelationshipFromIdCommand extends Command implements IDBImp private String oldName = null; private String oldStrength = null; private Integer oldAccessType = null; - private IFolder oldFolder = null; + private IFolder oldParentFolder = null; private IArchimateConcept oldSource = null; private IArchimateConcept oldTarget = null; private ArrayList oldProperties = null; @@ -79,13 +79,14 @@ public class DBImportRelationshipFromIdCommand extends Command implements IDBImp * Imports a relationship into the model
* @param importConnection connection to the database * @param archimateModel model into which the relationship will be imported + * @param mergedModelId ID of the model merged in the actual model, to search for its parent folder * @param archimateDiagramModel if a view is provided, then an ArchimateObject will be automatically created - * @param folder if a folder is provided, the relationship will be created inside this folder. Else, we'll check in the database if the view has already been part of this model in order to import it in the same folder. + * @param parentFolder if a folder is provided, the relationship will be created inside this parent folder. Else, we'll check in the database if the relationship has already been part of this model in order to import it in the same parent folder. * @param idToImport id of the relationship to import * @param versionToImport version of the relationship to import (0 if the latest found in the database should be imported) * @param importMode specifies if the relationship must be copied or shared */ - public DBImportRelationshipFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, IArchimateDiagramModel archimateDiagramModel, IFolder folder, String idToImport, int versionToImport, DBImportMode importMode) { + public DBImportRelationshipFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, IArchimateDiagramModel archimateDiagramModel, String mergedModelId, IFolder parentFolder, String idToImport, int versionToImport, DBImportMode importMode) { this.model = archimateModel; this.view = archimateDiagramModel; this.id = idToImport; @@ -109,10 +110,10 @@ public DBImportRelationshipFromIdCommand(DBDatabaseImportConnection importConnec this.newValues.put("name", (String)this.newValues.get("name") + DBPlugin.INSTANCE.getPreferenceStore().getString("copySuffix")); } - if ( (folder != null) && (archimateModel.getDBMetadata(folder).getRootFolderType() == DBMetadata.getDefaultFolderType((String)this.newValues.get("class"))) ) - this.newFolder = folder; + if ( (parentFolder != null) && (archimateModel.getDBMetadata(parentFolder).getRootFolderType() == DBMetadata.getDefaultFolderType((String)this.newValues.get("class"))) ) + this.newParentFolder = parentFolder; else - this.newFolder = importConnection.getLastKnownFolder(this.model, "IArchimateRelationship", this.id); + this.newParentFolder = importConnection.getLastKnownFolder(this.model, mergedModelId, "IArchimateRelationship", this.id); if ( DBPlugin.isEmpty((String)this.newValues.get("name")) ) { setLabel("import relationship"); @@ -170,7 +171,7 @@ public void execute() { this.oldFeatures.add(new DBProperty(feature.getName(), feature.getValue())); } - this.oldFolder = dbMetadata.getParentFolder(); + this.oldParentFolder = dbMetadata.getParentFolder(); this.isNew = false; } @@ -258,10 +259,10 @@ public void execute() { } } - if ( this.newFolder == null ) + if ( this.newParentFolder == null ) dbMetadata.setParentFolder(this.model.getDefaultFolderForObject(this.importedRelationship)); else - dbMetadata.setParentFolder(this.newFolder); + dbMetadata.setParentFolder(this.newParentFolder); if ( this.isNew ) this.model.countObject(this.importedRelationship, false); @@ -315,7 +316,7 @@ public void undo() { dbMetadata.setRelationshipSource(this.oldSource); dbMetadata.setRelationshipTarget(this.oldTarget); - dbMetadata.setParentFolder(this.oldFolder); + dbMetadata.setParentFolder(this.oldParentFolder); this.importedRelationship.getProperties().clear(); for ( DBProperty oldProperty: this.oldProperties ) { diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportViewConnectionFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportViewConnectionFromIdCommand.java index 351b052d..507cf201 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportViewConnectionFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportViewConnectionFromIdCommand.java @@ -84,12 +84,13 @@ public class DBImportViewConnectionFromIdCommand extends CompoundCommand impleme * Imports a view connection into the model
* @param importConnection connection to the database * @param archimateModel model into which the view connection will be imported + * @param mergedModelId ID of the model merged in the actual model, to search for its parent folder * @param idToImport id of the view connection to import * @param versionToImport version of the view connection to import (0 if the latest version should be imported) * @param mustCopy true if a copy must be imported (i.e. if a new id must be generated) or false if the view object should be its original id * @param importMode specifies if the view must be copied or shared */ - public DBImportViewConnectionFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String idToImport, int versionToImport, boolean mustCopy, DBImportMode importMode) { + public DBImportViewConnectionFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String mergedModelId, String idToImport, int versionToImport, boolean mustCopy, DBImportMode importMode) { this.model = archimateModel; this.id = idToImport; this.mustCreateCopy = mustCopy; @@ -114,7 +115,7 @@ public DBImportViewConnectionFromIdCommand(DBDatabaseImportConnection importConn // if the object references a relationship, then we import it if ( this.newValues.get("relationship_id") != null ) { - this.importRelationshipCommand = new DBImportRelationshipFromIdCommand(importConnection, archimateModel, null, null, (String)this.newValues.get("relationship_id"), 0, importMode); + this.importRelationshipCommand = new DBImportRelationshipFromIdCommand(importConnection, archimateModel, null, mergedModelId, null, (String)this.newValues.get("relationship_id"), 0, importMode); if ( this.importRelationshipCommand.getException() != null ) throw this.importRelationshipCommand.getException(); } diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportViewFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportViewFromIdCommand.java index 398f0285..1263366f 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportViewFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportViewFromIdCommand.java @@ -57,7 +57,7 @@ public class DBImportViewFromIdCommand extends Command implements IDBImportComma // new values that are retrieved from the database private HashMap newValues = null; - private IFolder newFolder = null; + private IFolder newParentFolder = null; // old values that need to be retain to allow undo private DBVersion oldInitialVersion; @@ -69,7 +69,7 @@ public class DBImportViewFromIdCommand extends Command implements IDBImportComma private Integer oldConnectionRouterType = null; private String oldViewpoint = null; private Integer oldBackground = null; - private IFolder oldFolder = null; + private IFolder oldParentFolder = null; private ArrayList oldProperties = null; private ArrayList oldFeatures = null; @@ -78,15 +78,16 @@ public class DBImportViewFromIdCommand extends Command implements IDBImportComma * Imports a view into the model
* @param importConnection connection to the database * @param archimateModel model into which the view will be imported + * @param mergedModelId ID of the model merged in the actual model, to search for its parent folder * @param view if a view is provided, then an ArchimateObject will be automatically created - * @param folder if a folder is provided, the view will be created inside this folder. Else, we'll check in the database if the view has already been part of this model in order to import it in the same folder. + * @param parentFolder if a folder is provided, the view will be created inside this parent folder. Else, we'll check in the database if the view has already been part of this model in order to import it in the same parent folder. * @param idToImport id of the view to import * @param versionToImport version of the view to import * @param importMode mode of the import (template, shared or copy mode) * @param mustImportContent true if the view content must be imported as well */ - public DBImportViewFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, IFolder folder, String idToImport, int versionToImport, DBImportMode importMode, boolean mustImportContent) { + public DBImportViewFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String mergedModelId, IFolder parentFolder, String idToImport, int versionToImport, DBImportMode importMode, boolean mustImportContent) { this.model = archimateModel; this.id = idToImport; this.mustImportViewContent = mustImportContent; @@ -109,10 +110,10 @@ public DBImportViewFromIdCommand(DBDatabaseImportConnection importConnection, DB this.newValues.put("name", (String)this.newValues.get("name") + DBPlugin.INSTANCE.getPreferenceStore().getString("copySuffix")); } - if ( (folder != null) && (archimateModel.getDBMetadata(folder).getRootFolderType() == DBMetadata.getDefaultFolderType((String)this.newValues.get("class"))) ) - this.newFolder = folder; + if ( (parentFolder != null) && (archimateModel.getDBMetadata(parentFolder).getRootFolderType() == DBMetadata.getDefaultFolderType((String)this.newValues.get("class"))) ) + this.newParentFolder = parentFolder; else - this.newFolder = importConnection.getLastKnownFolder(this.model, "IDiagramModel", this.id); + this.newParentFolder = importConnection.getLastKnownFolder(this.model, mergedModelId, "IDiagramModel", this.id); if ( this.mustImportViewContent ) { // we import the objects and create the corresponding elements if they do not exist yet @@ -121,7 +122,7 @@ public DBImportViewFromIdCommand(DBDatabaseImportConnection importConnection, DB ? new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT object_id, object_version, pos FROM "+importConnection.getSchemaPrefix()+"views_objects_in_view WHERE view_id = ? AND view_version = (SELECT MAX(view_version) FROM "+importConnection.getSchemaPrefix()+"views_objects_in_view WHERE view_id = ?) ORDER BY pos", idToImport, idToImport) : new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT DISTINCT object_id, object_version, pos FROM "+importConnection.getSchemaPrefix()+"views_objects_in_view WHERE view_id = ? AND view_version = ? ORDER BY pos", idToImport, versionToImport) ) { while ( result.next() ) { - DBImportViewObjectFromIdCommand command = new DBImportViewObjectFromIdCommand(importConnection, archimateModel, result.getString("object_id"), (versionToImport == 0) ? 0 : result.getInt("object_version"), this.mustCreateCopy, importMode); + DBImportViewObjectFromIdCommand command = new DBImportViewObjectFromIdCommand(importConnection, archimateModel, mergedModelId, result.getString("object_id"), (versionToImport == 0) ? 0 : result.getInt("object_version"), this.mustCreateCopy, importMode); if ( command.getException() != null ) throw command.getException(); this.importViewContentCommands.add(command); @@ -134,7 +135,7 @@ public DBImportViewFromIdCommand(DBDatabaseImportConnection importConnection, DB ? new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT DISTINCT connection_id, connection_version, pos FROM "+importConnection.getSchemaPrefix()+"views_connections_in_view WHERE view_id = ? AND view_version = (SELECT MAX(view_version) FROM "+importConnection.getSchemaPrefix()+"views_connections_in_view WHERE view_id = ?) ORDER BY pos", idToImport, idToImport) : new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT DISTINCT connection_id, connection_version, pos FROM "+importConnection.getSchemaPrefix()+"views_connections_in_view WHERE view_id = ? AND view_version = ? ORDER BY pos", idToImport, versionToImport) ) { while ( result.next() ) { - DBImportViewConnectionFromIdCommand command = new DBImportViewConnectionFromIdCommand(importConnection, archimateModel, result.getString("connection_id"), (versionToImport == 0) ? 0 : result.getInt("connection_version"), this.mustCreateCopy, importMode); + DBImportViewConnectionFromIdCommand command = new DBImportViewConnectionFromIdCommand(importConnection, archimateModel, mergedModelId, result.getString("connection_id"), (versionToImport == 0) ? 0 : result.getInt("connection_version"), this.mustCreateCopy, importMode); if ( command.getException() != null ) throw command.getException(); this.importViewContentCommands.add(command); @@ -199,7 +200,7 @@ public void execute() { this.oldFeatures.add(new DBProperty(feature.getName(), feature.getValue())); } - this.oldFolder = dbMetadata.getParentFolder(); + this.oldParentFolder = dbMetadata.getParentFolder(); this.isNew = false; } @@ -231,10 +232,10 @@ public void execute() { } } - if ( this.newFolder == null ) + if ( this.newParentFolder == null ) metadata.setParentFolder(this.model.getDefaultFolderForObject(this.importedView)); else - metadata.setParentFolder(this.newFolder); + metadata.setParentFolder(this.newParentFolder); if ( this.isNew ) this.model.countObject(this.importedView, false); @@ -294,7 +295,7 @@ public void undo() { dbMetadata.setViewpoint(this.oldViewpoint); dbMetadata.setBackground(this.oldBackground); - dbMetadata.setParentFolder(this.oldFolder); + dbMetadata.setParentFolder(this.oldParentFolder); this.importedView.getProperties().clear(); ((IProperties)this.importedView).getProperties().clear(); diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportViewObjectFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportViewObjectFromIdCommand.java index ced5c9e4..8a8813c8 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportViewObjectFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportViewObjectFromIdCommand.java @@ -100,12 +100,13 @@ public class DBImportViewObjectFromIdCommand extends CompoundCommand implements * Imports a view object into the model
* @param importConnection connection to the database * @param archimateModel model into which the view object will be imported + * @param mergedModelId ID of the model merged in the actual model, to search for its parent folder * @param idToImport id of the view object to import * @param version version of the view object to import * @param mustCopy true if a copy must be imported (i.e. if a new id must be generated) or false if the view object should be its original id * @param importMode specifies the mode to be used to import missing elements and relationships */ - public DBImportViewObjectFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String idToImport, int version, boolean mustCopy, DBImportMode importMode) { + public DBImportViewObjectFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String mergedModelId, String idToImport, int version, boolean mustCopy, DBImportMode importMode) { this.model = archimateModel; this.id = idToImport; this.mustCreateCopy = mustCopy; @@ -146,7 +147,7 @@ public DBImportViewObjectFromIdCommand(DBDatabaseImportConnection importConnecti // if the object references an element, then we import it if ( this.newValues.get("element_id") != null ) { - this.importElementCommand = new DBImportElementFromIdCommand(importConnection, archimateModel, null, null, (String)this.newValues.get("element_id"), 0, importMode, true); + this.importElementCommand = new DBImportElementFromIdCommand(importConnection, archimateModel, mergedModelId, null, null, (String)this.newValues.get("element_id"), 0, importMode, true); if ( this.importElementCommand.getException() != null ) throw this.importElementCommand.getException(); } @@ -155,7 +156,7 @@ public DBImportViewObjectFromIdCommand(DBDatabaseImportConnection importConnecti if ( (this.newValues.get("diagram_ref_id") != null) && !this.newValues.get("diagram_ref_id").equals(this.newValues.get("element_id")) && (archimateModel.getAllViews().get(this.model.getNewViewId((String)this.newValues.get("diagram_ref_id"))) == null) ) { if ( !importConnection.isAlreadyImported((String)this.newValues.get("diagram_ref_id")) ) { importConnection.declareAsImported((String)this.newValues.get("diagram_ref_id")); - DBImportViewFromIdCommand importLinkedViewCommand = new DBImportViewFromIdCommand(importConnection, archimateModel, null, (String)this.newValues.get("diagram_ref_id"), 0, importMode, true); + DBImportViewFromIdCommand importLinkedViewCommand = new DBImportViewFromIdCommand(importConnection, archimateModel, mergedModelId, null, (String)this.newValues.get("diagram_ref_id"), 0, importMode, true); if ( importLinkedViewCommand.getException() != null ) throw importLinkedViewCommand.getException(); this.importLinkedViewCommands.add(importLinkedViewCommand);