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 /** activity node type name. */ 035 public static final String NODE_TYPE = RepositoryConstants.NAMESPACE_PREFIX + ":activity"; 036 037 /** data name for the activity type id */ 038 public static final String ACTIVITY_TYPE_ID = "activityTypeId"; 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 /** Avalon Role for activity data types */ 050 private static final String __MODEL_ITEM_TYPE_EXTENSION_ROLE = ModelItemTypeExtensionPoint.class.getName() + ".Activity"; 051 052 private ActivityTypeExtensionPoint _activityTypeEP; 053 054 @Override 055 public void service(ServiceManager serviceManager) throws ServiceException 056 { 057 super.service(serviceManager); 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 @Override 068 protected String getModelItemTypeExtensionPointId() 069 { 070 return __MODEL_ITEM_TYPE_EXTENSION_ROLE; 071 } 072 073 /** 074 * Retrieve an {@link ActivityType} 075 * @param activityTypeId the type id 076 * @return the activity type 077 */ 078 public ActivityType getActivityType(String activityTypeId) 079 { 080 return _activityTypeEP.getExtension(activityTypeId); 081 } 082}