Search in sources :

Example 51 with Student

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

the class StudentServiceImpl method deleteStudentById.

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

Example 52 with Student

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

the class StudentServiceImpl method getStudentBySn.

public Student getStudentBySn(long id) throws StudentException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("?sn=");
        uri.append(id);
        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 StudentServiceException(message.getMessage());
        } else
            throw new StudentServiceException("The request might invalid or server is down");
    } catch (StudentServiceException e) {
        throw new StudentException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Student(com.remswork.project.alice.model.Student) StudentServiceException(com.remswork.project.alice.web.service.exception.StudentServiceException)

Example 53 with Student

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

the class XcellHelperBean method loadFile.

public List<Student> loadFile(File file) {
    List<Student> studentList = new ArrayList<>();
    try {
        FileInputStream fis = new FileInputStream(file);
        XSSFWorkbook workbook = new XSSFWorkbook(fis);
        XSSFSheet sheet = workbook.getSheetAt(0);
        final int size = sheet.getLastRowNum();
        for (int row = 1; row <= size; row++) {
            Student student = new Student();
            student.setStudentNumber((long) sheet.getRow(row).getCell(0).getNumericCellValue());
            student.setFirstName(sheet.getRow(row).getCell(1).getStringCellValue());
            student.setLastName(sheet.getRow(row).getCell(2).getStringCellValue());
            student.setMiddleName(sheet.getRow(row).getCell(3).getStringCellValue());
            studentList.add(student);
        }
        return studentList;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return studentList;
    } catch (IOException e) {
        e.printStackTrace();
        return studentList;
    } catch (RuntimeException e) {
        e.printStackTrace();
        return studentList;
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IOException(java.io.IOException) Student(com.remswork.project.alice.model.Student) FileInputStream(java.io.FileInputStream)

Example 54 with Student

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

the class XcellHelperBean method loadFile.

public List<Student> loadFile(File file, boolean withFormat) {
    List<Student> studentList = new ArrayList<>();
    try {
        if (!withFormat)
            return loadFile(file);
        FileInputStream fis = new FileInputStream(file);
        XSSFWorkbook workbook = new XSSFWorkbook(fis);
        XSSFSheet sheet = workbook.getSheetAt(0);
        final int size = sheet.getLastRowNum();
        final int colSize = sheet.getRow(0).getLastCellNum() > 6 ? 6 : sheet.getRow(0).getLastCellNum();
        final int[] header = new int[colSize];
        for (int i = 0; i < colSize; i++) {
            if (sheet.getRow(0).getCell(i).getCellType() != Cell.CELL_TYPE_STRING)
                continue;
            if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("studentNumber"))
                header[0] = i;
            if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("firstName"))
                header[1] = i;
            if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("lastName"))
                header[2] = i;
            if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("middleName"))
                header[3] = i;
            if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("gender"))
                header[4] = i;
            if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("age"))
                header[5] = i;
        }
        for (int row = 1; row <= size; row++) {
            Student student = new Student();
            if (sheet.getRow(row).getCell(header[0]).getCellType() == Cell.CELL_TYPE_NUMERIC)
                student.setStudentNumber((long) sheet.getRow(row).getCell(header[0]).getNumericCellValue());
            else
                student.setStudentNumber(0);
            if (sheet.getRow(row).getCell(header[1]).getCellType() == Cell.CELL_TYPE_STRING)
                student.setFirstName(sheet.getRow(row).getCell(header[1]).getStringCellValue());
            else
                student.setFirstName("none");
            if (sheet.getRow(row).getCell(header[2]).getCellType() == Cell.CELL_TYPE_STRING)
                student.setLastName(sheet.getRow(row).getCell(header[2]).getStringCellValue());
            else
                student.setLastName("none");
            if (sheet.getRow(row).getCell(header[3]).getCellType() == Cell.CELL_TYPE_STRING)
                student.setMiddleName(sheet.getRow(row).getCell(header[3]).getStringCellValue());
            else
                student.setMiddleName("none");
            if (sheet.getRow(row).getCell(header[4]).getCellType() == Cell.CELL_TYPE_STRING)
                student.setGender(sheet.getRow(row).getCell(header[4]).getStringCellValue());
            else
                student.setGender("Male");
            if (sheet.getRow(row).getCell(header[5]).getCellType() == Cell.CELL_TYPE_NUMERIC)
                student.setAge((int) sheet.getRow(row).getCell(header[5]).getNumericCellValue());
            else
                student.setAge(0);
            studentList.add(student);
        }
        return studentList;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return studentList;
    } catch (IOException e) {
        e.printStackTrace();
        return studentList;
    } catch (RuntimeException e) {
        e.printStackTrace();
        return studentList;
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IOException(java.io.IOException) Student(com.remswork.project.alice.model.Student) FileInputStream(java.io.FileInputStream)

Example 55 with Student

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

the class StudentResource method updateStudentById.

@PUT
@Path("{studentId}")
public Response updateStudentById(@PathParam("studentId") long id, Student newStudent) {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Student student = studentService.updateStudentById(id, newStudent, sectionId);
        student.addLink(resourceLinks.self(id));
        if (student.getSection() != null) {
            Section section = student.getSection();
            section.addLink(sectionResourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Aggregations

Student (com.remswork.project.alice.model.Student)82 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)29 CompoundButton (android.widget.CompoundButton)22 Message (com.remswork.project.alice.model.support.Message)21 Grade (com.remswork.project.alice.model.Grade)20 ArrayList (java.util.ArrayList)19 StudentException (com.remswork.project.alice.exception.StudentException)17 CardView (android.support.v7.widget.CardView)15 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)15 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)15 RecyclerView (android.support.v7.widget.RecyclerView)15 View (android.view.View)15 TextView (android.widget.TextView)15 ClassException (com.remswork.project.alice.exception.ClassException)14 Button (android.widget.Button)13 List (java.util.List)13 ToggleButton (android.widget.ToggleButton)11 Client (javax.ws.rs.client.Client)10 WebTarget (javax.ws.rs.client.WebTarget)10 Response (javax.ws.rs.core.Response)10