Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.11 KB | None | 0 0
  1. @GET
  2. @Path("/findPatientById/{idPatient}")
  3. @Produces(MediaType.APPLICATION_JSON)
  4. public Patient findPatientById(@PathParam("idPatient")int idPatient){
  5.  
  6. PatientService patientService = new PatientService();
  7. Patient patient = patientService.findPatientById(idPatient);
  8. return patient;
  9. }
  10.  
  11. public Patient findPatientById(int idPatient, Session session) {
  12. Patient patient = (Patient) session.get(Patient.class, idPatient);
  13. return patient;
  14. }
  15.  
  16. public Patient findPatientById(int idPatient) {
  17. Session session = patientDAOInterface.openCurrentSession();
  18. Transaction transaction = null;
  19.  
  20. Patient patient = new Patient();
  21. try {
  22. transaction = patientDAOInterface.openTransaction(session);
  23. patient = patientDAOInterface.findPatientById(idPatient, session);
  24. System.out.println("DATE CREATED - "+patient.getDateCreated());
  25. transaction.commit();
  26. } catch (Exception ex) {
  27. ex.printStackTrace();
  28. } finally {
  29. session.close();
  30.  
  31. Language language = new Language();
  32. if (patient.getLanguage() != null) {
  33. Integer idlanguage = patient.getLanguage().getIdlanguage();
  34. language.setIdlanguage(idlanguage);
  35. patient.setLanguage(language);
  36. }
  37.  
  38. if (patient.getDiabetesType() != null) {
  39. DiabetesType diabetesType = new DiabetesType();
  40. Integer iddiabetesType = patient.getDiabetesType().getIddiabetesType();
  41. diabetesType.setIddiabetesType(iddiabetesType);
  42. patient.setDiabetesType(diabetesType);
  43. }
  44.  
  45. // patient.setDateCreated(null);
  46. // patient.setLastUpdated(null);
  47. }
  48. return patient;
  49. }
  50.  
  51. import java.util.Date;
  52. import java.util.HashSet;
  53. import java.util.Set;
  54.  
  55. public class Patient implements java.io.Serializable {
  56.  
  57. private Integer idpatient;
  58. private DiabetesType diabetesType;
  59. private Language language;
  60. private String customId;
  61. private String diabetesOther;
  62. private String firstName;
  63. private String lastName;
  64. private String email;
  65. private Date dob;
  66. private String parentEmail;
  67. private String gender;
  68. private Date diagnosedDate;
  69. private Double height;
  70. private Double weight;
  71. private String heightUnit;
  72. private String weightUnit;
  73. private String theme;
  74. private String userName;
  75. private String password;
  76. private Date dateCreated;
  77. private Date lastUpdated;
  78.  
  79. public Patient() {
  80. }
  81.  
  82. public Patient(DiabetesType diabetesType, Language language, String customId, String firstName, String email, Date dob, String gender, String theme, String userName, String password, Date lastUpdated) {
  83. this.diabetesType = diabetesType;
  84. this.language = language;
  85. this.customId = customId;
  86. this.firstName = firstName;
  87. this.email = email;
  88. this.dob = dob;
  89. this.gender = gender;
  90. this.theme = theme;
  91. this.userName = userName;
  92. this.password = password;
  93. this.lastUpdated = lastUpdated;
  94. }
  95.  
  96. public Patient(DiabetesType diabetesType, Language language, String customId, String diabetesOther, String firstName, String lastName, String email, Date dob, String parentEmail, String gender, Date diagnosedDate, Double height, Double weight, String heightUnit, String weightUnit, String theme, String userName, String password, Date dateCreated, Date lastUpdated) {
  97. this.diabetesType = diabetesType;
  98. this.language = language;
  99. this.customId = customId;
  100. this.diabetesOther = diabetesOther;
  101. this.firstName = firstName;
  102. this.lastName = lastName;
  103. this.email = email;
  104. this.dob = dob;
  105. this.parentEmail = parentEmail;
  106. this.gender = gender;
  107. this.diagnosedDate = diagnosedDate;
  108. this.height = height;
  109. this.weight = weight;
  110. this.heightUnit = heightUnit;
  111. this.weightUnit = weightUnit;
  112. this.theme = theme;
  113. this.userName = userName;
  114. this.password = password;
  115. this.dateCreated = dateCreated;
  116. this.lastUpdated = lastUpdated;
  117. }
  118.  
  119. public Integer getIdpatient() {
  120. return this.idpatient;
  121. }
  122.  
  123. public void setIdpatient(Integer idpatient) {
  124. this.idpatient = idpatient;
  125. }
  126.  
  127. public DiabetesType getDiabetesType() {
  128. return this.diabetesType;
  129. }
  130.  
  131. public void setDiabetesType(DiabetesType diabetesType) {
  132. this.diabetesType = diabetesType;
  133. }
  134.  
  135. public Language getLanguage() {
  136. return this.language;
  137. }
  138.  
  139. public void setLanguage(Language language) {
  140. this.language = language;
  141. }
  142.  
  143. public String getCustomId() {
  144. return this.customId;
  145. }
  146.  
  147. public void setCustomId(String customId) {
  148. this.customId = customId;
  149. }
  150.  
  151. public String getDiabetesOther() {
  152. return this.diabetesOther;
  153. }
  154.  
  155. public void setDiabetesOther(String diabetesOther) {
  156. this.diabetesOther = diabetesOther;
  157. }
  158.  
  159. public String getFirstName() {
  160. return this.firstName;
  161. }
  162.  
  163. public void setFirstName(String firstName) {
  164. this.firstName = firstName;
  165. }
  166.  
  167. public String getLastName() {
  168. return this.lastName;
  169. }
  170.  
  171. public void setLastName(String lastName) {
  172. this.lastName = lastName;
  173. }
  174.  
  175. public String getEmail() {
  176. return this.email;
  177. }
  178.  
  179. public void setEmail(String email) {
  180. this.email = email;
  181. }
  182.  
  183. public Date getDob() {
  184. return this.dob;
  185. }
  186.  
  187. public void setDob(Date dob) {
  188. this.dob = dob;
  189. }
  190.  
  191. public String getParentEmail() {
  192. return this.parentEmail;
  193. }
  194.  
  195. public void setParentEmail(String parentEmail) {
  196. this.parentEmail = parentEmail;
  197. }
  198.  
  199. public String getGender() {
  200. return this.gender;
  201. }
  202.  
  203. public void setGender(String gender) {
  204. this.gender = gender;
  205. }
  206.  
  207. public Date getDiagnosedDate() {
  208. return this.diagnosedDate;
  209. }
  210.  
  211. public void setDiagnosedDate(Date diagnosedDate) {
  212. this.diagnosedDate = diagnosedDate;
  213. }
  214.  
  215. public Double getHeight() {
  216. return this.height;
  217. }
  218.  
  219. public void setHeight(Double height) {
  220. this.height = height;
  221. }
  222.  
  223. public Double getWeight() {
  224. return this.weight;
  225. }
  226.  
  227. public void setWeight(Double weight) {
  228. this.weight = weight;
  229. }
  230.  
  231. public String getHeightUnit() {
  232. return this.heightUnit;
  233. }
  234.  
  235. public void setHeightUnit(String heightUnit) {
  236. this.heightUnit = heightUnit;
  237. }
  238.  
  239. public String getWeightUnit() {
  240. return this.weightUnit;
  241. }
  242.  
  243. public void setWeightUnit(String weightUnit) {
  244. this.weightUnit = weightUnit;
  245. }
  246.  
  247. public String getTheme() {
  248. return this.theme;
  249. }
  250.  
  251. public void setTheme(String theme) {
  252. this.theme = theme;
  253. }
  254.  
  255. public String getUserName() {
  256. return this.userName;
  257. }
  258.  
  259. public void setUserName(String userName) {
  260. this.userName = userName;
  261. }
  262.  
  263. public String getPassword() {
  264. return this.password;
  265. }
  266.  
  267. public void setPassword(String password) {
  268. this.password = password;
  269. }
  270.  
  271. public Date getDateCreated() {
  272. return this.dateCreated;
  273. }
  274.  
  275. public void setDateCreated(Date dateCreated) {
  276. this.dateCreated = dateCreated;
  277. }
  278.  
  279. public Date getLastUpdated() {
  280. return this.lastUpdated;
  281. }
  282.  
  283. public void setLastUpdated(Date lastUpdated) {
  284. this.lastUpdated = lastUpdated;
  285. }
  286.  
  287. }
  288.  
  289. {
  290. "idpatient": 86,
  291. "diabetesType": null,
  292. "language": null,
  293. "customId": "CUS790",
  294. "diabetesOther": null,
  295. "firstName": "Nirodha",
  296. "lastName": "Wije",
  297. "email": "ni00@gmail.com",
  298. "dob": "2005-10-16",
  299. "parentEmail": "niaasa500@gmail.com",
  300. "gender": "male",
  301. "diagnosedDate": "2016-11-16",
  302. "height": 0,
  303. "weight": 0,
  304. "heightUnit": null,
  305. "weightUnit": null,
  306. "theme": "Lite",
  307. "userName": "ranja",
  308. "password": "N1YL3+M0lnORHnKk0dPN8HYd1IBhWKAGO9Qsop7POgw=",
  309. "dateCreated": 1479311638000,
  310. "lastUpdated": 1479311638000
  311. }
  312.  
  313. private Patient restcallGetPatient(int idPatient){
  314. GsonBuilder gsonBuilder = new GsonBuilder();
  315. gsonBuilder.registerTypeAdapter(Date.class, new DateTypeDeserializer());
  316. Gson gson = gsonBuilder.create();
  317.  
  318. Retrofit retrofit = new Retrofit.Builder()
  319. .baseUrl(RestCommon.URL)
  320. .addConverterFactory(GsonConverterFactory.create(gson))
  321. .build();
  322.  
  323. PatientEndPoint endPoint = retrofit.create(PatientEndPoint.class);
  324. Call<Patient> call = endPoint.findPatientById(idPatient);
  325. call.enqueue(new Callback<Patient>() {
  326. @Override
  327. public void onResponse(Response<Patient> response, Retrofit retrofit) {
  328. patients=response.body();
  329.  
  330. Log.d("PROFILE_USER"," PATIENT_DETAILS "+patients.getFirstName());
  331. }
  332.  
  333. @Override
  334. public void onFailure(Throwable t) {
  335. t.printStackTrace();
  336. Log.d("PROFILE_USER"," PATIENT_ERROR "+t.getMessage());
  337. }
  338. });
  339.  
  340. return patients;
  341. }
  342.  
  343. public class DateTypeDeserializer implements JsonDeserializer<Date> {
  344. private String[] DATE_FORMATS = new String[]{
  345. "yyyy-MM-dd'T'HH:mm:ssZ",
  346. "yyyy-MM-dd'T'HH:mm:ss",
  347. "yyyy-MM-dd",
  348. "EEE MMM dd HH:mm:ss z yyyy",
  349. "HH:mm:ss",
  350. "MM/dd/yyyy HH:mm:ss aaa",
  351. "yyyy-MM-dd'T'HH:mm:ss.SSSSSS",
  352. "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS",
  353. "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'",
  354. "MMM d',' yyyy H:mm:ss a"
  355. };
  356.  
  357. @Override
  358. public Date deserialize(JsonElement jsonElement, Type typeOF, JsonDeserializationContext context) throws JsonParseException {
  359. for (String format : DATE_FORMATS) {
  360. try {
  361. return new SimpleDateFormat(format, Locale.US).parse(jsonElement.getAsString());
  362. } catch (ParseException e) {
  363. }
  364. }
  365. throw new JsonParseException("Unparseable date: "" + jsonElement.getAsString()
  366. + "". Supported formats: n" + Arrays.toString(DATE_FORMATS));
  367. }
  368. }
  369.  
  370. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: com.google.gson.JsonParseException: Unparseable date: "1479317839000". Supported formats:
  371. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: [yyyy-MM-dd'T'HH:mm:ssZ, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd, EEE MMM dd HH:mm:ss z yyyy, HH:mm:ss, MM/dd/yyyy HH:mm:ss aaa, yyyy-MM-dd'T'HH:mm:ss.SSSSSS, yyyy-MM-dd'T'HH:mm:ss.SSSSSSS, yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z', MMM d',' yyyy H:mm:ss a]
  372. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at xxx.com.au.xyz.activities.ProfileUserActivity$DateTypeDeserializer.deserialize(ProfileUserActivity.java:474)
  373. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at xxx.com.au.xyz.activities.ProfileUserActivity$DateTypeDeserializer.deserialize(ProfileUserActivity.java:451)
  374. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
  375. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
  376. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
  377. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.google.gson.Gson.fromJson(Gson.java:810)
  378. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.google.gson.Gson.fromJson(Gson.java:775)
  379. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:36)
  380. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:24)
  381. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at retrofit.OkHttpCall.parseResponse(OkHttpCall.java:148)
  382. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at retrofit.OkHttpCall.access$100(OkHttpCall.java:29)
  383. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at retrofit.OkHttpCall$1.onResponse(OkHttpCall.java:94)
  384. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
  385. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
  386. 11-16 17:37:42.033 6534-6534/xxx.com.au.xyz W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  387. 11-16 17:37:42.043 6534-6534/xxx.com.au.xyz W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  388. 11-16 17:37:42.043 6534-6534/xxx.com.au.xyz W/System.err: at java.lang.Thread.run(Thread.java:818)
  389. 11-16 17:37:42.043 6534-6534/xxx.com.au.xyz D/PROFILE_USER: PATIENT_ERROR Unparseable date: "1479317839000". Supported formats:
  390. [yyyy-MM-dd'T'HH:mm:ssZ, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd, EEE MMM dd HH:mm:ss z yyyy, HH:mm:ss, MM/dd/yyyy HH:mm:ss aaa, yyyy-MM-dd'T'HH:mm:ss.SSSSSS, yyyy-MM-dd'T'HH:mm:ss.SSSSSSS, yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z', MMM d',' yyyy H:mm:ss a]
  391. 11-16 17:37:42.053 6534-6534/xxx.com.au.xyz I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@b3857a0 time:13147437
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement