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 java.time.ZonedDateTime;
019import java.util.List;
020
021import javax.jcr.Node;
022
023import org.ametys.cms.data.holder.ModifiableIndexableDataHolder;
024import org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder;
025import org.ametys.core.user.UserIdentity;
026import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
027import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData;
028import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObject;
029import org.ametys.plugins.workspaces.tasks.Task;
030import org.ametys.plugins.workspaces.tasks.TasksList;
031import org.ametys.plugins.workspaces.tasks.WorkspaceTasksListDAO;
032
033/**
034 * JCR implementation of the tasks list
035 */
036public class JCRTasksList extends DefaultTraversableAmetysObject<JCRTasksListFactory> implements TasksList
037{
038    /** Attribute Id */
039    public static final String ATTRIBUTE_ID = "id";
040    /** Attribute Position */
041    public static final String ATTRIBUTE_POSITION = "position";
042    /** Attribute Label */
043    public static final String ATTRIBUTE_LABEL = "label";
044    /** Attribute Color */
045    public static final String ATTRIBUTE_COLOR_ID = "colorId";
046    /** Attribute Icon */
047    public static final String ATTRIBUTE_ICON_ID = "iconId";
048    /** Attribute Author */
049    public static final String ATTRIBUTE_AUTHOR = "author";
050    /** Attribute Creationdate */
051    public static final String ATTRIBUTE_CREATIONDATE = "creationDate";
052    /** Attribute Lastmodified */
053    public static final String ATTRIBUTE_LASTMODIFIED = "lastModified";
054    
055    /**
056     * Default constructor for the JCRTasksList
057     * @param node The JCR node
058     * @param parentPath The JCR parent path
059     * @param factory The factory
060     */
061    public JCRTasksList(Node node, String parentPath, JCRTasksListFactory factory)
062    {
063        super(node, parentPath, factory);
064    }
065
066    public String getListId()
067    {
068        return getValue(ATTRIBUTE_ID);
069    }
070    
071    public void setListId(String label)
072    {
073        setValue(ATTRIBUTE_ID, label);
074    }
075    
076    public Long getPosition()
077    {
078        return getValue(ATTRIBUTE_POSITION);
079    }
080    
081    public void setPosition(Long position)
082    {
083        setValue(ATTRIBUTE_POSITION, position);
084    }
085    
086    public String getLabel()
087    {
088        return getValue(ATTRIBUTE_LABEL);
089    }
090
091    public void setLabel(String label)
092    {
093        setValue(ATTRIBUTE_LABEL, label);
094    }
095
096    public String getColor()
097    {
098        return getValue(ATTRIBUTE_COLOR_ID);
099    }
100    
101    public void setColor(String colorId)
102    {
103        setValue(ATTRIBUTE_COLOR_ID, colorId);
104    }
105    
106    public String getIcon()
107    {
108        return getValue(ATTRIBUTE_ICON_ID);
109    }
110    
111    public void setIcon(String iconId)
112    {
113        setValue(ATTRIBUTE_ICON_ID, iconId);
114    }
115    
116    public List<Task> getTasks()
117    {
118        return WorkspaceTasksListDAO.getChildTask(getId());
119    }
120
121    public void addTask(Task task)
122    {
123        task.setTasksListId(getId());
124    }
125    
126    public UserIdentity getAuthor()
127    {
128        return getValue(ATTRIBUTE_AUTHOR);
129    }
130    
131    public void setAuthor(UserIdentity author)
132    {
133        setValue(ATTRIBUTE_AUTHOR, author);
134    }
135    
136    public ZonedDateTime getCreationDate()
137    {
138        return getValue(ATTRIBUTE_CREATIONDATE);
139    }
140    
141    public void setCreationDate(ZonedDateTime creationDate)
142    {
143        setValue(ATTRIBUTE_CREATIONDATE, creationDate);
144    }
145    
146    public ZonedDateTime getLastModified()
147    {
148        return getValue(ATTRIBUTE_LASTMODIFIED);
149    }
150    
151    public void setLastModified(ZonedDateTime lastModifiedDate)
152    {
153        setValue(ATTRIBUTE_LASTMODIFIED, lastModifiedDate);
154    }
155
156    public ModifiableIndexableDataHolder getDataHolder()
157    {
158        ModifiableRepositoryData repositoryData = new JCRRepositoryData(getNode());
159        return new DefaultModifiableModelAwareDataHolder(repositoryData, _getFactory().getTaskListModel());
160    }
161}