Search in sources :

Example 6 with ClassServiceException

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

the class ClassServiceImpl method deleteStudentById.

@Override
public Student deleteStudentById(long classId, long studentId) throws ClassException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(classId);
        uri.append("/");
        uri.append("student");
        uri.append("/");
        uri.append(studentId);
        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 (Student) response.readEntity(Student.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ClassServiceException(message.getMessage());
        } else
            throw new ClassServiceException("The request might invalid or server is down");
    } catch (ClassServiceException e) {
        throw new ClassException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ClassServiceException(com.remswork.project.alice.web.service.exception.ClassServiceException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) ClassException(com.remswork.project.alice.exception.ClassException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Student(com.remswork.project.alice.model.Student)

Example 7 with ClassServiceException

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

the class ClassServiceImpl method getClassListBySubjectId.

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

Example 8 with ClassServiceException

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

the class ClassServiceImpl method getStudentById.

@Override
public Student getStudentById(long classId, long studentId) throws ClassException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(classId);
        uri.append("/");
        uri.append("student");
        uri.append("/");
        uri.append(studentId);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (Student) response.readEntity(Student.class);
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ClassServiceException(message.getMessage());
        } else
            throw new ClassServiceException("The request might invalid or server is down");
    } catch (ClassServiceException e) {
        throw new ClassException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ClassServiceException(com.remswork.project.alice.web.service.exception.ClassServiceException) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Student(com.remswork.project.alice.model.Student)

Example 9 with ClassServiceException

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

the class ClassServiceImpl method getScheduleById.

@Override
public Schedule getScheduleById(long classId, long scheduleId) throws ClassException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(classId);
        uri.append("/");
        uri.append("schedule");
        uri.append("/");
        uri.append(scheduleId);
        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 ClassServiceException(message.getMessage());
        } else
            throw new ClassServiceException("The request might invalid or server is down");
    } catch (ClassServiceException e) {
        throw new ClassException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ClassServiceException(com.remswork.project.alice.web.service.exception.ClassServiceException) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ClassException(com.remswork.project.alice.exception.ClassException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 10 with ClassServiceException

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

the class ClassServiceImpl method getScheduleList.

@Override
public Set<Schedule> getScheduleList(long classId) throws ClassException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(classId);
        uri.append("/");
        uri.append("schedule");
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.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 ClassServiceException(message.getMessage());
        } else
            throw new ClassServiceException("The request might invalid or server is down");
    } catch (ClassServiceException e) {
        throw new ClassException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ClassServiceException(com.remswork.project.alice.web.service.exception.ClassServiceException) 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) ClassException(com.remswork.project.alice.exception.ClassException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Aggregations

ClassException (com.remswork.project.alice.exception.ClassException)16 Message (com.remswork.project.alice.model.support.Message)16 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)16 Client (javax.ws.rs.client.Client)16 WebTarget (javax.ws.rs.client.WebTarget)16 Response (javax.ws.rs.core.Response)16 Class (com.remswork.project.alice.model.Class)8 ClientBuilder (javax.ws.rs.client.ClientBuilder)7 Builder (javax.ws.rs.client.Invocation.Builder)7 GenericType (javax.ws.rs.core.GenericType)6 Schedule (com.remswork.project.alice.model.Schedule)4 Student (com.remswork.project.alice.model.Student)4 List (java.util.List)4 Set (java.util.Set)2