Merge "logstash input"
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsToscaModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 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 org.onap.clamp.clds.dao.CldsDao;
29
30 public class CldsToscaModel extends CldsToscaModelRevision {
31
32     private String id;
33     private String policyType;
34     private String toscaModelName;
35     private String toscaModelYaml;
36
37     /**
38      * Creates or updates Tosca Model to DB
39      *
40      * @param cldsDao
41      * @param userId
42      */
43     public CldsToscaModel save(CldsDao cldsDao, String userId) {
44         CldsToscaModel cldsToscaModel = null;
45         // TODO tosca parsing logic
46         this.setToscaModelJson("{}");
47         this.setPolicyType("Aging");// TODO update with subString or node_type from the model name
48         List<CldsToscaModel> toscaModels = cldsDao.getToscaModelByName(this.getToscaModelName());
49         if (toscaModels != null && !toscaModels.isEmpty()) {
50             CldsToscaModel toscaModel = toscaModels.stream().findFirst().get();
51             // CldsToscaModelRevision modelRevision =
52             // revisions.stream().max(Comparator.comparingDouble(CldsToscaModelRevision::getVersion)).get();
53             this.setVersion(incrementVersion(toscaModel.getVersion()));
54             this.setId(toscaModel.getId());
55             this.setUserId(userId);
56             cldsToscaModel = cldsDao.updateToscaModelWithNewVersion(this, userId);
57         } else {
58             this.setVersion(1);
59             cldsToscaModel = cldsDao.insToscaModel(this, userId);
60         }
61         return cldsToscaModel;
62     }
63
64     private double incrementVersion(double curVersion) {
65         return curVersion + 1;
66     }
67
68     /**
69      * @return the id
70      */
71     public String getId() {
72         return id;
73     }
74
75     /**
76      * @param id
77      *        the id to set
78      */
79     public void setId(String id) {
80         this.id = id;
81     }
82
83     /**
84      * @return the policyType
85      */
86     public String getPolicyType() {
87         return policyType;
88     }
89
90     /**
91      * @param policyType
92      *        the policyType to set
93      */
94     public void setPolicyType(String policyType) {
95         this.policyType = policyType;
96     }
97
98     /**
99      * @return the toscaModelName
100      */
101     public String getToscaModelName() {
102         return toscaModelName;
103     }
104
105     /**
106      * @param toscaModelName
107      *        the toscaModelName to set
108      */
109     public void setToscaModelName(String toscaModelName) {
110         this.toscaModelName = toscaModelName;
111     }
112
113     /**
114      * @return the toscaModelYaml
115      */
116     @Override
117     public String getToscaModelYaml() {
118         return toscaModelYaml;
119     }
120
121     /**
122      * @param toscaModelYaml
123      *        the toscaModelYaml to set
124      */
125     @Override
126     public void setToscaModelYaml(String toscaModelYaml) {
127         this.toscaModelYaml = toscaModelYaml;
128     }
129
130 }