1 16 package com.blandware.atleap.service.core.impl; 17 18 import com.blandware.atleap.common.util.PartialCollection; 19 import com.blandware.atleap.common.util.QueryInfo; 20 import com.blandware.atleap.model.core.*; 21 import com.blandware.atleap.persistence.core.ContentDocumentDAO; 22 import com.blandware.atleap.persistence.core.ContentImageDAO; 23 import com.blandware.atleap.persistence.core.ContentLocaleDAO; 24 import com.blandware.atleap.persistence.core.ContentResourceDAO; 25 import com.blandware.atleap.persistence.exception.DeleteException; 26 import com.blandware.atleap.service.core.ContentResourceManager; 27 import com.blandware.atleap.service.core.UtilManager; 28 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 29 import com.blandware.atleap.service.exception.BeanNotFoundException; 30 import com.blandware.atleap.service.exception.ContentLocaleNotFoundException; 31 32 41 public class ContentResourceManagerImpl extends BaseManagerImpl implements ContentResourceManager { 42 43 46 protected ContentResourceDAO contentResourceDAO; 47 50 protected ContentImageDAO contentImageDAO; 51 54 protected ContentDocumentDAO contentDocumentDAO; 55 58 protected ContentLocaleDAO contentLocaleDAO; 59 60 63 protected UtilManager utilManager; 64 65 68 public ContentResourceManagerImpl() { 69 } 70 71 76 public void setContentResourceDAO(ContentResourceDAO contentResourceDAO) { 77 this.contentResourceDAO = contentResourceDAO; 78 } 79 80 85 public void setContentImageDAO(ContentImageDAO contentImageDAO) { 86 this.contentImageDAO = contentImageDAO; 87 } 88 89 94 public void setContentDocumentDAO(ContentDocumentDAO contentDocumentDAO) { 95 this.contentDocumentDAO = contentDocumentDAO; 96 } 97 98 103 public void setContentLocaleDAO(ContentLocaleDAO contentLocaleDAO) { 104 this.contentLocaleDAO = contentLocaleDAO; 105 } 106 107 112 public void setUtilManager(UtilManager utilManager) { 113 this.utilManager = utilManager; 114 } 115 116 117 119 120 122 125 public Long createContentResource(ContentResource contentResource, ResourceData resourceData) throws BeanAlreadyExistsException { 126 127 if ( log.isDebugEnabled() ) { 128 log.debug("Creating new content resource (uri=" + contentResource.getUri() + ")..."); 129 } 130 131 Long contentResourceId = null; 132 133 if ( contentResourceDAO.hasDuplicates(contentResource) ) { 134 throw new BeanAlreadyExistsException("Content resource with the same URI already exists"); 135 } 136 137 contentResourceId = contentResourceDAO.createContentResource(contentResource, resourceData); 139 140 141 if ( log.isDebugEnabled() ) { 142 log.debug("New resource has been created succefully. It's ID is " + contentResourceId); 143 } 144 145 return contentResourceId; 146 } 147 148 151 public ContentResource retrieveContentResource(Long contentResourceId) { 152 return contentResourceDAO.retrieveContentResource(contentResourceId); 153 } 154 155 158 public void updateContentResource(ContentResource contentResource, ResourceData resourceData) throws BeanAlreadyExistsException { 159 contentResourceDAO.removeFromCache(contentResource); 161 162 if ( log.isDebugEnabled() ) { 163 log.debug("Updating content resource (uri=" + contentResource.getUri() + ")..."); 164 } 165 166 if ( contentResourceDAO.hasDuplicates(contentResource) ) { 167 throw new BeanAlreadyExistsException("Content resource with the same URI already exists"); 168 } 169 170 ContentResource oldResource = contentResourceDAO.retrieveContentResource(contentResource.getId()); 172 if (oldResource != null) { 173 String oldUri = oldResource.getUri(); 174 String newUri = contentResource.getUri(); 175 if (!newUri.equals(oldUri)) { 176 utilManager.replaceLinkableObjectUriInLinkedObjects(oldUri, newUri, oldResource.getLinkedContentFieldValues(), oldResource.getLinkedMenuItems(), "", true); 177 } 178 contentResourceDAO.removeFromCache(oldResource); 179 } 180 181 contentResourceDAO.updateContentResource(contentResource, resourceData); 182 183 184 if ( log.isDebugEnabled() ) { 185 log.debug("Resource was updated succefully."); 186 } 187 } 188 189 192 public void deleteContentResource(Long contentResourceId) throws DeleteException, BeanNotFoundException { 193 ContentResource contentResource = contentResourceDAO.retrieveContentResource(contentResourceId); 194 if ( contentResource == null ) { 195 String errorMessage = "No content resource with ID=" + contentResource + "could be found"; 196 throw new BeanNotFoundException(errorMessage); 197 } 198 199 contentResourceDAO.deleteContentResource(contentResource); 200 } 201 202 204 207 public PartialCollection listContentResources(QueryInfo queryInfo) { 208 return contentResourceDAO.listContentResources(queryInfo); 209 } 210 211 214 public void increaseUsageCounter(Long resourceId, Integer value) throws BeanNotFoundException { 215 ContentResource resource = contentResourceDAO.retrieveContentResource(resourceId); 216 217 if ( resource == null ) { 218 String errorMessage = "Resource with ID=" + resourceId + " does not exist"; 220 if ( log.isErrorEnabled() ) { 221 log.error(errorMessage); 222 } 223 throw new BeanNotFoundException(errorMessage); 224 } 225 226 resource.setUsageCounter(new Integer (resource.getUsageCounter().intValue() + value.intValue())); 227 contentResourceDAO.updateContentResource(resource, resource.getResourceData()); 228 } 229 230 232 235 public ContentResource findContentResourceByUri(String uri) { 236 return contentResourceDAO.findContentResourceByUri(uri); 237 } 238 239 241 242 244 247 public Long createContentImage(ContentImage contentImage, ResourceData resourceData) throws BeanAlreadyExistsException { 248 249 if ( log.isDebugEnabled() ) { 250 log.debug("Creating new content image (uri=" + contentImage.getUri() + ")..."); 251 } 252 253 Long contentImageId = null; 254 if ( contentResourceDAO.hasDuplicates(contentImage) ) { 255 throw new BeanAlreadyExistsException("Content image with the same URI already exists"); 256 } 257 258 259 contentImageId = contentImageDAO.createContentImage(contentImage, resourceData); 261 262 263 if ( log.isDebugEnabled() ) { 264 log.debug("New image has been created succefully. It's ID is " + contentImageId); 265 } 266 267 return contentImageId; 268 } 269 270 273 public ContentImage retrieveContentImage(Long contentImageId) { 274 ContentImage contentImage = null; 275 contentImage = contentImageDAO.retrieveContentImage(contentImageId); 276 return contentImage; 277 } 278 279 282 public void updateContentImage(ContentImage contentImage, ResourceData resourceData) throws BeanAlreadyExistsException { 283 contentImageDAO.removeFromCache(contentImage); 285 if ( log.isDebugEnabled() ) { 286 log.debug("Updating content image (uri=" + contentImage.getUri() + ")..."); 287 } 288 289 if ( contentResourceDAO.hasDuplicates(contentImage) ) { 290 throw new BeanAlreadyExistsException("Content image with the same URI already exists"); 291 } 292 293 ContentImage oldImage = (ContentImage) contentResourceDAO.retrieveContentResource(contentImage.getId()); 295 if (oldImage != null) { 296 String oldUri = oldImage.getUri(); 297 int oldWidth = oldImage.getWidth().intValue(); 298 int oldHeight = oldImage.getHeight().intValue(); 299 String newUri = contentImage.getUri(); 300 int newWidth = contentImage.getWidth().intValue(); 301 int newHeight = contentImage.getHeight().intValue(); 302 if (newWidth != oldWidth || newHeight != oldHeight) { 303 utilManager.replaceImageSizesInLinkedObjects(oldUri, oldImage.getLinkedContentFieldValues(), oldWidth, oldHeight, newWidth, newHeight, "", true); 304 } 305 if (!newUri.equals(oldUri)) { 306 utilManager.replaceLinkableObjectUriInLinkedObjects(oldUri, newUri, oldImage.getLinkedContentFieldValues(), oldImage.getLinkedMenuItems(), "", true); 307 } 308 contentResourceDAO.removeFromCache(oldImage); 309 } 310 311 contentImageDAO.updateContentImage(contentImage, resourceData); 312 313 314 if ( log.isDebugEnabled() ) { 315 log.debug("Image was updated succefully."); 316 } 317 } 318 319 322 public void deleteContentImage(Long contentImageId) throws DeleteException, BeanNotFoundException { 323 324 ContentImage contentImage = contentImageDAO.retrieveContentImage(contentImageId); 325 if ( contentImage == null ) { 326 String errorMessage = "No content image with ID=" + contentImage + "could be found"; 327 throw new BeanNotFoundException(errorMessage); 328 } 329 330 contentImageDAO.deleteContentImage(contentImage); 331 } 332 333 335 338 public PartialCollection listContentImages(QueryInfo queryInfo) { 339 return contentImageDAO.listContentImages(queryInfo); 340 } 341 342 344 347 public ContentImage findContentImageByUri(String uri) { 348 return contentImageDAO.findContentImageByUri(uri); 349 } 350 351 352 353 355 357 360 public Long createContentDocument(ContentDocument contentDocument, ResourceData resourceData, String localeIdentifier) throws BeanNotFoundException, BeanAlreadyExistsException { 361 362 if ( log.isDebugEnabled() ) { 363 log.debug("Creating new content document (uri=" + contentDocument.getUri() + ")..."); 364 } 365 366 Long contentDocumentId = null; 367 if ( contentResourceDAO.hasDuplicates(contentDocument) ) { 368 throw new BeanAlreadyExistsException("Content document with the same URI already exists"); 369 } 370 371 ContentLocale contentLocale = null; 372 contentLocale = contentLocaleDAO.retrieveContentLocale(localeIdentifier); 373 374 if ( contentLocale == null ) { 375 String errorMessage = "No content locale with identifier=" + localeIdentifier + "could be found"; 376 if ( log.isErrorEnabled() ) { 377 log.error(errorMessage); 378 } 379 throw new ContentLocaleNotFoundException(errorMessage); 380 } 381 382 383 contentDocumentId = contentDocumentDAO.createContentDocument(contentDocument, resourceData, contentLocale); 385 386 387 if ( log.isDebugEnabled() ) { 388 log.debug("New document has been created succefully. It's ID is " + contentDocumentId); 389 } 390 391 return contentDocumentId; 392 } 393 394 397 public ContentDocument retrieveContentDocument(Long contentDocumentId) { 398 ContentDocument contentDocument = null; 399 contentDocument = contentDocumentDAO.retrieveContentDocument(contentDocumentId); 400 return contentDocument; 401 } 402 403 406 public void updateContentDocument(ContentDocument contentDocument, ResourceData resourceData, String localeIdentifier) throws BeanNotFoundException, BeanAlreadyExistsException { 407 contentDocumentDAO.removeFromCache(contentDocument); 409 if ( log.isDebugEnabled() ) { 410 log.debug("Updating content document (uri=" + contentDocument.getUri() + ")..."); 411 } 412 413 if ( contentResourceDAO.hasDuplicates(contentDocument) ) { 414 throw new BeanAlreadyExistsException("Content document with the same URI already exists"); 415 } 416 417 ContentLocale contentLocale = null; 418 contentLocale = contentLocaleDAO.retrieveContentLocale(localeIdentifier); 419 if ( contentLocale == null ) { 420 String errorMessage = "No content locale with identifier=" + localeIdentifier + "could be found"; 421 if ( log.isErrorEnabled() ) { 422 log.error(errorMessage); 423 } 424 throw new ContentLocaleNotFoundException(errorMessage); 425 } 426 427 ContentResource oldResource = contentResourceDAO.retrieveContentResource(contentDocument.getId()); 429 if (oldResource != null) { 430 String oldUri = oldResource.getUri(); 431 String newUri = contentDocument.getUri(); 432 if (!newUri.equals(oldUri)) { 433 utilManager.replaceLinkableObjectUriInLinkedObjects(oldUri, newUri, oldResource.getLinkedContentFieldValues(), oldResource.getLinkedMenuItems(), "", true); 434 } 435 contentResourceDAO.removeFromCache(oldResource); 436 } 437 438 contentDocumentDAO.updateContentDocument(contentDocument, resourceData, contentLocale); 439 440 441 if ( log.isDebugEnabled() ) { 442 log.debug("Document was updated succefully."); 443 } 444 } 445 446 449 public void deleteContentDocument(Long contentDocumentId) throws DeleteException, BeanNotFoundException { 450 451 ContentDocument contentDocument = contentDocumentDAO.retrieveContentDocument(contentDocumentId); 452 if ( contentDocument == null ) { 453 String errorMessage = "No content document with ID=" + contentDocument + "could be found"; 454 throw new BeanNotFoundException(errorMessage); 455 } 456 457 contentDocumentDAO.deleteContentDocument(contentDocument); 458 } 459 460 462 465 public PartialCollection listContentDocuments(QueryInfo queryInfo) { 466 return contentDocumentDAO.listContentDocuments(queryInfo); 467 } 468 469 471 474 public ContentDocument findContentDocumentByUri(String uri) { 475 return contentDocumentDAO.findContentDocumentByUri(uri); 476 } 477 478 } 479 | Popular Tags |