diff --git a/komodo-importer/src/main/resources/org/komodo/importer/messages.properties b/komodo-importer/src/main/resources/org/komodo/importer/messages.properties index 1dbf9d23..c78b15b8 100644 --- a/komodo-importer/src/main/resources/org/komodo/importer/messages.properties +++ b/komodo-importer/src/main/resources/org/komodo/importer/messages.properties @@ -5,7 +5,7 @@ IMPORTER.errorFileNotReadableMsg = The specified File "{0}" is not readable IMPORTER.errorEmptyMsg = The supplied content string is empty IMPORTER.ddlDoesNotSupportVDB = The DDL importer does not support importing vdb files. Use the Vdb importer IMPORTER.vdbOnlySupportsVDB = The Vdb importer only support importing of vdb files. -IMPORTER.nodeExistsReturn = The importer will not continue as node exists and HANDLE_EXISTING_NODE option = 'RETURN' +IMPORTER.nodeExistsReturn = The importer will not import "{0}". The node already exists, and HANDLE_EXISTING_NODE option = 'RETURN' IMPORTER.nodeExistCreateNew = The importer has found a node named {0} already exists. HANDLE_EXISTING_NODE option = 'CREATE_NEW' so will use the new name {1} IMPORTER.noNameFailure = No name has been provided. IMPORTER.newNameFailure = The importer failed to determine a new name from the original name {0} diff --git a/komodo-relational/src/main/java/org/komodo/relational/dataservice/internal/DataserviceConveyor.java b/komodo-relational/src/main/java/org/komodo/relational/dataservice/internal/DataserviceConveyor.java index 641cbf3e..c3b31711 100644 --- a/komodo-relational/src/main/java/org/komodo/relational/dataservice/internal/DataserviceConveyor.java +++ b/komodo-relational/src/main/java/org/komodo/relational/dataservice/internal/DataserviceConveyor.java @@ -120,7 +120,7 @@ protected boolean handleExistingNode(UnitOfWork transaction, KomodoObject parent // RETURN - Return 'false' - do not create a node. Log an error message case RETURN: importMessages.addErrorMessage(org.komodo.importer.Messages.getString( - org.komodo.importer.Messages.IMPORTER.nodeExistsReturn)); + org.komodo.importer.Messages.IMPORTER.nodeExistsReturn, dsName)); return false; // CREATE_NEW - Return 'true' - will create a new data service with new unique name. Log a progress message. case CREATE_NEW: diff --git a/komodo-relational/src/main/java/org/komodo/relational/importer/connection/ConnectionImporter.java b/komodo-relational/src/main/java/org/komodo/relational/importer/connection/ConnectionImporter.java index 7ddb8229..6e973912 100644 --- a/komodo-relational/src/main/java/org/komodo/relational/importer/connection/ConnectionImporter.java +++ b/komodo-relational/src/main/java/org/komodo/relational/importer/connection/ConnectionImporter.java @@ -85,7 +85,7 @@ protected void executeImport( UnitOfWork transaction, switch ( optionValue ) { case RETURN: case CREATE_NEW: - importMessages.addErrorMessage( Messages.getString( Messages.IMPORTER.nodeExistsReturn ) ); + importMessages.addErrorMessage( Messages.getString( Messages.IMPORTER.nodeExistsReturn, connection.getName() ) ); break; case OVERWRITE: shouldSequence = true; diff --git a/komodo-relational/src/main/java/org/komodo/relational/importer/vdb/VdbImporter.java b/komodo-relational/src/main/java/org/komodo/relational/importer/vdb/VdbImporter.java index 8c66138d..983ffde3 100644 --- a/komodo-relational/src/main/java/org/komodo/relational/importer/vdb/VdbImporter.java +++ b/komodo-relational/src/main/java/org/komodo/relational/importer/vdb/VdbImporter.java @@ -99,7 +99,7 @@ protected boolean handleExistingNode(UnitOfWork transaction, switch (exNodeOption) { // RETURN - Return 'false' - do not create a node. Log an error message case RETURN: - importMessages.addErrorMessage(Messages.getString(Messages.IMPORTER.nodeExistsReturn)); + importMessages.addErrorMessage(Messages.getString(Messages.IMPORTER.nodeExistsReturn, vdbName)); return false; // CREATE_NEW - Return 'true' - will create a new VDB with new unique name. Log a progress message. case CREATE_NEW: diff --git a/komodo-relational/src/main/java/org/komodo/relational/workspace/WorkspaceManager.java b/komodo-relational/src/main/java/org/komodo/relational/workspace/WorkspaceManager.java index 6c714fb6..b7a3b324 100644 --- a/komodo-relational/src/main/java/org/komodo/relational/workspace/WorkspaceManager.java +++ b/komodo-relational/src/main/java/org/komodo/relational/workspace/WorkspaceManager.java @@ -941,6 +941,23 @@ private void validateWorkspaceMember( final UnitOfWork uow, } } + /** + * + * @param transaction + * the transaction (cannot be null or have a state that is not + * {@link org.komodo.spi.repository.Repository.UnitOfWork.State#NOT_STARTED}) + * @param parent the parent of the imported vdb + * @param storageRef the reference to the destination within the storage + * @return the import messages (never null) + * @throws KException if error occurs + */ + public ImportMessages importArtifact(final UnitOfWork transaction, + final KomodoObject parent, + StorageReference storageRef) throws KException { + + return importArtifact(transaction,parent,storageRef,new ImportOptions()); + } + /** * * @param transaction @@ -948,11 +965,14 @@ private void validateWorkspaceMember( final UnitOfWork uow, * {@link org.komodo.spi.repository.Repository.UnitOfWork.State#NOT_STARTED}) * @param parent the parent of the imported vdb * @param storageRef the reference to the destination within the storage + * @param importOptions options for the import * @return the import messages (never null) * @throws KException if error occurs */ public ImportMessages importArtifact(final UnitOfWork transaction, - final KomodoObject parent, StorageReference storageRef) throws KException { + final KomodoObject parent, + StorageReference storageRef, + ImportOptions importOptions) throws KException { ArgCheck.isNotNull( transaction, "transaction" ); //$NON-NLS-1$ ArgCheck.isTrue( ( transaction.getState() == org.komodo.spi.repository.Repository.UnitOfWork.State.NOT_STARTED ), "transaction state is not NOT_STARTED" ); //$NON-NLS-1$ @@ -970,7 +990,6 @@ public ImportMessages importArtifact(final UnitOfWork transaction, connector = storageService.getConnector(storageRef.getParameters()); stream = connector.read(storageRef.getParameters()); - ImportOptions importOptions = new ImportOptions(); ImportMessages importMessages = new ImportMessages(); if (DocumentType.VDB_XML.equals(storageRef.getDocumentType())) { diff --git a/komodo-relational/src/test/java/org/komodo/relational/importer/vdb/TestTeiidVdbImporter.java b/komodo-relational/src/test/java/org/komodo/relational/importer/vdb/TestTeiidVdbImporter.java index 12aac455..e123567b 100644 --- a/komodo-relational/src/test/java/org/komodo/relational/importer/vdb/TestTeiidVdbImporter.java +++ b/komodo-relational/src/test/java/org/komodo/relational/importer/vdb/TestTeiidVdbImporter.java @@ -442,7 +442,7 @@ public void testBasicVdbImportCannotCreateVdb() throws Exception { // Error messages - expect error that the node already exists List errorMessages = importMessages.getErrorMessages(); assertEquals(1, errorMessages.size()); - assertEquals(Messages.getString(Messages.IMPORTER.nodeExistsReturn), errorMessages.get(0)); + assertEquals(Messages.getString(Messages.IMPORTER.nodeExistsReturn, TestUtilities.TWEET_EXAMPLE_VDB_NAME), errorMessages.get(0)); } @Test diff --git a/komodo-spi/src/main/java/org/komodo/spi/storage/StorageConnector.java b/komodo-spi/src/main/java/org/komodo/spi/storage/StorageConnector.java index 36176a11..a6b9bee9 100644 --- a/komodo-spi/src/main/java/org/komodo/spi/storage/StorageConnector.java +++ b/komodo-spi/src/main/java/org/komodo/spi/storage/StorageConnector.java @@ -92,6 +92,11 @@ public boolean isEncoded() { */ String DOWNLOADABLE_PATH_PROPERTY = "downloadable-path-property"; + /** + * Parameter to specify overwrite option for imports + */ + String IMPORT_OVERWRITE_PROPERTY = "import-overwrite-property"; + /** * @return the id of the connector */ diff --git a/server/komodo-rest/src/main/java/org/komodo/rest/relational/RelationalMessages.java b/server/komodo-rest/src/main/java/org/komodo/rest/relational/RelationalMessages.java index 20d03792..6767ed63 100644 --- a/server/komodo-rest/src/main/java/org/komodo/rest/relational/RelationalMessages.java +++ b/server/komodo-rest/src/main/java/org/komodo/rest/relational/RelationalMessages.java @@ -121,6 +121,11 @@ public enum Info { */ DRIVER_SUCCESSFULLY_UNDEPLOYED, + /** + * An import export service import success message + */ + IMPORT_EXPORT_SERVICE_IMPORT_SUCCESS_MESSAGE, + /** * VDB undeployment request sent but not yet undeployed */ @@ -1182,6 +1187,11 @@ public enum Error { */ IMPORT_EXPORT_SERVICE_IMPORT_ERROR, + /** + * An import export service import artifact error + */ + IMPORT_EXPORT_SERVICE_IMPORT_ARTIFACT_ERROR, + /** * An import export service storage types retrieval error */ diff --git a/server/komodo-rest/src/main/java/org/komodo/rest/relational/json/ImportExportStatusSerializer.java b/server/komodo-rest/src/main/java/org/komodo/rest/relational/json/ImportExportStatusSerializer.java index bf7e8b88..407a59ad 100644 --- a/server/komodo-rest/src/main/java/org/komodo/rest/relational/json/ImportExportStatusSerializer.java +++ b/server/komodo-rest/src/main/java/org/komodo/rest/relational/json/ImportExportStatusSerializer.java @@ -62,6 +62,9 @@ else if (name.equals(ImportExportStatus.DOWNLOADABLE_LABEL)) { else if (name.equals(ImportExportStatus.CONTENT_LABEL)) { status.setContent(in.nextString()); } + else if (name.equals(ImportExportStatus.MESSAGE_LABEL)) { + status.setMessage(in.nextString()); + } else if (name.equals(ImportExportStatus.DOWNLOADABLE_SIZE_LABEL)) { status.setDownloadableSize(in.nextLong()); } @@ -101,6 +104,9 @@ public void write( final JsonWriter out, out.name(ImportExportStatus.CONTENT_LABEL); out.value(value.getContent()); + out.name(ImportExportStatus.MESSAGE_LABEL); + out.value(value.getMessage()); + out.name(ImportExportStatus.DOWNLOADABLE_SIZE_LABEL); out.value(value.getDownloadableSize()); diff --git a/server/komodo-rest/src/main/java/org/komodo/rest/relational/response/ImportExportStatus.java b/server/komodo-rest/src/main/java/org/komodo/rest/relational/response/ImportExportStatus.java index 8e89e5e7..b69f386b 100644 --- a/server/komodo-rest/src/main/java/org/komodo/rest/relational/response/ImportExportStatus.java +++ b/server/komodo-rest/src/main/java/org/komodo/rest/relational/response/ImportExportStatus.java @@ -44,13 +44,18 @@ public class ImportExportStatus implements KRestEntity { /** * Label for the size of the downloadable */ - public static final String DOWNLOADABLE_SIZE_LABEL = "downloadableSize"; + public static final String DOWNLOADABLE_SIZE_LABEL = "downloadableSize"; //$NON-NLS-1$ /** * Label for the content */ public static final String CONTENT_LABEL = "content"; //$NON-NLS-1$ + /** + * Label for the message + */ + public static final String MESSAGE_LABEL = "message"; //$NON-NLS-1$ + /** * Label for the success flag */ @@ -64,6 +69,8 @@ public class ImportExportStatus implements KRestEntity { private String content; + private String message; + private boolean success; private long downloadableSize; @@ -106,6 +113,20 @@ public void setContent(String content) { this.content = content; } + /** + * @return message if provided or null + */ + public String getMessage() { + return message; + } + + /** + * @param message the message + */ + public void setMessage(String message) { + this.message = message; + } + /** * @return success */ diff --git a/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoDataserviceService.java b/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoDataserviceService.java index b953845b..44577827 100644 --- a/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoDataserviceService.java +++ b/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoDataserviceService.java @@ -21,6 +21,7 @@ */ package org.komodo.rest.service; +import static org.komodo.rest.Messages.Error.COMMIT_TIMEOUT; import static org.komodo.rest.relational.RelationalMessages.Error.DATASERVICE_SERVICE_CREATE_DATASERVICE_ERROR; import static org.komodo.rest.relational.RelationalMessages.Error.DATASERVICE_SERVICE_DELETE_DATASERVICE_ERROR; import static org.komodo.rest.relational.RelationalMessages.Error.DATASERVICE_SERVICE_FIND_SOURCE_VDB_ERROR; @@ -43,6 +44,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.TimeUnit; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -74,9 +76,11 @@ import org.komodo.relational.vdb.Vdb; import org.komodo.relational.workspace.WorkspaceManager; import org.komodo.repository.ObjectImpl; +import org.komodo.repository.SynchronousCallback; import org.komodo.rest.KomodoRestException; import org.komodo.rest.KomodoRestV1Application.V1Constants; import org.komodo.rest.KomodoService; +import org.komodo.rest.Messages; import org.komodo.rest.relational.KomodoProperties; import org.komodo.rest.relational.RelationalMessages; import org.komodo.rest.relational.connection.RestConnection; @@ -518,30 +522,112 @@ public Response cloneDataservice( final @Context HttpHeaders headers, return createErrorResponseWithForbidden(mediaTypes, RelationalMessages.Error.DATASERVICE_SERVICE_CLONE_SAME_NAME_ERROR, newDataserviceName); } - UnitOfWork uow = null; + UnitOfWork uow1 = null; + UnitOfWork uow2 = null; try { - uow = createTransaction(principal, "cloneDataservice", false ); //$NON-NLS-1$ + uow1 = createTransaction(principal, "cloneDataservice", false ); //$NON-NLS-1$ // Error if the repo already contains a dataservice with the supplied name. - if ( getWorkspaceManager(uow).hasChild( uow, newDataserviceName ) ) { + if ( getWorkspaceManager(uow1).hasChild( uow1, newDataserviceName ) ) { return createErrorResponseWithForbidden(mediaTypes, RelationalMessages.Error.DATASERVICE_SERVICE_CLONE_ALREADY_EXISTS); } - // create new Dataservice - // must be an update - final KomodoObject kobject = getWorkspaceManager(uow).getChild( uow, dataserviceName, DataVirtLexicon.DataService.NODE_TYPE ); - final Dataservice oldDataservice = getWorkspaceManager(uow).resolve( uow, kobject, Dataservice.class ); - - final Dataservice dataservice = getWorkspaceManager(uow).createDataservice( uow, null, newDataserviceName); - oldDataservice.clone(uow, dataservice); + // get the source dataservice + final KomodoObject kobject = getWorkspaceManager(uow1).getChild( uow1, dataserviceName, DataVirtLexicon.DataService.NODE_TYPE ); + final Dataservice srcDataservice = getWorkspaceManager(uow1).resolve( uow1, kobject, Dataservice.class ); + // Get the service Vdb from the source dataservice + Vdb srcServiceVdb = srcDataservice.getServiceVdb(uow1); + + // Create the new dataservice by cloning the source dataservice + final Dataservice newDataservice = getWorkspaceManager(uow1).createDataservice( uow1, null, newDataserviceName); + newDataservice.setServiceVdb(uow1, null); + String tgtServiceVdbName = newDataserviceName+SERVICE_VDB_SUFFIX; + if(getWorkspaceManager(uow1).hasChild(uow1, tgtServiceVdbName, VdbLexicon.Vdb.VIRTUAL_DATABASE)) { + KomodoObject svcVdbObj = getWorkspaceManager(uow1).getChild(uow1, tgtServiceVdbName, VdbLexicon.Vdb.VIRTUAL_DATABASE); + svcVdbObj.remove(uow1); + } - final RestDataservice entity = entityFactory.create(dataservice, uriInfo.getBaseUri(), uow ); - final Response response = commit( uow, mediaTypes, entity ); + // Create a new service VDB for the target dataservice + KomodoObject tgtServiceVdbObj = getWorkspaceManager(uow1).createVdb(uow1, null, tgtServiceVdbName, tgtServiceVdbName); + // Set owner property on the service vdb + tgtServiceVdbObj.setProperty(uow1, DSB_PROP_OWNER, uow1.getUserName()); + Vdb tgtServiceVdb = Vdb.RESOLVER.resolve(uow1, tgtServiceVdbObj); + + // Copy source dataservice model info to the new target + Model[] sourceModels = srcServiceVdb.getModels(uow1); + for(Model sourceModel : sourceModels) { + if( sourceModel.getModelType(uow1) == Model.Type.VIRTUAL ) { + // Add to the ServiceVdb a virtual model for the View + Model viewModel = tgtServiceVdb.addModel(uow1, SERVICE_VDB_VIEW_MODEL); + viewModel.setModelType(uow1, Type.VIRTUAL); + + // Get source model DDL + byte[] ddlBytes = sourceModel.export(uow1, new Properties()); + String viewDdl = new String(ddlBytes); + + String srcViewName = dataserviceName+SERVICE_VDB_VIEW_SUFFIX; + String tgtViewName = newDataserviceName+SERVICE_VDB_VIEW_SUFFIX; + + viewDdl = viewDdl.replaceFirst(srcViewName, tgtViewName); + + // Set DDL on new View Model + viewModel.setModelDefinition(uow1, viewDdl); + } else if ( sourceModel.getModelType(uow1) == Model.Type.PHYSICAL ) { + String modelName = sourceModel.getName(uow1); + // Add model to target + Model targetModel = tgtServiceVdb.addModel(uow1, modelName); + targetModel.setModelType(uow1, Type.PHYSICAL); + + // set the model DDL + Properties exportProps = new Properties(); + byte[] bytes = sourceModel.export(uow1, exportProps); + String sourceDdl = new String(bytes); + targetModel.setModelDefinition(uow1, sourceDdl); + + ModelSource[] srcModelSources = sourceModel.getSources(uow1); + ModelSource srcModelSource = srcModelSources[0]; + if(srcModelSource!=null) { + ModelSource tgtModelSource = targetModel.addSource(uow1, srcModelSource.getName(uow1)); + tgtModelSource.setJndiName(uow1, srcModelSource.getJndiName(uow1)); + tgtModelSource.setTranslatorName(uow1, srcModelSource.getTranslatorName(uow1)); + } + } + + } + + // ------------------------------------------------------------- + // Must commit the transaction before setting the service VDB + // ------------------------------------------------------------- + final SynchronousCallback callback = ( SynchronousCallback )uow1.getCallback(); + uow1.commit(); + + if ( !callback.await( 30, TimeUnit.SECONDS ) ) { + // callback timeout occurred + String errorMessage = Messages.getString( COMMIT_TIMEOUT, uow1.getName(), 30, TimeUnit.SECONDS ); + Object responseEntity = createErrorResponseEntity(mediaTypes, errorMessage); + return Response.status( Status.INTERNAL_SERVER_ERROR ) + .entity(responseEntity) + .build(); + } + + // ------------------------------------------------------------- + // Start a new transaction to complete the operation + // ------------------------------------------------------------- + uow2 = createTransaction(principal, "cloneDataservice", false ); //$NON-NLS-1$ + + // Set the service VDB for the cloned dataservice to the new targetServiceVdb + newDataservice.setServiceVdb(uow2, tgtServiceVdb); + + final RestDataservice entity = entityFactory.create(newDataservice, uriInfo.getBaseUri(), uow2 ); + final Response response = commit( uow2, mediaTypes, entity ); return response; } catch (final Exception e) { - if ((uow != null) && (uow.getState() != State.ROLLED_BACK)) { - uow.rollback(); + if ((uow1 != null) && (uow1.getState() != State.ROLLED_BACK)) { + uow1.rollback(); + } + if ((uow2 != null) && (uow2.getState() != State.ROLLED_BACK)) { + uow2.rollback(); } if (e instanceof KomodoRestException) { diff --git a/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoImportExportService.java b/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoImportExportService.java index d700053c..c2154e0a 100644 --- a/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoImportExportService.java +++ b/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoImportExportService.java @@ -42,6 +42,8 @@ import javax.ws.rs.core.UriInfo; import org.komodo.core.KEngine; import org.komodo.importer.ImportMessages; +import org.komodo.importer.ImportOptions; +import org.komodo.importer.ImportOptions.OptionKeys; import org.komodo.osgi.PluginService; import org.komodo.rest.KomodoRestException; import org.komodo.rest.KomodoRestV1Application.V1Constants; @@ -392,12 +394,32 @@ public Response importArtifact( final @Context HttpHeaders headers, parameters, new DocumentType(sta.getDocumentType())); - ImportMessages messages = getWorkspaceManager(uow).importArtifact(uow, importTarget, storageRef); - if (messages.hasError()) - throw new Exception(messages.errorMessagesToString()); + // Set desired overwrite setting in options + ImportOptions importOptions = new ImportOptions(); + if(parameters.containsKey(StorageConnector.IMPORT_OVERWRITE_PROPERTY)) { + String importOverwrite = parameters.getProperty(StorageConnector.IMPORT_OVERWRITE_PROPERTY); + // RETURN supplied + if( importOverwrite.equals(ImportOptions.ExistingNodeOptions.RETURN.name()) ) { + importOptions.setOption(OptionKeys.HANDLE_EXISTING, ImportOptions.ExistingNodeOptions.RETURN); + // CREATE_NEW supplied + } else if( importOverwrite.equals(ImportOptions.ExistingNodeOptions.CREATE_NEW.name()) ) { + importOptions.setOption(OptionKeys.HANDLE_EXISTING, ImportOptions.ExistingNodeOptions.CREATE_NEW); + // OVERWRITE supplied or no match + } else { + importOptions.setOption(OptionKeys.HANDLE_EXISTING, ImportOptions.ExistingNodeOptions.OVERWRITE); + } + } else { + importOptions.setOption(OptionKeys.HANDLE_EXISTING, ImportOptions.ExistingNodeOptions.OVERWRITE); + } + + ImportMessages messages = getWorkspaceManager(uow).importArtifact(uow, importTarget, storageRef, importOptions); + if (messages.hasError()) { + return createErrorResponseWithForbidden(mediaTypes, RelationalMessages.Error.IMPORT_EXPORT_SERVICE_IMPORT_ARTIFACT_ERROR, messages.errorMessagesToString()); + } status.setSuccess(true); status.setName(storageRef.getRelativeRef()); + status.setMessage(RelationalMessages.getString( RelationalMessages.Info.IMPORT_EXPORT_SERVICE_IMPORT_SUCCESS_MESSAGE, importOptions.getOption(OptionKeys.NAME) )); if(sta.getDocumentType().equals(DocumentType.JAR.toString())) { String driverName = storageRef.getParameters().getProperty(StorageReference.DRIVER_NAME_KEY); diff --git a/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoUtilService.java b/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoUtilService.java index a68db8de..d6268e6d 100644 --- a/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoUtilService.java +++ b/server/komodo-rest/src/main/java/org/komodo/rest/service/KomodoUtilService.java @@ -236,14 +236,12 @@ public Response importSampleData(final @Context HttpHeaders headers, importer.importVdb(uow, sampleStream, workspace, importOptions, importMessages); uow.commit(); - String existingVdbMsg = org.komodo.importer.Messages.getString( - org.komodo.importer.Messages.IMPORTER.nodeExistsReturn); List errorMsgs = importMessages.getErrorMessages(); if (errorMsgs.isEmpty()) { msg = RelationalMessages.getString( RelationalMessages.Error.VDB_SAMPLE_IMPORT_SUCCESS, sampleName); - } else if (existingVdbMsg.equals(errorMsgs.iterator().next())) { + } else if (errorMsgs.iterator().next().contains("node already exists")) { msg = RelationalMessages.getString( RelationalMessages.Error.VDB_SAMPLE_IMPORT_VDB_EXISTS, sampleName); diff --git a/server/komodo-rest/src/main/resources/org/komodo/rest/relational/relationalmessages.properties b/server/komodo-rest/src/main/resources/org/komodo/rest/relational/relationalmessages.properties index 40234c58..1434bce9 100644 --- a/server/komodo-rest/src/main/resources/org/komodo/rest/relational/relationalmessages.properties +++ b/server/komodo-rest/src/main/resources/org/komodo/rest/relational/relationalmessages.properties @@ -32,6 +32,7 @@ Info.DATA_SOURCE_SUCCESSFULLY_DEPLOYED = Data source successfully deployed to te Info.DATA_SOURCE_SUCCESSFULLY_UNDEPLOYED = Data source successfully undeployed from the teiid instance. Info.DATA_SOURCE_UNDEPLOYMENT_REQUEST_SENT = Data sourve undeployment request sent but cannot yet be verified Info.DATA_SOURCE_DEPLOYED_WITH_ERRORS = Data source attempted deployment but errors occurred +Info.IMPORT_EXPORT_SERVICE_IMPORT_SUCCESS_MESSAGE = '%s' was imported successfully. Info.VDB_DEPLOYMENT_STATUS_TITLE = Vdb Deployment Status Info.VDB_SUCCESSFULLY_DEPLOYED = Vdb successfully deployed to teiid instance Info.VDB_SUCCESSFULLY_UNDEPLOYED = Vdb successfully undeployed from the teiid instance. @@ -254,3 +255,5 @@ Error.IMPORT_EXPORT_SERVICE_EXPORT_ERROR = An error occurred while attempting to Error.IMPORT_EXPORT_SERVICE_IMPORT_ERROR = An error occurred while attempting to perform an import to storage of type %s: %s Error.IMPORT_EXPORT_SERVICE_STORAGE_TYPES_ERROR = An error occurred while attempting to retrieve the available import/export storage types: %s Error.IMPORT_EXPORT_SERVICE_MISSING_PARAMETER_ERROR = The parameter %s is required for the import/export operation but was not specified in the operation call +Error.IMPORT_EXPORT_SERVICE_IMPORT_ARTIFACT_ERROR = An error occurred while attempting to perform the import: %s + diff --git a/server/komodo-rest/src/test/java/org/komodo/rest/service/KomodoDataserviceServiceTest.java b/server/komodo-rest/src/test/java/org/komodo/rest/service/KomodoDataserviceServiceTest.java index d48ddc7c..ebbded81 100644 --- a/server/komodo-rest/src/test/java/org/komodo/rest/service/KomodoDataserviceServiceTest.java +++ b/server/komodo-rest/src/test/java/org/komodo/rest/service/KomodoDataserviceServiceTest.java @@ -840,5 +840,51 @@ public void shouldGenerateJoinCriteria() throws Exception { assertEquals("PART_ID", viewInfo.getCriteriaPredicates().get(0).getRhColumn()); assertEquals("=", viewInfo.getCriteriaPredicates().get(0).getOperator()); } + + @Test + public void shouldCloneDataservice() throws Exception { + createDataservice(DATASERVICE_NAME); + + URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); + final URI uri = UriBuilder.fromUri( dataservicesUri ) + .path( V1Constants.CLONE_SEGMENT ) + .path( DATASERVICE_NAME ) + .build(); + + ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); + addJsonConsumeContentType(request); + addBody(request, "newDataservice"); + + ClientResponse response = request.post(String.class); + + final String entity = response.getEntity(); + assertThat(entity, is(notNullValue())); + + RestDataservice dataservice = KomodoJsonMarshaller.unmarshall(entity, RestDataservice.class); + assertNotNull(dataservice); + + assertEquals(dataservice.getId(), "newDataservice"); + } + + @Test + public void shouldNotCloneDataservice() throws Exception { + createDataservice(DATASERVICE_NAME); + + URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); + final URI uri = UriBuilder.fromUri( dataservicesUri ) + .path( V1Constants.CLONE_SEGMENT ) + .path( DATASERVICE_NAME ) + .build(); + + // Attempt to clone using the same service name should fail... + ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); + addJsonConsumeContentType(request); + addBody(request, DATASERVICE_NAME); + + ClientResponse response = request.post(String.class); + + final String entity = response.getEntity(); + assertTrue(entity.contains("cannot be the same")); + } }