Search in sources :

Example 31 with Class

use of com.remswork.project.alice.model.Class 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 32 with Class

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

the class ClassServiceImpl method deleteClassById.

@Override
public Class deleteClassById(long id) 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(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 (Class) response.readEntity(Class.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) Class(com.remswork.project.alice.model.Class) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 33 with Class

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

the class ClassServiceImpl method getClassListByStudentId.

@Override
public List<Class> getClassListByStudentId(long studentId) 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("studentId", studentId).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 34 with Class

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

the class ClassServiceImpl method addClass.

@Override
public Class addClass(Class _class, long teacherId, long subjectId, long sectionId) 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());
        Builder builder = target.queryParam("teacherId", teacherId).queryParam("subjectId", subjectId).queryParam("sectionId", sectionId).request(MediaType.APPLICATION_JSON);
        Response response = builder.post(Entity.xml(_class));
        if (response.getStatus() == 200 || response.getStatus() == 201) {
            return (Class) response.readEntity(Class.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) Class(com.remswork.project.alice.model.Class) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 35 with Class

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

the class ClassServiceImpl method getClassById.

@Override
public Class getClassById(long id) 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(id);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (Class) response.readEntity(Class.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) Class(com.remswork.project.alice.model.Class) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Aggregations

Class (com.remswork.project.alice.model.Class)59 Session (org.hibernate.Session)35 ClassException (com.remswork.project.alice.exception.ClassException)18 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)16 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)16 Message (com.remswork.project.alice.model.support.Message)16 ClassDaoException (com.remswork.project.alice.dao.exception.ClassDaoException)15 Query (org.hibernate.Query)10 Student (com.remswork.project.alice.model.Student)9 ArrayList (java.util.ArrayList)9 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)8 Client (javax.ws.rs.client.Client)8 WebTarget (javax.ws.rs.client.WebTarget)8 Response (javax.ws.rs.core.Response)8 Grade (com.remswork.project.alice.model.Grade)7 Formula (com.remswork.project.alice.model.Formula)6 FormulaService (com.remswork.project.alice.service.FormulaService)6 GradeService (com.remswork.project.alice.service.GradeService)6 FormulaServiceImpl (com.remswork.project.alice.service.impl.FormulaServiceImpl)6 GradeServiceImpl (com.remswork.project.alice.service.impl.GradeServiceImpl)6