From 9c502341fbf8819f56b8fa0bf6f6e88de1e80ed6 Mon Sep 17 00:00:00 2001 From: tomas-muller Date: Fri, 20 Dec 2024 14:15:12 +0100 Subject: [PATCH] Localization: Solver Clutering - ensure that the current locale is passed on solver server calls - this is to make localized messages returned in the user's current locale, rather than just using the unitime.locale default --- .../solver/jgroups/CourseSolverContainerRemote.java | 9 +++++++-- .../solver/jgroups/ExaminationSolverContainerRemote.java | 9 +++++++-- .../jgroups/InstructorSchedulingContainerRemote.java | 9 +++++++-- .../jgroups/OnlineStudentSchedulingContainerRemote.java | 9 +++++++-- .../timetable/solver/jgroups/RemoteSolverContainer.java | 5 ++++- .../solver/jgroups/StudentSolverContainerRemote.java | 9 +++++++-- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/JavaSource/org/unitime/timetable/solver/jgroups/CourseSolverContainerRemote.java b/JavaSource/org/unitime/timetable/solver/jgroups/CourseSolverContainerRemote.java index 1efd6d6482..df6f08d085 100644 --- a/JavaSource/org/unitime/timetable/solver/jgroups/CourseSolverContainerRemote.java +++ b/JavaSource/org/unitime/timetable/solver/jgroups/CourseSolverContainerRemote.java @@ -41,6 +41,7 @@ import org.jgroups.util.Rsp; import org.jgroups.util.RspList; import org.unitime.commons.hibernate.util.HibernateUtil; +import org.unitime.localization.impl.Localization; import org.unitime.timetable.model.Assignment; import org.unitime.timetable.model.Class_; import org.unitime.timetable.model.Department; @@ -103,13 +104,14 @@ public boolean createRemoteSolver(String user, DataProperties config, Address ca } @Override - public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { + public Object invoke(String method, String user, String locale, Class[] types, Object[] args) throws Exception { try { SolverProxy solver = iCourseSolvers.get(user); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Solver " + user + " does not exist."); + if (locale != null) Localization.setLocale(locale); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) @@ -124,7 +126,10 @@ public Object invoke(String method, String user, Class[] types, Object[] args) t @Override public Object dispatch(Address address, String user, Method method, Object[] args) throws Exception { try { - return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), user, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); + return iDispatcher.callRemoteMethod(address, "invoke", + new Object[] { method.getName(), user, Localization.getLocale(), method.getParameterTypes(), args }, + new Class[] { String.class, String.class, String.class, Class[].class, Object[].class }, + SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception)e.getTargetException(); diff --git a/JavaSource/org/unitime/timetable/solver/jgroups/ExaminationSolverContainerRemote.java b/JavaSource/org/unitime/timetable/solver/jgroups/ExaminationSolverContainerRemote.java index b4f1f954c6..c2569234f2 100644 --- a/JavaSource/org/unitime/timetable/solver/jgroups/ExaminationSolverContainerRemote.java +++ b/JavaSource/org/unitime/timetable/solver/jgroups/ExaminationSolverContainerRemote.java @@ -34,6 +34,7 @@ import org.jgroups.blocks.RpcDispatcher; import org.jgroups.fork.ForkChannel; import org.unitime.commons.hibernate.util.HibernateUtil; +import org.unitime.localization.impl.Localization; import org.unitime.timetable.solver.exam.ExamSolverProxy; /** @@ -85,13 +86,14 @@ public boolean createRemoteSolver(String user, DataProperties config, Address ca } @Override - public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { + public Object invoke(String method, String user, String locale, Class[] types, Object[] args) throws Exception { try { ExamSolverProxy solver = iExamSolvers.get(user); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Solver " + user + " does not exist."); + if (locale != null) Localization.setLocale(locale); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) @@ -106,7 +108,10 @@ public Object invoke(String method, String user, Class[] types, Object[] args) t @Override public Object dispatch(Address address, String user, Method method, Object[] args) throws Exception { try { - return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), user, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); + return iDispatcher.callRemoteMethod(address, "invoke", + new Object[] { method.getName(), user, Localization.getLocale(), method.getParameterTypes(), args }, + new Class[] { String.class, String.class, String.class, Class[].class, Object[].class }, + SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception)e.getTargetException(); diff --git a/JavaSource/org/unitime/timetable/solver/jgroups/InstructorSchedulingContainerRemote.java b/JavaSource/org/unitime/timetable/solver/jgroups/InstructorSchedulingContainerRemote.java index c32326f535..370a00ec8d 100644 --- a/JavaSource/org/unitime/timetable/solver/jgroups/InstructorSchedulingContainerRemote.java +++ b/JavaSource/org/unitime/timetable/solver/jgroups/InstructorSchedulingContainerRemote.java @@ -33,6 +33,7 @@ import org.jgroups.blocks.RpcDispatcher; import org.jgroups.fork.ForkChannel; import org.unitime.commons.hibernate.util.HibernateUtil; +import org.unitime.localization.impl.Localization; import org.unitime.timetable.solver.exam.ExamSolverProxy; import org.unitime.timetable.solver.instructor.InstructorSchedulingProxy; @@ -85,13 +86,14 @@ public boolean createRemoteSolver(String user, DataProperties config, Address ca } @Override - public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { + public Object invoke(String method, String user, String locale, Class[] types, Object[] args) throws Exception { try { InstructorSchedulingProxy solver = iInstrSchdSolvers.get(user); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Solver " + user + " does not exist."); + if (locale != null) Localization.setLocale(locale); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) @@ -106,7 +108,10 @@ public Object invoke(String method, String user, Class[] types, Object[] args) t @Override public Object dispatch(Address address, String user, Method method, Object[] args) throws Exception { try { - return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), user, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); + return iDispatcher.callRemoteMethod(address, "invoke", + new Object[] { method.getName(), user, Localization.getLocale(), method.getParameterTypes(), args }, + new Class[] { String.class, String.class, String.class, Class[].class, Object[].class }, + SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception)e.getTargetException(); diff --git a/JavaSource/org/unitime/timetable/solver/jgroups/OnlineStudentSchedulingContainerRemote.java b/JavaSource/org/unitime/timetable/solver/jgroups/OnlineStudentSchedulingContainerRemote.java index a52528bd8f..78b3e14aba 100644 --- a/JavaSource/org/unitime/timetable/solver/jgroups/OnlineStudentSchedulingContainerRemote.java +++ b/JavaSource/org/unitime/timetable/solver/jgroups/OnlineStudentSchedulingContainerRemote.java @@ -33,6 +33,7 @@ import org.jgroups.blocks.RpcDispatcher; import org.jgroups.fork.ForkChannel; import org.unitime.commons.hibernate.util.HibernateUtil; +import org.unitime.localization.impl.Localization; import org.unitime.timetable.onlinesectioning.OnlineSectioningServer; import org.unitime.timetable.onlinesectioning.OnlineSectioningServerContext; import org.unitime.timetable.solver.SolverProxy; @@ -85,13 +86,14 @@ public boolean createRemoteSolver(String sessionId, DataProperties config, Addre } @Override - public Object invoke(String method, String sessionId, Class[] types, Object[] args) throws Exception { + public Object invoke(String method, String sessionId, String locale, Class[] types, Object[] args) throws Exception { try { OnlineSectioningServer solver = iInstances.get(Long.valueOf(sessionId)); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Server " + sessionId + " does not exist."); + if (locale != null) Localization.setLocale(locale); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) @@ -106,7 +108,10 @@ public Object invoke(String method, String sessionId, Class[] types, Object[] ar @Override public Object dispatch(Address address, String sessionId, Method method, Object[] args) throws Exception { try { - return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), sessionId, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); + return iDispatcher.callRemoteMethod(address, "invoke", + new Object[] { method.getName(), sessionId, Localization.getLocale(), method.getParameterTypes(), args }, + new Class[] { String.class, String.class, String.class, Class[].class, Object[].class }, + SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception)e.getTargetException(); diff --git a/JavaSource/org/unitime/timetable/solver/jgroups/RemoteSolverContainer.java b/JavaSource/org/unitime/timetable/solver/jgroups/RemoteSolverContainer.java index aee450efbf..34331861ae 100644 --- a/JavaSource/org/unitime/timetable/solver/jgroups/RemoteSolverContainer.java +++ b/JavaSource/org/unitime/timetable/solver/jgroups/RemoteSolverContainer.java @@ -37,7 +37,10 @@ public interface RemoteSolverContainer extends SolverContainer { public Object dispatch(Address address, String user, Method method, Object[] args) throws Exception; - public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception; + public Object invoke(String method, String user, String locale, Class[] types, Object[] args) throws Exception; + default Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { + return invoke(method, user, null, types, args); + } public T createProxy(Address address, String user); diff --git a/JavaSource/org/unitime/timetable/solver/jgroups/StudentSolverContainerRemote.java b/JavaSource/org/unitime/timetable/solver/jgroups/StudentSolverContainerRemote.java index 8431dceca4..b6e08f0bfc 100644 --- a/JavaSource/org/unitime/timetable/solver/jgroups/StudentSolverContainerRemote.java +++ b/JavaSource/org/unitime/timetable/solver/jgroups/StudentSolverContainerRemote.java @@ -34,6 +34,7 @@ import org.jgroups.blocks.RpcDispatcher; import org.jgroups.fork.ForkChannel; import org.unitime.commons.hibernate.util.HibernateUtil; +import org.unitime.localization.impl.Localization; import org.unitime.timetable.solver.studentsct.StudentSolverProxy; /** @@ -85,13 +86,14 @@ public boolean createRemoteSolver(String user, DataProperties config, Address ca } @Override - public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { + public Object invoke(String method, String user, String locale, Class[] types, Object[] args) throws Exception { try { StudentSolverProxy solver = iStudentSolvers.get(user); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Solver " + user + " does not exist."); + if (locale != null) Localization.setLocale(locale); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) @@ -106,7 +108,10 @@ public Object invoke(String method, String user, Class[] types, Object[] args) t @Override public Object dispatch(Address address, String user, Method method, Object[] args) throws Exception { try { - return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), user, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); + return iDispatcher.callRemoteMethod(address, "invoke", + new Object[] { method.getName(), user, Localization.getLocale(), method.getParameterTypes(), args }, + new Class[] { String.class, String.class, String.class, Class[].class, Object[].class }, + SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception)e.getTargetException();