001/* 002 * Copyright 2025 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.export.pdf; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.configuration.Configuration; 021import org.apache.avalon.framework.configuration.ConfigurationException; 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.quartz.SchedulerException; 025 026import org.ametys.cms.clientsideelement.SmartContentClientSideElement; 027import org.ametys.core.ui.Callable; 028import org.ametys.plugins.core.schedule.Scheduler; 029import org.ametys.runtime.authentication.AccessDeniedException; 030 031/** 032 * Client side element to schedule a generation of educational booklet 033 */ 034public class ScheduleEducationalBookletClientSideElement extends SmartContentClientSideElement 035{ 036 /** The Ametys scheduler */ 037 protected Scheduler _scheduler; 038 private String _schedulableId; 039 040 @Override 041 public void service(ServiceManager smanager) throws ServiceException 042 { 043 super.service(smanager); 044 _scheduler = (Scheduler) smanager.lookup(Scheduler.ROLE); 045 } 046 047 @Override 048 public void configure(Configuration configuration) throws ConfigurationException 049 { 050 super.configure(configuration); 051 _schedulableId = configuration.getChild("class").getChild("schedulable").getValue(); 052 } 053 054 /** 055 * Adds a new task. 056 * @param label The label 057 * @param description The description 058 * @param fireProcess the fire process 059 * @param cron The cron expression 060 * @param schedulableId The id of the schedulable model 061 * @param params The values of the parameters 062 * @return A result map 063 * @throws SchedulerException if an error occured 064 */ 065 @Callable(rights = Callable.CHECKED_BY_IMPLEMENTATION) 066 public Map<String, Object> add(String label, String description, String fireProcess, String cron, String schedulableId, Map<String, Object> params) throws SchedulerException 067 { 068 if (hasRight(getRights(null)) && schedulableId.equals(_schedulableId)) 069 { 070 return _scheduler.add(label, description, fireProcess, cron, schedulableId, params); 071 } 072 throw new AccessDeniedException(_currentUserProvider.getUser() + "' tried to execute schedulable '" + schedulableId + "' without any of the following rights: " + getRights(null)); 073 } 074}