List of usage examples for com.google.gson.reflect TypeToken TypeToken
@SuppressWarnings("unchecked") protected TypeToken()
From source file:backend.ws.BlockWS.java
public List<Block> getAllBlocksByHealthProfessional(int idHealthProfessional) { List<Block> bList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta params.add(new BasicNameValuePair("idHealthProfessional", String.valueOf(idHealthProfessional))); try {/*from w ww . j a v a2 s . c o m*/ responseWS = wrapperWS.sendRequest("Block", "getAllBlocksByHealthProfessional", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao aceder aos dados do Bloco"); } Type type = new TypeToken<List<Block>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json bList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tBlock data access success"); log.debug("\n\tBs : " + bList.toString()); return bList; }
From source file:backend.ws.BlockWS.java
public List<Block> getBlockByName(String name) { List<Block> bList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta params.add(new BasicNameValuePair("name", name)); try {/*from w ww . ja va2s . c om*/ responseWS = wrapperWS.sendRequest("Block", "getBlockByName", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao realizar a pesquisa"); } Type type = new TypeToken<List<Block>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json bList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tBlock search success"); log.debug("\n\tBs : " + bList.toString()); return bList; }
From source file:backend.ws.DomainWS.java
public List<Domain> getAllDomains() { List<Domain> dList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta try {/* www .ja v a2 s.c o m*/ responseWS = wrapperWS.sendRequest("Domain", "getAllDomains", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao aceder aos dados do Domnio"); } Type type = new TypeToken<List<Domain>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json dList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\t Domain data access success"); log.debug("\n\tDs : " + dList.toString()); return dList; }
From source file:backend.ws.ExerciseWS.java
public List<Exercise> getAllExercises() { List<Exercise> exList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta try {// w ww . j av a 2 s . com responseWS = wrapperWS.sendRequest("Exercise", "getAllExercises", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao aceder aos dados do Exerccio"); } Type type = new TypeToken<List<Exercise>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json exList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tExercise data access success"); log.debug("\n\tHPs : " + exList.toString()); return exList; }
From source file:backend.ws.ExerciseWS.java
public List<Exercise> getExerciseBySubDomain(int idSD) { List<Exercise> exList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta params.add(new BasicNameValuePair("idSubDomain", String.valueOf(idSD))); try {/*from w w w .j a v a 2 s . c o m*/ responseWS = wrapperWS.sendRequest("Exercise", "getExerciseBySubDomain", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao aceder aos dados do Exerccio"); } Type type = new TypeToken<List<Exercise>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json exList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tExercise data access success"); log.debug("\n\tPs : " + exList.toString()); return exList; }
From source file:backend.ws.HealthProfessionalWS.java
/** * Metodo que retorna todos os terapeutas * * @return Lista de HealthProfessionalWSs *///from ww w .j a v a 2 s. co m public List<HealthProfessional> getAllHealthProfessionals() { List<HealthProfessional> hpList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta try { responseWS = wrapperWS.sendRequest("HealthProfessional", "getAllHealthProfessionals", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao aceder aos dados do Profissional de Sade"); } Type type = new TypeToken<List<HealthProfessional>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json hpList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tHealth Professioonal data access success"); log.debug("\n\tHPs : " + hpList.toString()); return hpList; }
From source file:backend.ws.HealthProfessionalWS.java
public List<HealthProfessional> getHealthProfessionalByName(String name) { List<HealthProfessional> hpList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta params.add(new BasicNameValuePair("name", name)); try {//www . j a va2s .c o m responseWS = wrapperWS.sendRequest("HealthProfessional", "getHealthProfessionalByName", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao realizar a pesquisa"); } Type type = new TypeToken<List<HealthProfessional>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json hpList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tHealth Professionals search success"); log.debug("\n\tHPs : " + hpList.toString()); return hpList; }
From source file:backend.ws.PatientWS.java
public List<Patient> getPatientByName(String name, int idHealthPro) { List<Patient> pList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta params.add(new BasicNameValuePair("name", name)); params.add(new BasicNameValuePair("idHealthProfessional", String.valueOf(idHealthPro))); try {/*from w w w .j a v a2s . co m*/ responseWS = wrapperWS.sendRequest("Patient", "getPatientByName", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao realizar a pesquisa"); } Type type = new TypeToken<List<Patient>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json pList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tPatients search success"); log.debug("\n\tHPs : " + pList.toString()); return pList; }
From source file:backend.ws.PatientWS.java
public List<Patient> getPatientsByHPDate(int idHealthPro, String appointmentDate) { List<Patient> pList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta params.add(new BasicNameValuePair("idHealthProfessional", String.valueOf(idHealthPro))); params.add(new BasicNameValuePair("appointmentDate", appointmentDate)); try {//from w w w. j a v a2 s . co m responseWS = wrapperWS.sendRequest("Patient", "getPatientsByHPDate", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException( "Ocorreu um erro ao aceder aos Pacientes com consulta marcada para esta data"); } Type type = new TypeToken<List<Patient>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json pList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\tPacients by health professional and appointment date, data access succed"); log.debug("\n\tPacients: " + pList.toString()); return pList; }
From source file:backend.ws.PatientWS.java
public List<Patient> getAllPatients() { List<Patient> pList = null; List<NameValuePair> params = new ArrayList<>(); //array com os params necessrios para registar um terapeuta try {//from ww w .j av a2s. co m responseWS = wrapperWS.sendRequest("Patient", "getAllPatients", params); //efetua o pedido ao WS String jsonResp = wrapperWS.readResponse(responseWS); //Passa a responseWS para uma string int httpResponseCod = responseWS.getStatusLine().getStatusCode(); if (httpResponseCod != 200) { Validation v = gson.fromJson(jsonResp, Validation.class); //Converso do objecto Json para o objecto Java log.error("\n\tCod: " + v.getCod() + "\tMsg: " + v.getMsg()); throw new RuntimeException("Ocorreu um erro ao aceder aos dados do Paciente"); } Type type = new TypeToken<List<Patient>>() { }.getType(); //tipo do para o qual queros retornar a responseWS Json pList = gson.fromJson(jsonResp, type); } catch (RuntimeException e) { log.error("\n\t" + e.getMessage()); throw new RuntimeException(e.getMessage()); } log.debug("\n\t Patient data access success"); log.debug("\n\tHPs : " + pList.toString()); return pList; }