001/* 002 * Copyright 2016 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.explorer.tasks.jcr; 017 018import java.util.ArrayList; 019import java.util.Date; 020import java.util.List; 021 022import javax.jcr.Node; 023 024import org.ametys.plugins.explorer.ExplorerNode; 025import org.ametys.plugins.explorer.tasks.ModifiableTasksList; 026import org.ametys.plugins.explorer.tasks.Task; 027import org.ametys.plugins.repository.AmetysObject; 028import org.ametys.plugins.repository.AmetysRepositoryException; 029import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObject; 030 031/** 032 * JCR implementation of the tasks list 033 */ 034public class JCRTasksList extends DefaultTraversableAmetysObject<JCRTasksListFactory> implements ModifiableTasksList 035{ 036 /** application id for resources collections. */ 037 public static final String APPLICATION_ID = "Ametys.plugins.explorer.applications.TasksList"; 038 039 private static final String METADATA_DESCRIPTION = "description"; 040 041 /** 042 * Default constructor for the JCRTasksList 043 * @param node The JCR node 044 * @param parentPath The JCR parent path 045 * @param factory The factory 046 */ 047 public JCRTasksList(Node node, String parentPath, JCRTasksListFactory factory) 048 { 049 super(node, parentPath, factory); 050 } 051 052 public String getDescription() 053 { 054 return getMetadataHolder().getString(METADATA_DESCRIPTION); 055 } 056 057 public List<Task> getTasks() 058 { 059 return getTasks(null, null); 060 } 061 062 public List<Task> getTasks(Date startDate, Date endDate) 063 { 064 List<Task> tasks = new ArrayList<>(); 065 for (AmetysObject child : getChildren()) 066 { 067 if (child instanceof JCRTask) 068 { 069 JCRTask task = (JCRTask) child; 070 if ((startDate == null || task.getStartDate().before(startDate)) && (endDate == null || task.getEndDate().after(endDate))) 071 { 072 tasks.add(task); 073 } 074 } 075 } 076 077 return tasks; 078 } 079 080 public String getIconCls() 081 { 082 return "task"; 083 } 084 085 public String getApplicationId() 086 { 087 return APPLICATION_ID; 088 } 089 090 public String getExplorerPath() 091 { 092 AmetysObject parent = getParent(); 093 094 if (parent instanceof ExplorerNode) 095 { 096 return ((ExplorerNode) parent).getExplorerPath() + "/" + getName(); 097 } 098 else 099 { 100 return ""; 101 } 102 } 103 104 public boolean hasChildExplorerNodes() throws AmetysRepositoryException 105 { 106 for (AmetysObject child : getChildren()) 107 { 108 if (child instanceof ExplorerNode) 109 { 110 return true; 111 } 112 } 113 114 return false; 115 } 116 117 public void setDescription(String description) 118 { 119 getMetadataHolder().setMetadata(METADATA_DESCRIPTION, description); 120 } 121 122}