Search in sources :

Example 1 with TeacherServiceException

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

the class TeacherServiceImpl method updateTeacherById.

@Override
public Teacher updateTeacherById(long id, Teacher newTeacher, long departmentId) 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.queryParam("departmentId", departmentId).request();
        builder.accept("application/json");
        Response response = builder.put(Entity.json(newTeacher));
        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());
    }
}
Also used : Response(javax.ws.rs.core.Response) TeacherServiceException(com.remswork.project.alice.web.service.exception.TeacherServiceException) TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Teacher(com.remswork.project.alice.model.Teacher) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 2 with TeacherServiceException

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

the class TeacherServiceImpl method getTeacherById.

@Override
public Teacher getTeacherById(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());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (Teacher) response.readEntity(Teacher.class);
        } 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());
    }
}
Also used : Response(javax.ws.rs.core.Response) TeacherServiceException(com.remswork.project.alice.web.service.exception.TeacherServiceException) TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) Teacher(com.remswork.project.alice.model.Teacher) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 3 with TeacherServiceException

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

Example 4 with TeacherServiceException

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

Example 5 with TeacherServiceException

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

Aggregations

TeacherException (com.remswork.project.alice.exception.TeacherException)6 Teacher (com.remswork.project.alice.model.Teacher)6 Message (com.remswork.project.alice.model.support.Message)6 TeacherServiceException (com.remswork.project.alice.web.service.exception.TeacherServiceException)6 Client (javax.ws.rs.client.Client)6 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 ClientBuilder (javax.ws.rs.client.ClientBuilder)4 Builder (javax.ws.rs.client.Invocation.Builder)4 List (java.util.List)1 GenericType (javax.ws.rs.core.GenericType)1