Commit c3c44d43 authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Merge branch...

Merge branch '30-update-model-to-support-fix-https-labs-etsi-org-rep-osl-code-org-etsi-osl-tmf-api-issues-92' into 'develop'

Resolve "update model to support fix org.etsi.osl.tmf.api#92"

See merge request !35
parents 6646b2fc ff701493
Loading
Loading
Loading
Loading
Loading
+115 −0
Original line number Diff line number Diff line
@@ -19,12 +19,18 @@
 */
package org.etsi.osl.tmf.pcm620.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.etsi.osl.tmf.common.model.BaseEntity;
import org.etsi.osl.tmf.scm633.model.ServiceSpecCharRelationship;
import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristicValue;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.CascadeType;
@@ -379,4 +385,113 @@ public class ProductSpecificationCharacteristic extends BaseEntity {
		}
		return o.toString().replace("\n", "\n    ");
	}

  public void updateWith(ProductSpecificationCharacteristic src) {
    this.name = src.getName();
    this.description = src.getDescription();
    this.maxCardinality = src.getMaxCardinality();
    this.minCardinality = src.getMinCardinality();
    this.regex = src.getRegex();
    this.isUnique =src.isUnique;
    this.configurable =src.isConfigurable();
    this.extensible =src.isExtensible();
    this.valueType =src.valueType;

    this.updateProductSpecCharacteristicValues(src.getProductSpecCharacteristicValue());
    this.updateProductSpecCharRelationships(src.getProductSpecCharRelationship());

  }


  private void updateProductSpecCharacteristicValues(
      @Valid Set<ProductSpecificationCharacteristicValue> srcSet) {
    if ( srcSet == null ) {
      return;
    }
    
    Map<Integer, Boolean> idAddedUpdated = new HashMap<>();
    /**
     * update, add the incomings
     */
    for (ProductSpecificationCharacteristicValue r : srcSet) {
  
        boolean valueExists = false;
        for (ProductSpecificationCharacteristicValue thisCharVal : this.productSpecCharacteristicValue) {
            if ( thisCharVal.hashCode() == r.hashCode() ) {
                valueExists = true;
                idAddedUpdated.put(thisCharVal.hashCode(), true);
                break;
            }
        }
        
        if (!valueExists) {
            ProductSpecificationCharacteristicValue nr = new ProductSpecificationCharacteristicValue( r );
            this.addProductSpecCharacteristicValueItem( nr );
            idAddedUpdated.put( nr.hashCode(), true);
        }
        
    }
    
    /**
     * remove those that don't exist anymore
     */
    
    List<ProductSpecificationCharacteristicValue> toRemove = new ArrayList<>();
    for (ProductSpecificationCharacteristicValue ss : this.productSpecCharacteristicValue) {
        if ( idAddedUpdated.get( ss.hashCode() ) == null ) {
            toRemove.add(ss);
        }
    }
    
    for (ProductSpecificationCharacteristicValue r : toRemove) {
        this.productSpecCharacteristicValue.remove(r);
    }
    
    
  }
  

  private void updateProductSpecCharRelationships(
      @Valid Set<ProductSpecificationCharacteristicRelationship> productSpecCharRelationship2) {
    
    
    Map< String, Boolean> idAddedUpdated = new HashMap<>();
    /**
     * update, add the incomings
     */
    for (ProductSpecificationCharacteristicRelationship r : productSpecCharRelationship2) {

        boolean valueExists = false;
        for (ProductSpecificationCharacteristicRelationship thisCharVal : this.productSpecCharRelationship) {
            if ( (thisCharVal.getId()!=null) && (thisCharVal.getId().equals(r.getId() ) )) {
                valueExists = true;
                idAddedUpdated.put( thisCharVal.getId() , true);
                break;
            }
        }
        
        if (!valueExists) {
            this.productSpecCharRelationship.add( r.getNewProductSpecificationCharacteristicRelationship( r ));
            idAddedUpdated.put( r.getId(), true);
        }
        
    }
    
    /**
     * remove those that don't exist anymore
     */
    
    List<ProductSpecificationCharacteristicRelationship> toRemove = new ArrayList<>();
    for (ProductSpecificationCharacteristicRelationship ss : this.productSpecCharRelationship) {
        if ( idAddedUpdated.get( ss.getId() ) == null ) {
            toRemove.add(ss);
        }
    }
    
    for (ProductSpecificationCharacteristicRelationship r : toRemove) {
        this.productSpecCharRelationship.remove(r);
    }
    
  }

}
+13 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.etsi.osl.tmf.common.model.BaseEntity;
import org.etsi.osl.tmf.common.model.TimePeriod;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Entity;
@@ -50,6 +51,18 @@ public class ProductSpecificationCharacteristicRelationship extends BaseEntity
  private String relationshipType = null;


  
  public ProductSpecificationCharacteristicRelationship getNewProductSpecificationCharacteristicRelationship(
      ProductSpecificationCharacteristicRelationship src) {
    ProductSpecificationCharacteristicRelationship newp = new ProductSpecificationCharacteristicRelationship();
    newp.name = src.name;
    newp.relationshipType = src.relationshipType;
    newp.validFor = new TimePeriod( src.validFor );
    newp.id = src.id;
    
    return newp;
  }

  public ProductSpecificationCharacteristicRelationship id(String id) {
    this.id = id;
    return this;