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
78
79
80
81
82
83
84
|
package org.onap.sdc.dcae.composition.controller;
import org.onap.sdc.dcae.composition.restmodels.sdc.Asset;
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 {
private static final String VFCMT = "vfcmt";
@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 user_id,
@ModelAttribute("requestId") String requestId) {
try {
switch (assetType) {
case VFCMT:
Asset res_checkin = checkin(user_id, uuid.toString(), AssetType.RESOURCE, requestId);
return new ResponseEntity<>(res_checkin, HttpStatus.OK);
default:
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 user_id,
@ModelAttribute("requestId") String requestId) {
try {
switch (assetType) {
case VFCMT:
Asset asset = checkout(user_id, uuid.toString(), AssetType.RESOURCE, requestId);
return new ResponseEntity<>(asset, HttpStatus.OK);
default:
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 user_id,
@ModelAttribute("requestId") String requestId) {
try {
switch (assetType) {
case VFCMT:
ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(user_id, uuid, LifecycleOperationType.CERTIFY.name(), "certifying VFCMT", requestId);
return new ResponseEntity<>(vfcmt, HttpStatus.OK);
default:
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
} catch (Exception e) {
return handleException(e, ErrConfMgr.ApiType.CHECK_OUT_RESOURCE);
}
}
}
|