Merge "Remove overflow hidden / Decreasize size for visibility"
[ccsdk/cds.git] / cds-ui / server / src / controllers / blueprint-rest.controller.ts
index b529528..91d7e66 100644 (file)
@@ -20,42 +20,23 @@ limitations under the License.
 */
 
 
-
-import {
-  Count,
-  CountSchema,
-  Filter,
-  repository,
-  Where,
-} from '@loopback/repository';
-import {
-  post,
-  param,
-  get,
-  getFilterSchemaFor,
-  getWhereSchemaFor,
-  patch,
-  put,
-  del,
-  requestBody,
-  Request,
-  Response,
-  RestBindings,
-} from '@loopback/rest';
+import { get, param, post, Request, requestBody, Response, RestBindings, del } from '@loopback/rest';
 import { Blueprint } from '../models';
 import { inject } from '@loopback/core';
 import { BlueprintService } from '../services';
 import * as fs from 'fs';
 import * as multiparty from 'multiparty';
 import * as request_lib from 'request';
-import { processorApiConfig, appConfig } from '../config/app-config';
+import { appConfig, processorApiConfig } from '../config/app-config';
 import { bluePrintManagementServiceGrpcClient } from '../clients/blueprint-management-service-grpc-client';
+import { BlueprintDetail } from '../models/blueprint.detail.model';
 
 export class BlueprintRestController {
   constructor(
     @inject('services.BlueprintService')
     public bpservice: BlueprintService,
-  ) { }
+  ) {
+  }
 
   @get('/controllerblueprint/all', {
     responses: {
@@ -69,7 +50,65 @@ export class BlueprintRestController {
     return await this.bpservice.getAllblueprints();
   }
 
- @get('/controllerblueprint/meta-data/{keyword}', {
+  @get('/controllerblueprint/{id}', {
+    responses: {
+      '200': {
+        description: 'Blueprint model instance',
+        content: { 'application/json': { schema: { 'x-ts-type': BlueprintDetail } } },
+      },
+    },
+  })
+  async getOneBluePrint(@param.path.string('id') id: string) {
+    return await this.bpservice.getOneBluePrint(id);
+  }
+
+  @del('/controllerblueprint/{id}', {
+    responses: {
+      '200': {
+        description: 'Blueprint model instance',
+        content: { 'application/json': { schema: { 'x-ts-type': BlueprintDetail } } },
+      },
+    },
+  })
+  async deleteBluePrint(@param.path.string('id') id: string) {
+    return await this.bpservice.deleteBluePrint(id);
+  }
+
+
+  @get('/controllerblueprint/paged', {
+    responses: {
+      '200': {
+        description: 'Blueprint model instance with pagination',
+        content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } },
+      },
+    },
+  })
+  async getPagedBlueprints(
+    @param.query.number('limit') limit: number,
+    @param.query.number('offset') offset: number,
+    @param.query.string('sort') sort: string,
+    @param.query.string('sortType') sortType: string) {
+    return await this.bpservice.getPagedBueprints(limit, offset, sort, sortType);
+  }
+
+  @get('/controllerblueprint/metadata/paged/{keyword}', {
+    responses: {
+      '200': {
+        description: 'Blueprint model instance with pagination',
+        content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } },
+      },
+    },
+  })
+  async getMetaDataPagedBlueprints(
+    @param.path.string('keyword') keyword: string,
+    @param.query.number('limit') limit: number,
+    @param.query.number('offset') offset: number,
+    @param.query.string('sort') sort: string,
+    @param.query.string('sortType') sortType: string) {
+    return await this.bpservice.getMetaDataPagedBlueprints(limit, offset, sort, keyword, sortType);
+  }
+
+  @get('/controllerblueprint/meta-data/{keyword}', {
     responses: {
       '200': {
         description: 'Blueprint model instance',
@@ -81,7 +120,17 @@ export class BlueprintRestController {
     return await this.bpservice.getBlueprintsByKeyword(keyword);
   }
 
-
+  @get('/controllerblueprint/by-name/{name}/version/{version}', {
+    responses: {
+      '200': {
+        description: 'Blueprint model instance',
+        content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } },
+      },
+    },
+  })
+  async getPacakgesByNameAndVersion(@param.path.string('name') name: string, @param.path.string('version') version: string) {
+    return await this.bpservice.getBlueprintByNameAndVersion(name, version);
+  }
 
   @get('/controllerblueprint/searchByTags/{tags}', {
     responses: {
@@ -114,9 +163,9 @@ export class BlueprintRestController {
       this.getFileFromMultiPartForm(request).then(file => {
         // if (appConfig.action.deployBlueprint.grpcEnabled)
         if (appConfig.action.grpcEnabled)
-          return this.uploadFileToBlueprintProcessorGrpc(file, "DRAFT", response);
+          return this.uploadFileToBlueprintProcessorGrpc(file, 'DRAFT', response);
         else
-          return this.uploadFileToBlueprintController(file, "/blueprint-model/", response);
+          return this.uploadFileToBlueprintController(file, '/blueprint-model/', response);
       }, err => {
         reject(err);
       });
@@ -154,9 +203,9 @@ export class BlueprintRestController {
       this.getFileFromMultiPartForm(request).then(file => {
         // if (appConfig.action.deployBlueprint.grpcEnabled)
         if (appConfig.action.grpcEnabled)
-          return this.uploadFileToBlueprintProcessorGrpc(file, "PUBLISH", response);
+          return this.uploadFileToBlueprintProcessorGrpc(file, 'PUBLISH', response);
         else
-          return this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response);
+          return this.uploadFileToBlueprintController(file, '/blueprint-model/publish/', response);
       }, err => {
         reject(err);
       });
@@ -193,9 +242,9 @@ export class BlueprintRestController {
     return new Promise((resolve, reject) => {
       this.getFileFromMultiPartForm(request).then(file => {
         if (appConfig.action.grpcEnabled)
-          return this.uploadFileToBlueprintProcessorGrpc(file, "ENRICH", response);
+          return this.uploadFileToBlueprintProcessorGrpc(file, 'ENRICH', response);
         else
-          return this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response)
+          return this.uploadFileToBlueprintController(file, '/blueprint-model/enrich/', response);
         //   this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response).then(resp => {
         //     resolve(resp);
         //   }, err => {
@@ -217,7 +266,7 @@ export class BlueprintRestController {
     if (appConfig.action.grpcEnabled)
       return this.downloadFileFromBlueprintProcessorGrpc(name, version, response);
     else
-      return this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/" + name + "/version/" + version, response);
+      return this.downloadFileFromBlueprintController('/blueprint-model/download/by-name/' + name + '/version/' + version, response);
   }
 
 
@@ -233,7 +282,7 @@ export class BlueprintRestController {
           resolve(file);
         }
       });
-    })
+    });
   }
 
   @post('/controllerblueprint/deploy-blueprint')
@@ -256,9 +305,9 @@ export class BlueprintRestController {
       this.getFileFromMultiPartForm(request).then(file => {
         // if (appConfig.action.deployBlueprint.grpcEnabled)
         if (appConfig.action.grpcEnabled)
-          return this.uploadFileToBlueprintProcessorGrpc(file, "PUBLISH", response);
+          return this.uploadFileToBlueprintProcessorGrpc(file, 'PUBLISH', response);
         else
-          return this.uploadFileToBlueprintProcessor(file, "/execution-service/upload/", response);
+          return this.uploadFileToBlueprintProcessor(file, '/blueprint-model/publish', response);
       }, err => {
         reject(err);
       });
@@ -278,17 +327,17 @@ export class BlueprintRestController {
       url: url,
       headers: {
         Authorization: authToken,
-        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
+        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
       },
       formData: {
         file: {
           value: fs.createReadStream(file.path),
           options: {
             filename: 'cba.zip',
-            contentType: 'application/zip'
-          }
-        }
-      }
+            contentType: 'application/zip',
+          },
+        },
+      },
     };
 
     var removeTempFile = () => {
@@ -297,19 +346,19 @@ export class BlueprintRestController {
           console.error(err);
         }
       });
-    }
+    };
 
     return new Promise((resolve, reject) => {
       request_lib.post(options)
-        .on("error", err => {
+        .on('error', err => {
           reject(err);
         })
         .pipe(response)
-        .once("finish", () => {
+        .once('finish', () => {
           removeTempFile();
           resolve(response);
         });
-    })
+    });
   }
 
   async downloadFileFromBlueprintController(uri: string, response: Response): Promise<Response> {
@@ -321,18 +370,18 @@ export class BlueprintRestController {
       url: url,
       headers: {
         Authorization: authToken,
-      }
+      },
     };
     return new Promise((resolve, reject) => {
       request_lib.get(options)
-        .on("error", err => {
+        .on('error', err => {
           reject(err);
         })
         .pipe(response)
-        .once("finish", () => {
+        .once('finish', () => {
           resolve(response);
         });
-    })
+    });
   }
 
   async uploadFileToBlueprintProcessorGrpc(file: multiparty.File, actionName: string, response: Response): Promise<Response> {
@@ -346,6 +395,7 @@ export class BlueprintRestController {
       });
     });
   }
+
   async downloadFileFromBlueprintProcessorGrpc(blueprintName: string, blueprintVersion: string, response: Response): Promise<Response> {
     return new Promise<Response>((resolve, reject) => {
       bluePrintManagementServiceGrpcClient.downloadBlueprint(blueprintName, blueprintVersion)