1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.apache.log4j.Logger; 32 import org.exolab.castor.jdo.Database; 33 import org.infoglue.cms.entities.content.ContentVO; 34 import org.infoglue.cms.entities.content.ContentVersion; 35 import org.infoglue.cms.entities.kernel.BaseEntityVO; 36 import org.infoglue.cms.entities.management.AccessRight; 37 import org.infoglue.cms.entities.management.AccessRightGroup; 38 import org.infoglue.cms.entities.management.AccessRightGroupVO; 39 import org.infoglue.cms.entities.management.AccessRightRole; 40 import org.infoglue.cms.entities.management.AccessRightRoleVO; 41 import org.infoglue.cms.entities.management.AccessRightUser; 42 import org.infoglue.cms.entities.management.AccessRightUserVO; 43 import org.infoglue.cms.entities.management.AccessRightVO; 44 import org.infoglue.cms.entities.management.AvailableServiceBinding; 45 import org.infoglue.cms.entities.management.InterceptionPoint; 46 import org.infoglue.cms.entities.management.Language; 47 import org.infoglue.cms.entities.structure.Qualifyer; 48 import org.infoglue.cms.entities.structure.QualifyerVO; 49 import org.infoglue.cms.entities.structure.ServiceBinding; 50 import org.infoglue.cms.entities.structure.ServiceBindingVO; 51 import org.infoglue.cms.entities.structure.SiteNodeVersion; 52 import org.infoglue.cms.entities.structure.SiteNodeVersionVO; 53 import org.infoglue.cms.entities.structure.impl.simple.QualifyerImpl; 54 import org.infoglue.cms.entities.structure.impl.simple.ServiceBindingImpl; 55 import org.infoglue.cms.entities.workflow.EventVO; 56 import org.infoglue.cms.exception.ConstraintException; 57 import org.infoglue.cms.exception.SystemException; 58 import org.infoglue.cms.security.InfoGluePrincipal; 59 import org.infoglue.cms.util.ConstraintExceptionBuffer; 60 import org.infoglue.cms.util.DateHelper; 61 62 public class SiteNodeStateController extends BaseController 63 { 64 private final static Logger logger = Logger.getLogger(SiteNodeStateController.class.getName()); 65 66 69 70 public static SiteNodeStateController getController() 71 { 72 return new SiteNodeStateController(); 73 } 74 75 79 80 public SiteNodeVersion changeState(Integer oldSiteNodeVersionId, Integer stateId, String versionComment, boolean overrideVersionModifyer, InfoGluePrincipal infoGluePrincipal, Integer siteNodeId, List resultingEvents) throws ConstraintException, SystemException 81 { 82 SiteNodeVersion newSiteNodeVersion = null; 83 84 Database db = CastorDatabaseService.getDatabase(); 85 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 86 87 beginTransaction(db); 88 89 try 90 { 91 SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getSiteNodeVersionWithIdAsReadOnly(oldSiteNodeVersionId, db); 92 logger.info("siteNodeVersion:" + siteNodeVersion.getId() + ":" + siteNodeVersion.getStateId()); 93 94 newSiteNodeVersion = changeState(oldSiteNodeVersionId, stateId, versionComment, overrideVersionModifyer, infoGluePrincipal, siteNodeId, db, resultingEvents); 95 96 commitTransaction(db); 97 } 98 catch(Exception e) 99 { 100 logger.error("An error occurred so we should not complete the transaction:" + e, e); 101 rollbackTransaction(db); 102 throw new SystemException(e.getMessage()); 103 } 104 105 return newSiteNodeVersion; 106 } 107 108 109 113 114 public SiteNodeVersion changeState(Integer oldSiteNodeVersionId, Integer stateId, String versionComment, boolean overrideVersionModifyer, InfoGluePrincipal infoGluePrincipal, Integer siteNodeId, Database db, List resultingEvents) throws ConstraintException, SystemException 115 { 116 SiteNodeVersion newSiteNodeVersion = null; 117 118 try 119 { 120 SiteNodeVersion oldSiteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(oldSiteNodeVersionId, db); 121 122 if(stateId.intValue() == SiteNodeVersionVO.WORKING_STATE.intValue()) 124 { 125 logger.info("About to create a new working version"); 126 127 if (siteNodeId == null) 128 siteNodeId = new Integer (oldSiteNodeVersion.getOwningSiteNode().getId().intValue()); 129 130 SiteNodeVersionVO newSiteNodeVersionVO = new SiteNodeVersionVO(); 131 newSiteNodeVersionVO.setStateId(stateId); 132 newSiteNodeVersionVO.setVersionComment("New working version"); 133 newSiteNodeVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate()); 134 if(overrideVersionModifyer) 135 newSiteNodeVersionVO.setVersionModifier(infoGluePrincipal.getName()); 136 else 137 newSiteNodeVersionVO.setVersionModifier(oldSiteNodeVersion.getVersionModifier()); 138 139 newSiteNodeVersionVO.setContentType(oldSiteNodeVersion.getContentType()); 140 newSiteNodeVersionVO.setPageCacheKey(oldSiteNodeVersion.getPageCacheKey()); 141 newSiteNodeVersionVO.setDisableEditOnSight(oldSiteNodeVersion.getDisableEditOnSight()); 142 newSiteNodeVersionVO.setDisableLanguages(oldSiteNodeVersion.getDisableLanguages()); 143 newSiteNodeVersionVO.setDisablePageCache(oldSiteNodeVersion.getDisablePageCache()); 144 newSiteNodeVersionVO.setIsProtected(oldSiteNodeVersion.getIsProtected()); 145 146 newSiteNodeVersion = SiteNodeVersionController.create(siteNodeId, infoGluePrincipal, newSiteNodeVersionVO, db); 147 copyServiceBindings(oldSiteNodeVersion, newSiteNodeVersion, db); 148 copyAccessRights(oldSiteNodeVersion, newSiteNodeVersion, db); 149 } 150 151 if(stateId.intValue() == SiteNodeVersionVO.PUBLISH_STATE.intValue()) 153 { 154 logger.info("About to copy the working copy to a publish-one"); 155 157 if (siteNodeId == null) 158 siteNodeId = new Integer (oldSiteNodeVersion.getOwningSiteNode().getId().intValue()); 159 160 SiteNodeVersionVO oldSiteNodeVersionVO = oldSiteNodeVersion.getValueObject(); 161 oldSiteNodeVersion.setVersionComment(versionComment); 162 163 SiteNodeVersionVO newSiteNodeVersionVO = new SiteNodeVersionVO(); 165 newSiteNodeVersionVO.setStateId(stateId); 166 newSiteNodeVersionVO.setVersionComment(versionComment); 167 if(overrideVersionModifyer) 168 newSiteNodeVersionVO.setVersionModifier(infoGluePrincipal.getName()); 169 else 170 newSiteNodeVersionVO.setVersionModifier(oldSiteNodeVersion.getVersionModifier()); 171 172 newSiteNodeVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate()); 173 174 newSiteNodeVersionVO.setContentType(oldSiteNodeVersion.getContentType()); 175 newSiteNodeVersionVO.setPageCacheKey(oldSiteNodeVersion.getPageCacheKey()); 176 newSiteNodeVersionVO.setDisableEditOnSight(oldSiteNodeVersion.getDisableEditOnSight()); 177 newSiteNodeVersionVO.setDisableLanguages(oldSiteNodeVersion.getDisableLanguages()); 178 newSiteNodeVersionVO.setDisablePageCache(oldSiteNodeVersion.getDisablePageCache()); 179 newSiteNodeVersionVO.setIsProtected(oldSiteNodeVersion.getIsProtected()); 180 181 newSiteNodeVersion = SiteNodeVersionController.create(siteNodeId, infoGluePrincipal, newSiteNodeVersionVO, db); 182 copyServiceBindings(oldSiteNodeVersion, newSiteNodeVersion, db); 183 copyAccessRights(oldSiteNodeVersion, newSiteNodeVersion, db); 184 185 EventVO eventVO = new EventVO(); 187 eventVO.setDescription(newSiteNodeVersion.getVersionComment()); 188 eventVO.setEntityClass(SiteNodeVersion.class.getName()); 189 eventVO.setEntityId(new Integer (newSiteNodeVersion.getId().intValue())); 190 eventVO.setName(newSiteNodeVersion.getOwningSiteNode().getName()); 191 eventVO.setTypeId(EventVO.PUBLISH); 192 eventVO = EventController.create(eventVO, newSiteNodeVersion.getOwningSiteNode().getRepository().getId(), infoGluePrincipal, db); 193 resultingEvents.add(eventVO); 194 } 195 196 if(stateId.intValue() == SiteNodeVersionVO.PUBLISHED_STATE.intValue()) 197 { 198 logger.info("About to publish an existing version"); 199 oldSiteNodeVersion.setStateId(stateId); 200 oldSiteNodeVersion.setIsActive(new Boolean (true)); 201 newSiteNodeVersion = oldSiteNodeVersion; 202 } 203 204 changeStateOnMetaInfo(db, newSiteNodeVersion, stateId, versionComment, overrideVersionModifyer, infoGluePrincipal, resultingEvents); 205 } 206 catch(Exception e) 207 { 208 logger.error("An error occurred so we should not complete the transaction:" + e, e); 209 throw new SystemException(e.getMessage()); 210 } 211 212 return newSiteNodeVersion; 213 } 214 215 216 223 public void changeStateOnMetaInfo(Database db, SiteNodeVersion siteNodeVersion, Integer stateId, String versionComment, boolean overrideVersionModifyer, InfoGluePrincipal infoGluePrincipal, List events) throws ConstraintException, SystemException, Exception 224 { 225 logger.info("start changeStateOnMetaInfo"); 226 227 List languages = LanguageController.getController().getLanguageList(siteNodeVersion.getOwningSiteNode().getRepository().getId(), db); 228 Language masterLanguage = LanguageController.getController().getMasterLanguage(db, siteNodeVersion.getOwningSiteNode().getRepository().getId()); 229 230 logger.info("after languages"); 231 232 ContentVO contentVO = null; 233 if(siteNodeVersion.getOwningSiteNode().getMetaInfoContentId() != null) 234 { 235 contentVO = ContentController.getContentController().getContentVOWithId(siteNodeVersion.getOwningSiteNode().getMetaInfoContentId(), db); 236 } 237 else 238 { 239 logger.warn("There was no metaInfoContentId on the siteNode... run validation to improve performance.."); 240 241 Integer metaInfoAvailableServiceBindingId = null; 242 Integer serviceBindingId = null; 243 AvailableServiceBinding availableServiceBinding = AvailableServiceBindingController.getController().getAvailableServiceBindingWithName("Meta information", db, true); 244 if(availableServiceBinding != null) 245 metaInfoAvailableServiceBindingId = availableServiceBinding.getAvailableServiceBindingId(); 246 247 logger.info("after loading service binding for meta info"); 248 249 Collection serviceBindings = siteNodeVersion.getServiceBindings(); 250 Iterator serviceBindingIterator = serviceBindings.iterator(); 251 while(serviceBindingIterator.hasNext()) 252 { 253 ServiceBinding serviceBinding = (ServiceBinding)serviceBindingIterator.next(); 254 if(serviceBinding.getAvailableServiceBinding().getId().intValue() == metaInfoAvailableServiceBindingId.intValue()) 255 { 256 serviceBindingId = serviceBinding.getId(); 257 break; 258 } 259 } 260 261 if(serviceBindingId != null) 262 { 263 List boundContents = ContentController.getBoundContents(db, serviceBindingId); 264 logger.info("boundContents:" + boundContents.size()); 265 if(boundContents.size() > 0) 266 { 267 contentVO = (ContentVO)boundContents.get(0); 268 logger.info("contentVO:" + contentVO.getId()); 269 } 270 } 271 } 272 273 if(contentVO != null) 274 { 275 Iterator languageIterator = languages.iterator(); 276 while(languageIterator.hasNext()) 277 { 278 Language language = (Language)languageIterator.next(); 279 ContentVersion contentVersion = ContentVersionController.getContentVersionController().getLatestActiveContentVersion(contentVO.getId(), language.getId(), db); 280 281 logger.info("language:" + language.getId()); 282 283 286 if(contentVersion != null) 287 { 288 logger.info("contentVersion:" + contentVersion.getId() + ":" + contentVersion.getStateId()); 289 logger.info("State wanted:" + stateId); 290 } 291 292 if(contentVersion != null && contentVersion.getStateId().intValue() != stateId.intValue()) 294 { 295 logger.info("State on current:" + contentVersion.getStateId()); 296 logger.info("changing state on contentVersion:" + contentVersion.getId()); 297 contentVersion = ContentStateController.changeState(contentVersion.getId(), stateId, versionComment, overrideVersionModifyer, infoGluePrincipal, contentVO.getId(), db, events); 298 } 299 300 if(language.getId().equals(masterLanguage.getId()) && contentVersion != null) 301 { 302 RegistryController.getController().updateContentVersion(contentVersion, siteNodeVersion, db); 305 } 306 } 307 } 308 } 309 310 317 393 394 397 398 private static void copyServiceBindings(SiteNodeVersion originalSiteNodeVersion, SiteNodeVersion newSiteNodeVersion, Database db) throws ConstraintException, SystemException, Exception 399 { 400 Collection serviceBindings = originalSiteNodeVersion.getServiceBindings(); 401 Iterator iterator = serviceBindings.iterator(); 402 while(iterator.hasNext()) 403 { 404 ServiceBinding serviceBinding = (ServiceBinding)iterator.next(); 405 ServiceBindingVO serviceBindingVO = serviceBinding.getValueObject(); 406 ServiceBindingVO newServiceBindingVO = new ServiceBindingVO(); 407 newServiceBindingVO.setBindingTypeId(serviceBindingVO.getBindingTypeId()); 408 newServiceBindingVO.setName(serviceBindingVO.getName()); 409 newServiceBindingVO.setPath(serviceBindingVO.getPath()); 410 ServiceBinding newServiceBinding = ServiceBindingController.create(newServiceBindingVO, serviceBinding.getAvailableServiceBinding().getAvailableServiceBindingId(), newSiteNodeVersion.getSiteNodeVersionId(), serviceBinding.getServiceDefinition().getServiceDefinitionId(), db); 411 newSiteNodeVersion.getServiceBindings().add(newServiceBinding); 412 copyQualifyers(serviceBinding, newServiceBinding, db); 413 } 414 } 415 416 417 420 private static void copyQualifyers(ServiceBinding originalServiceBinding, ServiceBinding newServiceBinding, Database db) throws ConstraintException, SystemException, Exception 421 { 422 Collection qualifyers = originalServiceBinding.getBindingQualifyers(); 423 Collection newBindingQualifyers = new ArrayList (); 424 425 Iterator iterator = qualifyers.iterator(); 426 while(iterator.hasNext()) 427 { 428 Qualifyer qualifyer = (Qualifyer)iterator.next(); 429 QualifyerVO qualifyerVO = qualifyer.getValueObject(); 430 Qualifyer newQualifyer = new QualifyerImpl(); 431 newQualifyer.setValueObject(qualifyerVO); 432 newQualifyer.setServiceBinding((ServiceBindingImpl)newServiceBinding); 433 newBindingQualifyers.add(newQualifyer); 434 } 436 newServiceBinding.setBindingQualifyers(newBindingQualifyers); 437 438 } 439 440 443 444 private static void copyAccessRights(SiteNodeVersion originalSiteNodeVersion, SiteNodeVersion newSiteNodeVersion, Database db) throws ConstraintException, SystemException, Exception 445 { 446 List interceptionPointList = InterceptionPointController.getController().getInterceptionPointList("SiteNodeVersion", db); 447 logger.info("interceptionPointList:" + interceptionPointList.size()); 448 Iterator interceptionPointListIterator = interceptionPointList.iterator(); 449 while(interceptionPointListIterator.hasNext()) 450 { 451 InterceptionPoint interceptionPoint = (InterceptionPoint)interceptionPointListIterator.next(); 452 List accessRightList = AccessRightController.getController().getAccessRightListForEntity(interceptionPoint.getId(), originalSiteNodeVersion.getId().toString(), db); 453 logger.info("accessRightList:" + accessRightList.size()); 454 Iterator accessRightListIterator = accessRightList.iterator(); 455 while(accessRightListIterator.hasNext()) 456 { 457 AccessRight accessRight = (AccessRight)accessRightListIterator.next(); 458 logger.info("accessRight:" + accessRight.getId()); 459 460 AccessRightVO copiedAccessRight = accessRight.getValueObject().createCopy(); 461 copiedAccessRight.setParameters(newSiteNodeVersion.getId().toString()); 462 AccessRight newAccessRight = AccessRightController.getController().create(copiedAccessRight, interceptionPoint, db); 463 464 Iterator groupsIterator = accessRight.getGroups().iterator(); 465 while(groupsIterator.hasNext()) 466 { 467 AccessRightGroup accessRightGroup = (AccessRightGroup)groupsIterator.next(); 468 AccessRightGroupVO newAccessRightGroupVO = new AccessRightGroupVO(); 469 newAccessRightGroupVO.setGroupName(accessRightGroup.getGroupName()); 470 AccessRightGroup newAccessRightGroup = AccessRightController.getController().createAccessRightGroup(db, newAccessRightGroupVO, newAccessRight); 471 newAccessRight.getGroups().add(newAccessRightGroup); 472 } 473 474 Iterator rolesIterator = accessRight.getRoles().iterator(); 475 while(rolesIterator.hasNext()) 476 { 477 AccessRightRole accessRightRole = (AccessRightRole)rolesIterator.next(); 478 AccessRightRoleVO newAccessRightRoleVO = new AccessRightRoleVO(); 479 newAccessRightRoleVO.setRoleName(accessRightRole.getRoleName()); 480 AccessRightRole newAccessRightRole = AccessRightController.getController().createAccessRightRole(db, newAccessRightRoleVO, newAccessRight); 481 newAccessRight.getRoles().add(newAccessRightRole); 482 } 483 484 Iterator usersIterator = accessRight.getUsers().iterator(); 485 while(usersIterator.hasNext()) 486 { 487 AccessRightUser accessRightUser = (AccessRightUser)usersIterator.next(); 488 AccessRightUserVO newAccessRightUserVO = new AccessRightUserVO(); 489 newAccessRightUserVO.setUserName(accessRightUser.getUserName()); 490 AccessRightUser newAccessRightUser = AccessRightController.getController().createAccessRightUser(db, newAccessRightUserVO, newAccessRight); 491 newAccessRight.getUsers().add(newAccessRightUser); 492 } 493 494 } 495 } 496 } 497 498 501 502 public BaseEntityVO getNewVO() 503 { 504 return null; 505 } 506 507 } 508 509 | Popular Tags |