001/*
002 *  Copyright 2019 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.odf.ose.schedulable;
017
018import java.util.Set;
019
020import org.apache.avalon.framework.service.ServiceException;
021import org.apache.avalon.framework.service.ServiceManager;
022import org.quartz.JobDataMap;
023import org.quartz.JobExecutionContext;
024
025import org.ametys.core.schedule.Schedulable;
026import org.ametys.core.schedule.progression.ContainerProgressionTracker;
027import org.ametys.odf.ose.export.OSEExport;
028import org.ametys.odf.ose.export.OSEExportExtensionPoint;
029import org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable;
030import org.ametys.plugins.core.schedule.Scheduler;
031
032/**
033 * {@link Schedulable} for OSE export.
034 */
035public class ExportSchedulable extends AbstractStaticSchedulable
036{
037    private static final String __AMETYS_CATALOG = "ametys.catalog";
038    private static final String __OSE_CATALOG = "ose.catalog";
039    private static final String __JOBDATAMAP_AMETYS_CATALOG = Scheduler.PARAM_VALUES_PREFIX + __AMETYS_CATALOG;
040    private static final String __JOBDATAMAP_OSE_CATALOG = Scheduler.PARAM_VALUES_PREFIX + __OSE_CATALOG;
041    
042    /** The OSE export extension point */
043    protected OSEExportExtensionPoint _oseExportEP;
044
045    @Override
046    public void service(ServiceManager manager) throws ServiceException
047    {
048        super.service(manager);
049        _oseExportEP = (OSEExportExtensionPoint) manager.lookup(OSEExportExtensionPoint.ROLE);
050    }
051    
052    @Override
053    public void execute(JobExecutionContext context, ContainerProgressionTracker progressionTracker) throws Exception
054    {
055        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
056        String ametysCatalog = jobDataMap.getString(__JOBDATAMAP_AMETYS_CATALOG);
057        Long oseCatalog = jobDataMap.getLong(__JOBDATAMAP_OSE_CATALOG);
058
059        Set<String> exportIds = _oseExportEP.getExtensionsIds();
060        
061        for (String exportId : exportIds)
062        {
063            OSEExport export = _oseExportEP.getExtension(exportId);
064            export.populate(ametysCatalog, oseCatalog);
065        }
066    }
067}