NIHVIVO-945 code change for generation of local names with positive integers.
This commit is contained in:
parent
035c4c3735
commit
ef712eb11a
1 changed files with 18 additions and 16 deletions
|
@ -79,7 +79,6 @@ import edu.cornell.mannlib.vitro.webapp.utils.Csv2Rdf;
|
|||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.WorkflowOntology;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
|
||||
|
@ -443,6 +442,7 @@ public class JenaIngestController extends BaseEditController {
|
|||
}
|
||||
else if(oldModel!=null){
|
||||
doPermanentURI(oldModel,newModel,oldNamespace,newNamespace,dNamespace,maker,vreq);
|
||||
|
||||
request.setAttribute("title","Ingest Menu");
|
||||
request.setAttribute("bodyJsp",INGEST_MENU_JSP);
|
||||
}
|
||||
|
@ -979,7 +979,7 @@ public class JenaIngestController extends BaseEditController {
|
|||
if(oldNamespace.equals(res.getNameSpace())){
|
||||
Resource newRes = null;
|
||||
if(!newNamespace.equals("")){
|
||||
uri = getUnusedURI(newNamespace);
|
||||
uri = getUnusedURI(newNamespace,wdf);
|
||||
}
|
||||
else if(!dNamespace.equals("")){
|
||||
try{
|
||||
|
@ -1004,21 +1004,23 @@ public class JenaIngestController extends BaseEditController {
|
|||
|
||||
|
||||
}
|
||||
private String getUnusedURI(String newNamespace){
|
||||
private String getUnusedURI(String newNamespace,WebappDaoFactory wdf){
|
||||
String uri = null;
|
||||
Random random = new Random(Integer.MAX_VALUE);
|
||||
boolean resourcePresent=true;
|
||||
OntModel vitroJenaModel = (OntModel) getServletContext().getAttribute("baseOntModel");
|
||||
Resource res = null;
|
||||
do{
|
||||
uri = newNamespace + "n" + random.nextInt();
|
||||
res = vitroJenaModel.getResource(uri);
|
||||
StmtIterator stmtItr1 = vitroJenaModel.listStatements(res,(Property)null,(RDFNode)null);
|
||||
if(!stmtItr1.hasNext()){
|
||||
resourcePresent=false;
|
||||
res.removeAll((Property)null);
|
||||
}
|
||||
}while(resourcePresent);
|
||||
String errMsg = null;
|
||||
Random random = new Random();
|
||||
boolean uriIsGood = false;
|
||||
int attempts = 0;
|
||||
|
||||
while( uriIsGood == false && attempts < 30 ){
|
||||
uri = newNamespace + "n" + random.nextInt( Math.min(Integer.MAX_VALUE,(int)Math.pow(2,attempts + 13)) );
|
||||
errMsg = wdf.checkURI(uri);
|
||||
if( errMsg != null)
|
||||
uri = null;
|
||||
else
|
||||
uriIsGood = true;
|
||||
attempts++;
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
private String doMerge(String uri1, String uri2,HttpServletResponse response,HttpServletRequest request){
|
||||
|
|
Loading…
Add table
Reference in a new issue