if(serviceUri == null)
serviceUri = ConfigKeeper.getServiceUrl()+"/mbb/service/"+serviceId;
Graph g = lr.getGraph();
ValueFactory vf = g.getValueFactory();
URI xsdString = XSD_STRING.getURI(g);
URI xsdDateTime = XSD_DATETIME.getURI(g);
URI xsdInt = XSD_INT.getURI(g);
URI rdfType = vf.createURI(RDF.TYPE);
URI context = vf.createURI(url);
URI call = vf.createURI(serviceUri);
String actionUri = url+"/action/";
Resource lastAction = null;
// --------------- BEGIN : to be removed -------------------------
// if(axisPath.isInitial()) {
// lastAction = AxisPath.getLastAction(globalLr, context, _usedPath);
// if(lastAction != null)
// _usedPath.add(0);
// } else {
// ///--- follows along axis
// LocalRepository lr2 = Repository.TEMP_REPOSITORY.getLocalRepository();
// lastAction = axisPath.getLastOnList(globalLr, context, lr2.getGraph(), false, _usedPath);
//
// //--inferr isFollowedBy properties
// Graph ginf = SesameWrapper.performGraphQuery(lr2, QueryLanguage.SERQL, RDFQuery.RDFQ_INFER_ISFOLLOWEDBY.toString());
// lr2.getGraph().add(ginf);
// }
//
//
// URI action = vf.createURI(actionUri+AxisPath.pathToString(_usedPath));
//
// if(globalg.contains(action,
// globalg.getValueFactory().createURI(RDF.TYPE),
// MBB_BROWSEACTION.getURI(globalg))) {
// lastAction = AxisPath.getLastAction(globalLr, context, _usedPath);
// if(lastAction != null)
// _usedPath.add(0);
// action = vf.createURI(actionUri+AxisPath.pathToString(_usedPath));
// }
// --------------- END : to be removed -------------------------
Graph globalg = globalLr.getGraph();
boolean isGetLastAction = false;
//--A
if(axisPath.isInitial()) //--A.1
isGetLastAction = true;
else {//--A.2
LocalRepository lr2 = RepositoryFactory.createTempRepository();
lastAction = axisPath.getLastOnList(globalLr, context, lr2.getGraph(), false, _usedPath);
//--inferr isFollowedBy properties
Graph ginf = SesameWrapper.performGraphQuery(lr2, QueryLanguage.SERQL, RDFQuery.RDFQ_INFER_ISFOLLOWEDBY.toString());
lr2.getGraph().add(ginf);
//--B
if((axisPath.getPath().size() - 1) == _usedPath.size())//--B.1
_usedPath.add(axisPath.getPath().get(axisPath.getPath().size()-1));
else if(lastAction != null){//--B.2
StatementIterator stit = lr2.getGraph().getStatements(lastAction, MultiBeeBrowseRDF.MBB_ISFOLLOWEDSALONGAXIS.getURI(lr2.getGraph()), null);
Set<Integer> saxis = new HashSet<Integer>();
while(stit.hasNext()) {
saxis.add(Integer.parseInt(((Literal)stit.next().getObject()).getLabel()));
}
//--C
if(saxis.size() >= 6)//--C.1
_usedPath.add(0);
else {//--C.2
int i = 0;
while(saxis.contains(i) && i < 6) {
i++;
}
if(i < 6) //--C.2.1
_usedPath.add(i);
else //--C.2.2
isGetLastAction = true;
}
}else
_usedPath.clear();//XXX just to make sure
}
URI action = (!isGetLastAction)?vf.createURI(actionUri+AxisPath.pathToString(_usedPath)):null;
if(isGetLastAction ||
globalg.contains(action, globalg.getValueFactory().createURI(RDF.TYPE), MBB_BROWSEACTION.getURI(globalg))) {
_usedPath.clear();
lastAction = AxisPath.getLastAction(globalLr, context, _usedPath);
if(lastAction != null)
_usedPath.add(0);
action = vf.createURI(actionUri+AxisPath.pathToString(_usedPath));
}
g.add(action,
rdfType,
MBB_BROWSEACTION.getURI(g));
g.add(action,
DC_CREATOR.getURI(g),
(_user.indexOf("mailto:")==0 ||
_user.indexOf("user:")==0 ||
_user.indexOf("ip:")==0)?vf.createURI(_user):vf.createLiteral(_user, xsdString));
g.add(action,
MBB_CREATEDATE.getURI(g),
vf.createLiteral(date, xsdDateTime));
g.add(action,
MBB_ACCESSDATE.getURI(g),
vf.createLiteral(date, xsdDateTime));
g.add(action,
MBB_UPDATEDATE.getURI(g),
vf.createLiteral(date, xsdDateTime));
///--- is in context
g.add(action,
MBB_ISINCONTEXT.getURI(g),
context);
///--- execute
g.add(action,
MBB_EXECUTE.getURI(g),
call);
///--- type=mbb:Call
if(!globalLr.getGraph().contains(call, rdfType, MBB_CALL.getURI(g)))
g.add(call, rdfType, MBB_CALL.getURI(g));
// if(axisPath.isInitial()) {
if(_usedPath.size() == 0) {
if(lastAction != null) {
Repository.logger.severe("ActionAccessContextService:newAction - this should not happen!");
g.add(action,
MBB_FOLLOWSALONGAXIS.getURI(g),
vf.createLiteral("0", xsdInt));
g.add(action,
MBB_FOLLOWS.getURI(g),
lastAction);
}else
g.add(context, MBB_HASFIRSTACTION.getURI(g), action);
} else {
///--- follows along axis
int axis = _usedPath.get(_usedPath.size()-1);
if(lastAction != null) {
//TODO ******** check if the axis is allowed (reimplement with cartesian space support) *****************
URI pfollows = MBB_FOLLOWS.getURI(g);
//
// if(!g.contains(lastAction, pfollows, vf.createLiteral(String.valueOf((axis+3)%6), xsdInt))) { XXX
g.add(action,
MBB_FOLLOWSALONGAXIS.getURI(g),
vf.createLiteral(String.valueOf(axis), xsdInt));
g.add(action,
pfollows,
lastAction);