Merge "add service for searching in meta data pageable"
[ccsdk/cds.git] / cds-ui / server / src / controllers / blueprint-rest.controller.ts
index 7895898..1a8de6b 100644 (file)
@@ -69,6 +69,51 @@ export class BlueprintRestController {
     return await this.bpservice.getAllblueprints();
   }
 
+  @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) {
+    return await this.bpservice.getPagedBueprints(limit, offset, sort);
+  }
+
+    @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) {
+        return await this.bpservice.getMetaDataPagedBlueprints(limit, offset, sort,keyword);
+    }
+
+ @get('/controllerblueprint/meta-data/{keyword}', {
+    responses: {
+      '200': {
+        description: 'Blueprint model instance',
+        content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } },
+      },
+    },
+  })
+  async getAllPacakgesByKeword(@param.path.string('keyword') keyword: string) {
+    return await this.bpservice.getBlueprintsByKeyword(keyword);
+  }
+
+
+
   @get('/controllerblueprint/searchByTags/{tags}', {
     responses: {
       '200': {
@@ -98,15 +143,26 @@ export class BlueprintRestController {
   ): Promise<Response> {
     return new Promise((resolve, reject) => {
       this.getFileFromMultiPartForm(request).then(file => {
-        this.uploadFileToBlueprintController(file, "/blueprint-model/", response).then(resp => {
-          resolve(resp);
-        }, err => {
-          reject(err);
-        });
+        // if (appConfig.action.deployBlueprint.grpcEnabled)
+        if (appConfig.action.grpcEnabled)
+          return this.uploadFileToBlueprintProcessorGrpc(file, "DRAFT", response);
+        else
+          return this.uploadFileToBlueprintController(file, "/blueprint-model/", response);
       }, err => {
         reject(err);
       });
     });
+    // return new Promise((resolve, reject) => {
+    //   this.getFileFromMultiPartForm(request).then(file => {
+    //     this.uploadFileToBlueprintController(file, "/blueprint-model/", response).then(resp => {
+    //       resolve(resp);
+    //     }, err => {
+    //       reject(err);
+    //     });
+    //   }, err => {
+    //     reject(err);
+    //   });
+    // });
   }
 
   @post('/controllerblueprint/publish')
@@ -127,15 +183,26 @@ export class BlueprintRestController {
   ): Promise<Response> {
     return new Promise((resolve, reject) => {
       this.getFileFromMultiPartForm(request).then(file => {
-        this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response).then(resp => {
-          resolve(resp);
-        }, err => {
-          reject(err);
-        });
+        // if (appConfig.action.deployBlueprint.grpcEnabled)
+        if (appConfig.action.grpcEnabled)
+          return this.uploadFileToBlueprintProcessorGrpc(file, "PUBLISH", response);
+        else
+          return this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response);
       }, err => {
         reject(err);
       });
     });
+    // return new Promise((resolve, reject) => {
+    //   this.getFileFromMultiPartForm(request).then(file => {
+    //     this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response).then(resp => {
+    //       resolve(resp);
+    //     }, err => {
+    //       reject(err);
+    //     });
+    //   }, err => {
+    //     reject(err);
+    //   });
+    // });
   }
 
   @post('/controllerblueprint/enrich-blueprint')
@@ -156,13 +223,17 @@ export class BlueprintRestController {
   ): Promise<Response> {
     return new Promise((resolve, reject) => {
       this.getFileFromMultiPartForm(request).then(file => {
-        this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response).then(resp => {
-          resolve(resp);
-        }, err => {
-          reject(err);
-        });
-      }, err => {
-        reject(err);
+        if (appConfig.action.grpcEnabled)
+          return this.uploadFileToBlueprintProcessorGrpc(file, "ENRICH", response);
+        else
+          return this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response)
+        //   this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response).then(resp => {
+        //     resolve(resp);
+        //   }, err => {
+        //     reject(err);
+        //   });
+        // }, err => {
+        //   reject(err);
       });
     });
   }
@@ -173,9 +244,14 @@ export class BlueprintRestController {
     @param.path.string('version') version: string,
     @inject(RestBindings.Http.RESPONSE) response: Response,
   ): Promise<Response> {
-    return this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/" + name + "/version/" + version, response);
+
+    if (appConfig.action.grpcEnabled)
+      return this.downloadFileFromBlueprintProcessorGrpc(name, version, response);
+    else
+      return this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/" + name + "/version/" + version, response);
   }
 
+
   async getFileFromMultiPartForm(request: Request): Promise<multiparty.File> {
     return new Promise((resolve, reject) => {
       let form = new multiparty.Form();
@@ -209,8 +285,9 @@ export class BlueprintRestController {
   ): Promise<Response> {
     return new Promise((resolve, reject) => {
       this.getFileFromMultiPartForm(request).then(file => {
-        if (appConfig.action.deployBlueprint.grpcEnabled)
-          return this.uploadFileToBlueprintProcessorGrpc(file, response);
+        // if (appConfig.action.deployBlueprint.grpcEnabled)
+        if (appConfig.action.grpcEnabled)
+          return this.uploadFileToBlueprintProcessorGrpc(file, "PUBLISH", response);
         else
           return this.uploadFileToBlueprintProcessor(file, "/execution-service/upload/", response);
       }, err => {
@@ -289,9 +366,9 @@ export class BlueprintRestController {
     })
   }
 
-  async uploadFileToBlueprintProcessorGrpc(file: multiparty.File, response: Response): Promise<Response> {
+  async uploadFileToBlueprintProcessorGrpc(file: multiparty.File, actionName: string, response: Response): Promise<Response> {
     return new Promise<Response>((resolve, reject) => {
-      bluePrintManagementServiceGrpcClient.uploadBlueprint(file.path).then(output => {
+      bluePrintManagementServiceGrpcClient.uploadBlueprint(file.path, actionName).then(output => {
         response.send(output.status.message);
         resolve(response);
       }, err => {
@@ -300,4 +377,16 @@ export class BlueprintRestController {
       });
     });
   }
-}
\ No newline at end of file
+  async downloadFileFromBlueprintProcessorGrpc(blueprintName: string, blueprintVersion: string, response: Response): Promise<Response> {
+    return new Promise<Response>((resolve, reject) => {
+      bluePrintManagementServiceGrpcClient.downloadBlueprint(blueprintName, blueprintVersion)
+        .then(output => {
+          response.send(output.status.message);
+          resolve(response);
+        }, err => {
+          response.status(500).send(err);
+          resolve(response);
+        });
+    });
+  }
+}