2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorlicense.dao.types;
23 import com.datastax.driver.mapping.annotations.ClusteringColumn;
24 import com.datastax.driver.mapping.annotations.Column;
25 import com.datastax.driver.mapping.annotations.Enumerated;
26 import com.datastax.driver.mapping.annotations.Frozen;
27 import com.datastax.driver.mapping.annotations.PartitionKey;
28 import com.datastax.driver.mapping.annotations.Table;
29 import org.openecomp.sdc.vendorlicense.dao.types.xml.LicenseKeyTypeForXml;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
35 import java.util.Collection;
36 import java.util.HashSet;
37 import java.util.Objects;
40 @Table(keyspace = "dox", name = "license_key_group")
41 public class LicenseKeyGroupEntity implements VersionableEntity {
42 private static final String ENTITY_TYPE = "License Key Group";
45 @Column(name = "vlm_id")
46 private String vendorLicenseModelId;
47 @PartitionKey(value = 1)
49 private Version version;
51 @Column(name = "lkg_id")
54 private String description;
56 private LicenseKeyType type;
57 @Column(name = "operational_scope")
59 private MultiChoiceOrOther<OperationalScope> operationalScope;
60 @Column(name = "ref_fg_ids")
61 private Set<String> referencingFeatureGroups = new HashSet<>();
62 @Column(name = "version_uuid")
63 private String versionUuId;
65 private Collection<LimitEntity> limits;
67 public LicenseKeyGroupEntity() {
71 * Instantiates a new License key group entity.
73 * @param vendorLicenseModelId the vendor license model id
74 * @param version the version
77 public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
78 this.vendorLicenseModelId = vendorLicenseModelId;
79 this.version = version;
84 public String getEntityType() {
89 public String getFirstClassCitizenId() {
90 return getVendorLicenseModelId();
93 public String getId() {
97 public void setId(String id) {
101 public Version getVersion() {
105 public void setVersion(Version version) {
106 this.version = version;
110 public String getVersionUuId() {
115 public void setVersionUuId(String uuId) {
119 public String getVendorLicenseModelId() {
120 return vendorLicenseModelId;
123 public void setVendorLicenseModelId(String vendorLicenseModelId) {
124 this.vendorLicenseModelId = vendorLicenseModelId;
127 public String getName() {
131 public void setName(String name) {
135 public String getDescription() {
139 public void setDescription(String description) {
140 this.description = description;
143 public LicenseKeyType getType() {
147 public void setType(LicenseKeyType type) {
151 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
152 return operationalScope;
155 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
156 if(operationalScope != null) {
157 operationalScope.resolveEnum(OperationalScope.class);
159 this.operationalScope = operationalScope;
162 public Set<String> getReferencingFeatureGroups() {
163 return referencingFeatureGroups;
166 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
167 this.referencingFeatureGroups = referencingFeatureGroups;
170 public Collection<LimitEntity> getLimits() {
174 public void setLimits(Collection<LimitEntity> limits) {
175 this.limits = limits;
178 public LimitForXml getSPLimits(){
180 Set<LimitXml> hs = new HashSet<>();
181 for(LimitEntity obj : limits){
182 if(obj.getType().equals(LimitType.ServiceProvider)){
183 LimitXml xmlObj = new LimitXml();
184 xmlObj.setDescription(obj.getDescription());
185 xmlObj.setMetric(obj.getMetric().toString());
186 xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
187 xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
188 xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
189 xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
193 LimitForXml spLimitForXml = new LimitForXml();
194 spLimitForXml.setLimits(hs);
195 return spLimitForXml;
201 public LimitForXml getVendorLimits(){
203 Set<LimitXml> hs = new HashSet<>();
204 for(LimitEntity obj : limits){
205 if(obj.getType().equals(LimitType.Vendor)){
206 LimitXml xmlObj = new LimitXml();
207 xmlObj.setDescription(obj.getDescription());
208 xmlObj.setMetric(obj.getMetric().toString());
209 xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
210 xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
211 xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
212 xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
216 LimitForXml vendorLimitForXml = new LimitForXml();
217 vendorLimitForXml.setLimits(hs);
218 return vendorLimitForXml;
225 public int hashCode() {
227 .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
228 referencingFeatureGroups);
232 public boolean equals(Object obj) {
236 if (obj == null || getClass() != obj.getClass()) {
239 LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
240 return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
241 && Objects.equals(id, that.id)
242 && Objects.equals(name, that.name)
243 && Objects.equals(description, that.description)
245 && Objects.equals(operationalScope, that.operationalScope)
246 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups);
250 public String toString() {
251 return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
252 + ", version=" + version
253 + ", id='" + id + '\''
254 + ", name='" + name + '\''
255 + ", description='" + description + '\''
257 + ", operationalScope=" + operationalScope
258 + ", referencingFeatureGroups=" + referencingFeatureGroups
259 + ", versionUuId='" + versionUuId + '\''
264 * Gets operational scope for artifact.
266 * @return the operational scope for artifact
268 public Set<String> getOperationalScopeForArtifact() {
269 if (operationalScope != null) {
270 return operationalScope.getResults();
277 * Gets version for artifact.
278 * @return version in format suitable for artifact
280 public String getVersionForArtifact() {
281 return version.toString();
285 * Gets type for artifact.
287 * @return the type for artifact
289 public LicenseKeyTypeForXml getTypeForArtifact() {
290 LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
292 typeXml.setValue(type.toString());
294 typeXml.setValue(null);