001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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 /** Is the resource an XML content? */ 059 private boolean m_isXmlContent; 060 061 /** The resource name.*/ 062 private String m_name; 063 064 /** The permission info. */ 065 private CmsPermissionInfo m_permissionInfo; 066 067 /** The related resources.*/ 068 private List<CmsPublishResource> m_related; 069 070 /** Flag to indicate if the resource can be removed from the user's publish list.*/ 071 private boolean m_removable; 072 073 /** Name of the user who last modified the resource. */ 074 private String m_userLastModified; 075 076 /** 077 * Creates a new publish group bean.<p> 078 * 079 * @param id the resource id 080 * @param name the resource name 081 * @param title the resource title 082 * @param resourceType the resource type name 083 * @param state the resource state 084 * @param permissionInfo the permission info 085 * @þaram isXmlContent if the resource is an XML content 086 * @param dateLastModified the last modification date 087 * @param userLastModified name of the user who last modified the resource 088 * @param dateLastModifiedStr the last modification date as a formatted string 089 * @param removable to indicate if the resource can be removed from the user's publish list 090 * @param info the additional information, if any 091 * @param related the related resources 092 **/ 093 public CmsPublishResource( 094 CmsUUID id, 095 String name, 096 String title, 097 String resourceType, 098 CmsResourceState state, 099 CmsPermissionInfo permissionInfo, 100 boolean isXmlContent, 101 long dateLastModified, 102 String userLastModified, 103 String dateLastModifiedStr, 104 boolean removable, 105 CmsPublishResourceInfo info, 106 List<CmsPublishResource> related) { 107 108 super(CmsStringUtil.isEmptyOrWhitespaceOnly(title) ? name : title, name, null); 109 setResourceType(resourceType); 110 setResourceState(state); 111 setMarkChangedState(false); 112 m_id = id; 113 m_name = name; 114 m_related = ((related == null) ? new ArrayList<CmsPublishResource>() : related); 115 m_permissionInfo = permissionInfo; 116 m_isXmlContent = isXmlContent; 117 m_removable = removable; 118 m_info = info; 119 m_dateLastModified = dateLastModified; 120 m_dateLastModifiedStr = dateLastModifiedStr; 121 m_userLastModified = userLastModified; 122 } 123 124 /** 125 * For serialization.<p> 126 */ 127 protected CmsPublishResource() { 128 129 // for serialization 130 } 131 132 /** 133 * Gets the last modification date.<p> 134 * 135 * @return the last modification date 136 */ 137 public long getDateLastModified() { 138 139 return m_dateLastModified; 140 } 141 142 /** 143 * Gets the modification date formatted as a string.<p> 144 * 145 * @return the formatted modification date 146 */ 147 public String getDateLastModifiedString() { 148 149 return m_dateLastModifiedStr; 150 } 151 152 /** 153 * Returns the id.<p> 154 * 155 * @return the id 156 */ 157 public CmsUUID getId() { 158 159 return m_id; 160 } 161 162 /** 163 * Returns the additional info.<p> 164 * 165 * @return the additional info 166 */ 167 public CmsPublishResourceInfo getInfo() { 168 169 return m_info; 170 } 171 172 /** 173 * Returns the name.<p> 174 * 175 * @return the name 176 */ 177 public String getName() { 178 179 return m_name; 180 } 181 182 /** 183 * Returns the permission info.<p> 184 * 185 * @return the permission info 186 */ 187 public CmsPermissionInfo getPermissionInfo() { 188 189 return m_permissionInfo; 190 } 191 192 /** 193 * Returns the related resources.<p> 194 * 195 * @return the related resources 196 */ 197 public List<CmsPublishResource> getRelated() { 198 199 return m_related; 200 } 201 202 /** 203 * Gets the date to be used for sorting.<p> 204 * 205 * @return the date which should be used for sorting 206 */ 207 public long getSortDate() { 208 209 long result = getDateLastModified(); 210 if (m_related != null) { 211 for (CmsPublishResource rel : m_related) { 212 result = Math.max(result, rel.getSortDate()); 213 } 214 } 215 return result; 216 } 217 218 /** 219 * Gets the name of the user who last modified the resource.<p> 220 * 221 * @return the name of the user who last modified the resource 222 */ 223 public String getUserLastModified() { 224 225 return m_userLastModified; 226 } 227 228 /** 229 * Returns the removable flag.<p> 230 * 231 * @return the removable flag 232 */ 233 public boolean isRemovable() { 234 235 return m_removable; 236 } 237 238 /** 239 * Checks if the resource is an XML content. 240 * 241 * @return true if the resource is an XML content 242 */ 243 public boolean isXmlContent() { 244 245 return m_isXmlContent; 246 } 247 248 /** 249 * Sets the publish resource info.<p> 250 * 251 * @param info the publish resource info 252 */ 253 public void setInfo(CmsPublishResourceInfo info) { 254 255 m_info = info; 256 } 257 258 /** 259 * Enables/disables removability.<p> 260 * 261 * @param removable true if the item should be removable 262 */ 263 public void setRemovable(boolean removable) { 264 265 m_removable = removable; 266 } 267}