use of com.remswork.project.alice.exception.TeacherException in project classify-system by anverliedoit.
the class TeacherServiceImpl method addTeacher.
@Deprecated
@Override
public Teacher addTeacher(Teacher teacher) throws TeacherException {
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());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.post(Entity.json(teacher));
if (response.getStatus() == 201) {
return (Teacher) response.readEntity(Teacher.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new TeacherServiceException(message.getMessage());
} else
throw new TeacherServiceException("The request might invalid or server is down");
} catch (TeacherServiceException e) {
throw new TeacherException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.TeacherException in project classify-system by anverliedoit.
the class TeacherServiceImpl method getTeacherList.
@Override
public List<Teacher> getTeacherList() throws TeacherException {
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.request(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == 200) {
return (List<Teacher>) response.readEntity(new GenericType<List<Teacher>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new TeacherServiceException(message.getMessage());
} else
throw new TeacherServiceException("The request might invalid or server is down");
} catch (TeacherServiceException e) {
throw new TeacherException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.TeacherException in project classify-system by anverliedoit.
the class TeacherServiceImpl method addTeacher.
@Override
public Teacher addTeacher(Teacher teacher, long departmentId) throws TeacherException {
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());
Builder builder = target.queryParam("departmentId", departmentId).request();
builder.accept("application/json");
Response response = builder.post(Entity.json(teacher));
if (response.getStatus() == 201) {
return (Teacher) response.readEntity(Teacher.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new TeacherServiceException(message.getMessage());
} else
throw new TeacherServiceException("The request might invalid or server is down");
} catch (TeacherServiceException e) {
throw new TeacherException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.TeacherException in project classify-system by anverliedoit.
the class TeacherServiceImpl method deleteTeacherById.
@Override
public Teacher deleteTeacherById(long id) throws TeacherException {
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.delete();
if (response.getStatus() == 200) {
return (Teacher) response.readEntity(Teacher.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new TeacherServiceException(message.getMessage());
} else
throw new TeacherServiceException("The request might invalid or server is down");
} catch (TeacherServiceException e) {
throw new TeacherException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.TeacherException in project classify-system by anverliedoit.
the class TeacherResource method getTeacherById.
@GET
@Path("{teacherId}")
public Response getTeacherById(@PathParam("teacherId") long id) {
try {
TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
Teacher teacher = teacherService.getTeacherById(id);
teacher.addLink(resourceLink.self(id));
if (teacher.getDepartment() != null)
teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
return Response.status(Response.Status.OK).entity(teacher).build();
} catch (TeacherException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
Aggregations