PageRenderTime 45ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/eu/jlinkeditrdfconverter/entity/UserSessionEntity.java

https://gitlab.com/jlinkedit/jlinkservices
Java | 80 lines | 55 code | 23 blank | 2 comment | 5 complexity | a27fbfcb7d234391e83e9b2a593d5002 MD5 | raw file
  1. package eu.jlinkeditrdfconverter.entity;
  2. import java.io.Serializable;
  3. import org.bson.types.ObjectId;
  4. import org.json.simple.JSONArray;
  5. import org.json.simple.JSONObject;
  6. import org.json.simple.parser.JSONParser;
  7. import org.json.simple.parser.ParseException;
  8. import org.springframework.data.mongodb.core.mapping.Document;
  9. import org.springframework.http.converter.json.GsonBuilderUtils;
  10. import com.google.gson.Gson;
  11. import com.google.gson.GsonBuilder;
  12. import eu.jvisualrdf.graph.json.in.GraphJsonIn;
  13. import eu.jvisualrdf.graph.json.out.GraphJsonOut;
  14. @Document
  15. public class UserSessionEntity implements Serializable{
  16. private static final long serialVersionUID = 5055715636296431638L;
  17. private ObjectId _id;
  18. private String token;
  19. private String graphAsJsonStr;
  20. public ObjectId get_id() {
  21. return _id;
  22. }
  23. public void set_id(ObjectId _id) {
  24. this._id = _id;
  25. }
  26. public String getToken() {
  27. return token;
  28. }
  29. public void setToken(String token) {
  30. this.token = token;
  31. }
  32. public String getGraphAsJsonStr() {
  33. return graphAsJsonStr;
  34. }
  35. public void setGraphAsJsonStr(String graphAsJsonStr) throws ParseException {
  36. if(graphAsJsonStr==null || "".equals(graphAsJsonStr)){
  37. return;
  38. }
  39. JSONParser parser = new JSONParser();
  40. JSONObject jsonObj = (JSONObject) parser.parse(graphAsJsonStr);
  41. Gson gson = new GsonBuilder().create();
  42. GraphJsonIn graphin = null;
  43. GraphJsonOut graphout = null;
  44. JSONArray nodesArr = (JSONArray) parser.parse(jsonObj.get("nodes").toString());
  45. JSONObject json = (JSONObject) parser.parse(nodesArr.get(0).toString());
  46. //System.out.println(json.containsKey("id"));
  47. if(json.containsKey("x")|| json.containsKey("y") || json.containsKey("px") || json.containsKey("py")){
  48. graphin = gson.fromJson(graphAsJsonStr, GraphJsonIn.class);
  49. graphout = new GraphJsonOut(graphin.getNodes(),graphin.getLinks());
  50. this.graphAsJsonStr = gson.toJson(graphout);
  51. return;
  52. }
  53. //System.out.println(graphAsJsonStr);
  54. graphout = gson.fromJson(graphAsJsonStr, GraphJsonOut.class);
  55. this.graphAsJsonStr = gson.toJson(graphout);
  56. }
  57. }