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.apache.commons.lang3.StringUtils;
 
  30 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
 
  31 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
 
  32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LicenseKeyTypeForXml;
 
  33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
 
  34 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
 
  35 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
 
  36 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
 
  37 import org.openecomp.sdc.versioning.dao.types.Version;
 
  38 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
 
  40 import java.util.Collection;
 
  41 import java.util.HashSet;
 
  42 import java.util.Objects;
 
  45 @Table(keyspace = "dox", name = "license_key_group")
 
  46 public class LicenseKeyGroupEntity implements VersionableEntity {
 
  48   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
 
  49   private static final String ENTITY_TYPE = "License Key Group";
 
  52   @Column(name = "vlm_id")
 
  53   private String vendorLicenseModelId;
 
  54   @PartitionKey(value = 1)
 
  56   private Version version;
 
  58   @Column(name = "lkg_id")
 
  61   private String description;
 
  63   private LicenseKeyType type;
 
  64   @Column(name = "operational_scope")
 
  66   private MultiChoiceOrOther<OperationalScope> operationalScope;
 
  67   @Column(name = "ref_fg_ids")
 
  68   private Set<String> referencingFeatureGroups = new HashSet<>();
 
  69   @Column(name = "version_uuid")
 
  70   private String versionUuId;
 
  71   private Integer thresholdValue;
 
  72   private ThresholdUnit thresholdUnits;
 
  73   private String increments;
 
  75   private Collection<LimitEntity> limits;
 
  76   private String startDate;
 
  77   private String expiryDate;
 
  79   //Defined and used only for License Artifcat XMLs
 
  80   private String manufacturerReferenceNumber;
 
  83   public LicenseKeyGroupEntity() {
 
  87    * Instantiates a new License key group entity.
 
  89    * @param vendorLicenseModelId the vendor license model id
 
  90    * @param version              the version
 
  93   public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
 
  94     this.vendorLicenseModelId = vendorLicenseModelId;
 
  95     this.version = version;
 
 100   public String getEntityType() {
 
 105   public String getFirstClassCitizenId() {
 
 106     return getVendorLicenseModelId();
 
 109   public String getId() {
 
 113   public void setId(String id) {
 
 117   public Version getVersion() {
 
 121   public void setVersion(Version version) {
 
 122     this.version = version;
 
 126   public String getVersionUuId() {
 
 131   public void setVersionUuId(String uuId) {
 
 135   public String getVendorLicenseModelId() {
 
 136     return vendorLicenseModelId;
 
 139   public void setVendorLicenseModelId(String vendorLicenseModelId) {
 
 140     this.vendorLicenseModelId = vendorLicenseModelId;
 
 143   public String getName() {
 
 147   public void setName(String name) {
 
 151   public String getDescription() {
 
 155   public void setDescription(String description) {
 
 156     this.description = description;
 
 159   public LicenseKeyType getType() {
 
 163   public void setType(LicenseKeyType type) {
 
 167   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
 
 168     return operationalScope;
 
 171   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
 
 172     if (operationalScope != null) {
 
 173       operationalScope.resolveEnum(OperationalScope.class);
 
 175     this.operationalScope = operationalScope;
 
 178   public Set<String> getReferencingFeatureGroups() {
 
 179     return referencingFeatureGroups;
 
 182   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
 
 183     this.referencingFeatureGroups = referencingFeatureGroups;
 
 186   public Integer getThresholdValue() {
 
 187     return thresholdValue;
 
 190   public void setThresholdValue(Integer thresholdValue) {
 
 191     this.thresholdValue = thresholdValue;
 
 194   public ThresholdUnit getThresholdUnits() {
 
 195     return thresholdUnits;
 
 198   public void setThresholdUnits(ThresholdUnit thresholdUnit) {
 
 199     this.thresholdUnits = thresholdUnit;
 
 202   public String getIncrements() {
 
 206   public void setIncrements(String increments) {
 
 207     this.increments = increments;
 
 210   public ThresholdForXml getThresholdForArtifact() {
 
 211     ThresholdForXml threshold = new ThresholdForXml();
 
 212     threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
 
 213     threshold.setValue(getThresholdValue());
 
 217   public Collection<LimitEntity> getLimits() {
 
 221   public void setLimits(Collection<LimitEntity> limits) {
 
 222     this.limits = limits;
 
 225   public LimitForXml getSPLimits() {
 
 226     if (limits != null) {
 
 227       Set<LimitXml> hs = new HashSet<>();
 
 228       for (LimitEntity obj : limits) {
 
 229         if (obj.getType().equals(LimitType.ServiceProvider)) {
 
 230           LimitXml xmlObj = new LimitXml();
 
 231           xmlObj.setDescription(obj.getDescription());
 
 232           xmlObj.setMetric(obj.getMetric());
 
 233           xmlObj.setValues(obj.getValue());
 
 234           xmlObj.setUnit(obj.getUnit());
 
 235           xmlObj.setAggregationFunction(
 
 236               obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
 
 237           xmlObj.setTime(obj.getTime());
 
 241       LimitForXml spLimitForXml = new LimitForXml();
 
 242       spLimitForXml.setLimits(hs);
 
 243       return spLimitForXml;
 
 249   public LimitForXml getVendorLimits() {
 
 250     if (limits != null) {
 
 251       Set<LimitXml> hs = new HashSet<>();
 
 252       for (LimitEntity obj : limits) {
 
 253         if (obj.getType().equals(LimitType.Vendor)) {
 
 254           LimitXml xmlObj = new LimitXml();
 
 255           xmlObj.setDescription(obj.getDescription());
 
 256           xmlObj.setMetric(obj.getMetric());
 
 257           xmlObj.setValues(obj.getValue());
 
 258           xmlObj.setUnit(obj.getUnit());
 
 259           xmlObj.setAggregationFunction(
 
 260               obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
 
 261           xmlObj.setTime(obj.getTime());
 
 265       LimitForXml vendorLimitForXml = new LimitForXml();
 
 266       vendorLimitForXml.setLimits(hs);
 
 267       return vendorLimitForXml;
 
 273   public String getStartDate() {
 
 277   public void setStartDate(String startDate) {
 
 278     this.startDate = startDate;
 
 281   public String getExpiryDate() {
 
 285   public void setExpiryDate(String expiryDate) {
 
 286     this.expiryDate = expiryDate;
 
 290   public int hashCode() {
 
 292         .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
 
 293             referencingFeatureGroups, startDate, expiryDate,
 
 294             thresholdValue, thresholdUnits, increments);
 
 298   public boolean equals(Object obj) {
 
 302     if (obj == null || getClass() != obj.getClass()) {
 
 305     LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
 
 306     return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
 
 307         && Objects.equals(version, that.version)
 
 308         && Objects.equals(id, that.id)
 
 309         && Objects.equals(name, that.name)
 
 310         && Objects.equals(description, that.description)
 
 312         && Objects.equals(operationalScope, that.operationalScope)
 
 313         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
 
 314         && Objects.equals(startDate, that.startDate)
 
 315         && Objects.equals(expiryDate, that.expiryDate)
 
 316         && Objects.equals(thresholdValue, that.thresholdValue)
 
 317         && Objects.equals(thresholdUnits, that.thresholdUnits)
 
 318         && Objects.equals(increments, that.increments)
 
 319         && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber);
 
 323   public String toString() {
 
 324     return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
 
 325         + ", version=" + version
 
 326         + ", id='" + id + '\''
 
 327         + ", name='" + name + '\''
 
 328         + ", description='" + description + '\''
 
 330         + ", operationalScope=" + operationalScope
 
 331         + ", referencingFeatureGroups=" + referencingFeatureGroups
 
 332         + ", versionUuId='" + versionUuId + '\''
 
 333         + ", startDate=" + startDate
 
 334         + ", expiryDate=" + expiryDate
 
 335         + ", thresholdValue='" + thresholdValue + '\''
 
 336         + ", thresholdUnits='" + thresholdUnits + '\''
 
 337         + ", increments='" + increments + '\''
 
 342    * Gets operational scope for artifact.
 
 344    * @return the operational scope for artifact
 
 346   public OperationalScopeForXml getOperationalScopeForArtifact() {
 
 347     OperationalScopeForXml obj = new OperationalScopeForXml();
 
 348     if (operationalScope != null) {
 
 349       if (operationalScope.getResults().size() > 0) {
 
 350         obj.setValue(operationalScope.getResults());
 
 357    * Gets version for artifact.
 
 359    * @return version in format suitable for artifact
 
 361   public String getVersionForArtifact() {
 
 362     return version.toString();
 
 366    * Gets type for artifact.
 
 368    * @return the type for artifact
 
 370   public LicenseKeyTypeForXml getTypeForArtifact() {
 
 371     LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
 
 373       typeXml.setValue(type.toString());
 
 375       typeXml.setValue(null);
 
 380   //Defined and used only for License Artifcat XMLs
 
 381   public String getManufacturerReferenceNumber() {
 
 382     return manufacturerReferenceNumber;
 
 385   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
 
 386     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
 
 389   public String getIsoFormatStartDate() {
 
 390     mdcDataDebugMessage.debugEntryMessage("start date", startDate);
 
 391     String isoFormatStartDate = null;
 
 392     if (!StringUtils.isEmpty(startDate)) {
 
 393       isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
 
 394       mdcDataDebugMessage.debugExitMessage("start date", "iso format start date", startDate,
 
 397     return isoFormatStartDate;
 
 401   public String getIsoFormatExpiryDate() {
 
 402     mdcDataDebugMessage.debugEntryMessage("expiry date", expiryDate);
 
 403     String isoFormatExpDate = null;
 
 404     if (!StringUtils.isEmpty(expiryDate)) {
 
 405       isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
 
 406       mdcDataDebugMessage.debugExitMessage("expiry date", "iso format expiry date", expiryDate,
 
 409     return isoFormatExpDate;