Fix check style issues
[clamp.git] / src / main / java / org / onap / clamp / clds / model / DcaeEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.model;
25
26 import java.util.List;
27
28 import javax.ws.rs.BadRequestException;
29
30 /**
31  * Represent a DCAE Event.
32  */
33 public class DcaeEvent {
34     // this is an event we (clds) sends to dcae
35     public static final String EVENT_CREATED = "created";
36     public static final String EVENT_DISTRIBUTION = "distribute";
37     public static final String EVENT_DEPLOYMENT = "deployment";
38     public static final String EVENT_UNDEPLOYMENT = "undeployment";
39     public static final String ARTIFACT_NAME_SUFFIX = ".yml";
40
41     private String event;
42     private String serviceUuid;
43     private String resourceUuid;
44     private String artifactName; // controlName.yml
45     private List<CldsModelInstance> instances;
46
47     /**
48      * Transform a DCAE Event Action to a CldsEvent.actionCd.
49      *
50      * @return The clds action.
51      */
52     public String getCldsActionCd() {
53         if (event == null || event.length() == 0) {
54             throw new BadRequestException("action null or empty");
55         } else if (event.equalsIgnoreCase(EVENT_CREATED)) {
56             return CldsEvent.ACTION_CREATE;
57         } else if (event.equalsIgnoreCase(EVENT_DISTRIBUTION)) {
58             return CldsEvent.ACTION_DISTRIBUTE;
59         } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT) && (instances == null || instances.isEmpty())) {
60             return CldsEvent.ACTION_DEPLOY;
61         } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT)) {
62             return CldsEvent.ACTION_DEPLOY;
63             // EVENT_UNDEPLOYMENT is defunct - DCAE Proxy will not undeploy
64             // individual instances. It will send an empty list of
65             // deployed instances to indicate all have been removed. Or it will
66             // send an updated list to indicate those that
67             // are still deployed with any not on the list considered
68             // undeployed.
69         } else if (event.equals(EVENT_UNDEPLOYMENT)) {
70             return CldsEvent.ACTION_UNDEPLOY;
71         }
72
73         throw new BadRequestException("event value not valid: " + event);
74     }
75
76     /**
77      * Derive the controlName from the artifactName.
78      *
79      * @return the controlName
80      */
81     public String getControlName() {
82         if (artifactName != null && artifactName.endsWith(ARTIFACT_NAME_SUFFIX)) {
83             return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length());
84         } else {
85             throw new BadRequestException("artifactName value not valid (expecting it to end with "
86                 + ARTIFACT_NAME_SUFFIX + "): " + artifactName);
87         }
88     }
89
90     /**
91      * Get the event.
92      * @return the event
93      */
94     public String getEvent() {
95         return event;
96     }
97
98     /**
99      * Set the event.
100      * @param event
101      *        the event to set
102      */
103     public void setEvent(String event) {
104         this.event = event;
105     }
106
107     /**
108      * Get the serviceUUID.
109      * @return the serviceUUID
110      */
111     public String getServiceUUID() {
112         return serviceUuid;
113     }
114
115     /**
116      * Set the serviceUUID.
117      * @param serviceUUID
118      *        the serviceUUID to set
119      */
120     public void setServiceUUID(String serviceUuid) {
121         this.serviceUuid = serviceUuid;
122     }
123
124     /**
125      * Get the resourceUUID.
126      * @return the resourceUUID
127      */
128     public String getResourceUUID() {
129         return resourceUuid;
130     }
131
132     /**
133      * Set the resourceUUID.
134      * @param resourceUUID
135      *        the resourceUUID to set
136      */
137     public void setResourceUUID(String resourceUuid) {
138         this.resourceUuid = resourceUuid;
139     }
140
141     /**
142      * Get the artifact name.
143      * @return the artifactName
144      */
145     public String getArtifactName() {
146         return artifactName;
147     }
148
149     /**
150      * Set the artifact name.
151      * @param artifactName
152      *        the artifactName to set
153      */
154     public void setArtifactName(String artifactName) {
155         this.artifactName = artifactName;
156     }
157
158     /**
159      * Get the list of instances.
160      * @return The list of model instances
161      */
162     public List<CldsModelInstance> getInstances() {
163         return instances;
164     }
165
166     /**
167      * Set the list of model instances.
168      * @param instances The list of model instances to set
169      */
170     public void setInstances(List<CldsModelInstance> instances) {
171         this.instances = instances;
172     }
173 }