use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectListByTeacherId.
@Override
public List<Subject> getSubjectListByTeacherId(long teacherId) throws SubjectException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/1");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.queryParam("teacherId", teacherId).request(MediaType.APPLICATION_XML).get();
if (response.getStatus() == 200) {
return (List<Subject>) response.readEntity(new GenericType<List<Subject>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new SubjectServiceException(message.getMessage());
} else
throw new SubjectServiceException("The request might invalid or server is down");
} catch (SubjectServiceException e) {
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectById.
@Override
public Subject getSubjectById(long id) throws SubjectException {
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());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Subject) response.readEntity(Subject.class);
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new SubjectServiceException(message.getMessage());
} else
throw new SubjectServiceException("The request might invalid or server is down");
} catch (SubjectServiceException e) {
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectListByStudentId.
@Override
public List<Subject> getSubjectListByStudentId(long studentId) throws SubjectException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.queryParam("studentId", studentId).request(MediaType.APPLICATION_XML).get();
if (response.getStatus() == 200) {
return (List<Subject>) response.readEntity(new GenericType<List<Subject>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new SubjectServiceException(message.getMessage());
} else
throw new SubjectServiceException("The request might invalid or server is down");
} catch (SubjectServiceException e) {
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectController method updateSubjectById.
@RequestMapping(value = "update", method = RequestMethod.POST)
public String updateSubjectById(@RequestParam("id") long id, @RequestParam("name") String name, @RequestParam("code") String code, @RequestParam("description") String description, @RequestParam("unit") int unit, ModelMap modelMap) {
try {
Subject newSubject = new Subject(name, code, description, unit);
try {
subjectService.updateSubjectById(id, newSubject);
} catch (SubjectException e) {
e.printStackTrace();
}
List<Subject> subjectList = subjectService.getSubjectList();
modelMap.put("subjectList", subjectList);
return "subject";
} catch (SubjectException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectController method getTeacher.
@RequestMapping(value = "get", method = RequestMethod.POST)
public String getTeacher(@RequestParam("query") String query, ModelMap modelMap) {
try {
List<Subject> subjectList = new ArrayList<>();
Subject subject = null;
if (!query.trim().isEmpty()) {
try {
long id = Long.parseLong(query.trim());
subject = subjectService.getSubjectById(id);
} catch (NumberFormatException e) {
e.printStackTrace();
subject = null;
} catch (SubjectException e) {
e.printStackTrace();
subject = null;
}
if (subject != null)
subjectList.add(subject);
else {
for (Subject d : subjectService.getSubjectList()) {
if (d.getName().equals(query.trim())) {
subjectList.add(d);
continue;
}
if (d.getCode().equals(query.trim())) {
subjectList.add(d);
continue;
}
if (d.getDescription().equals(query.trim())) {
subjectList.add(d);
continue;
}
}
}
}
if (subjectList.size() < 1) {
subjectList = subjectService.getSubjectList();
modelMap.put("responseMessage", "No result found.");
} else {
modelMap.put("responseMessage", subjectList.size() + " Result found.");
}
modelMap.put("subjectList", subjectList);
return "subject-table";
} catch (SubjectException e) {
e.printStackTrace();
return "error";
}
}
Aggregations