diff --git a/src/main/java/org/nrg/xnat/configuration/SchedulerConfig.java b/src/main/java/org/nrg/xnat/configuration/SchedulerConfig.java index efe9951007fba0e6c216349b6d1b5a50d2820c35..83366e0e0bb15b5698a2e362299324c29ce7efa7 100644 --- a/src/main/java/org/nrg/xnat/configuration/SchedulerConfig.java +++ b/src/main/java/org/nrg/xnat/configuration/SchedulerConfig.java @@ -30,13 +30,6 @@ public class SchedulerConfig implements SchedulingConfigurer { return new TriggerTask(new ResetEmailRequests(_emailRequestLogService), new PeriodicTrigger(900000)); } - @Bean - public TriggerTask rebuildSessionXmls() throws SiteConfigurationException { - final PeriodicTrigger trigger = new PeriodicTrigger(_preferences.getSessionXmlRebuilderRepeat()); - trigger.setInitialDelay(60000); - return new TriggerTask(new SessionXMLRebuilder(_provider, _preferences.getSessionXmlRebuilderInterval(), _jmsTemplate), trigger); - } - @Bean(destroyMethod = "shutdown") public ThreadPoolTaskScheduler taskScheduler() { final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); @@ -47,6 +40,7 @@ public class SchedulerConfig implements SchedulingConfigurer { @Override public void configureTasks(final ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setScheduler(taskScheduler()); + _eventService.triggerEvent(new PreferenceEvent("sessionXmlRebuilderRepeat", String.valueOf(XDAT.getSiteConfigPreferences().getSessionXmlRebuilderRepeat()))); _eventService.triggerEvent(new PreferenceEvent("aliasTokenTimeout", String.valueOf(XDAT.getSiteConfigPreferences().getAliasTokenTimeout()))); _eventService.triggerEvent(new PreferenceEvent("inactivityBeforeLockout", String.valueOf(XDAT.getSiteConfigPreferences().getInactivityBeforeLockout()))); _eventService.triggerEvent(new PreferenceEvent("maxFailedLoginsLockoutDuration", String.valueOf(XDAT.getSiteConfigPreferences().getMaxFailedLoginsLockoutDuration()))); diff --git a/src/main/java/org/nrg/xnat/event/listeners/NotificationsPreferenceHandler.java b/src/main/java/org/nrg/xnat/event/listeners/NotificationsPreferenceHandler.java index c24b1eb0dbcbe089e7777be6d5e8b64c5c1eb411..f1df2e4b7c414cc8b4fb9aa433007b8e9e7b5a49 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/NotificationsPreferenceHandler.java +++ b/src/main/java/org/nrg/xnat/event/listeners/NotificationsPreferenceHandler.java @@ -3,9 +3,9 @@ package org.nrg.xnat.event.listeners; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nrg.prefs.events.AbstractPreferenceHandler; +import org.nrg.prefs.events.PreferenceHandlerMethod; import org.nrg.xdat.preferences.NotificationsPreferences; import org.nrg.xdat.preferences.PreferenceEvent; -import org.nrg.xdat.preferences.SiteConfigPreferences; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.jdbc.core.JdbcTemplate; @@ -13,13 +13,38 @@ import org.springframework.stereotype.Service; import reactor.bus.EventBus; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; @Service public class NotificationsPreferenceHandler extends AbstractPreferenceHandler<PreferenceEvent> { + private String _toolId=NotificationsPreferences.NOTIFICATIONS_TOOL_ID; + private final List<PreferenceHandlerMethod> _methods = new ArrayList<>(); @Inject public NotificationsPreferenceHandler(final EventBus eventBus){ - super(NotificationsPreferences.NOTIFICATIONS_TOOL_ID, eventBus); + super(eventBus); + } + + + @Override + public String getToolId() { + return _toolId; + } + + @Override + public void setToolId(String toolId) { + _toolId=toolId; + } + + @Override + public List<PreferenceHandlerMethod> getMethods(){ + return _methods; + } + + @Override + public void addMethod(PreferenceHandlerMethod method){ + _methods.add(method); } @Autowired diff --git a/src/main/java/org/nrg/xnat/event/listeners/SiteConfigPreferenceHandler.java b/src/main/java/org/nrg/xnat/event/listeners/SiteConfigPreferenceHandler.java index f7fa2c7a1b2aa8a4edcc1e984d380b0a89849b52..e65524e02433a6411d642ef35a74d320ee07ad95 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/SiteConfigPreferenceHandler.java +++ b/src/main/java/org/nrg/xnat/event/listeners/SiteConfigPreferenceHandler.java @@ -3,6 +3,7 @@ package org.nrg.xnat.event.listeners; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nrg.prefs.events.AbstractPreferenceHandler; +import org.nrg.prefs.events.PreferenceHandlerMethod; import org.nrg.xdat.preferences.PreferenceEvent; import org.nrg.xdat.preferences.SiteConfigPreferences; import org.springframework.beans.factory.annotation.Autowired; @@ -12,13 +13,37 @@ import org.springframework.stereotype.Service; import reactor.bus.EventBus; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; @Service public class SiteConfigPreferenceHandler extends AbstractPreferenceHandler<PreferenceEvent> { + private String _toolId=SiteConfigPreferences.SITE_CONFIG_TOOL_ID; + private final List<PreferenceHandlerMethod> _methods = new ArrayList<>(); @Inject public SiteConfigPreferenceHandler(final EventBus eventBus){ - super(SiteConfigPreferences.SITE_CONFIG_TOOL_ID, eventBus); + super(eventBus); + } + + @Override + public String getToolId() { + return _toolId; + } + + @Override + public void setToolId(String toolId) { + _toolId=toolId; + } + + @Override + public List<PreferenceHandlerMethod> getMethods(){ + return _methods; + } + + @Override + public void addMethod(PreferenceHandlerMethod method){ + _methods.add(method); } @Autowired diff --git a/src/main/java/org/nrg/xnat/event/listeners/methods/AliasTokenPreferenceHandlerMethod.java b/src/main/java/org/nrg/xnat/event/listeners/methods/AliasTokenPreferenceHandlerMethod.java index 67f60280b60bb4e23d7ef884fac129aed482eaa3..56669628955fd28850927d1e15a9d81541273ebe 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/methods/AliasTokenPreferenceHandlerMethod.java +++ b/src/main/java/org/nrg/xnat/event/listeners/methods/AliasTokenPreferenceHandlerMethod.java @@ -39,6 +39,7 @@ public class AliasTokenPreferenceHandlerMethod extends AbstractSiteConfigPrefere private void updateAliasTokenTimeout() { try { + _scheduler.getScheduledThreadPoolExecutor().setRemoveOnCancelPolicy(true); for (final ScheduledFuture future : _timeouts) { future.cancel(false); } diff --git a/src/main/java/org/nrg/xnat/event/listeners/methods/InactivityBeforeLockoutHandlerMethod.java b/src/main/java/org/nrg/xnat/event/listeners/methods/InactivityBeforeLockoutHandlerMethod.java index 860bdec49fd08a074cf8b36c50e85c9ddafd277d..47912087c54298c053e4fc3258e2982165b5cdd5 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/methods/InactivityBeforeLockoutHandlerMethod.java +++ b/src/main/java/org/nrg/xnat/event/listeners/methods/InactivityBeforeLockoutHandlerMethod.java @@ -41,12 +41,12 @@ public class InactivityBeforeLockoutHandlerMethod extends AbstractSiteConfigPref private void updateInactivityBeforeLockout(){ try { _scheduler.getScheduledThreadPoolExecutor().setRemoveOnCancelPolicy(true); - Iterator<Runnable> iter = _scheduler.getScheduledThreadPoolExecutor().getQueue().iterator(); + for(ScheduledFuture temp: scheduledInactivityBeforeLockout){ temp.cancel(false); } - + scheduledInactivityBeforeLockout.clear(); scheduledInactivityBeforeLockout.add(_scheduler.schedule(new DisableInactiveUsers((new Long(SiteConfigPreferences.convertPGIntervalToSeconds(XDAT.getSiteConfigPreferences().getInactivityBeforeLockout()))).intValue(),(new Long(SiteConfigPreferences.convertPGIntervalToSeconds(XDAT.getSiteConfigPreferences().getMaxFailedLoginsLockoutDuration()))).intValue()),new CronTrigger(XDAT.getSiteConfigPreferences().getInactivityBeforeLockoutSchedule()))); } catch (Exception e1) { diff --git a/src/main/java/org/nrg/xnat/event/listeners/methods/ResetFailedLoginsHandlerMethod.java b/src/main/java/org/nrg/xnat/event/listeners/methods/ResetFailedLoginsHandlerMethod.java index 0e0cbf98bfd268d828a5892b1e62cd27b87822ce..fd94e3146ff6068c9583bee3ec033cec416cf0a9 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/methods/ResetFailedLoginsHandlerMethod.java +++ b/src/main/java/org/nrg/xnat/event/listeners/methods/ResetFailedLoginsHandlerMethod.java @@ -45,7 +45,7 @@ public class ResetFailedLoginsHandlerMethod extends AbstractSiteConfigPreference for(ScheduledFuture temp: scheduledResetFailedLogins){ temp.cancel(false); } - + scheduledResetFailedLogins.clear(); scheduledResetFailedLogins.add(_scheduler.schedule(new ResetFailedLogins(_template,XDAT.getSiteConfigPreferences().getMaxFailedLoginsLockoutDuration()),new CronTrigger(XDAT.getSiteConfigPreferences().getResetFailedLoginsSchedule()))); } catch (Exception e1) { diff --git a/src/main/java/org/nrg/xnat/event/listeners/methods/SessionXmlRebuilderHandlerMethod.java b/src/main/java/org/nrg/xnat/event/listeners/methods/SessionXmlRebuilderHandlerMethod.java new file mode 100644 index 0000000000000000000000000000000000000000..c33cd22e4363d2f0072c8bbd83a190c2d8884c9e --- /dev/null +++ b/src/main/java/org/nrg/xnat/event/listeners/methods/SessionXmlRebuilderHandlerMethod.java @@ -0,0 +1,76 @@ +package org.nrg.xnat.event.listeners.methods; + +import com.google.common.collect.ImmutableList; +import org.nrg.xdat.XDAT; +import org.nrg.xnat.helpers.prearchive.SessionXMLRebuilder; +import org.nrg.xnat.utils.XnatUserProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.support.PeriodicTrigger; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.*; +import java.util.concurrent.ScheduledFuture; + +@Component +public class SessionXmlRebuilderHandlerMethod extends AbstractSiteConfigPreferenceHandlerMethod { + @Override + public List<String> getHandledPreferences() { + return PREFERENCES; + } + + @Override + public void handlePreferences(final Map<String, String> values) { + if (!Collections.disjoint(PREFERENCES, values.keySet())) { + updateSessionXmlRebuilder(); + } + } + + @Override + public void handlePreference(final String preference, final String value) { + if(PREFERENCES.contains(preference)){ + updateSessionXmlRebuilder(); + } + } + + private void updateSessionXmlRebuilder(){ + try { + _scheduler.getScheduledThreadPoolExecutor().setRemoveOnCancelPolicy(true); + + for(ScheduledFuture temp: scheduledXmlRebuilder){ + temp.cancel(false); + } + scheduledXmlRebuilder.clear(); + scheduledXmlRebuilder.add(_scheduler.schedule(new SessionXMLRebuilder(_provider, XDAT.getSiteConfigPreferences().getSessionXmlRebuilderInterval(), _jmsTemplate),new PeriodicTrigger(XDAT.getSiteConfigPreferences().getSessionXmlRebuilderRepeat()))); + + } catch (Exception e1) { + _log.error("", e1); + } + } + + private static final Logger _log = LoggerFactory.getLogger(SessionXmlRebuilderHandlerMethod.class); + private static final List<String> PREFERENCES = ImmutableList.copyOf(Arrays.asList("sessionXmlRebuilderRepeat", "sessionXmlRebuilderInterval")); + + @Autowired + @Lazy + private JdbcTemplate _template; + + private ArrayList<ScheduledFuture> scheduledXmlRebuilder = new ArrayList<>(); + + @Autowired + @Qualifier("taskScheduler") + private ThreadPoolTaskScheduler _scheduler; + + @Inject + private JmsTemplate _jmsTemplate; + + @Inject + private XnatUserProvider _provider; +} diff --git a/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java b/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java index 6523ee706b504559ab0d8689086162530066dce2..f7c84e17eb00f6b766d3b2ebef8aa541e0bc3e74 100644 --- a/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java +++ b/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java @@ -442,7 +442,12 @@ public final class PrearcDatabase { * @return The path to the project. */ static String projectPath(String project) { - return Paths.get(PrearcDatabase.prearcPath, project).toString(); + if(project==null){ + return PrearcDatabase.prearcPath; + } + else { + return Paths.get(PrearcDatabase.prearcPath, project).toString(); + } } /**