package kr.ac.kaist.resl.lilliput.rest;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kr.ac.kaist.resl.lilliput.ac.AccessController;
import kr.ac.kaist.resl.lilliput.ac.AccessibilityPair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import edu.stanford.smi.protege.model.Project;
import edu.stanford.smi.protege.server.RemoteProjectManager;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
import edu.stanford.smi.protegex.owl.model.OWLObjectProperty;
import edu.stanford.smi.protegex.owl.model.RDFIndividual;
public class GetAll extends ServerResource {
@Get("json")
public JsonRepresentation toJson() {
try
{
String epc = (String)getRequest().getAttributes().get("uid");
if( epc.contains("gid") != true )
{
//fr Test
RemoteProjectManager rpm = RemoteProjectManager.getInstance();
Project p = rpm.getProject("localhost:5100", "Lilliput", "1234", "IoTSocialGraph", true);
OWLModel owlModel = (OWLModel)p.getKnowledgeBase();
List<AccessibilityPair> acPair = AccessController.getAccessibilityList(owlModel, epc);
//
return null;
}
//Save Space to Ontology if it is not saved
RemoteProjectManager rpm = RemoteProjectManager.getInstance();
Project p = rpm.getProject("localhost:5100", "Lilliput", "1234", "IoTSocialGraph", true);
OWLModel owlModel = (OWLModel)p.getKnowledgeBase();
List<AccessibilityPair> acPair = AccessController.getAccessibilityList(owlModel, epc);
JSONArray resultArray = new JSONArray();
JSONObject resultObject;
for(int i = 0 ; i < acPair.size() ; i++ )
{
AccessibilityPair ac = acPair.get(i);
if( ac.subject.equals(epc))
{
resultObject = new JSONObject();
resultObject.put("epc", ac.object);
JSONObject returnObj = Information.getInformation(owlModel,ac.object);
if( returnObj != null )
{
resultObject.put("information", returnObj);
}
//���� �־����
JSONArray serviceArray = Information.getServices(owlModel, ac.object);
resultObject.put("services", serviceArray);
resultArray.put(resultObject);
JSONObject locationObject = Information.getLocation(owlModel, ac.object);
resultObject.put("location", locationObject);
}
}
System.out.println(resultArray.toString(2));
p.dispose();
JsonRepresentation representation = new JsonRepresentation(resultArray);
return representation;
}catch( Exception e)
{
e.printStackTrace();
return null;
}
}
}