use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.
the class ScheduleServiceImpl method getScheduleList.
@Override
public List<Schedule> getScheduleList() throws ScheduleException {
final List<Schedule> scheduleList = new ArrayList<>();
try {
return new AsyncTask<String, List<Schedule>, List<Schedule>>() {
@Override
protected List<Schedule> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload);
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
scheduleList.add(gson.fromJson(jsonArray.get(ctr).toString(), Schedule.class));
}
return scheduleList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Schedule");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return scheduleList;
} else
throw new ScheduleException("Server Error");
} catch (ScheduleException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.
the class ClassServiceImpl method getScheduleById.
@Override
public Schedule getScheduleById(long classId, long scheduleId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("schedule");
uri.append("/");
uri.append(scheduleId);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Schedule) response.readEntity(Schedule.class);
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.
the class ClassServiceImpl method getScheduleList.
@Override
public Set<Schedule> getScheduleList(long classId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("schedule");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Set<Schedule>) response.readEntity(new GenericType<Set<Schedule>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.
the class ClassServiceImpl method addScheduleById.
@Override
public Schedule addScheduleById(long classId, long scheduleId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("schedule");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Builder builder = target.queryParam("scheduleId", scheduleId).request(MediaType.APPLICATION_JSON);
Response response = builder.post(Entity.xml(new Schedule()));
if (response.getStatus() == 200) {
return (Schedule) response.readEntity(Schedule.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.
the class ScheduleServiceImpl method updateScheduleById.
@Override
public Schedule updateScheduleById(long id, Schedule newSchedule) throws ScheduleException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(id);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.put(Entity.json(newSchedule));
if (response.getStatus() == 200) {
return (Schedule) response.readEntity(Schedule.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new ScheduleServiceException(message.getMessage());
} else
throw new ScheduleServiceException("The request might invalid or server is down");
} catch (ScheduleServiceException e) {
throw new ScheduleException(e.getMessage());
}
}
Aggregations