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.ContentField; 21 import com.blandware.atleap.model.core.ContentFieldValue; 22 import com.blandware.atleap.model.core.ContentLocale; 23 import com.blandware.atleap.model.core.Localizable; 24 import com.blandware.atleap.persistence.core.ContentFieldDAO; 25 import com.blandware.atleap.persistence.core.ContentFieldValueDAO; 26 import com.blandware.atleap.persistence.core.ContentLocaleDAO; 27 import com.blandware.atleap.persistence.core.LocalizableDAO; 28 import com.blandware.atleap.service.core.ContentFieldManager; 29 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 30 import com.blandware.atleap.service.exception.BeanNotFoundException; 31 import com.blandware.atleap.service.exception.ContentLocaleNotFoundException; 32 import com.blandware.atleap.service.exception.OwnerNotFoundException; 33 34 import java.util.List ; 35 36 44 public class ContentFieldManagerImpl extends BaseManagerImpl implements ContentFieldManager { 45 46 49 protected LocalizableDAO localizableDAO; 50 53 protected ContentFieldValueDAO contentFieldValueDAO; 54 57 protected ContentFieldDAO contentFieldDAO; 58 61 protected ContentLocaleDAO contentLocaleDAO; 62 63 68 public void setLocalizableDAO(LocalizableDAO localizableDAO) { 69 this.localizableDAO = localizableDAO; 70 } 71 72 77 public void setContentFieldValueDAO(ContentFieldValueDAO contentFieldValueDAO) { 78 this.contentFieldValueDAO = contentFieldValueDAO; 79 } 80 81 86 public void setContentFieldDAO(ContentFieldDAO contentFieldDAO) { 87 this.contentFieldDAO = contentFieldDAO; 88 } 89 90 95 public void setContentLocaleDAO(ContentLocaleDAO contentLocaleDAO) { 96 this.contentLocaleDAO = contentLocaleDAO; 97 } 98 99 101 103 106 public Long createContentField(ContentField contentField, Long ownerId) throws BeanNotFoundException, BeanAlreadyExistsException { 107 108 if ( log.isDebugEnabled() ) { 109 log.debug("Creating new field..."); 110 } 111 112 Localizable localizable = null; 113 localizable = localizableDAO.retrieveLocalizable(ownerId); 114 115 if ( localizable == null ) { 116 String errorMessage = "No localizable with ID=" + ownerId + "could be found"; 117 if ( log.isErrorEnabled() ) { 118 log.error(errorMessage); 119 } 120 throw new OwnerNotFoundException(errorMessage); 121 } 122 123 if ( contentFieldDAO.hasDuplicates(contentField, ownerId) ) { 124 throw new BeanAlreadyExistsException("Content field with the same identifier already exists on owner with ID=" + ownerId); 125 } 126 127 Long fieldId = contentFieldDAO.createContentField(contentField, localizable); 128 129 if ( log.isDebugEnabled() ) { 130 log.debug("ContentField has been created successfully. Its ID is " + fieldId); 131 } 132 return fieldId; 133 } 134 135 138 public ContentField retrieveContentField(Long contentFieldId) { 139 ContentField field = null; 140 field = contentFieldDAO.retrieveContentField(contentFieldId); 141 return field; 142 } 143 144 147 public void updateContentField(ContentField contentField, Long localizableId) throws BeanNotFoundException, BeanAlreadyExistsException { 148 149 contentFieldDAO.removeFromCache(contentField); 151 152 if ( log.isDebugEnabled() ) { 153 log.debug("Updating contentField with ID=" + contentField.getId() + "..."); 154 } 155 156 Localizable localizable = null; 157 localizable = localizableDAO.retrieveLocalizable(localizableId); 158 159 if ( localizable == null ) { 160 String errorMessage = "No localizable with ID=" + localizableId + "could be found"; 161 if ( log.isErrorEnabled() ) { 162 log.error(errorMessage); 163 } 164 throw new OwnerNotFoundException(errorMessage); 165 } 166 167 if ( contentFieldDAO.hasDuplicates(contentField, localizableId) ) { 168 throw new BeanAlreadyExistsException("Content field with the same identifier already exists on owner with ID=" + localizableId); 169 } 170 171 contentFieldDAO.updateContentField(contentField, localizable); 173 174 175 if ( log.isDebugEnabled() ) { 176 log.debug("ContentField was updated successfully."); 177 } 178 } 179 180 183 public void deleteContentField(Long contentFieldId) throws BeanNotFoundException { 184 if ( log.isDebugEnabled() ) { 185 log.debug("Deleting field with ID=" + contentFieldId); 186 } 187 188 ContentField contentField = contentFieldDAO.retrieveContentField(contentFieldId); 189 if ( contentField == null ) { 190 String errorMessage = "No contentField with ID=" + contentFieldId + "could be found"; 191 throw new BeanNotFoundException(errorMessage); 192 } 193 194 contentFieldDAO.deleteContentField(contentField); 195 196 if ( log.isDebugEnabled() ) { 197 log.debug("Contentfield has been deleted successfully"); 198 } 199 } 200 201 203 206 public PartialCollection listContentFields(QueryInfo queryInfo) { 207 return contentFieldDAO.listContentFields(queryInfo); 208 } 209 210 212 215 public ContentField findContentFieldByLayoutDefinition(String identifier, String definition) { 216 return contentFieldDAO.findContentFieldByLayoutDefinition(identifier, definition); 217 } 218 219 222 public ContentField findContentFieldByPageUri(String identifier, String uri) { 223 return contentFieldDAO.findContentFieldByPageUri(identifier, uri); 224 } 225 226 229 public List findIndexedContentFieldsByLayoutDefinition(String identifier, String definition, String locale) { 230 return contentFieldDAO.findIndexedContentFieldsByLayoutDefinitionAndLocale(identifier, definition, locale); 231 } 232 233 236 public List findIndexedContentFieldsByPageUri(String identifier, String uri, String locale) { 237 return contentFieldDAO.findIndexedContentFieldsByPageUriAndLocale(identifier, uri, locale); 238 } 239 240 241 242 244 246 249 public Long createContentFieldValue(ContentFieldValue contentFieldValue, Long fieldId, String localeIdentifier) throws BeanNotFoundException, BeanAlreadyExistsException { 250 251 if ( log.isDebugEnabled() ) { 252 log.debug("Creating new content field value..."); 253 } 254 255 ContentField field = null; 256 field = contentFieldDAO.retrieveContentField(fieldId); 257 if ( field == null ) { 258 String errorMessage = "No content field with ID=" + fieldId + "could be found"; 259 if ( log.isErrorEnabled() ) { 260 log.error(errorMessage); 261 } 262 throw new OwnerNotFoundException(errorMessage); 263 } 264 265 ContentLocale contentLocale = null; 266 contentLocale = contentLocaleDAO.retrieveContentLocale(localeIdentifier); 267 268 if ( contentLocale == null ) { 269 String errorMessage = "No content locale with identifier=" + localeIdentifier + "could be found"; 270 if ( log.isErrorEnabled() ) { 271 log.error(errorMessage); 272 } 273 throw new ContentLocaleNotFoundException(errorMessage); 274 } 275 276 if ( contentFieldValueDAO.hasDuplicates(contentFieldValue, fieldId, localeIdentifier) ) { 277 throw new BeanAlreadyExistsException("Content field value already exists for field with ID=" + fieldId + " and locale with identifier='" + localeIdentifier + "'"); 278 } 279 280 Long contentFieldValueId = contentFieldValueDAO.createContentFieldValue(contentFieldValue, field, contentLocale); 281 282 if ( log.isDebugEnabled() ) { 283 log.debug("Content has been created successfully. Its ID is " + contentFieldValueId); 284 } 285 return contentFieldValueId; 286 } 287 288 291 public ContentFieldValue retrieveContentFieldValue(Long contentFieldValueId) { 292 ContentFieldValue contentFieldValue = null; 293 contentFieldValue = contentFieldValueDAO.retrieveContentFieldValue(contentFieldValueId); 294 return contentFieldValue; 295 } 296 297 300 public void updateContentFieldValue(ContentFieldValue contentFieldValue, Long fieldId, String localeIdentifier) throws BeanNotFoundException, BeanAlreadyExistsException { 301 302 contentFieldValueDAO.removeFromCache(contentFieldValue); 304 305 if ( log.isDebugEnabled() ) { 306 log.debug("Updating field content with ID=" + contentFieldValue.getId() + "..."); 307 } 308 309 ContentField field = null; 310 field = contentFieldDAO.retrieveContentField(fieldId); 311 if ( field == null ) { 312 String errorMessage = "No field with ID=" + fieldId + "could be found"; 313 if ( log.isErrorEnabled() ) { 314 log.error(errorMessage); 315 } 316 throw new OwnerNotFoundException(errorMessage); 317 } 318 319 ContentLocale contentLocale = null; 320 contentLocale = contentLocaleDAO.retrieveContentLocale(localeIdentifier); 321 if ( contentLocale == null ) { 322 String errorMessage = "No content locale with identifier=" + localeIdentifier + "could be found"; 323 if ( log.isErrorEnabled() ) { 324 log.error(errorMessage); 325 } 326 throw new ContentLocaleNotFoundException(errorMessage); 327 } 328 329 if ( contentFieldValueDAO.hasDuplicates(contentFieldValue, fieldId, localeIdentifier) ) { 330 throw new BeanAlreadyExistsException("Content field value already exists for field with ID=" + fieldId + " and locale with identifier='" + localeIdentifier + "'"); 331 } 332 333 contentFieldValueDAO.updateContentFieldValue(contentFieldValue, field, contentLocale); 335 336 if ( log.isDebugEnabled() ) { 337 log.debug("ContentField content was updated successfully."); 338 } 339 } 340 341 344 public void deleteContentFieldValue(Long contentFieldValueId) throws BeanNotFoundException { 345 if ( log.isDebugEnabled() ) { 346 log.debug("Deleting field content with ID=" + contentFieldValueId); 347 } 348 349 ContentFieldValue contentFieldValue = contentFieldValueDAO.retrieveContentFieldValue(contentFieldValueId); 350 if ( contentFieldValue == null ) { 351 String errorMessage = "No contentFieldValue with ID=" + contentFieldValueId + "could be found"; 352 throw new BeanNotFoundException(errorMessage); 353 } 354 355 contentFieldValueDAO.deleteContentFieldValue(contentFieldValue); 356 if ( log.isDebugEnabled() ) { 357 log.debug("ContentField content has been deleted successfully"); 358 } 359 } 360 361 363 366 public PartialCollection listContentFieldValues(QueryInfo queryInfo) { 367 return contentFieldValueDAO.listContentFieldValues(queryInfo); 368 } 369 370 372 375 public ContentFieldValue findContentFieldValueByUriAndIdentifierAndLocale(String uri, String identifier, String localeIdentifier) { 376 return contentFieldValueDAO.findContentFieldValueByUriAndIdentifierAndLocale(uri, identifier, localeIdentifier); 377 } 378 379 382 public ContentFieldValue findContentFieldValueByDefinitionAndIdentifierAndLocale(String definition, String identifier, String localeIdentifier) { 383 return contentFieldValueDAO.findContentFieldValueByDefinitionAndIdentifierAndLocale(definition, identifier, localeIdentifier); 384 } 385 386 389 public ContentFieldValue findContentFieldValueByLocalizableIdAndIdentifierAndLocale(Long localizableId, String identifier, String localeIdentifier) { 390 return contentFieldValueDAO.findContentFieldValueByLocalizableIdAndIdentifierAndLocale(localizableId, identifier, localeIdentifier); 391 } 392 393 396 public ContentFieldValue findContentFieldValueByContentFieldIdAndLocale(Long fieldId, String localeIdentifier) { 397 ContentField field = retrieveContentField(fieldId); 398 ContentLocale locale = contentLocaleDAO.retrieveContentLocale(localeIdentifier); 399 return contentFieldValueDAO.findContentFieldValueByContentFieldAndLocale(field, locale); 400 } 401 402 403 } 404 405 | Popular Tags |