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.Frozen;
 
  26 import com.datastax.driver.mapping.annotations.PartitionKey;
 
  27 import com.datastax.driver.mapping.annotations.Table;
 
  29 import org.apache.commons.lang3.StringUtils;
 
  30 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
 
  31 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
 
  32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
 
  33 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
 
  34 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
 
  35 import org.openecomp.sdc.versioning.dao.types.Version;
 
  36 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
 
  38 import java.util.Collection;
 
  39 import java.util.HashSet;
 
  40 import java.util.Objects;
 
  43 @Table(keyspace = "dox", name = "entitlement_pool")
 
  44 public class EntitlementPoolEntity implements VersionableEntity {
 
  45   private static final String ENTITY_TYPE = "Entitlement Pool";
 
  48   @Column(name = "vlm_id")
 
  49   private String vendorLicenseModelId;
 
  51   @PartitionKey(value = 1)
 
  53   private Version version;
 
  56   @Column(name = "ep_id")
 
  59   private String description;
 
  61   @Column(name = "threshold")
 
  62   private Integer thresholdValue;
 
  64   @Column(name = "threshold_unit")
 
  65   private ThresholdUnit thresholdUnit;
 
  67   private String increments;
 
  69   @Column(name = "operational_scope")
 
  71   private MultiChoiceOrOther<OperationalScope> operationalScope;
 
  73   @Column(name = "ref_fg_ids")
 
  74   private Set<String> referencingFeatureGroups = new HashSet<>();
 
  76   @Column(name = "version_uuid")
 
  77   private String versionUuId;
 
  80   private String startDate;
 
  81   private String expiryDate;
 
  83   private Collection<LimitEntity> limits;
 
  85   //Defined and used only for License Artifcat XMLs
 
  86   private String manufacturerReferenceNumber;
 
  89    * Every entity class must have a default constructor according to
 
  90    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
 
  91    * Definition of mapped classes</a>.
 
  93   public EntitlementPoolEntity() {
 
  94     // Don't delete! Default constructor is required by DataStax driver
 
  98    * Instantiates a new Entitlement pool entity.
 
 100    * @param vlmId   the vlm id
 
 101    * @param version the version
 
 104   public EntitlementPoolEntity(String vlmId, Version version, String id) {
 
 105     this.vendorLicenseModelId = vlmId;
 
 106     this.version = version;
 
 111   public String getEntityType() {
 
 116   public String getFirstClassCitizenId() {
 
 117     return getVendorLicenseModelId();
 
 121   public String getId() {
 
 126   public void setId(String id) {
 
 131   public Version getVersion() {
 
 136   public void setVersion(Version version) {
 
 137     this.version = version;
 
 141   public String getVersionUuId() {
 
 146   public void setVersionUuId(String uuId) {
 
 150   public String getVendorLicenseModelId() {
 
 151     return vendorLicenseModelId;
 
 154   public void setVendorLicenseModelId(String vendorLicenseModelId) {
 
 155     this.vendorLicenseModelId = vendorLicenseModelId;
 
 158   public Set<String> getReferencingFeatureGroups() {
 
 159     return referencingFeatureGroups;
 
 162   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
 
 163     this.referencingFeatureGroups = referencingFeatureGroups;
 
 166   public String getName() {
 
 170   public void setName(String name) {
 
 174   public String getDescription() {
 
 178   public void setDescription(String description) {
 
 179     this.description = description;
 
 182   public Integer getThresholdValue() {
 
 183     return thresholdValue;
 
 186   public void setThresholdValue(Integer thresholdValue) {
 
 187     this.thresholdValue = thresholdValue;
 
 190   public ThresholdUnit getThresholdUnit() {
 
 191     return thresholdUnit;
 
 194   public void setThresholdUnit(ThresholdUnit thresholdUnits) {
 
 195     this.thresholdUnit = thresholdUnits;
 
 198   public String getIncrements() {
 
 202   public void setIncrements(String increments) {
 
 203     this.increments = increments;
 
 206   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
 
 207     return operationalScope;
 
 210   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
 
 211     if (operationalScope != null) {
 
 212       operationalScope.resolveEnum(OperationalScope.class);
 
 214     this.operationalScope = operationalScope;
 
 218    * Gets threshold for artifact.
 
 220    * @return the threshold for artifact
 
 222   public ThresholdForXml getThresholdForArtifact() {
 
 223     ThresholdForXml threshold = new ThresholdForXml();
 
 224     threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
 
 225     threshold.setValue(getThresholdValue());
 
 230    * Gets version for artifact.
 
 232    * @return version in format suitable for artifact
 
 234   public String getVersionForArtifact() {
 
 235     return version.toString();
 
 238   public String getStartDate() {
 
 242   public void setStartDate(String startDate) {
 
 243     this.startDate = startDate;
 
 246   public String getExpiryDate() {
 
 250   public void setExpiryDate(String expiryDate) {
 
 251     this.expiryDate = expiryDate;
 
 254   public Collection<LimitEntity> getLimits() {
 
 258   public void setLimits(Collection<LimitEntity> limits) {
 
 259     this.limits = limits;
 
 262   public LimitForXml getSPLimits() {
 
 263     if (limits != null) {
 
 264       Set<LimitXml> hs = new HashSet<>();
 
 265       for (LimitEntity obj : limits) {
 
 266         if (obj.getType().equals(LimitType.ServiceProvider)) {
 
 267           LimitXml xmlObj = new LimitXml();
 
 268           xmlObj.setDescription(obj.getDescription());
 
 269           xmlObj.setMetric(obj.getMetric());
 
 270           xmlObj.setValues(obj.getValue());
 
 271           xmlObj.setUnit(obj.getUnit());
 
 272           xmlObj.setAggregationFunction(
 
 273               obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
 
 274           xmlObj.setTime(obj.getTime());
 
 278       LimitForXml spLimitForXml = new LimitForXml();
 
 279       spLimitForXml.setLimits(hs);
 
 280       return spLimitForXml;
 
 286   public LimitForXml getVendorLimits() {
 
 287     if (limits != null) {
 
 288       Set<LimitXml> hs = new HashSet<>();
 
 289       for (LimitEntity obj : limits) {
 
 290         if (obj.getType().equals(LimitType.Vendor)) {
 
 291           LimitXml xmlObj = new LimitXml();
 
 292           xmlObj.setDescription(obj.getDescription());
 
 293           xmlObj.setMetric(obj.getMetric());
 
 294           xmlObj.setValues(obj.getValue());
 
 295           xmlObj.setUnit(obj.getUnit());
 
 296           xmlObj.setAggregationFunction(
 
 297               obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
 
 298           xmlObj.setTime(obj.getTime());
 
 302       LimitForXml vendorLimitForXml = new LimitForXml();
 
 303       vendorLimitForXml.setLimits(hs);
 
 304       return vendorLimitForXml;
 
 312   public int hashCode() {
 
 314         .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
 
 315             increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
 
 319   public boolean equals(Object obj) {
 
 323     if (obj == null || getClass() != obj.getClass()) {
 
 326     EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
 
 327     return Objects.equals(that.thresholdValue, thresholdValue)
 
 328         && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
 
 329         && Objects.equals(id, that.id)
 
 330         && Objects.equals(name, that.name)
 
 331         && Objects.equals(description, that.description)
 
 332         && Objects.equals(thresholdUnit, that.thresholdUnit)
 
 333         && Objects.equals(increments, that.increments)
 
 334         && Objects.equals(that.operationalScope, operationalScope)
 
 335         && Objects.equals(startDate, that.startDate)
 
 336         && Objects.equals(expiryDate, that.expiryDate)
 
 337         && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
 
 338         && Objects.equals(version, that.version);
 
 342   public String toString() {
 
 343     return "EntitlementPoolEntity{"
 
 344         + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
 
 345         + ", version=" + version
 
 346         + ", id='" + id + '\''
 
 347         + ", name='" + name + '\''
 
 348         + ", description='" + description + '\''
 
 349         + ", thresholdValue=" + thresholdValue
 
 350         + ", thresholdUnit='" + thresholdUnit + '\''
 
 351         + ", increments='" + increments + '\''
 
 352         + ", operationalScope=" + operationalScope
 
 353         + ", referencingFeatureGroups=" + referencingFeatureGroups
 
 354         + ", version_uuid=" + versionUuId
 
 355         + ", startDate=" + startDate
 
 356         + ", expiryDate=" + expiryDate
 
 361    * Gets operational scope for artifact.
 
 363    * @return the operational scope for artifact
 
 365   public OperationalScopeForXml getOperationalScopeForArtifact() {
 
 366     OperationalScopeForXml obj = new OperationalScopeForXml();
 
 367     if (operationalScope != null) {
 
 368       if (operationalScope.getResults().size() > 0) {
 
 369         obj.setValue(operationalScope.getResults());
 
 375   //Defined and used only for License Artifcat XMLs
 
 376   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
 
 377     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
 
 380   public String getManufacturerReferenceNumber() {
 
 381     return manufacturerReferenceNumber;
 
 384   public String getIsoFormatStartDate() {
 
 385     String isoFormatStartDate = null;
 
 386     if (!StringUtils.isEmpty(startDate)) {
 
 387       isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
 
 389     return isoFormatStartDate;
 
 393   public String getIsoFormatExpiryDate() {
 
 394     String isoFormatExpDate = null;
 
 395     if (!StringUtils.isEmpty(expiryDate)) {
 
 396       isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
 
 398     return isoFormatExpDate;