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.DefaultAmetysObjectFactory; 024import org.ametys.plugins.repository.model.RepeaterDefinition; 025import org.ametys.plugins.workspaces.tasks.TaskAttributesTypeExtensionPoint; 026import org.ametys.runtime.model.ElementDefinition; 027import org.ametys.runtime.model.Model; 028import org.ametys.runtime.model.type.ModelItemTypeConstants; 029 030/** 031 * {@link AmetysObjectFactory} for handling {@link JCRTask}. 032 */ 033public class JCRTaskFactory extends DefaultAmetysObjectFactory 034{ 035 /** JCR nodetype for tasks */ 036 public static final String TASK_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":task"; 037 038 /** The task model */ 039 private Model _taskModel; 040 041 @Override 042 public JCRTask getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 043 { 044 return new JCRTask(node, parentPath, this); 045 } 046 047 /** 048 * Get the task model 049 * @return the task model 050 */ 051 public Model getTaskModel() 052 { 053 if (_taskModel == null) 054 { 055 try 056 { 057 String role = TaskAttributesTypeExtensionPoint.ROLE; 058 _taskModel = Model.of( 059 "task.model.id", 060 "task.model.family.id", 061 ElementDefinition.of(JCRTask.ATTRIBUTE_TASKSLISTID, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 062 ElementDefinition.of(JCRTask.ATTRIBUTE_TASKSLISTPOSITION, false, ModelItemTypeConstants.LONG_TYPE_ID, role), 063 ElementDefinition.of(JCRTask.ATTRIBUTE_LABEL, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 064 ElementDefinition.of(JCRTask.ATTRIBUTE_DESCRIPTION, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 065 ElementDefinition.of(JCRTask.ATTRIBUTE_STARTDATE, false, ModelItemTypeConstants.DATE_TYPE_ID, role), 066 ElementDefinition.of(JCRTask.ATTRIBUTE_DUEDATE, false, ModelItemTypeConstants.DATE_TYPE_ID, role), 067 ElementDefinition.of(JCRTask.ATTRIBUTE_ISCLOSED, false, ModelItemTypeConstants.BOOLEAN_TYPE_ID, role), 068 ElementDefinition.of(JCRTask.ATTRIBUTE_CLOSEAUTHOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role), 069 ElementDefinition.of(JCRTask.ATTRIBUTE_CLOSEDATE, false, ModelItemTypeConstants.DATE_TYPE_ID, role), 070 ElementDefinition.of(JCRTask.ATTRIBUTE_AUTHOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role), 071 ElementDefinition.of(JCRTask.ATTRIBUTE_ASSIGNMENTS, true, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, role), 072 ElementDefinition.of(JCRTask.ATTRIBUTE_CREATIONDATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 073 ElementDefinition.of(JCRTask.ATTRIBUTE_LASTMODIFIED, false, ModelItemTypeConstants.DATETIME_TYPE_ID, role), 074 ElementDefinition.of(JCRTask.ATTRIBUTE_ATTACHMENTS, true, org.ametys.cms.data.type.ModelItemTypeConstants.FILE_ELEMENT_TYPE_ID, role), 075 RepeaterDefinition.of(JCRTask.ATTRIBUTE_CHECKLIST, role, 076 ElementDefinition.of(JCRTask.ATTRIBUTE_CHECKLIST_LABEL, false, ModelItemTypeConstants.STRING_TYPE_ID, role), 077 ElementDefinition.of(JCRTask.ATTRIBUTE_CHECKLIST_ISCHECKED, false, ModelItemTypeConstants.BOOLEAN_TYPE_ID, role)) 078 ); 079 } 080 catch (Exception e) 081 { 082 getLogger().error("An error occurred getting the task model", e); 083 throw new RuntimeException("An error occurred getting the task model", e); 084 } 085 } 086 return _taskModel; 087 } 088}