Skip to content

Commit

Permalink
fix JSAP and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lroffia committed Dec 2, 2024
1 parent 37a5d54 commit 4897642
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@

public class SPARQL11Properties {
// Members.
protected SPARQL11ProtocolProperties sparql11protocol;
protected SPARQL11ProtocolProperties sparql11protocol;
protected GraphsProperties graphs = null;

protected URI uri = null;
private URI uri = null;

/**
* The Enum SPARQLPrimitive (QUERY, UPDATE).
Expand All @@ -97,7 +97,7 @@ public enum SPARQLPrimitive {
QUERY,
/** The update. */
UPDATE
};
}

/**
* The Enum UpdateResultsFormat (HTTP,HTTPS).
Expand All @@ -112,69 +112,57 @@ public enum ProtocolScheme {

private final String label;

private ProtocolScheme(String value) {
ProtocolScheme(String value) {
label = value;
}

public String getProtocolScheme() {
return label;
}
};

public SPARQL11Properties() {
this.sparql11protocol = new SPARQL11ProtocolProperties();
this.sparql11protocol.setProtocol(ProtocolScheme.http);

override(null);
}

public SPARQL11Properties(String args[]) {
this();

override(args);
public SPARQL11Properties() throws SEPAPropertiesException {
this((String[]) null);
}

public SPARQL11Properties(URI uri,String[] args) throws SEPAPropertiesException {
this();

Reader in = getReaderFromUri(uri);
parseJSAP(in);
try {
in.close();
} catch (IOException e) {
throw new SEPAPropertiesException(e);
}
public SPARQL11Properties(String uri) throws SEPAPropertiesException {
this(URI.create(uri));
}

override(args);
public SPARQL11Properties(String uri,String[] args) throws SEPAPropertiesException {
this(URI.create(uri),args);
}

this.uri = uri;
public SPARQL11Properties(String[] args) throws SEPAPropertiesException {
this((URI) null,args);
}

public SPARQL11Properties(URI uri) throws SEPAPropertiesException {
this(uri,null);
}
public SPARQL11Properties(URI uri,String[] args) throws SEPAPropertiesException {
if (uri != null) {
Reader in = getReaderFromUri(uri);

public SPARQL11Properties(String host,ProtocolScheme scheme) {
this.sparql11protocol = new SPARQL11ProtocolProperties();
this.sparql11protocol.setHost(host);
this.sparql11protocol.setProtocol(scheme);
SPARQL11Properties jsap;
try {
jsap = new Gson().fromJson(in, SPARQL11Properties.class);
} catch (JsonSyntaxException | JsonIOException e) {
Logging.logger.error(e.getMessage());
throw new SEPAPropertiesException(e);
}

override(null);
}
this.sparql11protocol = jsap.sparql11protocol;
this.graphs = jsap.graphs;

// public SPARQL11Properties(Reader in,String[] args) throws SEPAPropertiesException {
// this();
//
// parseJSAP(in);
//
// override(args);
// }
//
// public SPARQL11Properties(Reader in) throws SEPAPropertiesException {
// this(in,null);
// }
try {
in.close();
} catch (IOException e) {
throw new SEPAPropertiesException(e);
}
}
else sparql11protocol = new SPARQL11ProtocolProperties();

protected void override(String[] args) {
Map<String, String> envs = System.getenv();
for(String var : envs.keySet()) {
Logging.logger.trace("Environmental variable "+var+" : "+envs.get(var));
Expand All @@ -186,10 +174,44 @@ protected void override(String[] args) {
Logging.logger.trace("Argument "+args[i]+" : "+args[i+1]);
setParameter(args[i], args[i+1]);
}

this.uri = uri;
}

protected void setParameter(String key,String value) {
switch (key) {
case "-sparql11protocol.port":
sparql11protocol.setPort(Integer.parseInt(value));
break;
case "-sparql11protocol.host":
sparql11protocol.setHost(value);
break;
case "-sparql11protocol.protocol":
sparql11protocol.setProtocol((Objects.equals(value, "http") ? ProtocolScheme.http : ProtocolScheme.https));
break;
case "-sparql11protocol.update.method":
sparql11protocol.getUpdate().setMethod((Objects.equals(value, "post") ? UpdateHTTPMethod.POST : UpdateHTTPMethod.URL_ENCODED_POST));
break;
case "-sparql11protocol.update.format":
sparql11protocol.getUpdate().setFormat((Objects.equals(value, "json") ? UpdateResultsFormat.JSON : UpdateResultsFormat.HTML));
break;
case "-sparql11protocol.update.path":
sparql11protocol.getUpdate().setPath(value);
break;
case "-sparql11protocol.query.method":
sparql11protocol.getQuery().setMethod((Objects.equals(value, "get") ? QueryHTTPMethod.GET : (Objects.equals(value, "post") ? QueryHTTPMethod.POST : QueryHTTPMethod.URL_ENCODED_POST)));
break;
case "-sparql11protocol.query.format":
sparql11protocol.getQuery().setFormat((Objects.equals(value, "json") ? QueryResultsFormat.JSON : (Objects.equals(value, "xml") ? QueryResultsFormat.XML : QueryResultsFormat.CSV)));
break;
case "-sparql11protocol.query.path":
sparql11protocol.getQuery().setPath(value);
break;
}
}

private void parseJSAP(Reader in) throws SEPAPropertiesException {
SPARQL11Properties jsap = null;
SPARQL11Properties jsap;
try {
jsap = new Gson().fromJson(in, SPARQL11Properties.class);
} catch (JsonSyntaxException | JsonIOException e) {
Expand Down Expand Up @@ -240,38 +262,6 @@ protected Reader getReaderFromUri(URI uri) throws SEPAPropertiesException {
return in;
}

protected void setParameter(String key,String value) {
switch (key) {
case "-sparql11protocol.port":
this.sparql11protocol.setPort(Integer.valueOf(value));
break;
case "-sparql11protocol.host":
this.sparql11protocol.setHost(value);
break;
case "-sparql11protocol.protocol":
this.sparql11protocol.setProtocol((value == "http" ? ProtocolScheme.http : ProtocolScheme.https));
break;
case "-sparql11protocol.update.method":
this.sparql11protocol.getUpdate().setMethod((value == "post" ? UpdateHTTPMethod.POST : UpdateHTTPMethod.URL_ENCODED_POST));
break;
case "-sparql11protocol.update.format":
this.sparql11protocol.getUpdate().setFormat((value == "json" ? UpdateResultsFormat.JSON : UpdateResultsFormat.HTML));
break;
case "-sparql11protocol.update.path":
this.sparql11protocol.getUpdate().setPath(value);
break;
case "-sparql11protocol.query.method":
this.sparql11protocol.getQuery().setMethod((value == "get" ? QueryHTTPMethod.GET : (value == "post" ? QueryHTTPMethod.POST : QueryHTTPMethod.URL_ENCODED_POST)));
break;
case "-sparql11protocol.query.format":
this.sparql11protocol.getQuery().setFormat((value == "json" ? QueryResultsFormat.JSON : (value == "xml" ? QueryResultsFormat.XML : QueryResultsFormat.CSV)));
break;
case "-sparql11protocol.query.path":
this.sparql11protocol.getQuery().setPath(value);
break;
}
}

public String toString() {
return new Gson().toJson(this);
}
Expand Down Expand Up @@ -304,9 +294,7 @@ public int getPort() {

/**
* Sets the update port.
*
* @return the update port
*/
**/
public void setPort(int port) {
sparql11protocol.setPort(port);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

public class SPARQL11ProtocolProperties {
private String host = null;
private ProtocolScheme protocol = null;
private int port = -1;
private ProtocolScheme protocol = ProtocolScheme.http;
private int port = 8000;
private QueryProperties query = new QueryProperties();
private UpdateProperties update = new UpdateProperties();

public SPARQL11ProtocolProperties merge(SPARQL11ProtocolProperties temp) {
if (temp != null) {
this.setHost((temp.getHost() != null ? temp.getHost() : this.getHost()));
this.setProtocol((temp.getProtocol() != null ? temp.getProtocol() : this.getProtocol()));
this.setPort((temp.getPort() != -1 ? temp.getPort() : this.getPort()));
this.getQuery().merge(temp.getQuery());
this.getUpdate().merge(temp.getUpdate());
setHost((temp.getHost() != null ? temp.getHost() : getHost()));
setProtocol((temp.getProtocol() != null ? temp.getProtocol() : getProtocol()));
setPort((temp.getPort() != -1 ? temp.getPort() : getPort()));
getQuery().merge(temp.getQuery());
getUpdate().merge(temp.getUpdate());
}

return this;
Expand Down
Loading

0 comments on commit 4897642

Please sign in to comment.