use of com.remswork.project.alice.model.Subject in project classify-system by anverliedoit.
the class SubjectResource method getSubjectById.
@GET
@Path("{subjectId}")
public Response getSubjectById(@PathParam("subjectId") long id) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.getSubjectById(id);
subject.addLink(resourceLinks.self(id));
return Response.status(Response.Status.OK).entity(subject).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 SubjectResource method updateSubjectById.
@PUT
@Path("{subjectId}")
public Response updateSubjectById(@PathParam("subjectId") long id, Subject newSubject) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.updateSubjectById(id, newSubject);
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 getSubjectList.
@GET
public Response getSubjectList(@QueryParam("teacherId") long teacherId, @QueryParam("studentId") long studentId) {
try {
List<Subject> subjectList;
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
if (teacherId != 0)
subjectList = subjectService.getSubjectListByTeacherId(teacherId);
else if (studentId != 0)
subjectList = subjectService.getSubjectListByStudentId(studentId);
else
subjectList = subjectService.getSubjectList();
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 getSubjectListByTeacherId.
@Override
public List<Subject> getSubjectListByTeacherId(final long teacherId) 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("?teacherId=").concat(String.valueOf(teacherId));
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 getSubjectListByTeacherIdUnique.
public List<Subject> getSubjectListByTeacherIdUnique(final long teacherId) 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/unique").concat("?teacherId=").concat(String.valueOf(teacherId));
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