KomodoDataserviceService extends KomodoService { @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.DATA_SERVICE_PLACEHOLDER ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation( value = "Create a dataservice in the workspace", consumes=MediaType.APPLICATION_JSON ) @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) public Response createDataservice( final @Context HttpHeaders headers, final @Context UriInfo uriInfo, @ApiParam( value = "Name of the data service", required = true ) final @PathParam( "dataserviceName" ) String dataserviceName, @ApiParam( value = "" + "JSON of the properties of the new data service:<br>" + OPEN_PRE_TAG + OPEN_BRACE + BR + NBSP + "keng\\_\\_id: \"id of the data service\"" + COMMA + BR + NBSP + OPEN_PRE_CMT + "(identical to dataserviceName parameter)" + CLOSE_PRE_CMT + BR + BR + NBSP + "tko__description: \"the description\"" + BR + CLOSE_BRACE + CLOSE_PRE_TAG, required = true ) final String dataserviceJson) throws KomodoRestException { SecurityPrincipal principal = checkSecurityContext(headers); if (principal.hasErrorResponse()) return principal.getErrorResponse(); List<MediaType> mediaTypes = headers.getAcceptableMediaTypes(); if (! isAcceptable(mediaTypes, MediaType.APPLICATION_JSON_TYPE)) return notAcceptableMediaTypesBuilder().build(); if (StringUtils.isBlank( dataserviceName )) { return createErrorResponseWithForbidden(mediaTypes, RelationalMessages.Error.DATASERVICE_SERVICE_CREATE_MISSING_NAME); } final RestDataservice restDataservice = KomodoJsonMarshaller.unmarshall( dataserviceJson, RestDataservice.class ); final String jsonDataserviceName = restDataservice.getId(); if ( StringUtils.isBlank( jsonDataserviceName ) ) { return createErrorResponseWithForbidden(mediaTypes, RelationalMessages.Error.DATASERVICE_SERVICE_JSON_MISSING_NAME); } final boolean namesMatch = dataserviceName.equals( jsonDataserviceName ); if ( !namesMatch ) { return createErrorResponseWithForbidden(mediaTypes, DATASERVICE_SERVICE_SERVICE_NAME_ERROR, dataserviceName, jsonDataserviceName); } UnitOfWork uow = null; try { uow = createTransaction(principal, "createDataservice", false ); if ( getWorkspaceManager(uow).hasChild( uow, dataserviceName ) ) { return createErrorResponseWithForbidden(mediaTypes, RelationalMessages.Error.DATASERVICE_SERVICE_CREATE_ALREADY_EXISTS); } return doAddDataservice( uow, uriInfo.getBaseUri(), mediaTypes, restDataservice ); } catch (final Exception e) { if ((uow != null) && (uow.getState() != State.ROLLED_BACK)) { uow.rollback(); } if (e instanceof KomodoRestException) { throw (KomodoRestException)e; } return createErrorResponseWithForbidden(mediaTypes, e, DATASERVICE_SERVICE_CREATE_DATASERVICE_ERROR, dataserviceName); } } KomodoDataserviceService( final KEngine engine ); @GET @Produces( MediaType.APPLICATION_JSON ) @ApiOperation( value = "Return the collection of data services", response = RestDataservice[].class) @ApiImplicitParams({ @ApiImplicitParam( name = QueryParamKeys.PATTERN, value = "A regex expression used when searching. If not present, all objects are returned.", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam( name = QueryParamKeys.SIZE, value = "The number of objects to return. If not present, all objects are returned", required = false, dataType = "integer", paramType = "query"), @ApiImplicitParam( name = QueryParamKeys.START, value = "Index of the first dataservice to return", required = false, dataType = "integer", paramType = "query") }) @ApiResponses( value = { @ApiResponse( code = 403, message = "An error has occurred.") } ) Response getDataservices( final @Context HttpHeaders headers,
                                     final @Context UriInfo uriInfo ); @GET @Path( V1Constants.DATA_SERVICE_PLACEHOLDER ) @Produces( { MediaType.APPLICATION_JSON } ) @ApiOperation( value = "Find dataservice by name", response = RestDataservice.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "No Dataservice could be found with name"), @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getDataservice( final @Context HttpHeaders headers,
                                    final @Context UriInfo uriInfo,
                                    @ApiParam(
                                              value = "Id of the dataservice to be fetched, ie. the value of the 'keng__id' property",
                                              required = true
                                    )
                                    final @PathParam( "dataserviceName" ) String dataserviceName); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.DATA_SERVICE_PLACEHOLDER ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation( value = "Create a dataservice in the workspace", consumes=MediaType.APPLICATION_JSON ) @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response createDataservice( final @Context HttpHeaders headers,
                                       final @Context UriInfo uriInfo,
                                       @ApiParam(
                                                 value = "Name of the data service",
                                                 required = true
                                       )
                                       final @PathParam( "dataserviceName" ) String dataserviceName,
                                       @ApiParam(
                                                 value = "" + 
                                                         "JSON of the properties of the new data service:<br>" +
                                                         OPEN_PRE_TAG +
                                                         OPEN_BRACE + BR +
                                                         NBSP + "keng\\_\\_id: \"id of the data service\"" + COMMA + BR +
                                                         NBSP + OPEN_PRE_CMT + "(identical to dataserviceName parameter)" + CLOSE_PRE_CMT + BR + BR +
                                                         NBSP + "tko__description: \"the description\"" + BR +
                                                         CLOSE_BRACE +
                                                         CLOSE_PRE_TAG,
                                                 required = true
                                       )
                                       final String dataserviceJson); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.CLONE_SEGMENT + StringConstants.FORWARD_SLASH + V1Constants.DATA_SERVICE_PLACEHOLDER ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Clone a dataservice in the workspace") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response cloneDataservice( final @Context HttpHeaders headers,
                                       final @Context UriInfo uriInfo,
                                       @ApiParam(
                                                 value = "Name of the data service",
                                                 required = true
                                       )
                                       final @PathParam( "dataserviceName" ) String dataserviceName,
                                       @ApiParam(
                                                 value = "Name of the cloned data service",
                                                 required = true
                                       )
                                       final String newDataserviceName); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.SERVICE_VDB_FOR_SINGLE_TABLE ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Sets the data service's service vdb") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response setServiceVdbForSingleTable( final @Context HttpHeaders headers,
    		final @Context UriInfo uriInfo,
    		@ApiParam(
                      value = "" + 
                              "JSON specifying the service vdb:<br>" +
                              OPEN_PRE_TAG +
                              OPEN_BRACE + BR +
                              NBSP + "dataserviceName: \"name of the data service\"" + COMMA + BR +
                              NBSP + "tablePath: \"/path/to/table\"" + COMMA + BR +
                              NBSP + "modelSourcePath: \"/path/to/modelSource\"" + COMMA + BR +
                              NBSP + "columnNames: {name1, name2, ...} [OPTIONAL]" + COMMA + BR +
                              NBSP + "viewDdl: \"DDL for the service view\" [OPTIONAL]" + BR +
                              CLOSE_BRACE +
                              CLOSE_PRE_TAG,
                      required = true
            )
    		final String dataserviceUpdateAttributes); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.SERVICE_VIEW_DDL_FOR_SINGLE_TABLE ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Gets generated View DDL using parameters provided in the request body") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getServiceViewDdlForSingleTable( final @Context HttpHeaders headers,
                                                     final @Context UriInfo uriInfo,
                                                     @ApiParam(
                                                               value = "" + 
                                                                       "JSON parameters:<br>" +
                                                                       OPEN_PRE_TAG +
                                                                       OPEN_BRACE + BR +
                                                                       NBSP + "dataserviceName: \"name of the data service\"" + COMMA + BR +
                                                                       NBSP + "tablePath: \"/path/to/table\"" + COMMA + BR +
                                                                       NBSP + "modelSourcePath: \"/path/to/modelSource\"" + COMMA + BR +
                                                                       NBSP + "columnNames: {name1, name2, ...} [OPTIONAL]" + COMMA + BR +
                                                                       NBSP + "viewDdl: \"DDL for the service view\" [OPTIONAL]" + BR +
                                                                       CLOSE_BRACE +
                                                                       CLOSE_PRE_TAG,
                                                               required = true
                                                     )
                                                     final String dataserviceUpdateAttributes); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.SERVICE_VDB_FOR_JOIN_TABLES ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Sets the dataservice vdb using parameters provided in the request body") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response setServiceVdbForTwoTables( final @Context HttpHeaders headers,
            final @Context UriInfo uriInfo,
            @ApiParam(
                      value = "" + 
                              "JSON parameters:<br>" +
                              OPEN_PRE_TAG +
                              OPEN_BRACE + BR +
                              NBSP + "dataserviceName: \"name of the data service\"" + COMMA + BR +
                              NBSP + "tablePath: \"/path/to/table\"" + COMMA + BR +
                              NBSP + "rhTablePath: \"/path/to/table\"" + COMMA + BR +
                              NBSP + "modelSourcePath: \"/path/to/modelSource\"" + COMMA + BR +
                              NBSP + "rhModelSourcePath: \"/path/to/modelSource\"" + COMMA + BR +
                              NBSP + "columnNames: {name1, name2, ...} [OPTIONAL]" + COMMA + BR +
                              NBSP + "rhColumnNames: {name1, name2, ...} [OPTIONAL]" + COMMA + BR +
                              NBSP + "viewDdl: \"DDL for the service view\" [OPTIONAL]" + COMMA + BR +
                              NBSP + "joinType: \"Type of join\"" + COMMA + BR +
                              NBSP + "criteriaPredicates: []" + BR +
                              CLOSE_BRACE +
                              CLOSE_PRE_TAG,
                      required = true
            )
            final String dataserviceUpdateAttributes); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.SERVICE_VIEW_DDL_FOR_JOIN_TABLES ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Gets generated View DDL using parameters provided in the request body") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getServiceViewDdlForTwoTables( final @Context HttpHeaders headers,
            final @Context UriInfo uriInfo,
            @ApiParam(
                      value = "" + 
                              "JSON parameters:<br>" +
                              OPEN_PRE_TAG +
                              OPEN_BRACE + BR +
                              NBSP + "dataserviceName: \"name of the data service\"" + COMMA + BR +
                              NBSP + "tablePath: \"/path/to/table\"" + COMMA + BR +
                              NBSP + "rhTablePath: \"/path/to/table\"" + COMMA + BR +
                              NBSP + "columnNames: {name1, name2, ...} [OPTIONAL]" + COMMA + BR +
                              NBSP + "rhColumnNames: {name1, name2, ...} [OPTIONAL]" + COMMA + BR +
                              NBSP + "joinType: \"Type of join\"" + COMMA + BR +
                              NBSP + "criteriaPredicates: []" + BR +
                              CLOSE_BRACE +
                              CLOSE_PRE_TAG,
                      required = true
            )
            final String dataserviceUpdateAttributes); @POST @Path( StringConstants.FORWARD_SLASH + V1Constants.CRITERIA_FOR_JOIN_TABLES ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Generates join criteria using table parameters provided in the request body") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getJoinCriteriaForTables( final @Context HttpHeaders headers,
            final @Context UriInfo uriInfo,
            @ApiParam(
                      value = "" + 
                              "JSON parameters:<br>" +
                              OPEN_PRE_TAG +
                              OPEN_BRACE + BR +
                              NBSP + "tablePath: \"/path/to/table\"" + COMMA + BR +
                              NBSP + "rhTablePath: \"/path/to/table\"" + COMMA + BR +
                              CLOSE_BRACE +
                              CLOSE_PRE_TAG,
                      required = true
            )
            final String dataserviceUpdateAttributes); @PUT @Path( StringConstants.FORWARD_SLASH + V1Constants.DATA_SERVICE_PLACEHOLDER ) @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Update a dataservice in the workspace") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response updateDataservice( final @Context HttpHeaders headers,
                                       final @Context UriInfo uriInfo,
                                       @ApiParam(
                                                 value = "Name of the data service to be updated",
                                                 required = true
                                       )
                                       final @PathParam( "dataserviceName" ) String dataserviceName,
                                       @ApiParam(
                                                 value = "" + 
                                                         "JSON of the data service properties to update:<br>" +
                                                         OPEN_PRE_TAG +
                                                         OPEN_BRACE + BR +
                                                         NBSP + "keng\\_\\_id: \"id of the data service\"" + COMMA + BR +
                                                         NBSP + OPEN_PRE_CMT + "(identical to dataserviceName parameter)" + CLOSE_PRE_CMT + BR + BR +
                                                         NBSP + "tko__description: \"the description\"" + BR +
                                                         CLOSE_BRACE +
                                                         CLOSE_PRE_TAG,
                                                 required = true
                                       )
                                       final String dataserviceJson); @DELETE @Path("{dataserviceName}") @Produces( MediaType.APPLICATION_JSON ) @ApiOperation(value = "Delete a dataservice from the workspace") @ApiResponses(value = { @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response deleteDataservice( final @Context HttpHeaders headers,
                                       final @Context UriInfo uriInfo,
                                       @ApiParam(
                                                 value = "Name of the data service to be deleted",
                                                 required = true
                                       )
                                       final @PathParam( "dataserviceName" ) String dataserviceName); @GET @Path( V1Constants.DATA_SERVICE_PLACEHOLDER + StringConstants.FORWARD_SLASH + V1Constants.CONNECTIONS_SEGMENT) @Produces( { MediaType.APPLICATION_JSON } ) @ApiOperation(value = "Find a dataservice's connections ", response = RestDataservice.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "No Dataservice could be found with name"), @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getConnections( final @Context HttpHeaders headers,
                                    final @Context UriInfo uriInfo,
                                    @ApiParam(
                                              value = "Name of the data service containing the required connections",
                                              required = true
                                    )
                                    final @PathParam( "dataserviceName" ) String dataserviceName); @GET @Path( V1Constants.DATA_SERVICE_PLACEHOLDER + StringConstants.FORWARD_SLASH + V1Constants.DRIVERS_SEGMENT) @Produces( { MediaType.APPLICATION_JSON } ) @ApiOperation(value = "Find a dataservice's drivers ", response = RestConnectionDriver.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "No Dataservice could be found with name"), @ApiResponse(code = 406, message = "Only JSON is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getDrivers( final @Context HttpHeaders headers,
                                    final @Context UriInfo uriInfo,
                                    @ApiParam(
                                              value = "Name of the data service containing the required drivers",
                                              required = true
                                    )
                                    final @PathParam( "dataserviceName" ) String dataserviceName); @GET @Path( V1Constants.DATA_SERVICE_PLACEHOLDER + StringConstants.FORWARD_SLASH + V1Constants.SOURCE_VDB_MATCHES) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @ApiOperation(value = "Find workspace source VDB matches for a Dataservice", response = RestVdb[].class) @ApiResponses(value = { @ApiResponse(code = 404, message = "No dataservice could be found with name"), @ApiResponse(code = 406, message = "Only JSON or XML is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getSourceVdbsForDataService( final @Context HttpHeaders headers,
                                                 final @Context UriInfo uriInfo,
                                                 @ApiParam(
                                                           value = "Name of the data service containing the required source vdbs",
                                                           required = true
                                                 )
                                                 final @PathParam( "dataserviceName" ) String dataserviceName); @GET @Path( V1Constants.DATA_SERVICE_PLACEHOLDER + StringConstants.FORWARD_SLASH + V1Constants.SERVICE_VIEW_INFO) @Produces( { MediaType.APPLICATION_JSON } ) @ApiOperation(value = "retrieve the service view information for a dataservice") @ApiResponses(value = { @ApiResponse(code = 404, message = "No dataservice could be found with name"), @ApiResponse(code = 406, message = "Only JSON or XML is returned by this operation"), @ApiResponse(code = 403, message = "An error has occurred.") }) Response getServiceViewInfoForDataService( final @Context HttpHeaders headers,
                                                      final @Context UriInfo uriInfo,
                                                      @ApiParam(
                                                                value = "Name of the required data service",
                                                                required = true
                                                      )
                                                      final @PathParam( "dataserviceName" ) String dataserviceName); @GET @Path( V1Constants.NAME_VALIDATION_SEGMENT + StringConstants.FORWARD_SLASH + V1Constants.DATA_SERVICE_PLACEHOLDER ) @Produces( { MediaType.TEXT_PLAIN } ) @ApiOperation( value = "Returns an error message if the data service name is invalid" ) @ApiResponses( value = { @ApiResponse( code = 400, message = "The URI cannot contain encoded slashes or backslashes." ), @ApiResponse( code = 403, message = "An unexpected error has occurred." ), @ApiResponse( code = 500, message = "The dataservice name cannot be empty." ) } ) Response validateDataserviceName( final @Context HttpHeaders headers,
                                             final @Context UriInfo uriInfo,
                                             @ApiParam( value = "The dataservice name being checked", required = true )
                                             final @PathParam( "dataserviceName" ) String dataserviceName );  }
@Test public void shouldGetDataservices() throws Exception { createDataservice(DATASERVICE_NAME); URI uri = _uriBuilder.workspaceDataservicesUri(); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); ClientResponse<String> response = request.get(String.class); assertNotNull(response.getEntity()); final String entities = response.getEntity(); assertThat(entities, is(notNullValue())); RestDataservice[] dataservices = KomodoJsonMarshaller.unmarshallArray(entities, RestDataservice[].class); assertEquals(1, dataservices.length); RestDataservice myService = dataservices[0]; assertNotNull(myService.getId()); assertTrue(DATASERVICE_NAME.equals(myService.getId())); assertNotNull(myService.getDataPath()); assertNotNull(myService.getkType()); }
@Test public void shouldGetDataservice() throws Exception { createDataservice(DATASERVICE_NAME); Properties settings = _uriBuilder.createSettings(SettingNames.DATA_SERVICE_NAME, DATASERVICE_NAME); _uriBuilder.addSetting(settings, SettingNames.DATA_SERVICE_PARENT_PATH, _uriBuilder.workspaceDataservicesUri()); URI uri = _uriBuilder.dataserviceUri(LinkType.SELF, settings); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); ClientResponse<String> response = request.get(String.class); final String entity = response.getEntity(); assertThat(entity, is(notNullValue())); RestDataservice dataservice = KomodoJsonMarshaller.unmarshall(entity, RestDataservice.class); assertNotNull(dataservice); assertEquals(dataservice.getId(), DATASERVICE_NAME); }
@Test public void shouldNotSetServiceVdbForSingleTableMissingParameter() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/table"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("missing one or more required parameters")); }
@Test public void shouldNotSetServiceVdbForSingleTableBadTablePath() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/table"); updateAttr.setModelSourcePath("/path/to/ModelSource"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("specified Table does not exist")); }
@Test public void shouldNotSetServiceVdbForSingleTableBadDdl() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); updateAttr.setModelSourcePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/Accounts/vdb:sources/h2-connector"); updateAttr.setViewDdl("CREATE VIEW blah blah"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("DDL Parsing encountered a problem")); }
@Test public void shouldSetServiceVdbForSingleTable() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); updateAttr.setModelSourcePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/Accounts/vdb:sources/h2-connector"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("Successfully updated")); }
@Test public void shouldNotSetServiceVdbForJoinTablesMissingParameter() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/lhTable"); updateAttr.setRhTablePath("/path/to/rhTable"); updateAttr.setModelSourcePath("/path/to/lhModelSource"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("missing one or more required parameters")); }
@Test public void shouldNotSetServiceVdbForJoinTablesBadTablePath() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/lhTable"); updateAttr.setRhTablePath("/path/to/rhTable"); updateAttr.setModelSourcePath("/path/to/lhModelSource"); updateAttr.setRhModelSourcePath("/path/to/rhModelSource"); updateAttr.setViewDdl("CREATE VIEW blah blah"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("specified Table does not exist")); }
@Test public void shouldNotSetServiceVdbForJoinTablesBadDdl() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VDB_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); updateAttr.setRhTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); updateAttr.setModelSourcePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/Accounts/vdb:sources/h2-connector"); updateAttr.setRhModelSourcePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/Accounts/vdb:sources/h2-connector"); updateAttr.setViewDdl("CREATE VIEW blah blah"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("DDL Parsing encountered a problem")); }
@Test public void shouldNotGenerateViewDdlForSingleTableMissingParameter() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VIEW_DDL_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("missing one or more required parameters")); }
@Test public void shouldNotGenerateViewDdlForSingleTableBadTablePath() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VIEW_DDL_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/table"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("specified Table does not exist")); }
@Test public void shouldGenerateViewDdlForSingleTable() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VIEW_DDL_FOR_SINGLE_TABLE).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); RestDataserviceViewInfo viewInfo = KomodoJsonMarshaller.unmarshall(entity, RestDataserviceViewInfo.class); assertEquals(RestDataserviceViewInfo.DDL_INFO, viewInfo.getInfoType()); assertEquals("CREATE VIEW MyDataServiceView ( ROW_ID INTEGER, ACCOUNT_ID INTEGER, PRODUCT_TYPE STRING, PRODUCT_VALUE STRING, " + "CONSTRAINT PK0 PRIMARY KEY (ROW_ID)) AS \nSELECT ROW_ID, ACCOUNT_ID, PRODUCT_TYPE, PRODUCT_VALUE \nFROM Portfolio.Sheet1;", viewInfo.getViewDdl()); assertEquals(false, viewInfo.isViewEditable()); }
@Test public void shouldNotGenerateViewDdlForJoinTablesMissingParameter() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VIEW_DDL_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/lhTable"); updateAttr.setRhTablePath("/path/to/rhTable"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("missing one or more required parameters")); }
@Test public void shouldNotGenerateViewDdlForJoinTablesBadTablePath() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VIEW_DDL_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("/path/to/lhTable"); updateAttr.setRhTablePath("/path/to/rhTable"); updateAttr.setJoinType("INNER"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("specified Table does not exist")); }
@Test public void shouldGenerateViewDdlForJoinTables() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.SERVICE_VIEW_DDL_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setDataserviceName(DATASERVICE_NAME); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); updateAttr.setRhTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/Portfolio/PersonalValuations/Sheet1"); updateAttr.setJoinType("INNER"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); RestDataserviceViewInfo viewInfo = KomodoJsonMarshaller.unmarshall(entity, RestDataserviceViewInfo.class); assertEquals(RestDataserviceViewInfo.DDL_INFO, viewInfo.getInfoType()); assertEquals("CREATE VIEW MyDataServiceView (RowId integer PRIMARY KEY, A_ROW_ID INTEGER, A_ACCOUNT_ID INTEGER, A_PRODUCT_TYPE STRING, A_PRODUCT_VALUE STRING, " + "B_ROW_ID INTEGER, B_ACCOUNT_ID INTEGER, B_PRODUCT_TYPE STRING, B_PRODUCT_VALUE STRING) AS \n" + "SELECT ROW_NUMBER() OVER (ORDER BY A.ROW_ID), A.ROW_ID, A.ACCOUNT_ID, A.PRODUCT_TYPE, A.PRODUCT_VALUE, B.ROW_ID, B.ACCOUNT_ID, B.PRODUCT_TYPE, B.PRODUCT_VALUE \n" + "FROM \nPortfolio.Sheet1 AS A \nINNER JOIN \nPortfolio.Sheet1 AS B ;", viewInfo.getViewDdl()); assertEquals(false, viewInfo.isViewEditable()); }
@Test public void shouldFailNameValidationWhenNameAlreadyExists() throws Exception { createDataservice( DATASERVICE_NAME ); final URI dsUri = _uriBuilder.workspaceDataservicesUri(); final URI uri = UriBuilder.fromUri( dsUri ) .path( V1Constants.NAME_VALIDATION_SEGMENT ) .path( DATASERVICE_NAME ) .build(); final ClientRequest request = request( uri, MediaType.TEXT_PLAIN_TYPE ); final ClientResponse< String > response = request.get( String.class ); assertThat( response.getStatus(), is( Response.Status.OK.getStatusCode() ) ); final String errorMsg = response.getEntity(); assertThat( errorMsg, is( notNullValue() ) ); }
@Test public void shouldNotGenerateJoinCriteriaMissingParameter() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.CRITERIA_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setTablePath("/path/to/lhTable"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("missing one or more required parameters")); }
@Test public void shouldNotGenerateJoinCriteriaBadTablePath() throws Exception { createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.CRITERIA_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setTablePath("/path/to/lhTable"); updateAttr.setRhTablePath("/path/to/rhTable"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("specified Table does not exist")); }
@Test public void shouldGenerateJoinCriteriaEmpty() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.CRITERIA_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/MyPartsVDB_Dynamic/PartsSS/PARTS"); updateAttr.setRhTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/MyPartsVDB_Dynamic/PartsSS/STATUS"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertThat(entity, is(notNullValue())); RestDataserviceViewInfo viewInfo = KomodoJsonMarshaller.unmarshall(entity, RestDataserviceViewInfo.class); assertTrue("CRITERIA".equals(viewInfo.getInfoType())); assertEquals(viewInfo.getCriteriaPredicates().size(), 0); }
@Test public void shouldGenerateJoinCriteria() throws Exception { loadVdbs(); createDataservice(DATASERVICE_NAME); URI dataservicesUri = _uriBuilder.workspaceDataservicesUri(); URI uri = UriBuilder.fromUri(dataservicesUri).path(V1Constants.CRITERIA_FOR_JOIN_TABLES).build(); KomodoDataserviceUpdateAttributes updateAttr = new KomodoDataserviceUpdateAttributes(); updateAttr.setTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/MyPartsVDB_Dynamic/PartsSS/PARTS"); updateAttr.setRhTablePath("tko:komodo/tko:workspace/"+USER_NAME+"/MyPartsVDB_Dynamic/PartsSS/SUPPLIER_PARTS"); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, updateAttr); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertThat(entity, is(notNullValue())); RestDataserviceViewInfo viewInfo = KomodoJsonMarshaller.unmarshall(entity, RestDataserviceViewInfo.class); assertTrue("CRITERIA".equals(viewInfo.getInfoType())); assertEquals(1, viewInfo.getCriteriaPredicates().size()); assertEquals("PART_ID", viewInfo.getCriteriaPredicates().get(0).getLhColumn()); 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<String> 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(); ClientRequest request = request(uri, MediaType.APPLICATION_JSON_TYPE); addJsonConsumeContentType(request); addBody(request, DATASERVICE_NAME); ClientResponse<String> response = request.post(String.class); final String entity = response.getEntity(); assertTrue(entity.contains("cannot be the same")); }