Skip to content

Commit

Permalink
Code cleanup (#24)
Browse files Browse the repository at this point in the history
Optimize & reorder imports, fix various other code issues
  • Loading branch information
Ostrzyciel authored Sep 12, 2023
1 parent 31a1837 commit fe9f6e8
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package eu.ostrzyciel.jelly.core

import eu.ostrzyciel.jelly.core.proto.v1.*

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.jdk.CollectionConverters.*
import scala.collection.mutable.ListBuffer

/**
* IRI and datatype encoder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package eu.ostrzyciel.jelly.core
import eu.ostrzyciel.jelly.core.proto.v1.*
import eu.ostrzyciel.jelly.core.proto.v1.RdfGraph.Graph

import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer
import scala.reflect.ClassTag

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eu.ostrzyciel.jelly.core

import eu.ostrzyciel.jelly.core.proto.v1.*

import java.math.BigInteger
import scala.collection.mutable.ListBuffer

object ProtoEncoder:
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/eu/ostrzyciel/jelly/core/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ package object core:
object Constants:
val jellyName = "Jelly"
val jellyFileExtension = "jelly"
val jellyFileExtensionWithDot = s".$jellyFileExtension"
val jellyContentType = "application/x-jelly-rdf"
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import eu.ostrzyciel.jelly.core.proto.v1.*
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import scala.collection.immutable.{AbstractSeq, LinearSeq}

class ProtoEncoderSpec extends AnyWordSpec, Matchers:
import ProtoTestCases.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package eu.ostrzyciel.jelly.grpc

import com.typesafe.config.Config
import com.typesafe.scalalogging.LazyLogging
import eu.ostrzyciel.jelly.core.proto.v1.*
import org.apache.pekko.Done
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.http.scaladsl.Http
import org.apache.pekko.http.scaladsl.Http.ServerBinding
import org.apache.pekko.http.scaladsl.model.{HttpRequest, HttpResponse}
import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.scalalogging.LazyLogging
import eu.ostrzyciel.jelly.core.proto.v1.*

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration.*
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

object RdfStreamServer:
Expand Down
6 changes: 3 additions & 3 deletions grpc/src/test/scala/eu/ostrzyciel/jelly/grpc/GrpcSpec.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package eu.ostrzyciel.jelly.grpc

import com.typesafe.config.ConfigFactory
import eu.ostrzyciel.jelly.core.proto.v1.*
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import org.apache.pekko.NotUsed
import org.apache.pekko.actor.testkit.typed.scaladsl.ActorTestKit
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.actor.typed.scaladsl.Behaviors
import org.apache.pekko.grpc.GrpcClientSettings
import org.apache.pekko.stream.scaladsl.*
import com.typesafe.config.ConfigFactory
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import eu.ostrzyciel.jelly.core.proto.v1.*
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package eu.ostrzyciel.jelly.integration_tests

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import eu.ostrzyciel.jelly.core.*
import eu.ostrzyciel.jelly.core.proto.v1.RdfStreamOptions
import eu.ostrzyciel.jelly.stream.*
import org.apache.jena.graph.Graph
import org.apache.jena.riot.{Lang, RDFDataMgr, RDFParser}
import org.apache.jena.sparql.core.DatasetGraph
import org.apache.jena.sparql.util.IsoMatcher
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package eu.ostrzyciel.jelly.integration_tests

import org.apache.pekko.{Done, NotUsed}
import org.apache.pekko.stream.scaladsl.{Flow, Keep, Sink, Source}
import eu.ostrzyciel.jelly.core.proto.v1.{RdfStreamFrame, RdfStreamOptions}
import eu.ostrzyciel.jelly.stream.{DecoderFlow, EncoderFlow}
import org.apache.jena.graph.{Graph, Node, Triple}
import org.apache.jena.riot.{Lang, RDFDataMgr, RDFParser}
import org.apache.jena.graph.{Node, Triple}
import org.apache.jena.riot.system.AsyncParser
import org.apache.jena.riot.{Lang, RDFDataMgr, RDFParser}
import org.apache.pekko.stream.scaladsl.{Flow, Keep, Sink, Source}

import java.io.{InputStream, OutputStream}
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.ExecutionContext
import scala.jdk.CollectionConverters.*

case object JenaTestStream extends TestStream:
Expand All @@ -30,7 +29,7 @@ case object JenaTestStream extends TestStream:
val graphs: Iterator[(Node, Iterable[Triple])] = (
ds.listGraphNodes().asScala.map(gNode => (gNode, Iterable.from(ds.getGraph(gNode).find.asScala))) ++
Iterator((null, Iterable.from(ds.getDefaultGraph.find.asScala)))
).filter((_, g) => g.size > 0)
).filter((_, g) => g.nonEmpty)
Source.fromIterator(() => graphs)
.via(EncoderFlow.fromGraphs(streamOpt, jellyOpt))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package eu.ostrzyciel.jelly.integration_tests

import org.apache.pekko.{Done, NotUsed}
import org.apache.pekko.stream.scaladsl.*
import eu.ostrzyciel.jelly.core.proto.v1.{RdfStreamFrame, RdfStreamOptions}
import eu.ostrzyciel.jelly.stream.{DecoderFlow, EncoderFlow}
import org.eclipse.rdf4j.model.Model
import org.apache.pekko.Done
import org.apache.pekko.stream.scaladsl.*
import org.eclipse.rdf4j.rio.*
import org.eclipse.rdf4j.rio.helpers.StatementCollector

import java.io.{InputStream, OutputStream}
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.ExecutionContext
import scala.jdk.CollectionConverters.*

case object Rdf4jTestStream extends TestStream:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package eu.ostrzyciel.jelly.integration_tests

import org.apache.pekko.{Done, NotUsed}
import org.apache.pekko.stream.scaladsl.*
import eu.ostrzyciel.jelly.stream.EncoderFlow
import eu.ostrzyciel.jelly.core.proto.v1.{RdfStreamFrame, RdfStreamOptions}
import eu.ostrzyciel.jelly.stream.EncoderFlow
import org.apache.pekko.stream.scaladsl.*
import org.apache.pekko.{Done, NotUsed}

import java.io.{InputStream, OutputStream}
import scala.concurrent.{ExecutionContext, Future}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package eu.ostrzyciel.jelly.convert.jena

import eu.ostrzyciel.jelly.core.ProtoDecoderConverter
import org.apache.jena.JenaRuntime
import org.apache.jena.datatypes.RDFDatatype
import org.apache.jena.datatypes.xsd.impl.RDFLangString
import org.apache.jena.graph.*
import org.apache.jena.sparql.core.Quad

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package eu.ostrzyciel.jelly.stream

import eu.ostrzyciel.jelly.core.proto.v1.RdfStreamFrame
import eu.ostrzyciel.jelly.core.{ConverterFactory, ProtoDecoder}
import org.apache.pekko.NotUsed
import org.apache.pekko.stream.scaladsl.Flow
import eu.ostrzyciel.jelly.core.{ConverterFactory, ProtoDecoder}
import eu.ostrzyciel.jelly.core.proto.v1.RdfStreamFrame

/**
* Methods for creating Pekko Streams flows for decoding protobuf into RDF statements.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package eu.ostrzyciel.jelly.stream

import org.apache.pekko.NotUsed
import org.apache.pekko.stream.scaladsl.{Flow, Source}
import com.typesafe.config.Config
import eu.ostrzyciel.jelly.core.ConverterFactory
import eu.ostrzyciel.jelly.core.proto.v1.*
import org.apache.pekko.NotUsed
import org.apache.pekko.stream.scaladsl.{Flow, Source}

/**
* Factory of encoder flows for Jelly streams.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package eu.ostrzyciel.jelly.stream

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import eu.ostrzyciel.jelly.core.helpers.Assertions.*
import eu.ostrzyciel.jelly.core.helpers.MockConverterFactory
import eu.ostrzyciel.jelly.core.proto.v1.*
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import scala.collection.mutable.ArrayBuffer

class DecoderFlowSpec extends AnyWordSpec, Matchers, ScalaFutures:
import eu.ostrzyciel.jelly.core.helpers.Mrl.*
import ProtoTestCases.*
import eu.ostrzyciel.jelly.core.helpers.Mrl.*
implicit val converterFactory: MockConverterFactory.type = MockConverterFactory
implicit val actorSystem: ActorSystem = ActorSystem()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package eu.ostrzyciel.jelly.stream

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import eu.ostrzyciel.jelly.core.helpers.Assertions.*
import eu.ostrzyciel.jelly.core.helpers.MockConverterFactory
import eu.ostrzyciel.jelly.core.proto.v1.*
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.ostrzyciel.jelly.stream

import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import eu.ostrzyciel.jelly.core.proto.v1.RdfStreamType
import eu.ostrzyciel.jelly.core.{JellyOptions, ProtoTestCases}
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.*
import org.scalatest.concurrent.ScalaFutures
Expand Down

0 comments on commit fe9f6e8

Please sign in to comment.