Search in sources :

Example 6 with ScheduleServiceException

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

the class ScheduleServiceImpl method updateScheduleById.

@Override
public Schedule updateScheduleById(long id, Schedule newSchedule) throws ScheduleException {
    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(newSchedule));
        if (response.getStatus() == 200) {
            return (Schedule) response.readEntity(Schedule.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ScheduleServiceException(message.getMessage());
        } else
            throw new ScheduleServiceException("The request might invalid or server is down");
    } catch (ScheduleServiceException e) {
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ScheduleServiceException(com.remswork.project.alice.web.service.exception.ScheduleServiceException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Schedule(com.remswork.project.alice.model.Schedule) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Aggregations

ScheduleException (com.remswork.project.alice.exception.ScheduleException)6 Schedule (com.remswork.project.alice.model.Schedule)6 Message (com.remswork.project.alice.model.support.Message)6 ScheduleServiceException (com.remswork.project.alice.web.service.exception.ScheduleServiceException)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)3 Builder (javax.ws.rs.client.Invocation.Builder)3 GenericType (javax.ws.rs.core.GenericType)2 List (java.util.List)1 Set (java.util.Set)1