001/*
002 *  Copyright 2023 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.web.usermanagement;
017
018import java.util.HashMap;
019import java.util.List;
020import java.util.Map;
021
022import org.ametys.core.schedule.Runnable;
023import org.ametys.core.user.UserIdentity;
024import org.ametys.runtime.i18n.I18nizableText;
025
026/**
027 * A {@link Runnable} which schedules a {@link SendInvitationsSchedulable} for sending invitations emails
028 */
029public class SendInvitationsRunnable implements Runnable
030{
031    private String _id;
032    private UserIdentity _userIdentity;
033    private String _userDirectoryId;
034    private String _populationId;
035    private String _siteName;
036    private List<String> _guests;
037    private boolean _resendInvitation;
038
039    /**
040     * Constructor
041     * @param guestLines the user to invit such as email;lastname;firstname (extract from CVS file)
042     * @param siteName the site name
043     * @param populationId the id of population
044     * @param userDirectoryId the id of user directory
045     * @param resendInvitation true to resend invitations
046     * @param userIdentity the user identity who launch the job
047     */
048    public SendInvitationsRunnable(List<String> guestLines, String siteName, String populationId, String userDirectoryId, boolean resendInvitation, UserIdentity userIdentity)
049    {
050        _id = SendInvitationsRunnable.class.getName() + "$" + System.currentTimeMillis();
051        _userIdentity = userIdentity;
052        _siteName = siteName;
053        _populationId = populationId;
054        _userDirectoryId = userDirectoryId;
055        _guests = guestLines;
056        _resendInvitation = resendInvitation;
057    }
058    
059    public String getId()
060    {
061        return _id;
062    }
063
064    public I18nizableText getLabel()
065    {
066        return new I18nizableText("plugin.web", "PLUGINS_WEB_USERS_SEND_INVITATIONS_RUNNABLE_LABEL");
067    }
068
069    public I18nizableText getDescription()
070    {
071        return new I18nizableText("plugin.web", "PLUGINS_WEB_USERS_SEND_INVITATIONS_RUNNABLE_DESCRIPTION");
072    }
073
074    public FireProcess getFireProcess()
075    {
076        return FireProcess.NOW;
077    }
078
079    public String getCronExpression()
080    {
081        return null;
082    }
083
084    public String getSchedulableId()
085    {
086        return SendInvitationsSchedulable.class.getName();
087    }
088
089    public boolean isRemovable()
090    {
091        return false;
092    }
093
094    public boolean isModifiable()
095    {
096        return false;
097    }
098
099    public boolean isDeactivatable()
100    {
101        return false;
102    }
103
104    public MisfirePolicy getMisfirePolicy()
105    {
106        return MisfirePolicy.FIRE_ONCE;
107    }
108
109    public boolean isVolatile()
110    {
111        return false;
112    }
113
114    public Map<String, Object> getParameterValues()
115    {
116        Map<String, Object> values = new HashMap<>();
117        values.put(SendInvitationsSchedulable.SITE_NAME_KEY, _siteName);
118        values.put(SendInvitationsSchedulable.USER_POPULATION_ID_KEY, _populationId);
119        values.put(SendInvitationsSchedulable.USER_DIRECTORY_ID_KEY, _userDirectoryId);
120        values.put(SendInvitationsSchedulable.GUESTS_KEY, _guests);
121        values.put(SendInvitationsSchedulable.RESEND_INVITATIONS_KEY, _resendInvitation);
122        return values;
123    }
124
125    public UserIdentity getUserIdentity()
126    {
127        return _userIdentity;
128    }
129
130}