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 activity type id */ 041 public static final String ACTIVITY_TYPE_ID = "activityTypeId"; 042 043 /** data name for the date of the activity */ 044 public static final String DATE = "date"; 045 046 /** data name for the type of the event represented by the activity */ 047 public static final String TYPE = "type"; 048 049 /** data name for the author of the activity */ 050 public static final String AUTHOR = "author"; 051 052 private ModelItemTypeExtensionPoint _modelItemTypeEP; 053 054 private ActivityTypeExtensionPoint _activityTypeEP; 055 056 @Override 057 public void service(ServiceManager serviceManager) throws ServiceException 058 { 059 super.service(serviceManager); 060 _modelItemTypeEP = (ModelItemTypeExtensionPoint) serviceManager.lookup(MODEL_ITEM_TYPE_EXTENSION_ROLE); 061 _activityTypeEP = (ActivityTypeExtensionPoint) serviceManager.lookup(ActivityTypeExtensionPoint.ROLE); 062 } 063 064 @Override 065 public Activity getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException, RepositoryException 066 { 067 return new Activity(node, parentPath, this); 068 } 069 070 /** 071 * Retrieves the extension point with available modelItem types for 072 * {@link Activity} 073 * 074 * @return the extension point with available modelItem types for 075 * {@link Activity} 076 */ 077 public ModelItemTypeExtensionPoint getElementTypesExtensionPoint() 078 { 079 return _modelItemTypeEP; 080 } 081 082 /** 083 * Retrieve an {@link ActivityType} 084 * @param activityTypeId the type id 085 * @return the activity type 086 */ 087 public ActivityType getActivityType(String activityTypeId) 088 { 089 return _activityTypeEP.getExtension(activityTypeId); 090 } 091}