001/* 002 * Copyright 2016 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.plugins.repository.lock; 017 018import java.time.LocalDateTime; 019import java.util.ArrayList; 020import java.util.Collections; 021import java.util.HashMap; 022import java.util.List; 023import java.util.Map; 024 025import org.ametys.core.schedule.Runnable; 026import org.ametys.runtime.i18n.I18nizableText; 027 028/** 029 * A {@link Runnable} which schedules a {@link UnlockSchedulable} for unlocking an object. 030 */ 031public class UnlockRunnable implements Runnable 032{ 033 /** The id of the object to unlock */ 034 protected String _objectId; 035 /** The name of the object to unlock */ 036 protected String _objectName; 037 /** The date when to unlock the content */ 038 protected LocalDateTime _date; 039 040 /** 041 * Constructor 042 * @param objectId The id of the object to unlock 043 * @param objectName The name of the object to unlock 044 * @param date The date when to unlock the content 045 */ 046 public UnlockRunnable(String objectId, String objectName, LocalDateTime date) 047 { 048 _objectId = objectId; 049 _objectName = objectName; 050 _date = date; 051 } 052 053 @Override 054 public String getId() 055 { 056 return this.getClass().getName() + "." + _objectId; 057 } 058 059 @Override 060 public I18nizableText getLabel() 061 { 062 return new I18nizableText("plugin.repository", "PLUGINS_REPOSITORY_UNLOCK_RUNNABLE_LABEL", Collections.singletonList(_objectName)); 063 } 064 065 @Override 066 public I18nizableText getDescription() 067 { 068 List<String> parameters = new ArrayList<>(); 069 parameters.add(_objectId); 070 parameters.add(_objectName); 071 return new I18nizableText("plugin.repository", "PLUGINS_REPOSITORY_UNLOCK_RUNNABLE_DESCRIPTION", parameters); 072 } 073 074 @Override 075 public FireProcess getFireProcess() 076 { 077 return FireProcess.CRON; 078 } 079 080 @Override 081 public String getCronExpression() 082 { 083 return _date.getSecond() + " " + _date.getMinute() + " " + _date.getHour() + " " + _date.getDayOfMonth() + " " + _date.getMonthValue() + " ? " + _date.getYear(); 084 } 085 086 @Override 087 public String getSchedulableId() 088 { 089 return "org.ametys.plugins.repository.lock.UnlockSchedulable"; 090 } 091 092 @Override 093 public boolean isRemovable() 094 { 095 return false; 096 } 097 098 @Override 099 public boolean isModifiable() 100 { 101 return false; 102 } 103 104 @Override 105 public boolean isDeactivatable() 106 { 107 return false; 108 } 109 110 @Override 111 public MisfirePolicy getMisfirePolicy() 112 { 113 return MisfirePolicy.FIRE_ONCE; 114 } 115 116 @Override 117 public boolean isVolatile() 118 { 119 return false; 120 } 121 122 @Override 123 public Map<String, Object> getParameterValues() 124 { 125 Map<String, Object> values = new HashMap<>(); 126 values.put(UnlockSchedulable.OBJECT_ID_KEY, _objectId); 127 return values; 128 } 129}