use of com.remswork.project.alice.model.Subject in project classify-system by anverliedoit.
the class SubjectResource method deleteSubjectById.
@DELETE
@Path("{subjectId}")
public Response deleteSubjectById(@PathParam("subjectId") long id) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.deleteSubjectById(id);
subject.addLink(resourceLinks.self(id));
return Response.status(Response.Status.OK).entity(subject).build();
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.model.Subject in project classify-system by anverliedoit.
the class SubjectResource method getSubject.
@GET
@Path("0")
public Response getSubject(@QueryParam("classId") long classId, @QueryParam("scheduleId") long scheduleId, @QueryParam("teacherId") long teacherId) {
try {
if (classId != 0 && teacherId != 0) {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.getSubjectByClassAndTeacherId(classId, teacherId);
subject.addLink(resourceLinks.self(subject.getId()));
return Response.status(Response.Status.OK).entity(subject).build();
} else if (scheduleId != 0) {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.getSubjectByScheduleId(scheduleId);
subject.addLink(resourceLinks.self(subject.getId()));
return Response.status(Response.Status.OK).entity(subject).build();
} else
throw new SubjectException("No subject found");
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Subject in project classify-system by anverliedoit.
the class SubjectResource method getSubjectListByTeacherIdUnique.
@GET
@Path("1/unique")
@Deprecated
public Response getSubjectListByTeacherIdUnique(@QueryParam("teacherId") long teacherId) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
List<Subject> subjectList = subjectService.getSubjectListByTeacherIdUnique(teacherId);
for (Subject subject : subjectList) subject.addLink(resourceLinks.self(subject.getId()));
GenericEntity<List<Subject>> entity = new GenericEntity<List<Subject>>(subjectList) {
};
return Response.status(Response.Status.OK).entity(entity).build();
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Subject in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectList.
@Override
public List<Subject> getSubjectList() throws SubjectException {
final List<Subject> subjectList = new ArrayList<>();
try {
return new AsyncTask<String, List<Subject>, List<Subject>>() {
@Override
protected List<Subject> 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++) {
subjectList.add(gson.fromJson(jsonArray.get(ctr).toString(), Subject.class));
}
return subjectList;
} 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 : Subject");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return subjectList;
} else
throw new SubjectException("Server Error");
} catch (SubjectException 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.Subject in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectListByStudentId.
@Override
public List<Subject> getSubjectListByStudentId(final long studentId) throws SubjectException {
final List<Subject> subjectList = new ArrayList<>();
try {
return new AsyncTask<String, List<Subject>, List<Subject>>() {
@Override
protected List<Subject> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat("1").concat("?studentId=").concat(String.valueOf(studentId));
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++) {
subjectList.add(gson.fromJson(jsonArray.get(ctr).toString(), Subject.class));
}
return subjectList;
} 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 : Subject");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return subjectList;
} else
throw new SubjectException("Server Error");
} catch (SubjectException 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;
}
}
Aggregations