From fc0cfb2da4143273e9e81c6ce89100776682e98f Mon Sep 17 00:00:00 2001 From: Luca Roffia Date: Mon, 2 Dec 2024 12:49:27 +0100 Subject: [PATCH] fix updated pom, update parameters parsing --- .../properties/SPARQL11Properties.java | 27 ++----- .../properties/SPARQL11SEProperties.java | 79 +++++++++++-------- .../SPARQL11SEProtocolProperties.java | 3 - pom.xml | 8 +- 4 files changed, 57 insertions(+), 60 deletions(-) diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java index a3e9bfc6..510738c0 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java @@ -87,8 +87,6 @@ public class SPARQL11Properties { protected SPARQL11ProtocolProperties sparql11protocol; protected GraphsProperties graphs = null; - private URI uri = null; - /** * The Enum SPARQLPrimitive (QUERY, UPDATE). */ @@ -170,12 +168,14 @@ public SPARQL11Properties(URI uri,String[] args) throws SEPAPropertiesException } if (args != null) - for (int i = 0; i < args.length; i = i + 2) { - Logging.logger.trace("Argument "+args[i]+" : "+args[i+1]); - setParameter(args[i], args[i+1]); + // Setting values: -key=value + for (int i = 0; i < args.length; i++) { + Logging.logger.trace("Argument "+args[i]); + String[] params = args[i].split("="); + if (params.length == 2) { + setParameter(params[0], params[1]); + } } - - this.uri = uri; } protected void setParameter(String key,String value) { @@ -210,19 +210,6 @@ protected void setParameter(String key,String value) { } } - private void parseJSAP(Reader in) throws SEPAPropertiesException { - SPARQL11Properties jsap; - try { - jsap = new Gson().fromJson(in, SPARQL11Properties.class); - } catch (JsonSyntaxException | JsonIOException e) { - Logging.logger.error(e.getMessage()); - throw new SEPAPropertiesException(e); - } - - this.sparql11protocol = jsap.sparql11protocol; - this.graphs = jsap.graphs; - } - /* * Applications working with file paths and file URIs should take great care * to use the appropriate methods to convert between the two. diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java index 0a462f55..1552f53b 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java @@ -85,22 +85,23 @@ public enum SPARQL11SEPrimitive { protected SPARQL11SEProtocolProperties sparql11seprotocol; public SPARQL11SEProperties() throws SEPAPropertiesException { - this((URI) null,null); + this((URI) null, null); } - public SPARQL11SEProperties(String uri,String[] args) throws SEPAPropertiesException { - this(URI.create(uri),args); + + public SPARQL11SEProperties(String uri, String[] args) throws SEPAPropertiesException { + this(URI.create(uri), args); } public SPARQL11SEProperties(URI uri) throws SEPAPropertiesException { - this(uri,null); + this(uri, null); } public SPARQL11SEProperties(String uri) throws SEPAPropertiesException { - this(URI.create(uri),null); + this(URI.create(uri), null); } - public SPARQL11SEProperties(URI uri,String[] args) throws SEPAPropertiesException { - super(uri,args); + public SPARQL11SEProperties(URI uri, String[] args) throws SEPAPropertiesException { + super(uri, args); if (uri != null) { Reader in = getReaderFromUri(uri); @@ -118,44 +119,56 @@ public SPARQL11SEProperties(URI uri,String[] args) throws SEPAPropertiesExceptio } catch (IOException e) { throw new SEPAPropertiesException(e); } - } else sparql11seprotocol = new SPARQL11SEProtocolProperties(); + } else + sparql11seprotocol = new SPARQL11SEProtocolProperties(); Map envs = System.getenv(); - for(String var : envs.keySet()) { - Logging.logger.trace("Environmental variable "+var+" : "+envs.get(var)); - setSeParameter("-"+var, envs.get(var)); + for (String var : envs.keySet()) { + Logging.logger.trace("Environmental variable " + var + " : " + envs.get(var)); + setSeParameter("-" + var, envs.get(var)); } if (args != null) - for (int i = 0; i < args.length; i = i + 2) { - Logging.logger.trace("Argument "+args[i]+" : "+args[i+1]); - setSeParameter(args[i], args[i+1]); + for (int i = 0; i < args.length; i++) { + Logging.logger.trace("Argument " + args[i]); + String[] params = args[i].split("="); + if (params.length == 2) { + setParameter(params[0], params[1]); + } } } - protected void setSeParameter(String key,String value) { + protected void setSeParameter(String key, String value) { switch (key) { - case "-sparql11seprotocol.host": - sparql11seprotocol.setHost(value); - break; - case "-sparql11seprotocol.protocol": - sparql11seprotocol.setProtocol(value); - break; - case "-sparql11seprotocol.reconnect": - sparql11seprotocol.setReconnect(Boolean.parseBoolean(value)); - break; - default: - if (key.startsWith("-sparql11seprotocol.availableProtocols")) { - String[] token = key.split("\\."); - if (sparql11seprotocol == null) sparql11seprotocol = new SPARQL11SEProtocolProperties(); - if (sparql11seprotocol.getAvailableProtocols() == null) { - sparql11seprotocol.setAvailableProtocols(new HashMap<>()); + case "-sparql11seprotocol.host": + sparql11seprotocol.setHost(value); + break; + case "-sparql11seprotocol.protocol": + sparql11seprotocol.setProtocol(value); + break; + case "-sparql11seprotocol.reconnect": + sparql11seprotocol.setReconnect(Boolean.parseBoolean(value)); + break; + default: + if (key.startsWith("-sparql11seprotocol.availableProtocols")) { + String[] token = key.split("\\."); + if (sparql11seprotocol == null) + sparql11seprotocol = new SPARQL11SEProtocolProperties(); + if (sparql11seprotocol.getAvailableProtocols() == null) { + sparql11seprotocol.setAvailableProtocols(new HashMap<>()); + sparql11seprotocol.getAvailableProtocols().put(token[2], new SubscriptionProtocolProperties()); + } else { + if (sparql11seprotocol.getAvailableProtocols().get(token[2]) == null) { sparql11seprotocol.getAvailableProtocols().put(token[2], new SubscriptionProtocolProperties()); } - if (Objects.equals(token[3], "path")) sparql11seprotocol.getAvailableProtocols().get(token[2]).setPath(value); - else if (Objects.equals(token[3], "port")) sparql11seprotocol.getAvailableProtocols().get(token[2]).setPort(Integer.parseInt(value)); - else if (Objects.equals(token[3], "scheme")) sparql11seprotocol.getAvailableProtocols().get(token[2]).setScheme(value); } + if (Objects.equals(token[3], "path")) + sparql11seprotocol.getAvailableProtocols().get(token[2]).setPath(value); + else if (Objects.equals(token[3], "port")) + sparql11seprotocol.getAvailableProtocols().get(token[2]).setPort(Integer.parseInt(value)); + else if (Objects.equals(token[3], "scheme")) + sparql11seprotocol.getAvailableProtocols().get(token[2]).setScheme(value); + } } } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java index 091daec6..06dd6873 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java @@ -1,8 +1,5 @@ package it.unibo.arces.wot.sepa.commons.properties; -import it.unibo.arces.wot.sepa.api.SubscriptionProtocol; -import it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol; - import java.util.HashMap; public class SPARQL11SEProtocolProperties { diff --git a/pom.xml b/pom.xml index 77c69fb6..334eb3dd 100644 --- a/pom.xml +++ b/pom.xml @@ -48,10 +48,10 @@ - 11 - 11 - 11 - 11 + 23 + 23 + 23 + 23 UTF-8 1.0.0-SNAPSHOT 0