View Javadoc

1   /*
2    * #%L
3    * Bitrepository Integrity Service
4    * %%
5    * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 2.1 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  
23  package org.bitrepository.integrityservice.workflow;
24  
25  import org.bitrepository.common.settings.Settings;
26  import org.bitrepository.service.scheduler.JobScheduler;
27  import org.bitrepository.service.workflow.WorkflowManager;
28  import org.bitrepository.settings.referencesettings.Schedule;
29  import org.bitrepository.settings.referencesettings.Schedules;
30  import org.bitrepository.settings.referencesettings.WorkflowConfiguration;
31  import org.bitrepository.settings.referencesettings.WorkflowSettings;
32  
33  /**
34   * Manages the workflows for the integrity service. Delegates most functionality to the <code>Workflow</code>
35   * class, put handles som configation specif to the integrity workflows.
36   */
37  public class IntegrityWorkflowManager extends WorkflowManager {
38      public static final long DAILY = 86400000;
39      public static final long HOURLY = 360000;
40  
41      public IntegrityWorkflowManager(IntegrityWorkflowContext context, JobScheduler scheduler) {
42          super(context,
43                getWorkflowSettings(context.getSettings()),
44                scheduler);
45      }
46  
47      private static WorkflowSettings getWorkflowSettings(Settings settings) {
48          WorkflowSettings workflowSettings;
49          if (settings.getReferenceSettings().getIntegrityServiceSettings().isSetWorkflows()) {
50              workflowSettings = settings.getReferenceSettings().getIntegrityServiceSettings().getWorkflows();
51          } else {
52              workflowSettings = createDefaultWorkflowSettings();
53          }
54          return workflowSettings;
55      }
56  
57      /**
58       * Will create a default set of workflows. This is currently just the <code>CompleteIntegrityCheck</code>
59       * workflow running once a day on all collections.
60       */
61      protected static WorkflowSettings createDefaultWorkflowSettings() {
62          WorkflowSettings defaultWorkflowSettings = new WorkflowSettings();
63          WorkflowConfiguration completeIntegrityWorkflowConf = new WorkflowConfiguration();
64          completeIntegrityWorkflowConf.setWorkflowClass(CompleteIntegrityCheck.class.getCanonicalName());
65          Schedule schedule = new Schedule();
66          schedule.setWorkflowInterval(DAILY);
67          completeIntegrityWorkflowConf.setSchedules(new Schedules());
68          completeIntegrityWorkflowConf.getSchedules().getSchedule().add(schedule);
69          defaultWorkflowSettings.getWorkflow().add(completeIntegrityWorkflowConf);
70          return defaultWorkflowSettings;
71      }
72  
73      @Override
74      protected String getDefaultWorkflowPackage() {
75          return "org.bitrepository.integrityservice.workflow";
76      }
77  }