Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Muneeb Shere
Added: Aug 6, 2019 3:00 AM
Views: 3
Tags: no tags
  1.  
  2.  
  3.     protected fun verify(propertyName : String, otype : OType, readOnly : Boolean, nullable : Boolean) {
  4.         val signature = "$propertyName:$otype:$readOnly:$nullable";
  5.         val verified = verifiedProperties[kclass];
  6.         if (verified?.contains(signature) == true)
  7.             return;
  8.         val properties = allowedProperties[kclass] ?: throw RuntimeAPIConstraintError("No properties registered for this class.", kclass);
  9.         val property = properties.firstOrNull { it.a == propertyName } ?: throw SchemaMismatchException(propertyName, "No such property exists for this class.");
  10.         if (property != Tuple5(propertyName, otype, null, readOnly, nullable)) {
  11.             if (otype != property.b)
  12.                 throw SchemaMismatchException("$propertyName.otype", "${property.b}", "$otype", "Property type does not match.");
  13.             if (property.c != null)
  14.                 throw SchemaMismatchException("$propertyName.linked", "${property.c}", "null", "The property must be of linked/embedded type.");
  15.             if (readOnly != property.d)
  16.                 throw SchemaMismatchException("$propertyName.readOnly", "${property.d}", "$readOnly", "The property should ${readOnly .. "not" ?: ""} be read-only.");
  17.             if (nullable != property.e)
  18.                 throw SchemaMismatchException("$propertyName.nullable", "${property.e}", "$nullable", "The property ${nullable .. "cannot" ?: "must"} be nullable.");
  19.         }
  20.         if (verified == null)
  21.             verifiedProperties[kclass] = mutableListOf(signature);
  22.         else
  23.             verified += signature;
  24.     }
  25.  
  26.     protected fun verify(propertyName : String, otype : OType, linkedClass : String, readOnly : Boolean, nullable : Boolean) {
  27.         val signature = "$propertyName:$otype:${ linkedClass.toLowerCase() }:$readOnly:$nullable";
  28.         val verified = verifiedProperties[kclass];
  29.         if (verified?.contains(signature) == true)
  30.             return;
  31.         val properties = allowedProperties[kclass] ?: throw RuntimeAPIConstraintError("No properties registered for this class.", kclass);
  32.         val property = properties.firstOrNull { it.a == propertyName } ?: throw SchemaMismatchException(propertyName, "No such property exists for this class.");
  33.         val thisProp = Tuple5(propertyName, otype, linkedClass.toLowerCase().right(), readOnly, nullable);
  34.         if (property != thisProp && property.copy(c = "_".right()) != thisProp) {
  35.             if (otype != property.b)
  36.                 throw SchemaMismatchException("$propertyName.otype", "${property.b}", "$otype", "Property type does not match.");
  37.             property.c.also {
  38.                 if (it == null)
  39.                     throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of linked type.");
  40.                 else
  41.                     when (it) {
  42.                     is Either.Left ->
  43.                         throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of linked type.");
  44.                     is Either.Right ->
  45.                         if (it.b != linkedClass)
  46.                             throw SchemaMismatchException("$propertyName.linkedClass", it.b, linkedClass, "The property should be of a different linked class.");
  47.                 }
  48.             }
  49.             if (readOnly != property.d)
  50.                 throw SchemaMismatchException("$propertyName.readOnly", "${property.d}", "$readOnly", "The property should ${readOnly .. "not" ?: ""} be read-only.");
  51.             if (nullable != property.e)
  52.                 throw SchemaMismatchException("$propertyName.nullable", "${property.e}", "$nullable", "The property ${nullable .. "cannot" ?: "must"} be nullable.");
  53.         }
  54.         if (verified == null)
  55.             verifiedProperties[kclass] = mutableListOf(signature);
  56.         else
  57.             verified += signature;
  58.     }
  59.  
  60.     protected fun verify(propertyName : String, otype : OType, linkedType : OType, readOnly : Boolean, nullable : Boolean) {
  61.         val signature = "$propertyName:$otype:$linkedType:$readOnly:$nullable";
  62.         val verified = verifiedProperties[kclass];
  63.         if (verified?.contains(signature) == true)
  64.             return;
  65.         val properties = allowedProperties[kclass] ?: throw RuntimeAPIConstraintError("No properties registered for this class.", kclass);
  66.         val property = properties.firstOrNull { it.a == propertyName } ?: throw SchemaMismatchException(propertyName, "No such property exists for this class.");
  67.         if (property != Tuple5(propertyName, otype, linkedType.left(), readOnly, nullable)) {
  68.             if (otype != property.b)
  69.                 throw SchemaMismatchException("$propertyName.otype", "${property.b}", "$otype", "Property type does not match.");
  70.             property.c.also {
  71.                 if (it == null)
  72.                     throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of embedded type.");
  73.                 else when (it) {
  74.                     is Either.Right ->
  75.                         throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of embedded type.");
  76.                     is Either.Left ->
  77.                         if (it.a != linkedType)
  78.                             throw SchemaMismatchException("$propertyName.linkedType", "${it.a}", "$linkedType", "The property should be of a different embedded type.");
  79.                 }
  80.             }
  81.             if (readOnly != property.d)
  82.                 throw SchemaMismatchException("$propertyName.readOnly", "${property.d}", "$readOnly", "The property should ${readOnly .. "not" ?: ""} be read-only.");
  83.             if (nullable != property.e)
  84.                 throw SchemaMismatchException("$propertyName.nullable", "${property.e}", "$nullable", "The property ${nullable .. "cannot" ?: "must"} be nullable.");
  85.         }
  86.         if (verified == null)
  87.             verifiedProperties[kclass] = mutableListOf(signature);
  88.         else
  89.             verified += signature;
  90.     }