001/*
002 *  Copyright 2022 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 */
016
017package org.ametys.plugins.workspaces.calendars;
018
019import org.apache.avalon.framework.component.Component;
020import org.apache.avalon.framework.context.Context;
021import org.apache.avalon.framework.context.ContextException;
022import org.apache.avalon.framework.context.Contextualizable;
023import org.apache.avalon.framework.logger.AbstractLogEnabled;
024import org.apache.avalon.framework.service.ServiceException;
025import org.apache.avalon.framework.service.ServiceManager;
026import org.apache.avalon.framework.service.Serviceable;
027import org.apache.cocoon.components.ContextHelper;
028import org.apache.cocoon.environment.Request;
029
030import org.ametys.core.observation.ObservationManager;
031import org.ametys.core.right.RightManager;
032import org.ametys.core.user.CurrentUserProvider;
033import org.ametys.core.user.UserManager;
034import org.ametys.plugins.explorer.resources.actions.ExplorerResourcesDAO;
035import org.ametys.plugins.repository.AmetysObjectResolver;
036import org.ametys.plugins.workflow.support.WorkflowHelper;
037import org.ametys.plugins.workflow.support.WorkflowProvider;
038import org.ametys.plugins.workspaces.project.ProjectManager;
039import org.ametys.plugins.workspaces.project.modules.WorkspaceModuleExtensionPoint;
040import org.ametys.plugins.workspaces.project.objects.Project;
041import org.ametys.plugins.workspaces.tags.ProjectTagsDAO;
042
043/**
044 * Abstract class for Calendar DAO's
045 *
046 */
047public abstract class AbstractCalendarDAO extends AbstractLogEnabled implements Serviceable, Component, Contextualizable
048{
049
050    /** Right to add a calendar */
051    public static final String RIGHTS_CALENDAR_ADD = "Plugins_Workspaces_Calendar_Add";
052    /** Right to edit a calendar */
053    public static final String RIGHTS_CALENDAR_EDIT = "Plugins_Workspaces_Calendar_Edit";
054    /** Right to delete a calendar */
055    public static final String RIGHTS_CALENDAR_DELETE = "Plugins_Workspaces_Calendar_Delete";
056    /** Right to add a event */
057    public static final String RIGHTS_EVENT_ADD = "Plugins_Workspaces_Event_Add";
058    /** Right to edit a event */
059    public static final String RIGHTS_EVENT_EDIT = "Plugins_Workspaces_Event_Edit";
060    /** Right to edit a event */
061    public static final String RIGHTS_OWNED_EVENT_DELETE = "Plugins_Workspaces_Owned_Event_Delete";
062    /** Right to delete a event */
063    public static final String RIGHTS_EVENT_DELETE = "Plugins_Workspaces_Event_Delete";
064    /** Right to delete_own a event */
065    public static final String RIGHTS_EVENT_DELETE_OWN = "Plugins_Workspaces_Owned_Event_Delete";
066    /** Right to handle a resource */
067    public static final String RIGHTS_HANDLE_RESOURCE = "Plugins_Workspaces_Handle_Resource";
068    /** Right to book a resource */
069    public static final String RIGHTS_BOOK_RESOURCE = "Plugins_Workspaces_Book_Resource";
070    
071    /** Explorer resources DAO */
072    protected ExplorerResourcesDAO _explorerResourcesDAO;
073    
074    /** Ametys resolver */
075    protected AmetysObjectResolver _resolver;
076    
077    /** Observer manager. */
078    protected ObservationManager _observationManager;
079    
080    /** The current user provider. */
081    protected CurrentUserProvider _currentUserProvider;
082    
083    /** The rights manager */
084    protected RightManager _rightManager;
085    
086    /** User manager */
087    protected UserManager _userManager;
088    
089    /** The workflow provider */
090    protected WorkflowProvider _workflowProvider;
091    
092    /** The workflow helper */
093    protected WorkflowHelper _workflowHelper;
094
095    /** Workspaces project manager */
096    protected ProjectManager _projectManager;
097
098    /** The Messaging connector calendar manager */
099    protected MessagingConnectorCalendarManager _messagingConnectorCalendarManager;
100    
101    /** The avalon context */
102    protected Context _context;
103    
104    /** The project tags DAO */
105    protected ProjectTagsDAO _projectTagsDAO;
106
107    /** The workspace module EP */
108    protected WorkspaceModuleExtensionPoint _workspaceModuleEP;
109
110    /** The color component */
111    protected CalendarColorsComponent _calendarColors;
112    
113    public void contextualize(Context context) throws ContextException
114    {
115        _context = context;
116    }
117    
118    public void service(ServiceManager manager) throws ServiceException
119    {
120        _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE);
121        _explorerResourcesDAO = (ExplorerResourcesDAO) manager.lookup(ExplorerResourcesDAO.ROLE);
122        _observationManager = (ObservationManager) manager.lookup(ObservationManager.ROLE);
123        _currentUserProvider = (CurrentUserProvider) manager.lookup(CurrentUserProvider.ROLE);
124        _rightManager = (RightManager) manager.lookup(RightManager.ROLE);
125        _userManager = (UserManager) manager.lookup(UserManager.ROLE);
126        _workflowProvider = (WorkflowProvider) manager.lookup(WorkflowProvider.ROLE);
127        _workflowHelper = (WorkflowHelper) manager.lookup(WorkflowHelper.ROLE);
128        _projectManager = (ProjectManager) manager.lookup(ProjectManager.ROLE);
129        _messagingConnectorCalendarManager = (MessagingConnectorCalendarManager) manager.lookup(MessagingConnectorCalendarManager.ROLE);
130        _projectTagsDAO = (ProjectTagsDAO) manager.lookup(ProjectTagsDAO.ROLE);
131        _workspaceModuleEP = (WorkspaceModuleExtensionPoint) manager.lookup(WorkspaceModuleExtensionPoint.ROLE);
132        _calendarColors = (CalendarColorsComponent) manager.lookup(CalendarColorsComponent.ROLE);
133    }
134
135    /**
136     * Get the project name
137     * @return the project name
138     */
139    protected String _getProjectName()
140    {
141        Request request = ContextHelper.getRequest(_context);
142        return (String) request.getAttribute("projectName");
143    }
144    
145    /**
146     * Get the project
147     * @return the project
148     */
149    protected Project _getProject()
150    {
151        return _projectManager.getProject(_getProjectName());
152    }
153    
154}