package kr.ac.kaist.resl.lilliput.rest; 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.RDFIndividual; public class GetMyPeople extends ServerResource { @Get("json") public JsonRepresentation toJson() { try { String epc = (String)getRequest().getAttributes().get("uid"); //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(); @SuppressWarnings("unused") OWLNamedClass humanClass = owlModel.getOWLNamedClass("Human"); @SuppressWarnings("unused") OWLNamedClass indoorSpaceClass = owlModel.getOWLNamedClass("IndoorSpace"); @SuppressWarnings("unused") RDFIndividual humanInd; List<AccessibilityPair> acPair = AccessController.getAccessibilityList(owlModel, epc); JSONArray resultArray = new JSONArray(); JSONObject resultObject; humanInd = owlModel.getRDFIndividual(epc); for(int i = 0 ; i < acPair.size() ; i++ ) { AccessibilityPair acs = acPair.get(i); if( acs.subject.equals(epc) == true ) { String destEPC = acs.object; if( destEPC.split(":")[3].equals("gid") == true ) { resultObject = new JSONObject(); resultObject.put("epc", destEPC); JSONObject returnObj = Information.getInformation(owlModel, destEPC); if( returnObj != null ) { resultObject.put("information", returnObj); } resultArray.put(resultObject); } } } p.dispose(); JsonRepresentation representation = new JsonRepresentation(resultArray); return representation; }catch( Exception e) { e.printStackTrace(); return null; } } }