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

Multiplebindings #92

Merged
merged 18 commits into from
Jan 24, 2024
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
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
echo ENGINE PROPERTIES
cat engine.jpar
echo LOG4J
cat log4j2.xml
java -Dlog4j.configurationFile=./log4j2.xml -jar engine-1.0.0-SNAPSHOT.jar -engine engine.jpar -endpoint endpoint.jpar > log.txt &
cat log4j2-debug.xml
java -Dlog4j.configurationFile=./log4j2-debug.xml -jar engine-1.0.0-SNAPSHOT.jar -engine engine.jpar -endpoint endpoint.jpar > log.txt &
shell: bash
- name: wait for SEPA engine
uses: nev7n/wait_for_response@v1
Expand All @@ -74,9 +74,10 @@ jobs:
timeout: 20000
interval: 500
- name: verify
run: mvn verify -e
- name: Archive code coverage results
run: mvn verify -e -Dlog4j2.level=trace
- name: publish Engine log
uses: actions/upload-artifact@v2
if: always()
with:
name: engine-log
path: engine/target/log.txt
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ COPY --from=BUILD ./engine/src/main/resources/jmxremote.password /jmxremote.pass
COPY --from=BUILD ./engine/src/main/resources/jmxremote.access /jmxremote.access
COPY --from=BUILD ./engine/src/main/resources/jmx.properties /jmx.properties
COPY --from=BUILD ./engine/src/main/resources/endpoint.jpar /endpoint.jpar

# COPY ALL ENDPOINTS TO ALLOW CMD LINE CUSTOMIZATION
COPY --from=BUILD ./engine/src/main/resources/endpoints /endpoints

RUN chmod 600 /jmxremote.password

ENV JMX_HOSTNAME=0.0.0.0
ENV JMX_PORT=7090

EXPOSE 8000
EXPOSE 9000
EXPOSE 7091

ENV JMX_HOSTNAME=0.0.0.0
EXPOSE ${JMX_PORT}

ENTRYPOINT java -Djava.rmi.server.hostname=${JMX_HOSTNAME} -Dcom.sun.management.config.file=jmx.properties -jar engine.jar
ENTRYPOINT java -Djava.rmi.server.hostname=${JMX_HOSTNAME} -Dcom.sun.management.jmxremote.port=${JMX_PORT} -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT} -Dcom.sun.management.config.file=jmx.properties -jar engine.jar
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected final void setParameter(String key,String value) {
break;
default:
if (key.startsWith("-sparql11seprotocol.availableProtocols")) {
String[] token = key.split(".");
String[] token = key.split("\\.");
if (token[3] == "path") this.sparql11seprotocol.availableProtocols.get(token[2]).path = value;
else if (token[3] == "port") this.sparql11seprotocol.availableProtocols.get(token[2]).port = Integer.valueOf(value);
else if (token[3] == "scheme") this.sparql11seprotocol.availableProtocols.get(token[2]).scheme = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import com.google.gson.JsonPrimitive;
import it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException;

/**
Expand Down Expand Up @@ -92,7 +93,9 @@ public RDFTerm getRDFTerm(String variable) throws SEPABindingsException {
try {
String type = getType(variable);
String value = getValue(variable);


if (type == null || value == null) return null;

switch(type) {
case "uri":
return new RDFTermURI(value);
Expand All @@ -105,7 +108,7 @@ public RDFTerm getRDFTerm(String variable) throws SEPABindingsException {
}
}
catch(Exception e) {
throw new SEPABindingsException(e);
return null;
}

return null;
Expand Down Expand Up @@ -221,7 +224,12 @@ public boolean isBNode(String variable) throws SEPABindingsException {
* the value
*/
public void addBinding(String variable, RDFTerm value) {
solution.add(variable, value.toJson());
if (value == null) {
JsonObject undefObject = new JsonObject();
undefObject.add("value",null);
solution.add(variable,undefObject);
}
else solution.add(variable, value.toJson());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public boolean isBNode() {
*/
public String getValue() {
if (!json.has("value")) return null;
if (json.get("value") == null) return null;
return json.get("value").getAsString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import it.unibo.arces.wot.sepa.commons.request.UpdateRequest;
import it.unibo.arces.wot.sepa.commons.response.Response;

import java.util.ArrayList;

public abstract class Aggregator extends Consumer implements IConsumer, IProducer {
private final String sparqlUpdate;
protected final String updateId;
private final ForcedBindings updateForcedBindings;
private final SPARQL11Protocol sparql11;

private MultipleForcedBindings multipleForcedBindings;
public Aggregator(JSAP appProfile, String subscribeID, String updateID)
throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException {
super(appProfile, subscribeID);
Expand All @@ -49,11 +51,11 @@ public Aggregator(JSAP appProfile, String subscribeID, String updateID)
}

updateId = updateID;

sparqlUpdate = appProfile.getSPARQLUpdate(updateID);

updateForcedBindings = appProfile.getUpdateBindings(updateID);

multipleForcedBindings = appProfile.getUpdateMultipleBindings(updateID);

sparql11 = new SPARQL11Protocol(sm);
}

Expand All @@ -77,7 +79,35 @@ public final Response update(long timeout,long nRetry) throws SEPASecurityExcept
return retResponse;
}

public final Response multipleUpdate(long timeout,long nRetry)
throws SEPASecurityException, SEPAPropertiesException, SEPABindingsException, SEPAProtocolException {
UpdateRequest req = new UpdateRequest(appProfile.getUpdateMethod(updateId),
appProfile.getUpdateProtocolScheme(updateId), appProfile.getUpdateHost(updateId),
appProfile.getUpdatePort(updateId), appProfile.getUpdatePath(updateId),
appProfile.addPrefixesAndReplaceMultipleBindings(sparqlUpdate,
addDefaultDatatype(multipleForcedBindings.getBindings(), updateId, false)),
appProfile.getUsingGraphURI(updateId), appProfile.getUsingNamedGraphURI(updateId),
(appProfile.isSecure() ? appProfile.getAuthenticationProperties().getBearerAuthorizationHeader() : null), timeout,nRetry);

Logging.logger.trace(req);

Response retResponse = sparql11.update(req);

Logging.logger.trace(retResponse);

return retResponse;
}

public final Response multipleUpdate()
throws SEPASecurityException, SEPAProtocolException, SEPAPropertiesException, SEPABindingsException {
return multipleUpdate(TIMEOUT,NRETRY);
}

public final void setUpdateBindingValue(String variable, RDFTerm value) throws SEPABindingsException {
updateForcedBindings.setBindingValue(variable, value);
}

public final void setUpdateMultipleBindings(ArrayList<String> variables, ArrayList<ArrayList<RDFTerm>> values) throws SEPABindingsException {
multipleForcedBindings.setUpdateBindings(variables,values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package it.unibo.arces.wot.sepa.pattern;

import java.io.IOException;
import java.util.ArrayList;

import it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException;
import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException;
Expand Down Expand Up @@ -140,11 +141,16 @@ public void close() throws IOException {
* </pre>
**/

protected ArrayList<Bindings> addDefaultDatatype(ArrayList<Bindings> bindings, String id, boolean query) throws SEPABindingsException {
ArrayList<Bindings> temp = new ArrayList<>();
for (Bindings b : bindings) temp.add(addDefaultDatatype(b,id,query));
return temp;
}
protected Bindings addDefaultDatatype(Bindings bindings, String id, boolean query) throws SEPABindingsException {
if (id == null)
return bindings;
if (bindings == null)
return bindings;
return null;

// Forced bindings by JSAP
Bindings jsap_template;
Expand All @@ -154,9 +160,13 @@ protected Bindings addDefaultDatatype(Bindings bindings, String id, boolean quer
jsap_template = appProfile.getUpdateBindings(id);

// Add missing datatype, if any
Bindings retBindings = new Bindings();
Bindings retBindings = new ForcedBindings();
for (String varString : bindings.getVariables()) {
RDFTerm term = bindings.getRDFTerm(varString);
if (term == null) {
retBindings.addBinding(varString,null);
continue;
}
if (term.isLiteral()) {
RDFTermLiteral literal = (RDFTermLiteral) term;
if (literal.getDatatype() == null && jsap_template.getDatatype(varString) != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.unibo.arces.wot.sepa.pattern;

import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

import it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException;
Expand All @@ -10,6 +11,13 @@
import it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI;

public class ForcedBindings extends Bindings {
public ForcedBindings(JsonObject solution) {
super(solution);
}

public ForcedBindings() {
super();
}
/**
* Sets the binding value.
*
Expand Down
Loading
Loading