updates to include method that checks whether uri exists or not
This commit is contained in:
parent
d52b939743
commit
8fa8702462
4 changed files with 66 additions and 30 deletions
|
@ -28,6 +28,14 @@ public interface WebappDaoFactory {
|
||||||
*/
|
*/
|
||||||
public String checkURI(String uriStr, boolean checkUniqueness);
|
public String checkURI(String uriStr, boolean checkUniqueness);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given URI string exists in the system:
|
||||||
|
* checks for the following conditions: URI found as subject in a statement or an object or as a property
|
||||||
|
* @param uriStr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean hasExistingURI(String uriStr);
|
||||||
|
|
||||||
public String getDefaultNamespace();
|
public String getDefaultNamespace();
|
||||||
|
|
||||||
public Set<String> getNonuserNamespaces();
|
public Set<String> getNonuserNamespaces();
|
||||||
|
|
|
@ -83,6 +83,10 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
|
||||||
return innerWebappDaoFactory.checkURI(uriStr, checkUniqueness);
|
return innerWebappDaoFactory.checkURI(uriStr, checkUniqueness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasExistingURI(String uriStr) {
|
||||||
|
return innerWebappDaoFactory.hasExistingURI(uriStr);
|
||||||
|
}
|
||||||
|
|
||||||
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
||||||
//TODO: need to clone the filtering factory
|
//TODO: need to clone the filtering factory
|
||||||
return innerWebappDaoFactory.getUserAwareDaoFactory(userURI);
|
return innerWebappDaoFactory.getUserAwareDaoFactory(userURI);
|
||||||
|
|
|
@ -186,6 +186,25 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
errorMsg += (iri.violations(false).next())
|
errorMsg += (iri.violations(false).next())
|
||||||
.getShortMessage() + " ";
|
.getShortMessage() + " ";
|
||||||
} else if (checkUniqueness) {
|
} else if (checkUniqueness) {
|
||||||
|
boolean existingURI = this.hasExistingURI(uriStr);
|
||||||
|
if(existingURI) {
|
||||||
|
errorMsg+="Not a valid URI. Please enter another URI. ";
|
||||||
|
errorMsg+=duplicateMsg;
|
||||||
|
//the original code included an extra line "Not a valid URI. Please enter another URI. "
|
||||||
|
//in the error message in addition to the duplicate error message in the case where the uri
|
||||||
|
//is in the subject position of any of the statements in the system - but not so where the
|
||||||
|
//uri was only in the object position or was a propery. In this code, the same error message
|
||||||
|
//is returned for all duplicate uris
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (errorMsg.length()>0) ? errorMsg : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Check if URI already in use or not either as resource OR as property
|
||||||
|
public boolean hasExistingURI(String uriStr) {
|
||||||
|
boolean existingURI = false;
|
||||||
OntModel ontModel = ontModelSelector.getFullModel();
|
OntModel ontModel = ontModelSelector.getFullModel();
|
||||||
ontModel.enterCriticalSection(Lock.READ);
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
|
@ -194,30 +213,29 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
StmtIterator closeIt = ontModel.listStatements(
|
StmtIterator closeIt = ontModel.listStatements(
|
||||||
newURIAsRes, null, (RDFNode)null);
|
newURIAsRes, null, (RDFNode)null);
|
||||||
if (closeIt.hasNext()) {
|
if (closeIt.hasNext()) {
|
||||||
validURI = false;
|
existingURI = true;
|
||||||
errorMsg+="Not a valid URI. Please enter another URI. ";
|
|
||||||
errorMsg+=duplicateMsg;
|
|
||||||
}
|
}
|
||||||
if (validURI) {
|
//if not in the subject position, check in object position
|
||||||
|
if (!existingURI) {
|
||||||
closeIt = ontModel.listStatements(null, null, newURIAsRes);
|
closeIt = ontModel.listStatements(null, null, newURIAsRes);
|
||||||
if (closeIt.hasNext()) {
|
if (closeIt.hasNext()) {
|
||||||
validURI = false;
|
existingURI= true;
|
||||||
errorMsg+=duplicateMsg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (validURI) {
|
//Check for property
|
||||||
|
if (!existingURI) {
|
||||||
closeIt = ontModel.listStatements(
|
closeIt = ontModel.listStatements(
|
||||||
null, newURIAsProp, (RDFNode)null);
|
null, newURIAsProp, (RDFNode)null);
|
||||||
if (closeIt.hasNext()) {
|
if (closeIt.hasNext()) {
|
||||||
validURI = false;
|
existingURI = true;
|
||||||
errorMsg+=duplicateMsg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
ontModel.leaveCriticalSection();
|
ontModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return (errorMsg.length()>0) ? errorMsg : null;
|
return existingURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
||||||
|
|
|
@ -155,6 +155,12 @@ return this.objectPropertyStatementDao; }
|
||||||
"WebappDaoFactory.checkURI() not implemented.");
|
"WebappDaoFactory.checkURI() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasExistingURI(String uriStr) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"WebappDaoFactory.hasExistingURI() not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getNonuserNamespaces() {
|
public Set<String> getNonuserNamespaces() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
|
Loading…
Add table
Reference in a new issue