Search in sources :

Example 1 with SectionServiceException

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

the class SectionServiceImpl method deleteSectionById.

@Override
public Section deleteSectionById(long id) throws SectionException {
    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 (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(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) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 2 with SectionServiceException

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

the class SectionServiceImpl method getSectionList.

@Override
public List<Section> getSectionList() throws SectionException {
    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<Section>) response.readEntity(new GenericType<List<Section>>() {
            });
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Message(com.remswork.project.alice.model.support.Message) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 3 with SectionServiceException

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

the class SectionServiceImpl method updateSectionById.

@Override
public Section updateSectionById(long id, Section newSection, long departmentId) throws SectionException {
    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(newSection));
        if (response.getStatus() == 200) {
            return (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(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) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 4 with SectionServiceException

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

the class SectionServiceImpl method addSection.

@Override
public Section addSection(Section Section, long departmentId) throws SectionException {
    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(Section));
        if (response.getStatus() == 201) {
            return (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(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) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 5 with SectionServiceException

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

the class SectionServiceImpl method getSectionById.

@Override
public Section getSectionById(long id) throws SectionException {
    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 (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Aggregations

SectionException (com.remswork.project.alice.exception.SectionException)5 Section (com.remswork.project.alice.model.Section)5 Message (com.remswork.project.alice.model.support.Message)5 SectionServiceException (com.remswork.project.alice.web.service.exception.SectionServiceException)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)3 Builder (javax.ws.rs.client.Invocation.Builder)3 List (java.util.List)1 GenericType (javax.ws.rs.core.GenericType)1