use of com.remswork.project.alice.web.service.exception.SubjectServiceException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectByClassAndTeacherId.
@Override
public Subject getSubjectByClassAndTeacherId(long classId, long teacherId) 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("classId", classId).queryParam("teacherId", teacherId).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.web.service.exception.SubjectServiceException in project classify-system by anverliedoit.
the class SubjectServiceImpl method getSubjectList.
@Deprecated
@Override
public List<Subject> getSubjectList() 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.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.web.service.exception.SubjectServiceException in project classify-system by anverliedoit.
the class SubjectServiceImpl method updateSubjectById.
@Override
public Subject updateSubjectById(long id, Subject newSubject) 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());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.put(Entity.json(newSubject));
if (response.getStatus() == 200) {
return (Subject) response.readEntity(Subject.class);
} else if (response.getStatus() == 400) {
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.web.service.exception.SubjectServiceException in project classify-system by anverliedoit.
the class SubjectServiceImpl method addSubject.
@Override
public Subject addSubject(Subject schedule) 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());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.post(Entity.json(schedule));
if (response.getStatus() == 201) {
return (Subject) response.readEntity(Subject.class);
} else if (response.getStatus() == 400) {
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());
}
}
Aggregations