Skip to content

Commit

Permalink
Merge pull request #314 from vincentmigot/fix-empty-max-id-bug
Browse files Browse the repository at this point in the history
Fix bug when URI are generated and no objects already exists in triplestore
  • Loading branch information
annetireau authored Sep 13, 2019
2 parents 150bb55 + 757161e commit b10f70e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 32 deletions.
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/ActuatorDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.BooleanQuery;
import org.eclipse.rdf4j.query.MalformedQueryException;
Expand Down Expand Up @@ -244,10 +245,13 @@ public int getLastIdFromYear(String year) {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

@Override
Expand Down
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/MethodDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.jena.sparql.expr.Expr;
import org.apache.jena.sparql.expr.ExprList;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;

/**
* Method DAO.
Expand Down Expand Up @@ -213,10 +214,13 @@ public int getLastId() {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.apache.jena.sparql.expr.ExprList;
import org.apache.jena.sparql.path.PathFactory;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;

/**
* Allows CRUD methods of scientific objects in the triplestore.
Expand Down Expand Up @@ -168,10 +169,13 @@ public int getLastScientificObjectIdFromYear(String year) {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/SensorDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.jena.sparql.expr.ExprList;
import org.apache.jena.sparql.path.PathFactory;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;

/**
* Sensor DAO.
Expand Down Expand Up @@ -156,10 +157,13 @@ public int getLastIdFromYear(String year) {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/TraitDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.MalformedQueryException;
import org.eclipse.rdf4j.query.QueryLanguage;
Expand Down Expand Up @@ -174,10 +175,13 @@ public int getLastId() {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/UnitDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.jena.sparql.expr.Expr;
import org.apache.jena.sparql.expr.ExprList;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;

/**
* Unit DAO.
Expand Down Expand Up @@ -204,10 +205,13 @@ public int getLastId() {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/VariableDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.jena.sparql.expr.Expr;
import org.apache.jena.sparql.expr.ExprList;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;

/**
* Variable DAO.
Expand Down Expand Up @@ -249,10 +250,13 @@ public int getLastId() {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions phis2-ws/src/main/java/opensilex/service/dao/VectorDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.jena.sparql.path.PathFactory;
import org.apache.jena.update.UpdateRequest;
import org.apache.jena.vocabulary.XSD;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.Update;

/**
Expand Down Expand Up @@ -432,10 +433,13 @@ public int getLastIdFromYear(String year) {

if (result.hasNext()) {
BindingSet bindingSet = result.next();
return Integer.valueOf(bindingSet.getValue(MAX_ID).stringValue());
} else {
return 0;
}
Value maxId = bindingSet.getValue(MAX_ID);
if (maxId != null) {
return Integer.valueOf(maxId.stringValue());
}
}

return 0;
}

/**
Expand Down

0 comments on commit b10f70e

Please sign in to comment.