001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ade.publish.shared; 029 030import org.opencms.db.CmsResourceState; 031import org.opencms.gwt.shared.CmsListInfoBean; 032import org.opencms.gwt.shared.CmsPermissionInfo; 033import org.opencms.util.CmsStringUtil; 034import org.opencms.util.CmsUUID; 035 036import java.util.ArrayList; 037import java.util.List; 038 039/** 040 * A publish resource.<p> 041 * 042 * @since 7.6 043 */ 044public class CmsPublishResource extends CmsListInfoBean { 045 046 /** The last modification date. */ 047 private long m_dateLastModified; 048 049 /** The last modification date as a formatted string. */ 050 private String m_dateLastModifiedStr; 051 052 /** The resource id.*/ 053 private CmsUUID m_id; 054 055 /** The additional information, if any. */ 056 private CmsPublishResourceInfo m_info; 057 058 /** The resource name.*/ 059 private String m_name; 060 061 /** The permission info. */ 062 private CmsPermissionInfo m_permissionInfo; 063 064 /** The related resources.*/ 065 private List<CmsPublishResource> m_related; 066 067 /** Flag to indicate if the resource can be removed from the user's publish list.*/ 068 private boolean m_removable; 069 070 /** Name of the user who last modified the resource. */ 071 private String m_userLastModified; 072 073 /** 074 * Creates a new publish group bean.<p> 075 * 076 * @param id the resource id 077 * @param name the resource name 078 * @param title the resource title 079 * @param resourceType the resource type name 080 * @param state the resource state 081 * @param permissionInfo the permission info 082 * @param dateLastModified the last modification date 083 * @param userLastModified name of the user who last modified the resource 084 * @param dateLastModifiedStr the last modification date as a formatted string 085 * @param removable to indicate if the resource can be removed from the user's publish list 086 * @param info the additional information, if any 087 * @param related the related resources 088 **/ 089 public CmsPublishResource( 090 CmsUUID id, 091 String name, 092 String title, 093 String resourceType, 094 CmsResourceState state, 095 CmsPermissionInfo permissionInfo, 096 long dateLastModified, 097 String userLastModified, 098 String dateLastModifiedStr, 099 boolean removable, 100 CmsPublishResourceInfo info, 101 List<CmsPublishResource> related) { 102 super(CmsStringUtil.isEmptyOrWhitespaceOnly(title) ? name : title, name, null); 103 setResourceType(resourceType); 104 setResourceState(state); 105 setMarkChangedState(false); 106 m_id = id; 107 m_name = name; 108 m_related = ((related == null) ? new ArrayList<CmsPublishResource>() : related); 109 m_permissionInfo = permissionInfo; 110 m_removable = removable; 111 m_info = info; 112 m_dateLastModified = dateLastModified; 113 m_dateLastModifiedStr = dateLastModifiedStr; 114 m_userLastModified = userLastModified; 115 } 116 117 /** 118 * For serialization.<p> 119 */ 120 protected CmsPublishResource() { 121 122 // for serialization 123 } 124 125 /** 126 * Gets the last modification date.<p> 127 * 128 * @return the last modification date 129 */ 130 public long getDateLastModified() { 131 132 return m_dateLastModified; 133 } 134 135 /** 136 * Gets the modification date formatted as a string.<p> 137 * 138 * @return the formatted modification date 139 */ 140 public String getDateLastModifiedString() { 141 142 return m_dateLastModifiedStr; 143 } 144 145 /** 146 * Returns the id.<p> 147 * 148 * @return the id 149 */ 150 public CmsUUID getId() { 151 152 return m_id; 153 } 154 155 /** 156 * Returns the additional info.<p> 157 * 158 * @return the additional info 159 */ 160 public CmsPublishResourceInfo getInfo() { 161 162 return m_info; 163 } 164 165 /** 166 * Returns the name.<p> 167 * 168 * @return the name 169 */ 170 public String getName() { 171 172 return m_name; 173 } 174 175 /** 176 * Returns the permission info.<p> 177 * 178 * @return the permission info 179 */ 180 public CmsPermissionInfo getPermissionInfo() { 181 182 return m_permissionInfo; 183 } 184 185 /** 186 * Returns the related resources.<p> 187 * 188 * @return the related resources 189 */ 190 public List<CmsPublishResource> getRelated() { 191 192 return m_related; 193 } 194 195 /** 196 * Gets the date to be used for sorting.<p> 197 * 198 * @return the date which should be used for sorting 199 */ 200 public long getSortDate() { 201 202 long result = getDateLastModified(); 203 if (m_related != null) { 204 for (CmsPublishResource rel : m_related) { 205 result = Math.max(result, rel.getSortDate()); 206 } 207 } 208 return result; 209 } 210 211 /** 212 * Gets the name of the user who last modified the resource.<p> 213 * 214 * @return the name of the user who last modified the resource 215 */ 216 public String getUserLastModified() { 217 218 return m_userLastModified; 219 } 220 221 /** 222 * Returns the removable flag.<p> 223 * 224 * @return the removable flag 225 */ 226 public boolean isRemovable() { 227 228 return m_removable; 229 } 230 231 /** 232 * Sets the publish resource info.<p> 233 * 234 * @param info the publish resource info 235 */ 236 public void setInfo(CmsPublishResourceInfo info) { 237 238 m_info = info; 239 } 240 241 /** 242 * Enables/disables removability.<p> 243 * 244 * @param removable true if the item should be removable 245 */ 246 public void setRemovable(boolean removable) { 247 248 m_removable = removable; 249 } 250}