Skip to content

Commit

Permalink
https://jira.catena-x.net/browse/KA-197 - improvement for the skill r…
Browse files Browse the repository at this point in the history
…ecursion binding.
  • Loading branch information
drcgjung committed May 16, 2023
1 parent e2140cc commit 5dd8053
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected MediaType getDefaultResultType() {
return srx;
}
} catch(IllegalArgumentException iae) {
System.err.printf("Warning: Ingoring unsupported accepted mediatype %s%n",qualifiers[0]);
}
}
return null;
Expand Down Expand Up @@ -211,9 +212,7 @@ protected String getSimpleXml(String bindingVar) {
protected Response.ResponseBuilder compute(MediaType resultType, String bindingVar) {
AtomicReference<Response.ResponseBuilder> response= new AtomicReference<>(Response.status(status));
Map<String,byte[]> body=computeBody(resultType, bindingVar);
body.entrySet().forEach( result -> {
response.set(response.get().type(result.getKey()).entity(result.getValue()));
});
body.forEach((key, value) -> response.set(response.get().type(key).entity(value)));
return response.get();
}

Expand Down Expand Up @@ -265,6 +264,9 @@ public Response postAgent(Object body, String asset, String queryLn, String que

@Override
public Response postSkill(String body, @NotNull String asset) throws NotFoundException {
if(asset.length()==0) {
return Response.status(400,"KA-BIND/KA-MATCH postSkill requires a non-empty asset name.").build();
}
MediaType bodyType=MediaType.valueOf(headers.getHeaderString("Content-Type"));
if(!bodyType.isCompatible(sq)) {
return Response.status(400,"KA-BIND/KA-MATCH postSkill only accepts application/sparql-query|results+json|xml in body.").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
package io.catenax.knowledge.dataspace.edc;

import dev.failsafe.RetryPolicy;
import io.catenax.knowledge.dataspace.edc.http.AgentController;
import io.catenax.knowledge.dataspace.edc.http.HttpClientFactory;
import io.catenax.knowledge.dataspace.edc.http.transfer.AgentSourceFactory;
Expand All @@ -21,7 +20,6 @@
import org.apache.jena.sparql.serializer.*;
import org.apache.jena.sparql.service.ServiceExecutorRegistry;
import org.eclipse.edc.connector.dataplane.http.params.HttpRequestFactory;
import org.eclipse.edc.connector.dataplane.spi.pipeline.DataTransferExecutorServiceContainer;
import org.eclipse.edc.spi.http.EdcHttpClient;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.spi.monitor.Monitor;
Expand Down Expand Up @@ -58,9 +56,6 @@ public class AgentExtension implements ServiceExtension {
@Inject
protected WebService webService;

@Inject
@SuppressWarnings("rawtypes")
protected RetryPolicy retryPolicy;

@Inject
protected PipelineService pipelineService;
Expand All @@ -69,9 +64,9 @@ public class AgentExtension implements ServiceExtension {
protected Vault vault;

@Inject
protected DataTransferExecutorServiceContainer executorContainer;
protected EdcHttpClient edcHttpClient;
@Inject
private EdcHttpClient edcHttpClient;
protected TypeManager typeManager;

/**
* refers a scheduler
Expand All @@ -89,6 +84,7 @@ public class AgentExtension implements ServiceExtension {
*/
protected OkHttpClient httpClient;


/**
* @return name of the extension
*/
Expand All @@ -109,7 +105,6 @@ public void initialize(ServiceExtensionContext context) {

AgentConfig config = new AgentConfig(monitor,context.getConfig());
httpClient= HttpClientFactory.create(config);
TypeManager typeManager = context.getTypeManager();

DataManagement catalogService=new DataManagement(monitor,typeManager,httpClient,config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ public Response getRepositoryQuery(@QueryParam("asset") String asset,
@GET
@Path("/repositories/AGENT/import/active")
public Response getRepositoryImportQuery(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET repository import active request %s",request));
return Response.status(406,"Not Acceptable (HTTP status 406)").build();
}
Expand All @@ -202,10 +203,11 @@ public Response getRepositoryImportQuery(
@GET
@Path("/rest/repositories/AGENT/size")
public Response getRestRepositorySizeQuery(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET rest repository size request %s",request));
return Response.ok("{\n" +
" \"inferred\": 70,\n" +
Expand All @@ -221,10 +223,11 @@ public Response getRestRepositorySizeQuery(
@GET
@Path("/repositories/AGENT/size")
public Response getRepositorySizeQuery(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET repository size request %s",request));
return Response.ok("0" ).type(jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE).build();
}
Expand All @@ -236,10 +239,11 @@ public Response getRepositorySizeQuery(
@GET
@Path("/rest/repositories/AGENT/import/active")
public Response getRestRepositoryImportQuery(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET rest repository import active request %s",request));
return Response.ok("0").type(jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE).build();
}
Expand All @@ -251,10 +255,11 @@ public Response getRestRepositoryImportQuery(
@GET
@Path("/rest/info/version")
public String getVersion(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET Version request %s",request));
return "0.8.4";
}
Expand All @@ -266,10 +271,11 @@ public String getVersion(
@GET
@Path("/protocol")
public String getProtocol(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET Protocol request %s",request));
return "12";
}
Expand All @@ -281,10 +287,11 @@ public String getProtocol(
@GET
@Path("/rest/locations/id")
public String getId(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET Id request %s",request));
return "Catena-X Knowledge Agent";
}
Expand All @@ -296,10 +303,11 @@ public String getId(
@GET
@Path("/rest/repositories")
public String getRestRepositories(
@Context HttpHeaders headers,
//@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpServletResponse response,
@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET Rest Repositories request %s",request));
String url=uri.toString();
url=url.substring(0,url.length()-18);
Expand Down Expand Up @@ -328,10 +336,11 @@ public String getRestRepositories(
@GET
@Path("/repositories")
public Response getRepositories(
@Context HttpHeaders headers,
//@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpServletResponse response,
@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET Repositories request %s",request));
String url=uri.toString();
url=url.substring(0,url.length()-13);
Expand All @@ -348,10 +357,11 @@ public Response getRepositories(
@GET
@Path("/repositories/AGENT/namespaces")
public Response getNamespaces(
@Context HttpHeaders headers,
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context UriInfo uri) {
//@Context HttpHeaders headers,
@Context HttpServletRequest request
//,@Context HttpServletResponse response,
//@Context UriInfo uri
) {
monitor.debug(String.format("Received a GET Namespaces request %s",request));
Response.ResponseBuilder builder=Response.ok("prefix,namespace\n" +
"rdf,http://www.w3.org/1999/02/22-rdf-syntax-ns#\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public QueryIterator createExecution(OpService opOriginal, String serviceURL, Se
bb.add(idVar, keyNode);
newBindings.put(keyNode, new ArrayList<>());
Binding newBinding = bb.build();
bb = BindingBuilder.create(newBinding);
//bb = BindingBuilder.create(newBinding);
resultingBindings.put(key, newBinding);
}
final BindingBuilder bb2 = BindingBuilder.create(originalBinding);
Expand Down Expand Up @@ -362,7 +362,7 @@ public QueryIterator createExecution(OpService opOriginal, String serviceURL, Se
// -- End setup

// Build the execution
QueryExecBuilder qExecBuilder = QueryExec.newBuilder()
QueryExecutorBuilder qExecBuilder = QueryExecutor.newBuilder()
.endpoint(serviceURL)
.timeout(timeoutMillis, TimeUnit.MILLISECONDS)
.query(query)
Expand All @@ -380,7 +380,7 @@ public QueryIterator createExecution(OpService opOriginal, String serviceURL, Se
qExecBuilder = qExecBuilder.httpHeader(authKeyProp, authCodeProp);
}

try (QueryExec qExec = qExecBuilder.build()) {
try (QueryExecutor qExec = qExecBuilder.build()) {
// Detach from the network stream.
RowSet rowSet = qExec.select().materialize();
QueryIterator qIter = QueryIterPlainWrapper.create(rowSet);
Expand Down Expand Up @@ -445,7 +445,7 @@ public List<Binding> getRows() {
bb.add(idVar,keyNode);
newBindings.put(keyNode,new ArrayList<>());
Binding newBinding=bb.build();
bb=BindingBuilder.create(newBinding);
//bb=BindingBuilder.create(newBinding);
resultingBindings.put(key,newBinding);
}
final BindingBuilder bb2=BindingBuilder.create(originalBinding);
Expand Down
Loading

0 comments on commit 5dd8053

Please sign in to comment.