All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.symphony.oss.models.fundmental.canon.SecurityContextMemberKeysEntity Maven / Gradle / Ivy

/**
 * GENERATED CODE - DO NOT EDIT OR CHECK IN TO SOURCE CODE CONTROL
 *
 * Copyright 2020 Symphony Communication Services, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------------------------------
 * Generated from
 *    Input source         file:/Users/bruce/symphony/git-SymphonyOSF/oss-models/target/checkout/fundamental-model/src/main/resources/canon/fundamental.json
 *    Template groupId     org.symphonyoss.s2.canon
 *           artifactId    canon-template-java
 *    Template name        template/java/Object/_Entity.java.ftl
 *    At                   2020-01-28 16:55:36 GMT
 *----------------------------------------------------------------------------------------------------
 */

package com.symphony.oss.models.fundmental.canon;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.symphonyoss.s2.common.immutable.ImmutableByteArray;

import org.symphonyoss.s2.canon.runtime.IEntity;
import org.symphonyoss.s2.canon.runtime.IModelRegistry;
import org.symphonyoss.s2.canon.runtime.CanonRuntime;
import org.symphonyoss.s2.canon.runtime.Entity;
import org.symphonyoss.s2.canon.runtime.EntityBuilder;
import org.symphonyoss.s2.canon.runtime.EntityFactory;
import org.symphonyoss.s2.canon.runtime.IBuilderFactory;

import org.symphonyoss.s2.common.type.provider.IBooleanProvider;
import org.symphonyoss.s2.common.type.provider.IStringProvider;
import org.symphonyoss.s2.common.type.provider.IIntegerProvider;
import org.symphonyoss.s2.common.type.provider.ILongProvider;
import org.symphonyoss.s2.common.type.provider.IFloatProvider;
import org.symphonyoss.s2.common.type.provider.IDoubleProvider;
import org.symphonyoss.s2.common.type.provider.IImmutableByteArrayProvider;
import org.symphonyoss.s2.common.dom.json.IJsonDomNode;
import org.symphonyoss.s2.common.dom.json.IImmutableJsonDomNode;
import org.symphonyoss.s2.common.dom.json.ImmutableJsonList;
import org.symphonyoss.s2.common.dom.json.ImmutableJsonSet;
import org.symphonyoss.s2.common.dom.json.ImmutableJsonObject;
import org.symphonyoss.s2.common.dom.json.MutableJsonList;
import org.symphonyoss.s2.common.dom.json.MutableJsonSet;
import org.symphonyoss.s2.common.dom.json.MutableJsonObject;
import org.symphonyoss.s2.common.dom.json.JsonArray;
import org.symphonyoss.s2.common.dom.json.JsonList;
import org.symphonyoss.s2.common.dom.json.JsonSet;

import java.util.HashSet;
import java.util.List;
import java.util.LinkedList;
import java.util.Set;
import java.util.Iterator;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.LinkedList;
import com.google.common.collect.ImmutableList;
import org.symphonyoss.s2.common.immutable.ImmutableByteArray;
import org.symphonyoss.s2.common.hash.Hash;
import com.symphony.oss.models.fundamental.canon.facade.*;
import com.symphony.oss.models.crypto.canon.facade.*;
import com.symphony.oss.models.crypto.canon.*;
import com.symphony.oss.models.core.canon.facade.*;
import com.symphony.oss.models.core.canon.*;

/**
 * Object ObjectSchema(SecurityContextMemberKeys)
 *
 * wrappedKey is the SecurityContext SecretKey wrapped by the member's Public ExchangeKey. encryptedKey is the SecurityContext SecretKey encrypted with the member's AccountSecretKey. This may be added as an update by the member as a performance optimization.
 * Generated from ObjectSchema(SecurityContextMemberKeys) at #/components/schemas/SecurityContextMemberKeys
 */
@Immutable
@SuppressWarnings("unused")
public abstract class SecurityContextMemberKeysEntity extends VersionedObject
 implements ISecurityContextMemberKeys, IFundamentalModelEntity
{
  /** Type ID */
  public static final String  TYPE_ID = "com.symphony.s2.model.fundamental.SecurityContextMemberKeys";
  /** Type version */
  public static final String  TYPE_VERSION = "1.0";
  /** Type major version */
  public static final Integer TYPE_MAJOR_VERSION = 1;
  /** Type minor version */
  public static final Integer TYPE_MINOR_VERSION = 0;
  /** Factory instance */
  public static final Factory FACTORY = new Factory();
  
  /**
   *  Builder factory instance
   *
   *  @deprecated use new SecurityContextMemberKeys.Builder() or new SecurityContextMemberKeys.Builder(ISecurityContextMemberKeysEntity) 
   */
  @Deprecated
  public static final IBuilderFactory BUILDER = new BuilderFactory();

  private final ImmutableSet        unknownKeys_;
  private final Hash                       _securityContextHash_;
  private final Hash                       _memberExchangeKeyHash_;
  private final WrappedKey                 _wrappedKey_;
  private final WrappedKey                 _encryptedKey_;
  private final Integer                    _kdfVersion_;
  private final ImmutableByteArray         _keyId_;
  private final EncodedSignature           _relaySignature_;
  private final Integer                    _version_;

  /**
   * Constructor from builder.
   * 
   * @param builder A mutable builder containing all values.
   */
  public SecurityContextMemberKeysEntity(SecurityContextMemberKeys.AbstractSecurityContextMemberKeysBuilder builder)
  {
    super(builder);
    
    _securityContextHash_ = builder.getSecurityContextHash();

    _memberExchangeKeyHash_ = builder.getMemberExchangeKeyHash();

    _wrappedKey_ = builder.getWrappedKey();

 
    _encryptedKey_ = builder.getEncryptedKey();

 
    _kdfVersion_ = builder.getKdfVersion();

 
    _keyId_ = builder.getKeyId();

 
    _relaySignature_ = builder.getRelaySignature();

 
    _version_ = builder.getVersion();

 


    unknownKeys_ = ImmutableSet.of();
  }
  
  /**
   * Set the _type attribute of the given mutable JSON object to the type ID of this type if it is null and
   * return an immutable copy.
   *
   * @param mutableJsonObject A mutable JSON Object.
   *
   * @return An immutable copy of the given object with the _type attribute set.
   */
  public static ImmutableJsonObject setType(MutableJsonObject mutableJsonObject)
  {
    if(mutableJsonObject.get(CanonRuntime.JSON_TYPE) == null)
      mutableJsonObject.addIfNotNull(CanonRuntime.JSON_TYPE, TYPE_ID);
    
    return mutableJsonObject.immutify();
  }
  
  /**
   * Constructor from mutable JSON object.
   * 
   * @param mutableJsonObject A mutable JSON object containing the serialized form of the object.
   * @param modelRegistry A model registry to use to deserialize any nested objects.
   */
  public SecurityContextMemberKeysEntity(MutableJsonObject mutableJsonObject, IModelRegistry modelRegistry)
  {
    this(setType(mutableJsonObject), modelRegistry);
  }
   
  /**
   * Constructor from serialised form.
   * 
   * @param jsonObject An immutable JSON object containing the serialized form of the object.
   * @param modelRegistry A model registry to use to deserialize any nested objects.
   */
  public SecurityContextMemberKeysEntity(ImmutableJsonObject jsonObject, IModelRegistry modelRegistry)
  {
    super(jsonObject, modelRegistry);
    
    if(jsonObject == null)
      throw new IllegalArgumentException("jsonObject is required");
  
    Set keySet = new HashSet<>(super.getCanonUnknownKeys());
    
    if(keySet.remove("securityContextHash"))
    {
      IJsonDomNode  node = jsonObject.get("securityContextHash");
      if(node instanceof IImmutableByteArrayProvider)
      {
        ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

        try
        {
          _securityContextHash_ = Hash.build(value);
        }
        catch(RuntimeException e)
        {
            throw new IllegalArgumentException("Value \"" + value + "\" for securityContextHash is not a valid value", e);
        }
      }
      else 
      {
          throw new IllegalArgumentException("securityContextHash must be an instance of ImmutableByteArray not " + node.getClass().getName());
      }     
    }
    else
    {
      _securityContextHash_ = null;
    }
    if(keySet.remove("memberExchangeKeyHash"))
    {
      IJsonDomNode  node = jsonObject.get("memberExchangeKeyHash");
      if(node instanceof IImmutableByteArrayProvider)
      {
        ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

        try
        {
          _memberExchangeKeyHash_ = Hash.build(value);
        }
        catch(RuntimeException e)
        {
            throw new IllegalArgumentException("Value \"" + value + "\" for memberExchangeKeyHash is not a valid value", e);
        }
      }
      else 
      {
          throw new IllegalArgumentException("memberExchangeKeyHash must be an instance of ImmutableByteArray not " + node.getClass().getName());
      }     
    }
    else
    {
      _memberExchangeKeyHash_ = null;
    }
    if(keySet.remove("wrappedKey"))
    {
      IJsonDomNode  node = jsonObject.get("wrappedKey");
      if(node instanceof IImmutableByteArrayProvider)
      {
        ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

        try
        {
          _wrappedKey_ = WrappedKey.newBuilder().build(value);
        }
        catch(RuntimeException e)
        {
            throw new IllegalArgumentException("Value \"" + value + "\" for wrappedKey is not a valid value", e);
        }
      }
      else 
      {
          throw new IllegalArgumentException("wrappedKey must be an instance of ImmutableByteArray not " + node.getClass().getName());
      }     
    }
    else
    {
      _wrappedKey_ = null;
    }
    if(keySet.remove("encryptedKey"))
    {
      IJsonDomNode  node = jsonObject.get("encryptedKey");
      if(node instanceof IImmutableByteArrayProvider)
      {
        ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

        try
        {
          _encryptedKey_ = WrappedKey.newBuilder().build(value);
        }
        catch(RuntimeException e)
        {
            throw new IllegalArgumentException("Value \"" + value + "\" for encryptedKey is not a valid value", e);
        }
      }
      else 
      {
          throw new IllegalArgumentException("encryptedKey must be an instance of ImmutableByteArray not " + node.getClass().getName());
      }     
    }
    else
    {
      _encryptedKey_ = null;
    }
    if(keySet.remove("kdfVersion"))
    {
      IJsonDomNode  node = jsonObject.get("kdfVersion");
      if(node instanceof IIntegerProvider)
      {
        Integer value = ((IIntegerProvider)node).asInteger();
        _kdfVersion_ = value;
      }
      else 
      {
          throw new IllegalArgumentException("kdfVersion must be an instance of Integer not " + node.getClass().getName());
      }
    }
    else
    {
      _kdfVersion_ = null;
    }
    if(keySet.remove("keyId"))
    {
      IJsonDomNode  node = jsonObject.get("keyId");
      if(node instanceof IImmutableByteArrayProvider)
      {
        ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();
        _keyId_ = value;
      }
      else 
      {
          throw new IllegalArgumentException("keyId must be an instance of ImmutableByteArray not " + node.getClass().getName());
      }
    }
    else
    {
      _keyId_ = null;
    }
    if(keySet.remove("relaySignature"))
    {
      IJsonDomNode  node = jsonObject.get("relaySignature");
      if(node instanceof IImmutableByteArrayProvider)
      {
        ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

        try
        {
          _relaySignature_ = EncodedSignature.newBuilder().build(value);
        }
        catch(RuntimeException e)
        {
            throw new IllegalArgumentException("Value \"" + value + "\" for relaySignature is not a valid value", e);
        }
      }
      else 
      {
          throw new IllegalArgumentException("relaySignature must be an instance of ImmutableByteArray not " + node.getClass().getName());
      }     
    }
    else
    {
      _relaySignature_ = null;
    }
    if(keySet.remove("version"))
    {
      IJsonDomNode  node = jsonObject.get("version");
      if(node instanceof IIntegerProvider)
      {
        Integer value = ((IIntegerProvider)node).asInteger();
        _version_ = value;
      }
      else 
      {
          throw new IllegalArgumentException("version must be an instance of Integer not " + node.getClass().getName());
      }
    }
    else
    {
      _version_ = null;
    }

    unknownKeys_ = ImmutableSet.copyOf(keySet);
  }
   
  /**
   * Copy constructor.
   * 
   * @param other Another instance from which all attributes are to be copied.
   */
  public SecurityContextMemberKeysEntity(ISecurityContextMemberKeys other)
  {
    super(other);
    
    _securityContextHash_ = other.getSecurityContextHash();
    _memberExchangeKeyHash_ = other.getMemberExchangeKeyHash();
    _wrappedKey_ = other.getWrappedKey();
    _encryptedKey_ = other.getEncryptedKey();
    _kdfVersion_ = other.getKdfVersion();
    _keyId_ = other.getKeyId();
    _relaySignature_ = other.getRelaySignature();
    _version_ = other.getVersion();

    unknownKeys_ = other.getCanonUnknownKeys();
  }
  
  @Override
  public ImmutableSet getCanonUnknownKeys()
  {
    return unknownKeys_;
  }
  
  @Override
  public Hash getSecurityContextHash()
  {
    return _securityContextHash_;
  }
    
  
  @Override
  public Hash getMemberExchangeKeyHash()
  {
    return _memberExchangeKeyHash_;
  }
    
  
  @Override
  public WrappedKey getWrappedKey()
  {
    return _wrappedKey_;
  }
    
  
  @Override
  public WrappedKey getEncryptedKey()
  {
    return _encryptedKey_;
  }
    
  
  @Override
  public Integer getKdfVersion()
  {
    return _kdfVersion_;
  }
    
  
  @Override
  public ImmutableByteArray getKeyId()
  {
    return _keyId_;
  }
    
  
  @Override
  public EncodedSignature getRelaySignature()
  {
    return _relaySignature_;
  }
    
  
  @Override
  public Integer getVersion()
  {
    return _version_;
  }
    


  @Override
  public boolean equals(Object obj)
  {
    if(obj instanceof SecurityContextMemberKeysEntity)
      return toString().equals(((SecurityContextMemberKeysEntity)obj).toString());
    
    return false;
  }
  

  
  /**
   * Factory class for SecurityContextMemberKeys.
   */
  public static class Factory extends EntityFactory
  {
    protected Factory()
    {
      super(ISecurityContextMemberKeys.class, ISecurityContextMemberKeysEntity.class);
    }
    
    /**
     * Return the type identifier (_type JSON attribute) for entities created by this factory.
     * 
     * @return The type identifier for entities created by this factory.
     */
    @Override
    public String getCanonType()
    {
      return TYPE_ID;
    }
    
    /**
     * Return the type version (_version JSON attribute) for entities created by this factory.
     * 
     * @return The type version for entities created by this factory.
     */
    public String getCanonVersion()
    {
      return TYPE_VERSION;
    }
    
    /**
     * Return the major type version for entities created by this factory.
     * 
     * @return The major type version for entities created by this factory.
     */
    public @Nullable Integer getCanonMajorVersion()
    {
      return TYPE_MAJOR_VERSION;
    }
    
    /**
     * Return the minjor type version for entities created by this factory.
     * 
     * @return The minor type version for entities created by this factory.
     */
    public @Nullable Integer getCanonMinorVersion()
    {
      return TYPE_MINOR_VERSION;
    }
        
    /**
     * Return a new entity instance created from the given JSON serialization.
     * 
     * @param jsonObject The JSON serialized form of the required entity.
     * @param modelRegistry A model registry to use to deserialize any nested objects.
     * 
     * @return An instance of the entity represented by the given serialized form.
     * 
     * @throws IllegalArgumentException If the given JSON is not valid.
     */
    @Override
    public ISecurityContextMemberKeys newInstance(ImmutableJsonObject jsonObject, IModelRegistry modelRegistry)
    {
      return new SecurityContextMemberKeys(jsonObject, modelRegistry);
    }
    
    /**
     * Return a new entity instance created from the given builder instance.
     * This is used to construct an entity from its builder as the builder also
     * implements the interface of the entity.
     * 
     * @param builder a builder containing values of all fields for the required entity.
     * 
     * @return An instance of the entity represented by the given values.
     * 
     */
    public ISecurityContextMemberKeys newInstance(Builder builder)
    {
      return new SecurityContextMemberKeys(builder);
    }
  }
 
  
  /**
   *  Builder factory
   *
   *  @deprecated use new SecurityContextMemberKeys.Builder() or new SecurityContextMemberKeys.Builder(ISecurityContextMemberKeysEntity) 
   */
  @Deprecated
  private static class BuilderFactory implements IBuilderFactory
  {
    /**
     *  @deprecated use new SecurityContextMemberKeys.Builder() 
     */
    @Deprecated
    @Override
    public Builder newInstance()
    {
      return new Builder();
    }

    /**
     *  @deprecated use new SecurityContextMemberKeys.Builder(ISecurityContextMemberKeysEntity) 
     */
    @Deprecated
    @Override
    public Builder newInstance(ISecurityContextMemberKeysEntity initial)
    {
      return new Builder(initial);
    }
  }
   
  /**
   * Builder for SecurityContextMemberKeys
   * 
   * Created by calling BUILDER.newInstance();
   *
   */
  public static class Builder extends SecurityContextMemberKeys.AbstractSecurityContextMemberKeysBuilder
  {
    /**
     * Constructor.
     */
    public Builder()
    {
      super(Builder.class);
    }

    /**
     * Constructor initialised from another object instance.
     * 
     * @param initial An instance of the built type from which values are to be initialised.
     */
    public Builder(ISecurityContextMemberKeysEntity initial)
    {
      super(Builder.class, initial);
    }

    @Override
    protected ISecurityContextMemberKeys construct()
    {
      return new SecurityContextMemberKeys(this);
    }
  }
  
  
  /**
   * Abstract builder for SecurityContextMemberKeys. If there are sub-classes of this type then their builders sub-class this builder.
   *
   * @param  The concrete type of the builder, used for fluent methods.
   * @param  The concrete type of the built object.
   */
   public static abstract class AbstractSecurityContextMemberKeysBuilder, T extends ISecurityContextMemberKeysEntity>
    extends VersionedObject.AbstractVersionedObjectBuilder
  {
    protected Hash                       _securityContextHash_;
    protected Hash                       _memberExchangeKeyHash_;
    protected WrappedKey                 _wrappedKey_;
    protected WrappedKey                 _encryptedKey_;
    protected Integer                    _kdfVersion_;
    protected ImmutableByteArray         _keyId_;
    protected EncodedSignature           _relaySignature_;
    protected Integer                    _version_;
  
    protected AbstractSecurityContextMemberKeysBuilder(Class type)
    {
      super(type);
    }
    
    protected AbstractSecurityContextMemberKeysBuilder(Class type, ISecurityContextMemberKeysEntity initial)
    {
      super(type, initial);
      
      _securityContextHash_ = initial.getSecurityContextHash();
      _memberExchangeKeyHash_ = initial.getMemberExchangeKeyHash();
      _wrappedKey_ = initial.getWrappedKey();
      _encryptedKey_ = initial.getEncryptedKey();
      _kdfVersion_ = initial.getKdfVersion();
      _keyId_ = initial.getKeyId();
      _relaySignature_ = initial.getRelaySignature();
      _version_ = initial.getVersion();
    }
    
    public B withValues(ImmutableJsonObject jsonObject, boolean ignoreValidation, IModelRegistry modelRegistry)
    {
      super.withValues(jsonObject, ignoreValidation, modelRegistry);
      if(jsonObject.containsKey("securityContextHash"))
      {
        IJsonDomNode  node = jsonObject.get("securityContextHash");
        if(node instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

          try
          {
            _securityContextHash_ = Hash.build(value);
          }
          catch(RuntimeException e)
          {
             if(!ignoreValidation) throw new IllegalArgumentException("Value \"" + value + "\" for securityContextHash is not a valid value", e);
          }
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("securityContextHash must be an instance of ImmutableByteArray not " + node.getClass().getName());
        }     
      }
      if(jsonObject.containsKey("memberExchangeKeyHash"))
      {
        IJsonDomNode  node = jsonObject.get("memberExchangeKeyHash");
        if(node instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

          try
          {
            _memberExchangeKeyHash_ = Hash.build(value);
          }
          catch(RuntimeException e)
          {
             if(!ignoreValidation) throw new IllegalArgumentException("Value \"" + value + "\" for memberExchangeKeyHash is not a valid value", e);
          }
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("memberExchangeKeyHash must be an instance of ImmutableByteArray not " + node.getClass().getName());
        }     
      }
      if(jsonObject.containsKey("wrappedKey"))
      {
        IJsonDomNode  node = jsonObject.get("wrappedKey");
        if(node instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

          try
          {
            _wrappedKey_ = WrappedKey.newBuilder().build(value);
          }
          catch(RuntimeException e)
          {
             if(!ignoreValidation) throw new IllegalArgumentException("Value \"" + value + "\" for wrappedKey is not a valid value", e);
          }
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("wrappedKey must be an instance of ImmutableByteArray not " + node.getClass().getName());
        }     
      }
      if(jsonObject.containsKey("encryptedKey"))
      {
        IJsonDomNode  node = jsonObject.get("encryptedKey");
        if(node instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

          try
          {
            _encryptedKey_ = WrappedKey.newBuilder().build(value);
          }
          catch(RuntimeException e)
          {
             if(!ignoreValidation) throw new IllegalArgumentException("Value \"" + value + "\" for encryptedKey is not a valid value", e);
          }
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("encryptedKey must be an instance of ImmutableByteArray not " + node.getClass().getName());
        }     
      }
      if(jsonObject.containsKey("kdfVersion"))
      {
        IJsonDomNode  node = jsonObject.get("kdfVersion");
        if(node instanceof IIntegerProvider)
        {
          Integer value = ((IIntegerProvider)node).asInteger();
          _kdfVersion_ = value;
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("kdfVersion must be an instance of Integer not " + node.getClass().getName());
        }
      }
      if(jsonObject.containsKey("keyId"))
      {
        IJsonDomNode  node = jsonObject.get("keyId");
        if(node instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();
          _keyId_ = value;
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("keyId must be an instance of ImmutableByteArray not " + node.getClass().getName());
        }
      }
      if(jsonObject.containsKey("relaySignature"))
      {
        IJsonDomNode  node = jsonObject.get("relaySignature");
        if(node instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)node).asImmutableByteArray();

          try
          {
            _relaySignature_ = EncodedSignature.newBuilder().build(value);
          }
          catch(RuntimeException e)
          {
             if(!ignoreValidation) throw new IllegalArgumentException("Value \"" + value + "\" for relaySignature is not a valid value", e);
          }
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("relaySignature must be an instance of ImmutableByteArray not " + node.getClass().getName());
        }     
      }
      if(jsonObject.containsKey("version"))
      {
        IJsonDomNode  node = jsonObject.get("version");
        if(node instanceof IIntegerProvider)
        {
          Integer value = ((IIntegerProvider)node).asInteger();
          _version_ = value;
        }
        else if(!ignoreValidation)
        {
            throw new IllegalArgumentException("version must be an instance of Integer not " + node.getClass().getName());
        }
      }
      return self();
    }
    
    public void populateAllFields(List result)
    {
      super.populateAllFields(result);
      result.add(_securityContextHash_);
      result.add(_memberExchangeKeyHash_);
      result.add(_wrappedKey_);
      result.add(_encryptedKey_);
      result.add(_kdfVersion_);
      result.add(_keyId_);
      result.add(_relaySignature_);
      result.add(_version_);
    }
    
    public Hash getSecurityContextHash()
    {
      return _securityContextHash_;
    }
  
    public B withSecurityContextHash(Hash value)
    {
      _securityContextHash_ = value;
      return self();
    }
    
    public B withSecurityContextHash(ImmutableByteArray value)
    {
      _securityContextHash_ = Hash.build(value);
      return self();
    }
    
    public Hash getMemberExchangeKeyHash()
    {
      return _memberExchangeKeyHash_;
    }
  
    public B withMemberExchangeKeyHash(Hash value)
    {
      _memberExchangeKeyHash_ = value;
      return self();
    }
    
    public B withMemberExchangeKeyHash(ImmutableByteArray value)
    {
      _memberExchangeKeyHash_ = Hash.build(value);
      return self();
    }
    
    public WrappedKey getWrappedKey()
    {
      return _wrappedKey_;
    }
  
    public B withWrappedKey(WrappedKey value)
    {
      _wrappedKey_ = value;
      return self();
    }
    
    public B withWrappedKey(ImmutableByteArray value)
    {
      _wrappedKey_ = WrappedKey.newBuilder().build(value);
      return self();
    }
    
    public WrappedKey getEncryptedKey()
    {
      return _encryptedKey_;
    }
  
    public B withEncryptedKey(WrappedKey value)
    {
      _encryptedKey_ = value;
      return self();
    }
    
    public B withEncryptedKey(ImmutableByteArray value)
    {
      _encryptedKey_ = WrappedKey.newBuilder().build(value);
      return self();
    }
    
    public Integer getKdfVersion()
    {
      return _kdfVersion_;
    }
  
    public B withKdfVersion(Integer value)
    {
      _kdfVersion_ = value;
      return self();
    }
    
    public ImmutableByteArray getKeyId()
    {
      return _keyId_;
    }
  
    public B withKeyId(ImmutableByteArray value)
    {
      _keyId_ = value;
      return self();
    }
    
    public EncodedSignature getRelaySignature()
    {
      return _relaySignature_;
    }
  
    public B withRelaySignature(EncodedSignature value)
    {
      _relaySignature_ = value;
      return self();
    }
    
    public B withRelaySignature(ImmutableByteArray value)
    {
      _relaySignature_ = EncodedSignature.newBuilder().build(value);
      return self();
    }
    
    public Integer getVersion()
    {
      return _version_;
    }
  
    public B withVersion(Integer value)
    {
      _version_ = value;
      return self();
    }
  
    @Override 
    public ImmutableJsonObject getJsonObject()
    {
      MutableJsonObject jsonObject = new MutableJsonObject();
      
      jsonObject.addIfNotNull(CanonRuntime.JSON_TYPE, SecurityContextMemberKeysEntity.TYPE_ID);
      jsonObject.addIfNotNull(CanonRuntime.JSON_VERSION, SecurityContextMemberKeysEntity.TYPE_VERSION);

      getJsonObject(jsonObject);
  
      return jsonObject.immutify();
    }
    
    @Override 
    public void getJsonObject(MutableJsonObject jsonObject)
    {
      super.getJsonObject(jsonObject);
  
      if(getSecurityContextHash() != null)
      {
          jsonObject.addIfNotNull("securityContextHash", Hash.toImmutableByteArray(getSecurityContextHash()));
      }
  
      if(getMemberExchangeKeyHash() != null)
      {
          jsonObject.addIfNotNull("memberExchangeKeyHash", Hash.toImmutableByteArray(getMemberExchangeKeyHash()));
      }
  
      if(getWrappedKey() != null)
      {
          jsonObject.addIfNotNull("wrappedKey", getWrappedKey().getValue());
      }
  
      if(getEncryptedKey() != null)
      {
          jsonObject.addIfNotNull("encryptedKey", getEncryptedKey().getValue());
      }
  
      if(getKdfVersion() != null)
      {
          jsonObject.addIfNotNull("kdfVersion", getKdfVersion());
      }
  
      if(getKeyId() != null)
      {
          jsonObject.addIfNotNull("keyId", getKeyId());
      }
  
      if(getRelaySignature() != null)
      {
          jsonObject.addIfNotNull("relaySignature", getRelaySignature().getValue());
      }
  
      if(getVersion() != null)
      {
          jsonObject.addIfNotNull("version", getVersion());
      }
    }
        
    /**
     * Return the type id (_type JSON attribute) for this entity.
     * 
     * @return The type id for this entity.
     */
    @Override
    public String getCanonType()
    {
      return TYPE_ID;
    }
    
    /**
     * Return the type version (_version JSON attribute) for this entity.
     * 
     * @return The type version for this entity.
     */
    public String getCanonVersion()
    {
      return TYPE_VERSION;
    }
    
    /**
     * Return the major type version for entities created by this factory.
     * 
     * @return The major type version for entities created by this factory.
     */
    @Override
    public @Nullable Integer getCanonMajorVersion()
    {
      return TYPE_MAJOR_VERSION;
    }
    
    /**
     * Return the minjor type version for entities created by this factory.
     * 
     * @return The minor type version for entities created by this factory.
     */
    @Override
    public @Nullable Integer getCanonMinorVersion()
    {
      return TYPE_MINOR_VERSION;
    }
  }
}

/*----------------------------------------------------------------------------------------------------
 * End of template template/java/Object/_Entity.java.ftl
 * End of code generation
 *------------------------------------------------------------------------------------------------- */