DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_be / src / main / java / org / onap / sdc / dcae / composition / controller / LifecycleController.java
1 package org.onap.sdc.dcae.composition.controller;
2
3 import org.onap.sdc.dcae.composition.restmodels.sdc.Asset;
4 import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
5 import org.onap.sdc.dcae.enums.AssetType;
6 import org.onap.sdc.dcae.enums.LifecycleOperationType;
7 import org.onap.sdc.dcae.errormng.ErrConfMgr;
8 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
9 import org.springframework.http.HttpStatus;
10 import org.springframework.http.ResponseEntity;
11 import org.springframework.web.bind.annotation.*;
12
13 import java.util.UUID;
14
15 @RestController
16 @EnableAutoConfiguration
17 @CrossOrigin
18 public class LifecycleController extends BaseController {
19
20     private static final String VFCMT = "vfcmt";
21
22     @RequestMapping(value={"/checkin/{assetType}/{uuid}"}, method={RequestMethod.PUT}, produces={"application/json"})
23     public ResponseEntity putCheckin(
24             @PathVariable("assetType") String assetType,
25             @PathVariable("uuid") UUID uuid,
26             @RequestHeader("USER_ID") String user_id,
27             @ModelAttribute("requestId") String requestId)  {
28
29         try {
30             switch (assetType) {
31                 case VFCMT:
32                      Asset res_checkin = checkin(user_id, uuid.toString(), AssetType.RESOURCE, requestId);
33                      return new ResponseEntity<>(res_checkin, HttpStatus.OK);
34
35                 default:
36                     return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
37             }
38         } catch (Exception e) {
39             return handleException(e, ErrConfMgr.ApiType.CHECK_IN_RESOURCE);
40         }
41     }
42
43     @RequestMapping(value={"/checkout/{assetType}/{uuid}"}, method={RequestMethod.PUT}, produces={"application/json"})
44     public ResponseEntity putCheckout(
45             @PathVariable("assetType") String assetType,
46             @PathVariable("uuid") UUID uuid,
47             @RequestHeader("USER_ID") String user_id,
48             @ModelAttribute("requestId") String requestId)  {
49
50         try {
51             switch (assetType) {
52                 case VFCMT:
53                      Asset asset = checkout(user_id, uuid.toString(), AssetType.RESOURCE, requestId);
54                      return new ResponseEntity<>(asset, HttpStatus.OK);
55
56                 default:
57                     return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
58             }
59         } catch (Exception e) {
60             return handleException(e, ErrConfMgr.ApiType.CHECK_OUT_RESOURCE);
61         }
62     }
63
64     @RequestMapping(value={"/certify/{assetType}/{uuid}"}, method={RequestMethod.PUT}, produces={"application/json"})
65     public ResponseEntity putCertify(
66             @PathVariable("assetType") String assetType,
67             @PathVariable("uuid") String uuid,
68             @RequestHeader("USER_ID") String user_id,
69             @ModelAttribute("requestId") String requestId)  {
70
71         try {
72             switch (assetType) {
73             case VFCMT:
74                 ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(user_id, uuid, LifecycleOperationType.CERTIFY.name(), "certifying VFCMT", requestId);
75                 return new ResponseEntity<>(vfcmt, HttpStatus.OK);
76
77             default:
78                 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
79             }
80         } catch (Exception e) {
81             return handleException(e, ErrConfMgr.ApiType.CHECK_OUT_RESOURCE);
82         }
83     }
84 }