package kr.ac.kaist.resl.lilliput.rest;
import java.util.Collection;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import com.mongodb.MongoException;
import edu.stanford.smi.protege.model.Project;
import edu.stanford.smi.protege.server.RemoteProjectManager;
import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.model.RDFIndividual;
public class InsertDataType extends ServerResource {
@SuppressWarnings("rawtypes")
@Get("json")
public JsonRepresentation toJson() throws JSONException {
try {
String targetEpc = (String)getRequest().getAttributes().get("target");
String datatypeProperty = (String)getRequest().getAttributes().get("property");
String data = getQuery().getValues("data");
RemoteProjectManager rpm = RemoteProjectManager.getInstance();
Project p = rpm.getProject("localhost:5100", "Lilliput", "1234", "IoTSocialGraph", true);
OWLModel owlModel = (OWLModel)p.getKnowledgeBase();
RDFIndividual targetInd = owlModel.getOWLIndividual(targetEpc);
OWLDatatypeProperty prop = owlModel.getOWLDatatypeProperty(datatypeProperty);
//����Ʈ ����
targetInd.setPropertyValue(prop, data);
p.dispose();
JSONObject returnJson = new JSONObject();
returnJson.put("message", "Datatype is modified");
JsonRepresentation representation = new JsonRepresentation(returnJson);
return representation;
} catch (MongoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject returnJson = new JSONObject();
returnJson.put("message", "error occured");
JsonRepresentation representation = new JsonRepresentation(returnJson);
return representation;
}
}