001/* 002 * Copyright 2013 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.cms.content; 017 018import java.util.Collections; 019import java.util.LinkedList; 020import java.util.List; 021 022/** 023 * The report object, used internally to provide useful informations once 024 * the whole duplication process has ended. 025 */ 026public final class CopyReport 027{ 028 private String _viewName; 029 private String _fallbackViewName; 030 private String _baseContentId; 031 private String _baseContentTitle; 032 private Boolean _baseContentIsReferenceTable; 033 034 private CopyMode _mode; 035 036 private String _targetContentId; 037 private String _targetContentTitle; 038 private boolean _targetContentIsReferenceTable; 039 040 private List<CopyReport> _innerReports; 041 042 private List<String> _copiedAttachments; 043 044 private CopyState _state; 045 046 /** Available copy mode */ 047 public enum CopyMode 048 { 049 /** Creation : a new content is created to perform the copy */ 050 CREATION, 051 /** Edition : attributes are duplicated into an already existing target content */ 052 EDITION 053 } 054 055 /** The possible state of the copy */ 056 public enum CopyState 057 { 058 /** Running : when the copy is still running */ 059 RUNNING, 060 /** Success : when the copy has ended well */ 061 SUCCESS, 062 /** Error : when an error was encountered during the copy (except for attributes copy errors). */ 063 ERROR 064 } 065 066 /** 067 * Constructor. 068 * If the title of the base content if available, should be used. 069 * @param baseContentId The content id of the base content 070 * @param baseContentIsRefTable Indicates if the base content is a reference table's entry (can be null if unavailable) 071 * @param viewName The view name 072 * @param fallbackViewName The fallback view name. Use for legacy purpose. 073 * @param copyMode The mode of copy 074 */ 075 public CopyReport(String baseContentId, Boolean baseContentIsRefTable, String viewName, String fallbackViewName, CopyMode copyMode) 076 { 077 this(baseContentId, null, baseContentIsRefTable, viewName, fallbackViewName, copyMode); 078 } 079 080 /** 081 * Constructor. 082 * @param baseContentId The content id of the base content 083 * @param baseContentTitle The title of the base content 084 * @param baseContentIsRefTable Indicates if the base content is a reference table's entry 085 * @param viewName The view name 086 * @param fallbackViewName The fallback view name. Use for legacy purpose. 087 * @param copyMode The mode of copy 088 */ 089 public CopyReport(String baseContentId, String baseContentTitle, Boolean baseContentIsRefTable, String viewName, String fallbackViewName, CopyMode copyMode) 090 { 091 _baseContentId = baseContentId; 092 _baseContentTitle = baseContentTitle; 093 _baseContentIsReferenceTable = baseContentIsRefTable; 094 _viewName = viewName; 095 _fallbackViewName = fallbackViewName; 096 _mode = copyMode; 097 098 _innerReports = new LinkedList<>(); 099 _copiedAttachments = new LinkedList<>(); 100 101 _state = CopyState.RUNNING; 102 } 103 104 /** 105 * Set whether the base content is a reference table's entry. 106 * @param isRefTable true for reference table's entry. 107 */ 108 public void setReferenceTable(boolean isRefTable) 109 { 110 _baseContentIsReferenceTable = isRefTable; 111 } 112 113 /** 114 * Set the target content title. 115 * @param title The target content title. 116 */ 117 public void setTargetContentTitle(String title) 118 { 119 _targetContentTitle = title; 120 } 121 122 /** 123 * Notify information about the target content to the report. 124 * @param id The content id 125 * @param title The content title 126 * @param isRefTable Indicates if the target content is a reference table's entry. 127 */ 128 public void notifyContentCreation(String id, String title, boolean isRefTable) 129 { 130 _targetContentId = id; 131 _targetContentTitle = title; 132 _targetContentIsReferenceTable = isRefTable; 133 } 134 135 /** 136 * Notify a copy success 137 */ 138 public void notifyContentCopySuccess() 139 { 140 _state = CopyState.SUCCESS; 141 } 142 143 /** 144 * Notify that the copy ended with an error 145 */ 146 public void notifyContentCopyError() 147 { 148 _state = CopyState.ERROR; 149 } 150 151 /** 152 * Add an attachments to the copied attachments report list 153 * @param relPath The relative path where to copy 154 */ 155 public void addAttachment(String relPath) 156 { 157 _copiedAttachments.add(relPath); 158 } 159 160 /** 161 * Get the status of the copy 162 * @return A copy state enum value 163 */ 164 public CopyState getStatus() 165 { 166 return _state; 167 } 168 169 /** 170 * Get the mode of the copy 171 * @return A cope mode enum value 172 */ 173 public CopyMode getMode() 174 { 175 return _mode; 176 } 177 178 /** 179 * Get the name of the view used for the copy. 180 * @return the view name 181 */ 182 public String getViewName() 183 { 184 return _viewName; 185 } 186 187 /** 188 * Get the name of the fallback view used for the copy. 189 * @return the fallback view name 190 */ 191 public String getFallbackViewName() 192 { 193 return _fallbackViewName; 194 } 195 196 /** 197 /** 198 * Get the base content identifier 199 * @return The identifier 200 */ 201 public String getBaseContentId() 202 { 203 return _baseContentId; 204 } 205 206 /** 207 * Get the base content title. 208 * @return The title or null (if unavailable) 209 */ 210 public String getBaseContentTitle() 211 { 212 return _baseContentTitle; 213 } 214 215 /** 216 * Is the base content a reference table entry ? 217 * @return true if it is, null if unknown. 218 */ 219 public Boolean getBaseContentIsReferenceTable() 220 { 221 return _baseContentIsReferenceTable; 222 } 223 224 /** 225 * Get the target content identifier 226 * @return The identifier 227 */ 228 public String getTargetContentId() 229 { 230 return _targetContentId; 231 } 232 233 /** 234 * Get the target content title 235 * @return The title 236 */ 237 public String getTargetContentTitle() 238 { 239 return _targetContentTitle; 240 } 241 242 /** 243 * Is the target content a reference table entry? 244 * @return true if it is. 245 */ 246 public boolean getTargetContentIsReferenceTable() 247 { 248 return _targetContentIsReferenceTable; 249 } 250 251 /** 252 * Get the list of child copy reports. 253 * Each child report denotes an inner copy 254 * @return The list of copy reports. 255 */ 256 public List<CopyReport> getChildReports() 257 { 258 return Collections.unmodifiableList(_innerReports); 259 } 260 261 /** 262 * Get the list of the copied attachments. 263 * @return List of paths (relative to the root attachment node of the target content) 264 */ 265 public List<String> getCopiedAttachments() 266 { 267 return Collections.unmodifiableList(_copiedAttachments); 268 } 269 270 /** 271 * Add a child report to the report. This must be done when an copy is requested 272 * @param report The report of the copy to add 273 */ 274 public void addReport(CopyReport report) 275 { 276 _innerReports.add(report); 277 } 278}