this.pnamespace = PredefinedNamespace.get();
}
@Override
public LocalRepository execute(LocalRepository inGraph) {
LocalRepository lr = RepositoryFactory.getServiceRepository(this.getUri());
//otherwise we need to execute the query
boolean isNegation = MBBService.NEGATION.equals(this.params.get(1));
boolean isInverse = MBBService.INVERSE.equals(this.params.get(2));
String sFullProperty = this.params.get(3);
String sPropertyNS = this.params.get(4);
String sPropertyName = this.params.get(5);
boolean uriprop = (null == sPropertyNS || "".equals(sPropertyNS));
String[] asFullProperty = null;
if(uriprop) {
if(null != sPropertyName && !"".equals(sPropertyName))
sFullProperty = sPropertyName;
sFullProperty = URLDecode.decode(sFullProperty); // -- sFullProperty can be a property name or a URL-encoded URI
URI u;
try {
u = new URI(sFullProperty);
} catch (URISyntaxException e) {
u = null;
}
String prop;
if(u == null || !u.isAbsolute()){
asFullProperty = this.pproperty.getURI(sFullProperty); // if sFullProperty is a property name - get all URI
prop = sFullProperty;
} else {
asFullProperty = new String[1];
asFullProperty[0] = sFullProperty;
prop = this.pproperty.getName(sFullProperty);
}
this.params.set(3, prop);
}
try {
if(lr.getGraph().getStatements().hasNext())
return lr;//it means that we already invoked this query
} catch (AccessDeniedException e) {
Repository.logger.warning(e.toString());
}
RDFQuery rdfquery;
// String pparam;
String restparam;
String using;
//this is the type of browse when you match values
rdfquery = (isInverse)?RDFQuery.RDFQ_BROWSE_LISTVALUES_PROPERTY_INVERSE:RDFQuery.RDFQ_BROWSE_LISTVALUES_PROPERTY;
if(uriprop) {
using = "";
// pparam = "prop";//(isNegation)?"prop":"<"+sFullProperty+">";
restparam = (isNegation)?"NOT (":"(";
if(asFullProperty != null)
for(String s : asFullProperty){
restparam += "prop = <"+s+"> OR ";
}
if(restparam.length() > 4)
restparam = restparam.substring(0, restparam.length()-4);
restparam += ")";
// restparam = (isNegation)?"NOT prop = <"+sFullProperty+">":"TRUE";
}else {
// String property = this.pproperty.getURI(sPropertyName);
// pparam = "prop";//(sPropertyNS == null)?"<"+property+">":"prop";
restparam = "TRUE";
if(!"*".equals(sPropertyNS))
restparam += ((!isNegation)?" AND (":" AND (NOT ")+"namespace(prop) = property:";
//namespace(prop) = property: AND localName(prop) LIKE "*digitaltype*" //IGNORE CASE
if(!"*".equals(sPropertyName) && !"*".equals(sPropertyNS))
restparam += (!isNegation)?" AND ":" OR ";
if(!"*".equals(sPropertyName))
restparam += ((!isNegation)?"":"NOT")+" localName(prop)=\""+sPropertyName+"\"";
if(!"*".equals(sPropertyNS))
restparam += ") ";
using = (!"*".equals(sPropertyNS))?" USING NAMESPACE mbb = <http://s3b.corrib.org/mbb#>"+RDFQuery.RDFQ_ADD_NAMESPACE.toString(this.pnamespace.getURI(sPropertyNS)):"";
}
String valueQueryPart = rdfquery.toString(/*pparam, */restparam);
valueQueryPart += using;
//no need for predefined properties
Repository.logger.info(valueQueryPart);
Value[] avUris = SesameWrapper.performVectorQuery(inGraph, QueryLanguage.SERQL, valueQueryPart);
try {
SesameWrapper.loadResources(avUris, Repository.MAIN_REPOSITORY.getLocalRepository(), lr.getGraph());
} catch (AccessDeniedException e) {
e.printStackTrace();
}
this.annotateResults(lr, avUris);