Skip to content

Commit

Permalink
Localization: Solver Clutering
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tomas-muller committed Dec 20, 2024
1 parent c9d4f8f commit 9c50234
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public interface RemoteSolverContainer<T> extends SolverContainer<T> {

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down

0 comments on commit 9c50234

Please sign in to comment.