summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/LifecycleController.java
blob: 1c9035988839dd5a912a9884dcc6347845fa2fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.onap.sdc.dcae.composition.controller;

import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.onap.sdc.dcae.enums.AssetType;
import org.onap.sdc.dcae.enums.LifecycleOperationType;
import org.onap.sdc.dcae.errormng.ErrConfMgr;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@EnableAutoConfiguration
@CrossOrigin
public class LifecycleController extends BaseController {

    @RequestMapping(value={"/checkin/{assetType}/{uuid}"}, method={RequestMethod.PUT}, produces={"application/json"})
    public ResponseEntity putCheckin(
            @PathVariable("assetType") String assetType,
            @PathVariable("uuid") UUID uuid,
            @RequestHeader("USER_ID") String userId,
            @ModelAttribute("requestId") String requestId)  {

        try {
        	if (AssetType.VFCMT == baseBusinessLogic.getValidAssetTypeOrNull(assetType)) {
				ResourceDetailed resCheckin = baseBusinessLogic.checkinVfcmt(userId, uuid.toString(), requestId);
				return new ResponseEntity<>(resCheckin, HttpStatus.OK);
            } else {
				return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
			}
        } catch (Exception e) {
            return handleException(e, ErrConfMgr.ApiType.CHECK_IN_RESOURCE);
        }
    }

    @RequestMapping(value={"/checkout/{assetType}/{uuid}"}, method={RequestMethod.PUT}, produces={"application/json"})
    public ResponseEntity putCheckout(
            @PathVariable("assetType") String assetType,
            @PathVariable("uuid") UUID uuid,
            @RequestHeader("USER_ID") String userId,
            @ModelAttribute("requestId") String requestId)  {

        try {
			if (AssetType.VFCMT == baseBusinessLogic.getValidAssetTypeOrNull(assetType)) {
				ResourceDetailed asset = baseBusinessLogic.checkoutVfcmt(userId, uuid.toString(), requestId);
				return new ResponseEntity<>(asset, HttpStatus.OK);
			} else {
				return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
            }
        } catch (Exception e) {
            return handleException(e, ErrConfMgr.ApiType.CHECK_OUT_RESOURCE);
        }
    }

    @RequestMapping(value={"/certify/{assetType}/{uuid}"}, method={RequestMethod.PUT}, produces={"application/json"})
    public ResponseEntity putCertify(
            @PathVariable("assetType") String assetType,
            @PathVariable("uuid") String uuid,
            @RequestHeader("USER_ID") String userId,
            @ModelAttribute("requestId") String requestId)  {

        try {
			if (AssetType.VFCMT == baseBusinessLogic.getValidAssetTypeOrNull(assetType)) {
				ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CERTIFY.name(), "certifying VFCMT", requestId);
				return new ResponseEntity<>(vfcmt, HttpStatus.OK);

			} else {
                return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
            }
        } catch (Exception e) {
            return handleException(e, ErrConfMgr.ApiType.CHECK_OUT_RESOURCE);
        }
    }

}