diff options
Diffstat (limited to 'cds-ui/server')
34 files changed, 1172 insertions, 0 deletions
diff --git a/cds-ui/server/.npmrc b/cds-ui/server/.npmrc new file mode 100644 index 000000000..43c97e719 --- /dev/null +++ b/cds-ui/server/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/cds-ui/server/.prettierignore b/cds-ui/server/.prettierignore new file mode 100644 index 000000000..c6911da9e --- /dev/null +++ b/cds-ui/server/.prettierignore @@ -0,0 +1,2 @@ +dist +*.json diff --git a/cds-ui/server/.prettierrc b/cds-ui/server/.prettierrc new file mode 100644 index 000000000..f58b81dd7 --- /dev/null +++ b/cds-ui/server/.prettierrc @@ -0,0 +1,6 @@ +{ + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all" +} diff --git a/cds-ui/server/.yo-rc.json b/cds-ui/server/.yo-rc.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/cds-ui/server/.yo-rc.json @@ -0,0 +1 @@ +{} diff --git a/cds-ui/server/README.md b/cds-ui/server/README.md new file mode 100644 index 000000000..5591df002 --- /dev/null +++ b/cds-ui/server/README.md @@ -0,0 +1,24 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +# cds-ui-server + +[![LoopBack](https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/) diff --git a/cds-ui/server/index.js b/cds-ui/server/index.js new file mode 100644 index 000000000..b79f7d6d3 --- /dev/null +++ b/cds-ui/server/index.js @@ -0,0 +1,42 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +const application = require('./dist'); + +module.exports = application; + +if (require.main === module) { + // Run the application + const config = { + rest: { + port: +process.env.PORT || 3000, + host: process.env.HOST || 'localhost', + openApiSpec: { + // useful when used with OASGraph to locate your application + setServersFromRequest: true, + }, + }, + }; + application.main(config).catch(err => { + console.error('Cannot start the application.', err); + process.exit(1); + }); +} diff --git a/cds-ui/server/index.ts b/cds-ui/server/index.ts new file mode 100644 index 000000000..8717b8dcf --- /dev/null +++ b/cds-ui/server/index.ts @@ -0,0 +1,22 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +export * from './src'; diff --git a/cds-ui/server/package.json b/cds-ui/server/package.json new file mode 100644 index 000000000..4d0f946d3 --- /dev/null +++ b/cds-ui/server/package.json @@ -0,0 +1,64 @@ +{ + "name": "cds-ui-server", + "version": "1.0.0", + "description": "Intermediate layer between UI and backend. Implemented in loopback 4", + "keywords": [ + "loopback-application", + "loopback" + ], + "main": "index.js", + "engines": { + "node": ">=8.9" + }, + "scripts": { + "build:apidocs": "lb-apidocs", + "build": "lb-tsc es2017 --outDir dist", + "build:watch": "lb-tsc --watch", + "clean": "lb-clean dist", + "lint": "npm run prettier:check && npm run tslint", + "lint:fix": "npm run tslint:fix && npm run prettier:fix", + "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"", + "prettier:check": "npm run prettier:cli -- -l", + "prettier:fix": "npm run prettier:cli -- --write", + "tslint": "lb-tslint", + "tslint:fix": "npm run tslint -- --fix", + "pretest": "npm run clean && npm run build", + "test": "lb-mocha --allow-console-logs \"dist/test\"", + "posttest": "npm run lint", + "test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest", + "migrate": "node ./dist/src/migrate", + "prestart": "npm run build", + "start": "node .", + "prepublishOnly": "npm run test" + }, + "repository": { + "type": "git" + }, + "author": "", + "license": "", + "files": [ + "README.md", + "index.js", + "index.d.ts", + "dist/src", + "dist/index*", + "src" + ], + "dependencies": { + "@loopback/boot": "^1.0.8", + "@loopback/context": "^1.4.0", + "@loopback/core": "^1.1.3", + "@loopback/openapi-v3": "^1.1.5", + "@loopback/repository": "^1.1.1", + "@loopback/rest": "^1.5.1", + "@loopback/rest-explorer": "^1.1.4", + "@loopback/service-proxy": "^1.0.8", + "loopback-connector-rest": "^3.4.1" + }, + "devDependencies": { + "@loopback/build": "^1.1.0", + "@loopback/testlab": "^1.0.3", + "@loopback/tslint-config": "^1.0.0", + "@types/node": "^10.11.2" + } +} diff --git a/cds-ui/server/pom.xml b/cds-ui/server/pom.xml new file mode 100644 index 000000000..bac8b03d2 --- /dev/null +++ b/cds-ui/server/pom.xml @@ -0,0 +1,99 @@ +<!-- +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.ccsdk.cds</groupId> + <artifactId>controller-design-studio</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>../..</relativePath> + </parent> + + <groupId>org.onap.ccsdk.cds.server</groupId> + <artifactId>controller-design-studio-server</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>cds-ui-server</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <npm.executable>npm</npm.executable> + <onap.nexus.url>https://nexus.onap.org</onap.nexus.url> + </properties> + + + + <build> + <plugins> + <plugin> + <groupId>com.github.eirslett</groupId> + <artifactId>frontend-maven-plugin</artifactId> + <!-- Use the latest released version: https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ --> + <version>1.3</version> + <configuration> + <nodeVersion>v8.12.0</nodeVersion> + <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot> + <npmDownloadRoot>https://nodejs.org/dist/npm/</npmDownloadRoot> + <installDirectory>./</installDirectory> + </configuration> + <executions> + <execution> + <id>install node and npm</id> + <goals> + <goal>install-node-and-npm</goal> + </goals> + <phase>generate-resources</phase> + </execution> + + <execution> + <id>npm install</id> + <goals> + <goal>npm</goal> + </goals> + + <phase>generate-resources</phase> + + <configuration> + <arguments>install</arguments> + </configuration> + </execution> + + <execution> + <id>npm build</id> + <goals> + <goal>npm</goal> + </goals> + + <phase>generate-resources</phase> + + <configuration> + <arguments>run build</arguments> + </configuration> + </execution> + + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/cds-ui/server/public/index.html b/cds-ui/server/public/index.html new file mode 100644 index 000000000..81e972890 --- /dev/null +++ b/cds-ui/server/public/index.html @@ -0,0 +1,19 @@ +<!-- +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ --> diff --git a/cds-ui/server/src/application.ts b/cds-ui/server/src/application.ts new file mode 100644 index 000000000..463f330b8 --- /dev/null +++ b/cds-ui/server/src/application.ts @@ -0,0 +1,63 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +import { BootMixin } from '@loopback/boot'; +import { ApplicationConfig } from '@loopback/core'; +import { + RestExplorerBindings, + RestExplorerComponent, +} from '@loopback/rest-explorer'; +import { RepositoryMixin } from '@loopback/repository'; +import { RestApplication } from '@loopback/rest'; +import { ServiceMixin } from '@loopback/service-proxy'; +import * as path from 'path'; +import { MySequence } from './sequence'; + +export class CdsUiServerApplication extends BootMixin( + ServiceMixin(RepositoryMixin(RestApplication)), +) { + constructor(options: ApplicationConfig = {}) { + super(options); + + // Set up the custom sequence + this.sequence(MySequence); + + // Set up default home page + this.static('/', path.join(__dirname, '../../public')); + + // Customize @loopback/rest-explorer configuration here + this.bind(RestExplorerBindings.CONFIG).to({ + path: '/explorer', + }); + this.component(RestExplorerComponent); + + this.projectRoot = __dirname; + // Customize @loopback/boot Booter Conventions here + this.bootOptions = { + controllers: { + // Customize ControllerBooter Conventions here + dirs: ['controllers'], + extensions: ['.controller.js'], + nested: true, + }, + }; + } +} diff --git a/cds-ui/server/src/controllers/README.md b/cds-ui/server/src/controllers/README.md new file mode 100644 index 000000000..837a462dc --- /dev/null +++ b/cds-ui/server/src/controllers/README.md @@ -0,0 +1,30 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +# Controllers + +This directory contains source files for the controllers exported by this app. + +To add a new empty controller, type in `lb4 controller [<name>]` from the +command-line of your application's root directory. + +For more information, please visit +[Controller generator](http://loopback.io/doc/en/lb4/Controller-generator.html). diff --git a/cds-ui/server/src/controllers/blueprint-rest.controller.ts b/cds-ui/server/src/controllers/blueprint-rest.controller.ts new file mode 100644 index 000000000..960f09fbe --- /dev/null +++ b/cds-ui/server/src/controllers/blueprint-rest.controller.ts @@ -0,0 +1,160 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + + +import { + Count, + CountSchema, + Filter, + repository, + Where, +} from '@loopback/repository'; +import { + post, + param, + get, + getFilterSchemaFor, + getWhereSchemaFor, + patch, + put, + del, + requestBody, +} from '@loopback/rest'; +import {Blueprint} from '../models'; +import {BlueprintRepository} from '../repositories'; + +export class BlueprintRestController { + constructor( + @repository(BlueprintRepository) + public blueprintRepository : BlueprintRepository, + ) {} + + @post('/blueprints', { + responses: { + '200': { + description: 'Blueprint model instance', + content: {'application/json': {schema: {'x-ts-type': Blueprint}}}, + }, + }, + }) + async create(@requestBody() blueprint: Blueprint): Promise<Blueprint> { + return await this.blueprintRepository.create(blueprint); + } + + @get('/blueprints/count', { + responses: { + '200': { + description: 'Blueprint model count', + content: {'application/json': {schema: CountSchema}}, + }, + }, + }) + async count( + @param.query.object('where', getWhereSchemaFor(Blueprint)) where?: Where, + ): Promise<Count> { + return await this.blueprintRepository.count(where); + } + + @get('/blueprints', { + responses: { + '200': { + description: 'Array of Blueprint model instances', + content: { + 'application/json': { + schema: {type: 'array', items: {'x-ts-type': Blueprint}}, + }, + }, + }, + }, + }) + async find( + @param.query.object('filter', getFilterSchemaFor(Blueprint)) filter?: Filter, + ): Promise<Blueprint[]> { + return await this.blueprintRepository.find(filter); + } + + @patch('/blueprints', { + responses: { + '200': { + description: 'Blueprint PATCH success count', + content: {'application/json': {schema: CountSchema}}, + }, + }, + }) + async updateAll( + @requestBody() blueprint: Blueprint, + @param.query.object('where', getWhereSchemaFor(Blueprint)) where?: Where, + ): Promise<Count> { + return await this.blueprintRepository.updateAll(blueprint, where); + } + + @get('/blueprints/{id}', { + responses: { + '200': { + description: 'Blueprint model instance', + content: {'application/json': {schema: {'x-ts-type': Blueprint}}}, + }, + }, + }) + async findById(@param.path.number('id') id: number): Promise<Blueprint> { + return await this.blueprintRepository.findById(id); + } + + @patch('/blueprints/{id}', { + responses: { + '204': { + description: 'Blueprint PATCH success', + }, + }, + }) + async updateById( + @param.path.number('id') id: number, + @requestBody() blueprint: Blueprint, + ): Promise<void> { + await this.blueprintRepository.updateById(id, blueprint); + } + + @put('/blueprints/{id}', { + responses: { + '204': { + description: 'Blueprint PUT success', + }, + }, + }) + async replaceById( + @param.path.number('id') id: number, + @requestBody() blueprint: Blueprint, + ): Promise<void> { + await this.blueprintRepository.replaceById(id, blueprint); + } + + @del('/blueprints/{id}', { + responses: { + '204': { + description: 'Blueprint DELETE success', + }, + }, + }) + async deleteById(@param.path.number('id') id: number): Promise<void> { + await this.blueprintRepository.deleteById(id); + } +} diff --git a/cds-ui/server/src/controllers/index.ts b/cds-ui/server/src/controllers/index.ts new file mode 100644 index 000000000..bf2bd6fb7 --- /dev/null +++ b/cds-ui/server/src/controllers/index.ts @@ -0,0 +1,22 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +export * from './ping.controller'; diff --git a/cds-ui/server/src/controllers/ping.controller.ts b/cds-ui/server/src/controllers/ping.controller.ts new file mode 100644 index 000000000..d3098bc69 --- /dev/null +++ b/cds-ui/server/src/controllers/ping.controller.ts @@ -0,0 +1,72 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +import { Request, RestBindings, get, ResponseObject } from '@loopback/rest'; +import { inject } from '@loopback/context'; + +/** + * OpenAPI response for ping() + */ +const PING_RESPONSE: ResponseObject = { + description: 'Ping Response', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + greeting: { type: 'string' }, + date: { type: 'string' }, + url: { type: 'string' }, + headers: { + type: 'object', + properties: { + 'Content-Type': { type: 'string' }, + }, + additionalProperties: true, + }, + }, + }, + }, + }, +}; + +/** + * A simple controller to bounce back http requests + */ +export class PingController { + constructor(@inject(RestBindings.Http.REQUEST) private req: Request) { } + + // Map to `GET /ping` + @get('/ping', { + responses: { + '200': PING_RESPONSE, + }, + }) + ping(): object { + // Reply with a greeting, the current time, the url, and request headers + return { + greeting: 'Hello from LoopBack', + date: new Date(), + url: this.req.url, + headers: Object.assign({}, this.req.headers), + }; + } +} diff --git a/cds-ui/server/src/datasources/README.md b/cds-ui/server/src/datasources/README.md new file mode 100644 index 000000000..2d4d4c3be --- /dev/null +++ b/cds-ui/server/src/datasources/README.md @@ -0,0 +1,24 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +# Datasources + +This directory contains config for datasources used by this app. diff --git a/cds-ui/server/src/datasources/db.datasource.json b/cds-ui/server/src/datasources/db.datasource.json new file mode 100644 index 000000000..a68f220be --- /dev/null +++ b/cds-ui/server/src/datasources/db.datasource.json @@ -0,0 +1,6 @@ +{ + "name": "db", + "connector": "memory", + "localStorage": "", + "file": "./data/db.json" +} diff --git a/cds-ui/server/src/datasources/db.datasource.ts b/cds-ui/server/src/datasources/db.datasource.ts new file mode 100644 index 000000000..f1b19a1af --- /dev/null +++ b/cds-ui/server/src/datasources/db.datasource.ts @@ -0,0 +1,36 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +import {inject} from '@loopback/core'; +import {juggler} from '@loopback/repository'; +import * as config from './db.datasource.json'; + +export class DbDataSource extends juggler.DataSource { + static dataSourceName = 'db'; + + constructor( + @inject('datasources.config.db', {optional: true}) + dsConfig: object = config, + ) { + super(dsConfig); + } +} diff --git a/cds-ui/server/src/datasources/index.ts b/cds-ui/server/src/datasources/index.ts new file mode 100644 index 000000000..1726b4515 --- /dev/null +++ b/cds-ui/server/src/datasources/index.ts @@ -0,0 +1,23 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +export * from './db.datasource'; diff --git a/cds-ui/server/src/datasources/rest.config.json b/cds-ui/server/src/datasources/rest.config.json new file mode 100644 index 000000000..86f33fbd4 --- /dev/null +++ b/cds-ui/server/src/datasources/rest.config.json @@ -0,0 +1,39 @@ +{ + "name": "restConfig", + "connector": "rest", + "options": { + "headers": { + "accept": "application/json", + "content-type": "application/json" + } + }, + "operations": [ + { + "template": { + "method": "GET", + "url": "" + }, + "functions": { + "getEnricheddata": [""] + } + }, + { + "template": { + "method": "POST", + "url": "" + }, + "functions": { + "saveBlueprint": [""] + } + }, + { + "template": { + "method": "POST", + "url": "" + }, + "functions": { + "test": [""] + } + } +] +}
\ No newline at end of file diff --git a/cds-ui/server/src/datasources/rest.datasource.ts b/cds-ui/server/src/datasources/rest.datasource.ts new file mode 100644 index 000000000..42cdb8018 --- /dev/null +++ b/cds-ui/server/src/datasources/rest.datasource.ts @@ -0,0 +1,32 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +import { juggler } from '@loopback/service-proxy'; +import * as config from './rest.config.json'; + + +export class RestDataSource extends juggler.DataSource { + static dataSourceName = 'rest'; + constructor(dsConfig: object = config) { + super(dsConfig); + } +} diff --git a/cds-ui/server/src/index.ts b/cds-ui/server/src/index.ts new file mode 100644 index 000000000..04852494f --- /dev/null +++ b/cds-ui/server/src/index.ts @@ -0,0 +1,37 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +import { CdsUiServerApplication } from './application'; +import { ApplicationConfig } from '@loopback/core'; + +export { CdsUiServerApplication }; + +export async function main(options: ApplicationConfig = {}) { + const app = new CdsUiServerApplication(options); + await app.boot(); + await app.start(); + + const url = app.restServer.url; + console.log(`Server is running at ${url}`); + console.log(`Try ${url}/ping`); + + return app; +} diff --git a/cds-ui/server/src/migrate.ts b/cds-ui/server/src/migrate.ts new file mode 100644 index 000000000..0897b980b --- /dev/null +++ b/cds-ui/server/src/migrate.ts @@ -0,0 +1,41 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +import { CdsUiServerApplication } from './application'; + +export async function migrate(args: string[]) { + const existingSchema = args.includes('--rebuild') ? 'drop' : 'alter'; + console.log('Migrating schemas (%s existing schema)', existingSchema); + + const app = new CdsUiServerApplication(); + await app.boot(); + await app.migrateSchema({ existingSchema }); + + // Connectors usually keep a pool of opened connections, + // this keeps the process running even after all work is done. + // We need to exit explicitly. + process.exit(0); +} + +migrate(process.argv).catch(err => { + console.error('Cannot migrate database schema', err); + process.exit(1); +}); diff --git a/cds-ui/server/src/models/README.md b/cds-ui/server/src/models/README.md new file mode 100644 index 000000000..b4bbe4ac0 --- /dev/null +++ b/cds-ui/server/src/models/README.md @@ -0,0 +1,24 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +# Models + +This directory contains code for models provided by this app. diff --git a/cds-ui/server/src/models/blueprint.model.ts b/cds-ui/server/src/models/blueprint.model.ts new file mode 100644 index 000000000..d9fe1a84a --- /dev/null +++ b/cds-ui/server/src/models/blueprint.model.ts @@ -0,0 +1,52 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +import {Entity, model, property} from '@loopback/repository'; + +@model() +export class Blueprint extends Entity { + @property({ + type: 'number', + id: true, + }) + id?: number; + + @property({ + type: 'object', + }) + metadata?: object; + + @property({ + type: 'array', + itemType: 'object', + }) + fileImports?: object[]; + + @property({ + type: 'object', + }) + topologyTemplates?: object; + + constructor(data?: Partial<Blueprint>) { + super(data); + } +} diff --git a/cds-ui/server/src/models/index.ts b/cds-ui/server/src/models/index.ts new file mode 100644 index 000000000..b4de6a58c --- /dev/null +++ b/cds-ui/server/src/models/index.ts @@ -0,0 +1,23 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +export * from './blueprint.model'; diff --git a/cds-ui/server/src/repositories/README.md b/cds-ui/server/src/repositories/README.md new file mode 100644 index 000000000..dc7af9055 --- /dev/null +++ b/cds-ui/server/src/repositories/README.md @@ -0,0 +1,24 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +# Repositories + +This directory contains code for repositories provided by this app. diff --git a/cds-ui/server/src/repositories/blueprint.repository.ts b/cds-ui/server/src/repositories/blueprint.repository.ts new file mode 100644 index 000000000..3af5c1163 --- /dev/null +++ b/cds-ui/server/src/repositories/blueprint.repository.ts @@ -0,0 +1,37 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +import {DefaultCrudRepository, juggler} from '@loopback/repository'; +import {Blueprint} from '../models'; +import {DbDataSource} from '../datasources'; +import {inject} from '@loopback/core'; + +export class BlueprintRepository extends DefaultCrudRepository< + Blueprint, + typeof Blueprint.prototype.id +> { + constructor( + @inject('datasources.db') dataSource: DbDataSource, + ) { + super(Blueprint, dataSource); + } +} diff --git a/cds-ui/server/src/repositories/index.ts b/cds-ui/server/src/repositories/index.ts new file mode 100644 index 000000000..ac56b3c14 --- /dev/null +++ b/cds-ui/server/src/repositories/index.ts @@ -0,0 +1,23 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + + +export * from './blueprint.repository'; diff --git a/cds-ui/server/src/sequence.ts b/cds-ui/server/src/sequence.ts new file mode 100644 index 000000000..b27093147 --- /dev/null +++ b/cds-ui/server/src/sequence.ts @@ -0,0 +1,56 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +import { inject } from '@loopback/context'; +import { + FindRoute, + InvokeMethod, + ParseParams, + Reject, + RequestContext, + RestBindings, + Send, + SequenceHandler, +} from '@loopback/rest'; + +const SequenceActions = RestBindings.SequenceActions; + +export class MySequence implements SequenceHandler { + constructor( + @inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute, + @inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams, + @inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod, + @inject(SequenceActions.SEND) public send: Send, + @inject(SequenceActions.REJECT) public reject: Reject, + ) { } + + async handle(context: RequestContext) { + try { + const { request, response } = context; + const route = this.findRoute(request); + const args = await this.parseParams(request, route); + const result = await this.invoke(route, args); + this.send(response, result); + } catch (err) { + this.reject(context, err); + } + } +} diff --git a/cds-ui/server/src/services/rest.service.ts b/cds-ui/server/src/services/rest.service.ts new file mode 100644 index 000000000..b94ea4dd3 --- /dev/null +++ b/cds-ui/server/src/services/rest.service.ts @@ -0,0 +1,46 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============LICENSE_END============================================ +*/ + +import {getService, juggler} from '@loopback/service-proxy'; +import {inject, Provider} from '@loopback/core'; +import {RestDataSource} from '../datasources/rest.datasource'; + + +export interface RestResponseData { + userId: number; + id: number; + title: string; + completed: boolean; +} + +export interface RestService { + getrestdata(id?: number): Promise<RestResponseData>; +} +export class RestProvider implements Provider<RestService> { + constructor( + @inject('datasources.rest') + protected dataSource: juggler.DataSource = new RestDataSource(), + ) {} + + value(): Promise<RestService> { + return getService(this.dataSource); + } +}
\ No newline at end of file diff --git a/cds-ui/server/tsconfig.json b/cds-ui/server/tsconfig.json new file mode 100644 index 000000000..eb96bb53c --- /dev/null +++ b/cds-ui/server/tsconfig.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json.schemastore.org/tsconfig", + "extends": "@loopback/build/config/tsconfig.common.json", + "include": [ + "src", + "test", + "index.ts" + ], + "exclude": [ + "node_modules/**", + "packages/*/node_modules/**", + "**/*.d.ts" + ] +} diff --git a/cds-ui/server/tslint.build.json b/cds-ui/server/tslint.build.json new file mode 100644 index 000000000..121b8adb2 --- /dev/null +++ b/cds-ui/server/tslint.build.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["@loopback/tslint-config/tslint.build.json"] +} diff --git a/cds-ui/server/tslint.json b/cds-ui/server/tslint.json new file mode 100644 index 000000000..2bb931e66 --- /dev/null +++ b/cds-ui/server/tslint.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["@loopback/tslint-config/tslint.common.json"] +} |