Search in sources :

Example 16 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleServiceImpl method addSchedule.

@Override
public Schedule addSchedule(Schedule schedule) throws ScheduleException {
    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 (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)

Example 17 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleServiceImpl method getScheduleListByTeacherId.

@Override
public Set<Schedule> getScheduleListByTeacherId(long teacherId) throws ScheduleException {
    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("teacherId", teacherId).request().get();
        if (response.getStatus() == 200) {
            return (Set<Schedule>) response.readEntity(new GenericType<Set<Schedule>>() {
            });
        } else if (response.getStatus() == 404) {
            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) GenericType(javax.ws.rs.core.GenericType) Set(java.util.Set) Message(com.remswork.project.alice.model.support.Message) 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)

Example 18 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleServiceImpl method getScheduleList.

@Override
public List<Schedule> getScheduleList() throws ScheduleException {
    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<Schedule>) response.readEntity(new GenericType<List<Schedule>>() {
            });
        } else if (response.getStatus() == 404) {
            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) GenericType(javax.ws.rs.core.GenericType) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 19 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleServiceImpl method getScheduleById.

@Override
public Schedule getScheduleById(long id) 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());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (Schedule) response.readEntity(Schedule.class);
        } else if (response.getStatus() == 404) {
            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) 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)

Example 20 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleServiceImpl method deleteScheduleById.

@Override
public Schedule deleteScheduleById(long id) 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.delete();
        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

Schedule (com.remswork.project.alice.model.Schedule)36 ScheduleException (com.remswork.project.alice.exception.ScheduleException)22 Message (com.remswork.project.alice.model.support.Message)22 ClassException (com.remswork.project.alice.exception.ClassException)13 Client (javax.ws.rs.client.Client)10 WebTarget (javax.ws.rs.client.WebTarget)10 Response (javax.ws.rs.core.Response)10 ScheduleServiceException (com.remswork.project.alice.web.service.exception.ScheduleServiceException)6 ScheduleResourceLinks (com.remswork.project.alice.resource.links.ScheduleResourceLinks)5 ArrayList (java.util.ArrayList)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)5 Builder (javax.ws.rs.client.Invocation.Builder)5 Session (org.hibernate.Session)5 ScheduleDaoException (com.remswork.project.alice.dao.exception.ScheduleDaoException)4 ClassScheduleListResourceLinks (com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks)4 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)4 Set (java.util.Set)4 AsyncTask (android.os.AsyncTask)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3