001/* 002 * Copyright 2014 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.workspaces.calendars.jcr; 017 018import javax.jcr.Node; 019 020import org.ametys.cms.model.ModelAwareBasicTypesExtensionPoint; 021import org.ametys.plugins.repository.AmetysObjectFactory; 022import org.ametys.plugins.repository.AmetysRepositoryException; 023import org.ametys.plugins.repository.RepositoryConstants; 024import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObjectFactory; 025import org.ametys.runtime.model.ElementDefinition; 026import org.ametys.runtime.model.Model; 027import org.ametys.runtime.model.type.ModelItemTypeConstants; 028 029/** 030 * {@link AmetysObjectFactory} for handling {@link JCRCalendarEvent}s. 031 */ 032public class JCRCalendarEventFactory extends DefaultTraversableAmetysObjectFactory 033{ 034 /** JCR nodetype for resources collection */ 035 public static final String CALENDAR_EVENT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":calendar-event"; 036 037 /** The calendar event model */ 038 private Model _calendarEvent; 039 040 @Override 041 public JCRCalendarEvent getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 042 { 043 return new JCRCalendarEvent(node, parentPath, this); 044 } 045 046 /** 047 * Get the calendar event model 048 * @return the calendar event model 049 */ 050 public Model getCalendarEventModel() 051 { 052 if (_calendarEvent == null) 053 { 054 try 055 { 056 String role = ModelAwareBasicTypesExtensionPoint.ROLE; 057 _calendarEvent = Model.of( 058 "calendar.event.model.id", 059 "calendar.event.model.family.id", 060 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_CREATOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role), 061 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_CREATION, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 062 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_CONTRIBUTOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role), 063 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_MODIFIED, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 064 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_TITLE, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 065 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_DESC, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 066 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_KEYWORDS, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 067 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_LOCATION, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 068 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_START_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 069 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_END_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 070 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_DATE_ZONE, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 071 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_FULL_DAY, false, ModelItemTypeConstants.BOOLEAN_TYPE_ID, role), 072 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_RECURRENCE_TYPE, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 073 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_UNTIL_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 074 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_EXCLUDED_DATE, true, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 075 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_RESOURCES, true, ModelItemTypeConstants.STRING_TYPE_ID, role), 076 ElementDefinition.of(JCRCalendarEvent.ATTRIBUTE_ORGANISER, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role) 077 ); 078 } 079 catch (Exception e) 080 { 081 getLogger().error("An error occurred getting the calendar resource model", e); 082 throw new RuntimeException("An error occurred getting the calendar resource model", e); 083 } 084 } 085 return _calendarEvent; 086 } 087}