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 */
016package org.ametys.plugins.repository.activities;
017
018import javax.jcr.Node;
019import javax.jcr.RepositoryException;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024import org.ametys.plugins.repository.AmetysRepositoryException;
025import org.ametys.plugins.repository.RepositoryConstants;
026import org.ametys.plugins.repository.data.type.ModelItemTypeExtensionPoint;
027import org.ametys.plugins.repository.jcr.SimpleAmetysObjectFactory;
028
029/**
030 * AmetysObject factory associated with {@link Activity}
031 */
032public class ActivityFactory extends SimpleAmetysObjectFactory
033{
034    /** Avalon Role for activity data types */
035    public static final String MODEL_ITEM_TYPE_EXTENSION_ROLE = ModelItemTypeExtensionPoint.class.getName() + ".Activity";
036    
037    /** activity node type name. */
038    public static final String NODE_TYPE = RepositoryConstants.NAMESPACE_PREFIX + ":activity";
039    
040    /** data name for the date of the activity */
041    public static final String DATE = "date";
042
043    /** data name for the type of the event represented by the activity */
044    public static final String TYPE = "type";
045
046    /** data name for the author of the activity */
047    public static final String AUTHOR = "author";
048    
049    private ModelItemTypeExtensionPoint _modelItemTypeEP;
050
051    private ActivityTypeExtensionPoint _activityTypeEP;
052
053    @Override
054    public void service(ServiceManager serviceManager) throws ServiceException
055    {
056        super.service(serviceManager);
057        _modelItemTypeEP = (ModelItemTypeExtensionPoint) serviceManager.lookup(MODEL_ITEM_TYPE_EXTENSION_ROLE);
058        _activityTypeEP = (ActivityTypeExtensionPoint) serviceManager.lookup(ActivityTypeExtensionPoint.ROLE);
059    }
060    
061    @Override
062    public Activity getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException, RepositoryException
063    {
064        return new Activity(node, parentPath, this);
065    }
066
067    /**
068     * Retrieves the extension point with available modelItem types for
069     * {@link Activity}
070     * 
071     * @return the extension point with available modelItem types for
072     *         {@link Activity}
073     */
074    public ModelItemTypeExtensionPoint getElementTypesExtensionPoint()
075    {
076        return _modelItemTypeEP;
077    }
078
079    /**
080     * Retrieve an {@link ActivityType} based on a event id
081     * @param id the event id
082     * @return the activity type
083     */
084    public ActivityType getActivityTypeFromId(String id)
085    {
086        return _activityTypeEP.getActivityType(id);
087    }
088}