Skip to content

Commit

Permalink
initial push to github
Browse files Browse the repository at this point in the history
  • Loading branch information
gnomadix committed Jul 2, 2014
1 parent 03e27cf commit 61df54b
Show file tree
Hide file tree
Showing 21 changed files with 820 additions and 307 deletions.
1 change: 1 addition & 0 deletions Common.iml → scorpio4core.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/factcore/iq/exec/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Map<String, Future> execute(String listURI, Map bindings) throws Reposito

protected Map<String, Future> doExecutables(URI execURI, Map bindings) throws RepositoryException, ExecutionException, IQException, InterruptedException, IOException, AssetNotSupported {
RepositoryConnection connection = factSpace.getConnection();
Map beans = findBeans(connection, (URI) execURI);
Map beans = findBeans(connection, execURI);
if (beans==null|beans.isEmpty()) return null;
Asset asset = assetRegister.getAsset(execURI.stringValue(), null);
if (asset==null) return null; //throw new IQException("Missing asset: "+execURI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
* Date : 17/06/2014
* Time : 9:56 PM
*/
public class Publishing implements Executable {
public class Templating implements Executable {
private final Logger log = LoggerFactory.getLogger(this.getClass());

public Publishing() {
public Templating() {
}

@Override
Expand All @@ -45,7 +45,7 @@ public Future execute(Asset asset, Map bindings) throws IQException {
}

class NotFutureTemplate implements Future {
private final Logger log = LoggerFactory.getLogger(Publishing.class);
private final Logger log = LoggerFactory.getLogger(Templating.class);
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
Object result = null;

Expand Down
164 changes: 0 additions & 164 deletions src/main/java/com/factcore/vendor/camel/RDFRoutePlanner.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Obje
boolean autoClose = false;
Repository repository = null;
if (connection==null && manager!=null) {
// if (remaining.equals("")) remaining =
repository = manager.getRepository(remaining);
connection = repository.getConnection();
autoClose = true;
}
if (connection==null) throw new IQException("Failed to resolve connection: "+remaining);
log.debug("Remaining: "+remaining);
log.debug("SPARQL Endpoint: "+sparql);
log.debug("SPARQL Repository: "+remaining);
log.debug("SPARQL Query: "+sparql);
return new BeanEndpoint(uri, this, new BeanProcessor(new SesameHandler(connection, sparql, isInferred, maxQueryTime, autoClose ), getCamelContext()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package com.factcore.vendor.camel.component.core;

import com.factcore.assets.AssetHelper;
import com.factcore.iq.exec.Executable;
import com.factcore.oops.AssetNotSupported;
import com.factcore.oops.IQException;
import com.factcore.vendor.camel.component.CoreComponent;
import com.factcore.vocab.COMMON;
import org.apache.camel.Exchange;
import org.apache.camel.Handler;
import org.apache.camel.Message;
import org.apache.camel.util.ExchangeHelper;
import org.openrdf.repository.RepositoryException;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
Expand All @@ -36,27 +31,6 @@ public Executable getExecutable() {

@Handler
public void execute(Exchange exchange) throws RepositoryException, ExecutionException, IQException, InterruptedException, IOException, AssetNotSupported {

Message in = exchange.getIn();
Map<String, Object> headers = in.getHeaders();
Message out = exchange.getOut();
out.setHeaders(headers);

String contentType = ExchangeHelper.getContentType(exchange);
String mimeType = COMMON.MIME_TYPE+contentType;

if (asset==null) {
asset = coreComponent.getAssetRegister().getAsset(uri,mimeType);
if (asset==null) {
log.debug("Missing (" + contentType + ") Raw Asset: " + getClass().getSimpleName() + " -> " + uri);
out.setBody(in.getBody());
return;
}
}
if (asset!=null) {
asset = AssetHelper.getAsset(asset, headers);
log.debug("Asset: "+getClass().getSimpleName()+" -> "+uri);
out.setBody(asset.getContent());
}
super.execute(exchange);
}
}
57 changes: 39 additions & 18 deletions src/main/java/com/factcore/vendor/camel/component/core/Base.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.factcore.vendor.camel.component.core;

import com.factcore.assets.Asset;
import com.factcore.assets.AssetHelper;
import com.factcore.iq.exec.Executable;
import com.factcore.oops.AssetNotSupported;
import com.factcore.oops.IQException;
import com.factcore.vendor.camel.component.CoreComponent;
import com.factcore.vocab.COMMON;
import org.apache.camel.Exchange;
import org.apache.camel.Handler;
import org.apache.camel.Message;
import org.apache.camel.util.ExchangeHelper;
import org.openrdf.repository.RepositoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand All @@ -36,32 +39,50 @@ public Base(CoreComponent coreComponent, String uri) throws IOException {
this.uri=uri;
asset = coreComponent.getAssetRegister().getAsset(uri,null);

log.info(getClass().getSimpleName()+"Asset -> "+asset==null?"":asset.getMimeType()+" -> "+uri+"\n"+asset);
log.info(getClass().getSimpleName()+":Asset -> "+(asset==null?"not found: ":asset.getMimeType())+" -> "+uri+"\n"+asset);
}

public abstract Executable getExecutable();


@Handler
public void execute(Exchange exchange) throws RepositoryException, ExecutionException, IQException, InterruptedException, IOException, AssetNotSupported {
Executable exec = getExecutable();
Map<String, Object> headers = exchange.getIn().getHeaders();
Map body = exchange.getIn().getBody(Map.class);
body = body==null?headers:body;
Message in = exchange.getIn();
Message out = exchange.getOut();

Map<String, Object> headers = in.getHeaders();
Map body = in.getBody(Map.class);
String contentType = ExchangeHelper.getContentType(exchange);
if (asset!=null) {
log.debug("Asset: "+getClass().getSimpleName()+" -> "+uri+"\n\t"+asset.getMimeType());
if (asset.getMimeType()==null) asset.setMimeType(COMMON.MIME_TYPE+contentType);
Future done = exec.execute(asset, body);
exchange.getOut().setBody(done.get());
exchange.getOut().setHeaders(headers);
String mimeType = COMMON.MIME_TYPE+contentType;

if (asset==null) {
asset = coreComponent.getAssetRegister().getAsset(uri,mimeType);
if (asset==null) {
log.debug("Missing (" + contentType + ") Raw Asset: " + getClass().getSimpleName() + " -> " + uri);
out.setBody(in.getBody());
out.setFault(true);
return;
}
}
String endpointUri = exchange.getFromEndpoint().getEndpointUri();
asset = AssetHelper.getAsset(asset, headers);
log.debug("Asset: " + getClass().getSimpleName() + " -> " + uri);

out.setHeaders(headers);
out.setAttachments(in.getAttachments());

Executable exec = getExecutable();
if (exec!=null) {
log.debug("Executing: "+ endpointUri);
Map parameters = new HashMap();
parameters.put("exchange", exchange);
parameters.put("header", headers);
parameters.put("body", body);
Future done = exec.execute(asset, parameters);
out.setBody(done.get());
} else {
asset = coreComponent.getAssetRegister().getAsset(uri,COMMON.MIME_TYPE+contentType);
if (asset!=null) log.debug("Found !!");
log.debug("Missing ("+contentType+") Asset: "+getClass().getSimpleName()+" -> "+uri);
log.debug("\t{}", headers);
exchange.getOut().setBody(exchange.getIn().getBody());
exchange.getOut().setHeaders(headers);
log.debug("Asset Only: "+ endpointUri);
out.setBody(asset.getContent());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.factcore.iq.exec.Executor;
import com.factcore.iq.exec.Inferring;
import com.factcore.iq.exec.Publishing;
import com.factcore.iq.exec.Templating;
import com.factcore.iq.exec.Scripting;
import com.factcore.oops.AssetNotSupported;
import com.factcore.oops.FactException;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void execute(Exchange exchange) throws RepositoryException, ExecutionExce

Executor executor = new Executor(coreComponent.getFactSpace());
executor.addExecutable(new Scripting());
executor.addExecutable(new Publishing());
executor.addExecutable(new Templating());
executor.addExecutable(new Inferring(coreComponent.getFactSpace()));

Map<String,Future> executed = executor.execute(uri, headers);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.factcore.vendor.camel.component.core;

import com.factcore.iq.exec.Executable;
import com.factcore.iq.exec.Publishing;
import com.factcore.iq.exec.Templating;
import com.factcore.vendor.camel.component.CoreComponent;

import java.io.IOException;
Expand All @@ -21,6 +21,6 @@ public Publish(CoreComponent coreComponent, String substring) throws IOException

@Override
public Executable getExecutable() {
return new Publishing();
return new Templating();
}
}
Loading

0 comments on commit 61df54b

Please sign in to comment.