Search in sources :

Example 16 with Subject

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

the class SubjectServiceImpl method getSubjectByClassAndTeacherId.

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

Example 17 with Subject

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

the class SubjectServiceImpl method getSubjectList.

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

Example 18 with Subject

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

the class SubjectServiceImpl method updateSubjectById.

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

Example 19 with Subject

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

the class SubjectServiceImpl method addSubject.

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

Example 20 with Subject

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

the class SubjectResource method getSubjectListByTeacherId.

@GET
@Path("1")
@Deprecated
public Response getSubjectListByTeacherId(@QueryParam("teacherId") long teacherId) {
    try {
        SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
        List<Subject> subjectList = subjectService.getSubjectListByTeacherId(teacherId);
        for (Subject subject : subjectList) subject.addLink(resourceLinks.self(subject.getId()));
        GenericEntity<List<Subject>> entity = new GenericEntity<List<Subject>>(subjectList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) Subject(com.remswork.project.alice.model.Subject)

Aggregations

Subject (com.remswork.project.alice.model.Subject)29 SubjectException (com.remswork.project.alice.exception.SubjectException)23 Message (com.remswork.project.alice.model.support.Message)20 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)7 List (java.util.List)6 Teacher (com.remswork.project.alice.model.Teacher)5 ArrayList (java.util.ArrayList)5 AsyncTask (android.os.AsyncTask)4 Gson (com.google.gson.Gson)4 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ExecutionException (java.util.concurrent.ExecutionException)4 JSONArray (org.json.JSONArray)4