Skip to content

Commit

Permalink
Merge pull request #513 from aml-org/publish-6.0.7-master
Browse files Browse the repository at this point in the history
publish 6.0.7 master
  • Loading branch information
tomsfernandez authored Apr 11, 2022
2 parents 0c31df4 + 3684418 commit 0a23ce9
Show file tree
Hide file tree
Showing 127 changed files with 29,363 additions and 554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ abstract class AnyMapping(override private[amf] val _internal: InternalAnyMappin
def and(): ClientList[StrField] = _internal.and.asClient
def or(): ClientList[StrField] = _internal.or.asClient
def components(): ClientList[StrField] = _internal.components.asClient
def ifMapping(): StrField = _internal.ifMapping
def thenMapping(): StrField = _internal.thenMapping
def elseMapping(): StrField = _internal.elseMapping

def withAnd(andMappings: ClientList[String]): AnyMapping = {
_internal.withAnd(andMappings.asInternal)
Expand All @@ -26,4 +29,16 @@ abstract class AnyMapping(override private[amf] val _internal: InternalAnyMappin
_internal.withOr(components.asInternal)
this
}
def withIfMapping(ifMapping: String): AnyMapping = {
_internal.withIfMapping(ifMapping)
this
}
def withThenMapping(thenMapping: String): AnyMapping = {
_internal.withIfMapping(thenMapping)
this
}
def withElseMapping(elseMapping: String): AnyMapping = {
_internal.withIfMapping(elseMapping)
this
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ import amf.core.client.scala.model.StrField
import amf.core.client.scala.model.domain.DomainElement
import amf.core.internal.parser.domain.Fields

// TODO This should inherit from NodeMappable and be a class (a simple allof or oneOf should be of this class).
// But the meta field of NodeMappable make impossible to have hierarchy of classes currently. Thats why this is abstract.
abstract class AnyMapping(fields: Fields) extends DomainElement {

def and: Seq[StrField] = fields.field(And)
def or: Seq[StrField] = fields.field(Or)
def components: Seq[StrField] = fields.field(Components)
def ifMapping: StrField = fields.field(If)
def thenMapping: StrField = fields.field(Then)
def elseMapping: StrField = fields.field(Else)

def withAnd(andMapping: Seq[String]): AnyMapping = set(And, andMapping)
def withOr(orMapping: Seq[String]): AnyMapping = set(Or, orMapping)
def withComponents(components: Seq[String]): AnyMapping = set(Components, components)
def withIfMapping(ifMapping: String): AnyMapping = set(If, ifMapping)
def withThenMapping(thenMapping: String): AnyMapping = set(Then, thenMapping)
def withElseMapping(elseMapping: String): AnyMapping = set(Else, elseMapping)

private[amf] def hasAny: Boolean = and.nonEmpty
private[amf] def hasOr: Boolean = or.nonEmpty
private[amf] def hasConditional: Boolean = ifMapping.nonEmpty

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class NodeMapping(override val fields: Fields, override val annotations: Annotat
def withIdTemplate(idTemplate: String): NodeMapping = set(IdTemplate, idTemplate)
def withResolvedExtends(ids: Seq[String]): NodeMapping = set(ResolvedExtends, ids)

private[amf] def hasProperties: Boolean = propertiesMapping().nonEmpty

/**
* Returns the properties forming the primary key for this node.
* Properties are already sorted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private[amf] object AMLEntities extends Entities {
BaseUnitProcessingDataModel,
BaseUnitSourceInformationModel,
LocationInformationModel,
ConditionalNodeMappingModel,
AnyMappingModel
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ trait AnyMappingModel
"Array of component mappings in case of component combination generated mapping")
)

val If: Field = Field(
Iri,
Namespace.AmfAml + "if",
ModelDoc(ExternalModelVocabularies.Shacl,
"if",
"Conditional constraint if over the type of the mapped graph property")
)

val Then: Field = Field(
Iri,
Namespace.AmfAml + "then",
ModelDoc(ExternalModelVocabularies.Shacl,
"then",
"Conditional constraint then over the type of the mapped graph property")
)

val Else: Field = Field(
Iri,
Namespace.AmfAml + "else",
ModelDoc(ExternalModelVocabularies.Shacl,
"else",
"Conditional constraint else over the type of the mapped graph property")
)

override val `type`
: List[ValueType] = Namespace.Meta + "AnyMapping" :: Namespace.Shacl + "Shape" :: DomainElementModel.`type`

Expand All @@ -47,5 +71,5 @@ object AnyMappingModel extends AnyMappingModel {

override def modelInstance = throw new Exception("AnyMapping is an abstract class")

override val fields: List[Field] = List(And, Or, Components)
override val fields: List[Field] = List(And, Or, Components, If, Then, Else)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import amf.aml.internal.validate.DialectValidations.MissingVocabulary
import amf.core.client.scala.model.domain.{AmfObject, DomainElement}
import amf.core.client.scala.model.domain.extensions.{CustomDomainProperty, DomainExtension}
import amf.core.client.scala.parse.document.ParserContext
import amf.core.internal.annotations.SourceAST
import amf.core.internal.metamodel.domain.DomainElementModel.CustomDomainProperties
import amf.core.internal.metamodel.domain.extensions.DomainExtensionModel
import amf.core.internal.parser.domain.Annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait DialectSyntax { this: DialectContext =>
)

val anyMapping: Map[String, Required] = Map(
"anyOf" -> false,
"allOf" -> false,
"oneOf" -> false,
"components" -> false
)
Expand All @@ -46,10 +46,6 @@ trait DialectSyntax { this: DialectContext =>
"additionalProperties" -> false
)

val conditionalMapping: Map[String, Required] = anyMapping ++ Map(
"conditional" -> true
)

val conditionalMappingInner: Map[String, Required] = Map(
"if" -> true,
"then" -> true,
Expand Down Expand Up @@ -113,7 +109,6 @@ trait DialectSyntax { this: DialectContext =>
case "fragment" => fragment
case "nodeMapping" => nodeMapping
case "conditionalMappingInner" => conditionalMappingInner
case "conditionalMapping" => conditionalMapping
case "annotationMapping" => annotationMapping
case "propertyMapping" => propertyMapping
case "documentsMapping" => documentsMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package amf.aml.internal.parse.dialects
import amf.aml.client.scala.model.document.{Dialect, DialectFragment, DialectLibrary}
import amf.aml.client.scala.model.domain._
import amf.aml.internal.metamodel.document.DialectModel
import amf.aml.internal.metamodel.document.DialectModel.{Externals, fields}
import amf.aml.internal.metamodel.document.DialectModel.Externals
import amf.aml.internal.metamodel.domain.UnionNodeMappingModel.ObjectRange
import amf.aml.internal.metamodel.domain.{ConditionalNodeMappingModel, NodeMappingModel, PropertyMappingModel}
import amf.aml.internal.metamodel.domain.{NodeMappingModel, PropertyMappingModel}
import amf.aml.internal.parse.common.{DeclarationKey, DeclarationKeyCollector}
import amf.aml.internal.parse.dialects.DialectAstOps._
import amf.aml.internal.parse.dialects.nodemapping.like.NodeMappingLikeParser
Expand Down Expand Up @@ -294,16 +294,19 @@ class DialectsParser(root: Root)(implicit override val ctx: DialectContext)

val allMembers = mappable.and.flatMap(member => findIdOrError(member, mappable))
if (allMembers.nonEmpty) mappable.withAnd(allMembers)

val oneMembers = mappable.or.flatMap(member => findIdOrError(member, mappable))
if (oneMembers.nonEmpty) mappable.withOr(oneMembers)

val components = mappable.components.flatMap(member => findIdOrError(member, mappable))
if (components.nonEmpty) mappable.withComponents(components)
if (mappable.ifMapping.nonEmpty)
findIdOrError(mappable.ifMapping, mappable).foreach(mappable.withIfMapping)
if (mappable.thenMapping.nonEmpty)
findIdOrError(mappable.thenMapping, mappable).foreach(mappable.withThenMapping)
if (mappable.elseMapping.nonEmpty)
findIdOrError(mappable.elseMapping, mappable).foreach(mappable.withElseMapping)

mappable match {
case unionNodeMapping: UnionNodeMapping => checkNodeMappableReferences(unionNodeMapping)
case conditionalNodeMapping: ConditionalNodeMapping => checkNodeMappableReferences(conditionalNodeMapping)
case unionNodeMapping: UnionNodeMapping => checkNodeMappableReferences(unionNodeMapping)
case nodeMapping: Member =>
nodeMapping.propertiesMapping().foreach { propertyMapping =>
checkNodeMappableReferences(propertyMapping)
Expand Down Expand Up @@ -370,16 +373,6 @@ class DialectsParser(root: Root)(implicit override val ctx: DialectContext)
}
}

// Replaces inner conditional fields references from names to ids
protected def checkNodeMappableReferences[T <: DomainElement](mappable: ConditionalNodeMapping): Unit = {
if (mappable.ifMapping.nonEmpty)
findIdOrError(mappable.ifMapping, mappable).foreach(mappable.withIfMapping)
if (mappable.thenMapping.nonEmpty)
findIdOrError(mappable.thenMapping, mappable).foreach(mappable.withThenMapping)
if (mappable.elseMapping.nonEmpty)
findIdOrError(mappable.elseMapping, mappable).foreach(mappable.withElseMapping)
}

private def memberIdFromName[T <: DomainElement](name: String, union: NodeWithDiscriminator[_]): Option[String] = {
if (name == (Namespace.Meta + "anyNode").iri()) Some(name)
else {
Expand Down Expand Up @@ -514,10 +507,9 @@ class DialectsParser(root: Root)(implicit override val ctx: DialectContext)
}

parseNodeMapping(entry, adopt) match {
case Some(nodeMapping: NodeMapping) => ctx.declarations += nodeMapping
case Some(unionMapping: UnionNodeMapping) => ctx.declarations += unionMapping
case Some(conditionalMapping: ConditionalNodeMapping) => ctx.declarations += conditionalMapping
case _ => ctx.eh.violation(DialectError, parent, s"Error parsing shape '$entry'", entry.location)
case Some(nodeMapping: NodeMapping) => ctx.declarations += nodeMapping
case Some(unionMapping: UnionNodeMapping) => ctx.declarations += unionMapping
case _ => ctx.eh.violation(DialectError, parent, s"Error parsing shape '$entry'", entry.location)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ trait AnyMappingParser {
processAnyMappingField(map, mapping, "allOf", AnyMappingModel.And)
processAnyMappingField(map, mapping, "oneOf", AnyMappingModel.Or)
processAnyMappingField(map, mapping, "components", AnyMappingModel.Components)
ConditionalParser.parse(map, mapping)
mapping

}
Expand Down
Loading

0 comments on commit 0a23ce9

Please sign in to comment.