Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-12276263 - Created parsing plugin and extracted common methods #1715

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import amf.core.internal.validation.core.ValidationProfile
import amf.shapes.client.scala.{JsonLDSchemaElementClient, ShapesConfiguration, ShapesElementClient}
import amf.shapes.client.scala.model.document.JsonSchemaDocument
import amf.shapes.internal.convert.JsonLDSchemaRegister
import amf.shapes.internal.plugins.parser.AMFJsonLDSchemaGraphParsePlugin
import amf.shapes.internal.plugins.render.AMFJsonLDSchemaGraphRenderPlugin
import amf.shapes.internal.spec.jsonldschema.JsonLDSchemaParsePlugin
import amf.shapes.internal.transformation.JsonLDSchemaEditingPipeline
Expand Down Expand Up @@ -237,6 +238,7 @@ object JsonLDSchemaConfiguration {
base.listeners,
base.options
).withTransformationPipeline(JsonLDSchemaEditingPipeline())
.withPlugin(AMFJsonLDSchemaGraphRenderPlugin)
.withPlugins(List(AMFJsonLDSchemaGraphRenderPlugin, AMFJsonLDSchemaGraphParsePlugin))

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package amf.shapes.internal.plugins.document.graph.parser

import amf.core.client.scala.parse.document.SyamlParsedDocument
import amf.core.internal.parser.ParseConfiguration
import amf.core.internal.plugins.document.graph.parser.{
FlattenedGraphParser,
FlattenedUnitGraphParser,
GraphParserContext
}

class FlattenedJsonLdInstanceParser(startingPoint: String, overrideAliases: Map[String, String] = Map.empty)(implicit
ctx: GraphParserContext
) extends FlattenedGraphParser(startingPoint, overrideAliases) {

// TODO override sorted array parsing

}

class FlattenedJsonLdInstanceUnitGraphParser(overrideAliases: Map[String, String] = Map.empty)(implicit
ctx: GraphParserContext
) extends FlattenedUnitGraphParser(overrideAliases) {

override def parserProvider(
rootId: String,
overrideAliases: Map[String, String],
ctx: GraphParserContext
): FlattenedGraphParser = new FlattenedJsonLdInstanceParser(rootId, overrideAliases)(ctx)

}

object FlattenedJsonLdInstanceUnitGraphParser {

def apply(config: ParseConfiguration, aliases: Map[String, String]): FlattenedJsonLdInstanceUnitGraphParser =
new FlattenedJsonLdInstanceUnitGraphParser(aliases)(new GraphParserContext(config = config))

def canParse(document: SyamlParsedDocument, aliases: Map[String, String] = Map.empty): Boolean =
FlattenedUnitGraphParser.canParse(document, aliases)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package amf.shapes.internal.plugins.parser

import amf.core.client.scala.exception.UnsupportedParsedDocumentException
import amf.core.client.scala.model.document.BaseUnit
import amf.core.client.scala.parse.document.{ParserContext, SyamlParsedDocument}
import amf.core.internal.parser.Root
import amf.core.internal.plugins.parse.AMFGraphParsePlugin
import amf.shapes.internal.plugins.document.graph.parser.FlattenedJsonLdInstanceUnitGraphParser

object AMFJsonLDSchemaGraphParsePlugin extends AMFGraphParsePlugin {

override def applies(element: Root): Boolean = element.parsed match {
case parsed: SyamlParsedDocument => FlattenedJsonLdInstanceUnitGraphParser.canParse(parsed, aliases)
case _ => false
}
override def parse(document: Root, ctx: ParserContext): BaseUnit = document.parsed match {
case parsed: SyamlParsedDocument =>
FlattenedJsonLdInstanceUnitGraphParser(ctx.config, aliases)
.parse(parsed.document, effectiveUnitUrl(document.location, ctx.parsingOptions))
case _ => throw UnsupportedParsedDocumentException
}

override def mediaTypes: Seq[String] = Seq(
"application/schemald+json"
)
}