css.controller.AdmissionGradesController.java Source code

Java tutorial

Introduction

Here is the source code for css.controller.AdmissionGradesController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package css.controller;

import com.css.admission.AdmissionContestSolver;
import com.css.admission.PdfPublisher;
import com.css.database.clause.Filter;
import com.css.database.clause.StudentFilterById;
import com.css.database.dao.Student;
import com.css.database.entitymanager.EntityManager;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author Radu
 */
public class AdmissionGradesController extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest,
            HttpServletResponse httpServletResponse) throws Exception {
        EntityManager em = new EntityManager();
        if (httpServletRequest.getMethod().equals("POST")) {
            String stringid[] = httpServletRequest.getParameterValues("id[]");
            int id[] = new int[stringid.length];
            for (int i = 0; i < stringid.length; i++) {
                id[i] = Integer.parseInt(stringid[i]);
            }
            String names[] = httpServletRequest.getParameterValues("name[]");
            String cnps[] = httpServletRequest.getParameterValues("cnp[]");
            String sgradesh[] = httpServletRequest.getParameterValues("gradeh[]");
            double gradesh[] = new double[sgradesh.length];
            for (int i = 0; i < sgradesh.length; i++) {
                gradesh[i] = Double.parseDouble(sgradesh[i]);
            }
            String sgradesb[] = httpServletRequest.getParameterValues("gradeb[]");
            double gradesb[] = new double[sgradesb.length];
            for (int i = 0; i < sgradesb.length; i++) {
                gradesb[i] = Double.parseDouble(sgradesb[i]);
            }
            String sgradesa[] = httpServletRequest.getParameterValues("gradea[]");
            double gradesa[] = new double[sgradesa.length];
            for (int i = 0; i < sgradesa.length; i++) {
                gradesa[i] = Double.parseDouble(sgradesa[i]);
            }

            for (int i = 0; i < id.length; i++) {
                List<Student> by = em.getBy(Student.class, new StudentFilterById(id[i]));
                if (!by.isEmpty()) {
                    Student student = by.get(0);
                    student.setNume(names[i]);
                    student.setCNP(cnps[i]);
                    student.setBacGrade(gradesb[i]);
                    student.setHighSchoolGrade(gradesh[i]);
                    student.setExamGrade(gradesa[i]);
                    em.update(student);
                }
            }
        }
        ModelAndView model = new ModelAndView("admissiongrades");
        List<Student> students = em.getAll(Student.class);
        model.addObject("liststud", students);

        return model;
    }
}