    public void fillCurrentUserSubjectList(Subject[] subjects) {
        UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Person person = personDAO.findByUsername(userDetails.getUsername());
        LOGGER.debug("User: " + person.getUsername() + " [" + person.getIndeks() + "] submitted subjects: " +
                Arrays.asList(subjects));
        final List<Subject> toRemove = new ArrayList<>();
        final List<Subject> personSubjects = person.getSubjects();
        for (Subject s : personSubjects) {
            boolean contained = false;
            for (Subject s2 : subjects) {
                if (s2.equals(s)) {
                    contained = true;
                    break;
                }
            }
            if (!contained) {
                toRemove.add(s);
            }
        }
        LOGGER.debug("To remove list computed: " + toRemove);
        for (Subject s : toRemove) {
            s = getByPK(s.getSubjectID());
            final List<Term> termsBySubject = termDAO.getTermsBySubject(s);
            LOGGER.debug("Terms of subject: " + s + " retrieved");
            for (Term t : termsBySubject) {
                final StudentPointsPerTerm byPersonAndTerm = pointsDAO.getByPersonAndTerm(person, t);
                if (byPersonAndTerm != null) {
                    pointsDAO.remove(byPersonAndTerm);
                    LOGGER.debug("Points of term: " + t + " removed");
                }
            }
            s.getPersons().remove(person);
            LOGGER.debug("Person removed from subject");
        }
        personSubjects.removeAll(toRemove);
        LOGGER.debug("Unnecessary subjects removed");
        for (Subject subject : subjects) {
            subject.addPerson(person);
            person.addSubject(subject);
            LOGGER.debug("add new subject to student: " + subject);
        }
        em.merge(person);
        LOGGER.debug("Person updated");
    }

    public void fillCurrentUserSubjectList(Subject[] subjects) {
        UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Person person = personDAO.findByUsername(userDetails.getUsername());
        LOGGER.debug("User: " + person.getUsername() + " [" + person.getIndeks() + "] submitted subjects: " +
                Arrays.asList(subjects));
        final List<Subject> toRemove = new ArrayList<>();
        final List<Subject> personSubjects = person.getSubjects();
        for (Subject s : personSubjects) {
            boolean contained = false;
            for (Subject s2 : subjects) {
                if (s2.equals(s)) {
                    contained = true;
                    break;
                }
            }
            if (!contained) {
                toRemove.add(s);
            }
        }
        LOGGER.debug("To remove list computed: " + toRemove);
        for (Subject s : toRemove) {
            s = getByPK(s.getSubjectID());
            final List<Term> termsBySubject = termDAO.getTermsBySubject(s);
            LOGGER.debug("Terms of subject: " + s + " retrieved");
            for (Term t : termsBySubject) {
                final StudentPointsPerTerm byPersonAndTerm = pointsDAO.getByPersonAndTerm(person, t);
                if (byPersonAndTerm != null) {
                    pointsDAO.remove(byPersonAndTerm);
                    LOGGER.debug("Points of term: " + t + " removed");
                }
            }
            s.getPersons().remove(person);
            LOGGER.debug("Person removed from subject");
        }
        personSubjects.removeAll(toRemove);
        LOGGER.debug("Unnecessary subjects removed");
        for (Subject subject : subjects) {
            subject = getByPK(subject.getSubjectID());
            subject.addPerson(person);
            person.addSubject(subject);
            LOGGER.debug("add new subject to student: " + subject);
        }
        em.merge(person);
        LOGGER.debug("Person updated");
    }
