use of com.remswork.project.alice.web.service.exception.ClassServiceException in project classify-system by anverliedoit.
the class ClassServiceImpl method getClassList.
@Override
public List<Class> getClassList() throws ClassException {
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().get();
if (response.getStatus() == 200) {
return (List<Class>) response.readEntity(new GenericType<List<Class>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.ClassServiceException in project classify-system by anverliedoit.
the class ClassServiceImpl method addStudentById.
@Override
public Student addStudentById(long classId, long studentId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("student");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Builder builder = target.queryParam("studentId", studentId).request(MediaType.APPLICATION_JSON);
Response response = builder.post(Entity.xml(new Student()));
if (response.getStatus() == 200) {
return (Student) response.readEntity(Student.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.ClassServiceException in project classify-system by anverliedoit.
the class ClassServiceImpl method getStudentList.
@Override
public Set<Student> getStudentList(long classId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("student");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Set<Student>) response.readEntity(new GenericType<Set<Student>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.ClassServiceException in project classify-system by anverliedoit.
the class ClassServiceImpl method deleteScheduleById.
@Override
public Schedule deleteScheduleById(long classId, long scheduleId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("schedule");
uri.append("/");
uri.append(scheduleId);
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 (Schedule) response.readEntity(Schedule.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.web.service.exception.ClassServiceException in project classify-system by anverliedoit.
the class ClassServiceImpl method getClassListByTeacherId.
@Override
public List<Class> getClassListByTeacherId(long teacherId) throws ClassException {
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("teacherId", teacherId).request().get();
if (response.getStatus() == 200) {
return (List<Class>) response.readEntity(new GenericType<List<Class>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
Aggregations