2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.model;
26 import java.util.List;
28 import org.onap.clamp.clds.dao.CldsDao;
30 public class CldsToscaModel extends CldsToscaModelRevision {
33 private String policyType;
34 private String toscaModelName;
35 private String toscaModelYaml;
38 * Creates or updates Tosca Model to DB
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);
59 cldsToscaModel = cldsDao.insToscaModel(this, userId);
61 return cldsToscaModel;
64 private double incrementVersion(double curVersion) {
65 return curVersion + 1;
71 public String getId() {
79 public void setId(String id) {
84 * @return the policyType
86 public String getPolicyType() {
92 * the policyType to set
94 public void setPolicyType(String policyType) {
95 this.policyType = policyType;
99 * @return the toscaModelName
101 public String getToscaModelName() {
102 return toscaModelName;
106 * @param toscaModelName
107 * the toscaModelName to set
109 public void setToscaModelName(String toscaModelName) {
110 this.toscaModelName = toscaModelName;
114 * @return the toscaModelYaml
117 public String getToscaModelYaml() {
118 return toscaModelYaml;
122 * @param toscaModelYaml
123 * the toscaModelYaml to set
126 public void setToscaModelYaml(String toscaModelYaml) {
127 this.toscaModelYaml = toscaModelYaml;