use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.
the class AssignmentResource method getAssignmentById.
@GET
@Path("{assignmentId}")
public Response getAssignmentById(@PathParam("assignmentId") long id) {
try {
AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
Assignment assignment = assignmentService.getAssignmentById(id);
assignment.addLink(resourceLinks.self(id));
if (assignment.get_class() != null)
assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
return Response.status(Response.Status.OK).entity(assignment).build();
} catch (GradingFactorException 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.Assignment in project classify-system by anverliedoit.
the class AssignmentServiceImpl method getAssignmentListByClassId.
@Override
public List<Assignment> getAssignmentListByClassId(final long classId) throws GradingFactorException {
final List<Assignment> assignmentList = new ArrayList<>();
try {
return new AsyncTask<String, List<Assignment>, List<Assignment>>() {
@Override
protected List<Assignment> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?classId=").concat(String.valueOf(classId));
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++) {
assignmentList.add(gson.fromJson(jsonArray.get(ctr).toString(), Assignment.class));
}
return assignmentList;
} 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 : Assignment");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return assignmentList;
} else
throw new GradingFactorException("Server Error");
} catch (GradingFactorException 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.Assignment in project classify-system by anverliedoit.
the class AssignmentServiceImpl method getAssignmentListByStudentId.
@Override
public List<Assignment> getAssignmentListByStudentId(final long studentId, final long termId) throws GradingFactorException {
final List<Assignment> assignmentList = new ArrayList<>();
try {
return new AsyncTask<String, List<Assignment>, List<Assignment>>() {
@Override
protected List<Assignment> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?studentId=").concat(String.valueOf(studentId)).concat("&termId=").concat(String.valueOf(termId));
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++) {
assignmentList.add(gson.fromJson(jsonArray.get(ctr).toString(), Assignment.class));
}
return assignmentList;
} 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 : Assignment");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return assignmentList;
} else
throw new GradingFactorException("Server Error");
} catch (GradingFactorException 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.Assignment in project classify-system by anverliedoit.
the class AssignmentAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(AssignmentViewHolder holder, int position) {
Assignment assignment = assignmentList.get(position);
holder.setView(assignment, position);
}
use of com.remswork.project.alice.model.Assignment in project classify-system by anverliedoit.
the class AssignmentAdapterF method onBindViewHolder.
@Override
public void onBindViewHolder(AssignmentViewHolder holder, int position) {
Assignment assignment = assignmentList.get(position);
holder.setView(assignment, position);
}
Aggregations