001/* 002 * Copyright 2020 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.tasks.jcr; 017 018import javax.jcr.Node; 019 020import org.ametys.plugins.repository.AmetysObjectFactory; 021import org.ametys.plugins.repository.AmetysRepositoryException; 022import org.ametys.plugins.repository.RepositoryConstants; 023import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObjectFactory; 024import org.ametys.plugins.workspaces.data.type.ModelItemTypeExtensionPoint; 025import org.ametys.runtime.model.DefaultElementDefinition; 026import org.ametys.runtime.model.Model; 027import org.ametys.runtime.model.type.ModelItemTypeConstants; 028 029/** 030 * {@link AmetysObjectFactory} for handling {@link JCRTasksList}. 031 */ 032public class JCRTasksListFactory extends DefaultTraversableAmetysObjectFactory 033{ 034 /** JCR nodetype for tasks */ 035 public static final String TASKS_LIST_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":tasks-list"; 036 037 /** The task list model */ 038 private Model _taskListModel; 039 040 @Override 041 public JCRTasksList getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 042 { 043 return new JCRTasksList(node, parentPath, this); 044 } 045 046 /** 047 * Get the task list model 048 * @return the task list model 049 */ 050 public Model getTaskListModel() 051 { 052 if (_taskListModel == null) 053 { 054 try 055 { 056 String role = ModelItemTypeExtensionPoint.ROLE_TASK_LIST; 057 _taskListModel = Model.of( 058 "task.list.model.id", 059 "task.list.model.family.id", 060 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_ID, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 061 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_POSITION, false, ModelItemTypeConstants.LONG_TYPE_ID, role), 062 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_LABEL, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 063 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_COLOR_ID, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 064 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_ICON_ID, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 065 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_AUTHOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role), 066 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_CREATIONDATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 067 DefaultElementDefinition.of(JCRTasksList.ATTRIBUTE_LASTMODIFIED, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role) 068 ); 069 } 070 catch (Exception e) 071 { 072 getLogger().error("An error occurred getting the task list model", e); 073 throw new RuntimeException("An error occurred getting the task list model", e); 074 } 075 } 076 return _taskListModel; 077 } 078}