steveblackmon commented on code in PR #11:
URL: 
https://github.com/apache/streams-activitypub/pull/11#discussion_r1510126752


##########
streams-activitypub-graph/src/main/scala/org/apache/streams/activitypub/graph/impl/ProfileGraphImpl.scala:
##########
@@ -0,0 +1,127 @@
+package org.apache.streams.activitypub.graph.impl
+
+import org.apache.http.client.utils.URIBuilder
+import org.apache.jena.graph.Node
+import org.apache.jena.graph.NodeFactory
+import org.apache.jena.query.DatasetFactory
+import org.apache.jena.query.ParameterizedSparqlString
+import org.apache.jena.rdf.model.Resource
+import org.apache.jena.rdf.model.impl.ModelCom
+import org.apache.jena.riot.RDFFormat
+import org.apache.jena.riot.system.PrefixMap
+import org.apache.jena.riot.system.PrefixMapStd
+import org.apache.jena.riot.writer.JsonLD11Writer
+import org.apache.jena.shared.PrefixMapping
+import org.apache.jena.sparql.exec.http.QueryExecutionHTTP
+import org.apache.jena.sparql.util.Context
+import org.apache.jena.sparql.util.PrefixMapping2
+import org.apache.juneau.collections.JsonMap
+import org.apache.juneau.json.JsonParser
+import org.apache.streams.activitypub.api.NodeinfoApi
+import org.apache.streams.activitypub.api.ProfileApi
+import org.apache.streams.activitypub.api.pojo.profile.ProfileQueryRequest
+import org.apache.streams.activitypub.api.pojo.profile.ProfileQueryResponse
+import org.apache.streams.activitypub.graph.config.ProfileGraphImplConfig
+import org.apache.streams.activitypub.graph.impl.BaseGraphImpl.jsonParser
+import org.apache.streams.activitypub.server.NodeinfoApiStaticImpl
+import org.apache.streams.activitypub.utils.JsonLdHelper
+import org.apache.streams.config.ComponentConfigurator
+
+import java.io.Reader
+import java.io.StringWriter
+import java.net.URI
+import scala.io.Source
+import scala.jdk.CollectionConverters.*
+
+/**
+ * Implementation of the Profile API using jena/fuseki as back-end.
+ */
+object ProfileGraphImpl {
+
+  private final val configurator: 
ComponentConfigurator[ProfileGraphImplConfig] = new 
ComponentConfigurator(classOf[ProfileGraphImplConfig])
+  final val config: ProfileGraphImplConfig = configurator.detectConfiguration()
+  final val DEFAULT: ProfileGraphImpl = new ProfileGraphImpl(config)
+
+  given nodeinfo : NodeinfoApi = NodeinfoApiStaticImpl.DEFAULT
+
+}
+
+class ProfileGraphImpl(config: ProfileGraphImplConfig) extends 
BaseGraphImpl(config) with ProfileApi {
+
+  import ProfileGraphImpl.nodeinfo
+
+  /**
+   * Get the profile page for a user
+   * @return
+   */
+  override def profile(request: ProfileQueryRequest): ProfileQueryResponse = {
+    doProfile(request)
+  }
+
+  def doProfile(request: ProfileQueryRequest)(using nodeinfo: NodeinfoApi): 
ProfileQueryResponse = {
+
+    val profileUri: URI = new 
URIBuilder(nodeinfo.nodeinfoQuery.getServer.getBaseUrl).setPathSegments("users",
 request.getUsername).build()
+    val profileNode: Node = NodeFactory.createURI(profileUri.toString)
+    val askQueryBody: String = 
Source.fromResource("queries/profileAsk.sparql").getLines.mkString
+    val askQueryTemplate: ParameterizedSparqlString = new 
ParameterizedSparqlString(askQueryBody)
+    askQueryTemplate.setParam("subjectParam", profileNode)
+    val askQuery = askQueryTemplate.asQuery()
+    val askExecution: QueryExecutionHTTP = 
sparqlBuilder.query(askQuery).build()
+    val askResult = askExecution.execAsk()
+    if (!askResult) throw new Exception("Requested resource not found in 
dataset.")
+
+//    val selectQueryBody: String = 
Source.fromResource("queries/profileSelect.sparql").getLines.mkString
+//    val selectQueryTemplate: ParameterizedSparqlString = new 
ParameterizedSparqlString(selectQueryBody)
+//    selectQueryTemplate.setIri("resourceParam", profileUri.toString)
+//    val selectQuery = selectQueryTemplate.asQuery()
+//    val selectExecution: QueryExecutionHTTP = 
sparqlBuilder.query(selectQuery).build()
+//    val resultSet: ResultSet = selectExecution.execSelect()
+//    val model: Model = RDFOutput.encodeAsModel(resultSet)

Review Comment:
   should have removed this block - construct is the superior query type when 
the result is json/json-ld really anything other than a table



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@streams.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to