Search in sources :

Example 1 with SubjectServiceException

use of com.remswork.project.alice.web.service.exception.SubjectServiceException in project classify-system by anverliedoit.

the class SubjectServiceImpl method deleteSubjectById.

@Override
public Subject deleteSubjectById(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());
        Builder builder = target.request();
        builder.accept("application/json");
        Response response = builder.delete();
        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());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) SubjectException(com.remswork.project.alice.exception.SubjectException) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Example 2 with SubjectServiceException

use of com.remswork.project.alice.web.service.exception.SubjectServiceException in project classify-system by anverliedoit.

the class SubjectServiceImpl method getSubjectByScheduleId.

@Override
public Subject getSubjectByScheduleId(long scheduleId) 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("scheduleId", scheduleId).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());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Example 3 with SubjectServiceException

use of com.remswork.project.alice.web.service.exception.SubjectServiceException 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());
    }
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Example 4 with SubjectServiceException

use of com.remswork.project.alice.web.service.exception.SubjectServiceException 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());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Example 5 with SubjectServiceException

use of com.remswork.project.alice.web.service.exception.SubjectServiceException 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());
    }
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Aggregations

SubjectException (com.remswork.project.alice.exception.SubjectException)9 Subject (com.remswork.project.alice.model.Subject)9 Message (com.remswork.project.alice.model.support.Message)9 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 List (java.util.List)3 ClientBuilder (javax.ws.rs.client.ClientBuilder)3 Builder (javax.ws.rs.client.Invocation.Builder)3 GenericType (javax.ws.rs.core.GenericType)3