Commit 281f88ab authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette

Unified Student/Professor ID getter in User ID getter

It unified the methods "getIdFromLoggedInStudent" and  "getIdFromLoggedInProfessor"
in a single method called "getIdFromLoggedInUser", because they were the same thing.
Signed-off-by: Bruno Nocera Zanette's avatarBruno Nocera Zanette <brunonzanette@gmail.com>
parent ab9d19d1
......@@ -29,6 +29,7 @@ import br.ufpr.c3sl.sapos.models.people.Student;
import br.ufpr.c3sl.sapos.models.scholar.enums.LanguageKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.RegistrationKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.RegistrationStatus;
import br.ufpr.c3sl.sapos.models.util.KerberosAuthProvider;
import br.ufpr.c3sl.sapos.models.util.PermissionProvider;
import br.ufpr.c3sl.sapos.models.util.ReportUtil;
......@@ -160,7 +161,7 @@ public class Registration {
}
public static Collection<Registration> findStudentRegistration() {
String studentId = PermissionProvider.getIdFromLoggedInStudent();
String studentId = KerberosAuthProvider.getIdFromLoggedInUser();
return entityManager().createNativeQuery(
"SELECT * FROM registration r" +
" WHERE r.student = " + "'" + studentId + "'",
......@@ -195,7 +196,7 @@ public class Registration {
}
public static Object findRegistrationsPerAdvisor() {
String professorId = PermissionProvider.getIdFromLoggedInProfessor();
String professorId = KerberosAuthProvider.getIdFromLoggedInUser();
return entityManager().createNativeQuery(
"SELECT * FROM registration r where "+
" advisor = "+"'"+professorId+"'" , Registration.class).getResultList();
......
......@@ -57,7 +57,7 @@ public class StudentGrant {
}
public static Object findGrantsPerKindAndPerAdvisor(String grant) {
String professorId = KerberosAuthProvider.getIdFromLoggedInProfessor();
String professorId = KerberosAuthProvider.getIdFromLoggedInUser();
return entityManager().createNativeQuery(
"SELECT * FROM student_grant a, grant_kind b, registration r"+
" WHERE a.end_date is null"+
......
......@@ -46,19 +46,12 @@ public class KerberosAuthProvider implements UserDetailsService {
public static Collection<? extends GrantedAuthority> authAluno = AuthorityUtils
.createAuthorityList("Aluno");
public static String getIdFromLoggedInStudent(){
public static String getIdFromLoggedInUser(){
return Registration.entityManager().createNativeQuery(
"SELECT r.id from registration r, person p"+
" WHERE r.student = p.id"+
" and p.user_name ="+"'"+getPersonUsername()+"'").getSingleResult().toString();
"SELECT id from person"+
" WHERE user_name ="+"'"+getPersonUsername()+"'").getSingleResult().toString();
}
public static String getIdFromLoggedInProfessor(){
return Registration.entityManager().createNativeQuery(
"SELECT p.id from person p"+
" WHERE p.user_name ="+"'"+getPersonUsername()+"'").getSingleResult().toString();
}
// This method is used to remove the suffix added by Kerberos
// By Kerberos's definition: krbPrincipalName = Username@Server
private static String removeKrbSuffix(String username){
......
......@@ -50,7 +50,7 @@ public class RegistrationController {
if (KerberosAuthProvider.getPersonAuth().equals(KerberosAuthProvider.authProfessor))
model.addAttribute("registrations", Registration.findRegistrations(
KerberosAuthProvider.getIdFromLoggedInProfessor(),year, kind, status));
KerberosAuthProvider.getIdFromLoggedInUser(),year, kind, status));
else
model.addAttribute("registrations", Registration.findRegistrations(year, kind, status));
......@@ -71,7 +71,7 @@ public class RegistrationController {
if (KerberosAuthProvider.getPersonAuth().equals(KerberosAuthProvider.authProfessor))
model.addAttribute("registrations",Registration.findStudentsPerCourseYear(
KerberosAuthProvider.getIdFromLoggedInProfessor(), regKind, year,regStatus));
KerberosAuthProvider.getIdFromLoggedInUser(), regKind, year,regStatus));
else
model.addAttribute("registrations",
Registration.findStudentsPerCourseYear(regKind, year,regStatus));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment