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.HashMap ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 33 import org.apache.log4j.Logger; 34 import org.exolab.castor.jdo.Database; 35 import org.exolab.castor.jdo.OQLQuery; 36 import org.exolab.castor.jdo.QueryResults; 37 import org.infoglue.cms.entities.kernel.BaseEntityVO; 38 import org.infoglue.cms.entities.management.AccessRight; 39 import org.infoglue.cms.entities.management.AccessRightGroup; 40 import org.infoglue.cms.entities.management.AccessRightRole; 41 import org.infoglue.cms.entities.management.AccessRightUser; 42 import org.infoglue.cms.entities.management.InterceptionPoint; 43 import org.infoglue.cms.entities.management.InterceptionPointVO; 44 import org.infoglue.cms.entities.management.Interceptor; 45 import org.infoglue.cms.entities.management.impl.simple.InterceptionPointImpl; 46 import org.infoglue.cms.exception.Bug; 47 import org.infoglue.cms.exception.ConstraintException; 48 import org.infoglue.cms.exception.SystemException; 49 import org.infoglue.cms.util.ConstraintExceptionBuffer; 50 import org.infoglue.deliver.util.NullObject; 51 import org.infoglue.deliver.util.CacheController; 52 53 58 59 public class InterceptionPointController extends BaseController 60 { 61 private final static Logger logger = Logger.getLogger(InterceptionPointController.class.getName()); 62 63 public final static Map systemInterceptionPoints = new HashMap (); 64 65 static 66 { 67 systemInterceptionPoints.put("Category.Read", new InterceptionPointVO("Category", "Category.Read", "This intercepts any read towards a category", true)); 68 systemInterceptionPoints.put("Content.Read", new InterceptionPointVO("Content", "Content.Read", "Intercepts the read of a content", true)); 69 systemInterceptionPoints.put("Content.Write", new InterceptionPointVO("Content", "Content.Write", "Intercepts the write of a content", true)); 70 systemInterceptionPoints.put("Content.Create", new InterceptionPointVO("Content", "Content.Create", "Intercepts the creation of a new content or folder", true)); 71 systemInterceptionPoints.put("Content.Delete", new InterceptionPointVO("Content", "Content.Delete", "Intercepts the deletion of a content", true)); 72 systemInterceptionPoints.put("Content.Move", new InterceptionPointVO("Content", "Content.Move", "Intercepts the movement of a content", true)); 73 systemInterceptionPoints.put("Content.SubmitToPublish", new InterceptionPointVO("Content", "Content.SubmitToPublish", "Intercepts the submittance to publish of all content versions", true)); 74 systemInterceptionPoints.put("Content.ChangeAccessRights", new InterceptionPointVO("Content", "Content.ChangeAccessRights", "Intercepts the attempt to change access rights", true)); 75 systemInterceptionPoints.put("Content.CreateVersion", new InterceptionPointVO("Content", "Content.CreateVersion", "Intercepts the creation of a new contentversion", true)); 76 systemInterceptionPoints.put("ContentTool.Read", new InterceptionPointVO("ContentTool", "ContentTool.Read", "Gives a user access to the content tool", false)); 77 systemInterceptionPoints.put("ContentTypeDefinition.Read", new InterceptionPointVO("ContentTypeDefinition", "ContentTypeDefinition.Read", "This point checks access to read/use a content type definition", true)); 78 systemInterceptionPoints.put("ContentVersion.Delete", new InterceptionPointVO("ContentVersion", "ContentVersion.Delete", "Intercepts the deletion of a contentversion", true)); 79 systemInterceptionPoints.put("ContentVersion.Write", new InterceptionPointVO("ContentVersion", "ContentVersion.Write", "Intercepts the editing of a contentversion", true)); 80 systemInterceptionPoints.put("ContentVersion.Read", new InterceptionPointVO("ContentVersion", "ContentVersion.Read", "Intercepts the read of a contentversion", true)); 81 systemInterceptionPoints.put("ContentVersion.Publish", new InterceptionPointVO("ContentVersion", "ContentVersion.Publish", "Intercepts the direct publishing of a content version", true)); 82 systemInterceptionPoints.put("ManagementTool.Read", new InterceptionPointVO("ManagementTool", "ManagementTool.Read", "Gives a user access to the management tool", false)); 83 systemInterceptionPoints.put("MyDesktopTool.Read", new InterceptionPointVO("MyDesktopTool", "MyDesktopTool.Read", "Gives the user access to the mydesktop tool", false)); 84 systemInterceptionPoints.put("PublishingTool.Read", new InterceptionPointVO("PublishingTool", "PublishingTool.Read", "Gives the user access to the publishing tool", false)); 85 systemInterceptionPoints.put("Repository.Read", new InterceptionPointVO("Repository", "Repository.Read", "Gives a user access to look at a repository", true)); 86 systemInterceptionPoints.put("Repository.ReadForBinding", new InterceptionPointVO("Repository", "Repository.ReadForBinding", "This point intercepts when a user tries to read the repository in a binding dialog", true)); 87 systemInterceptionPoints.put("SiteNodeVersion.Read", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.Read", "Intercepts the read of a SiteNodeVersion", true)); 88 systemInterceptionPoints.put("SiteNodeVersion.Write", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.Write", "Intercepts the write of a SiteNodeVersion", true)); 89 systemInterceptionPoints.put("SiteNodeVersion.CreateSiteNode", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.CreateSiteNode", "Intercepts the creation of a new sitenode", true)); 90 systemInterceptionPoints.put("SiteNodeVersion.DeleteSiteNode", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.DeleteSiteNode", "Intercepts the deletion of a sitenode", true)); 91 systemInterceptionPoints.put("SiteNodeVersion.MoveSiteNode", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.MoveSiteNode", "Intercepts the movement of a sitenode", true)); 92 systemInterceptionPoints.put("SiteNodeVersion.SubmitToPublish", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.SubmitToPublish", "Intercepts the submittance to publish of all content versions", true)); 93 systemInterceptionPoints.put("SiteNodeVersion.ChangeAccessRights", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.ChangeAccessRights", "Intercepts the attempt to change access rights", true)); 94 systemInterceptionPoints.put("SiteNodeVersion.Publish", new InterceptionPointVO("SiteNodeVersion", "SiteNodeVersion.Publish", "Intercepts the direct publishing of a siteNode version", true)); 95 systemInterceptionPoints.put("StructureTool.Read", new InterceptionPointVO("StructureTool", "StructureTool.Read", "Gives a user access to the structure tool", false)); 96 systemInterceptionPoints.put("StructureTool.SaveTemplate", new InterceptionPointVO("StructureTool", "StructureTool.SaveTemplate", "This interception point limits who get the save-button in the toolbar", false)); 97 systemInterceptionPoints.put("StructureTool.Palette", new InterceptionPointVO("StructureTool", "StructureTool.Palette", "This interception point limits who sees the toolbar", false)); 98 systemInterceptionPoints.put("ComponentEditor.ChangeSlotAccess", new InterceptionPointVO("ComponentEditor", "ComponentEditor.ChangeSlotAccess", "This interception point limits who can set access rights to a slot", false)); 99 systemInterceptionPoints.put("ComponentEditor.AddComponent", new InterceptionPointVO("ComponentEditor", "ComponentEditor.AddComponent", "This interception point limits who can add a component to a specific slot", true)); 100 systemInterceptionPoints.put("ComponentEditor.DeleteComponent", new InterceptionPointVO("ComponentEditor", "ComponentEditor.DeleteComponent", "This interception point limits who can delete a component in a specific slot", true)); 101 systemInterceptionPoints.put("ComponentPropertyEditor.EditProperty", new InterceptionPointVO("ComponentPropertyEditor", "ComponentPropertyEditor.EditProperty", "This interception point limits who can edit a specific component property", true)); 102 systemInterceptionPoints.put("Publication.Write", new InterceptionPointVO("Publication", "Publication.Write", "This interception point intercepts publications", true)); 103 } 104 105 108 109 public static InterceptionPointController getController() 110 { 111 return new InterceptionPointController(); 112 } 113 114 public InterceptionPoint getInterceptionPointWithId(Integer interceptionPointId, Database db) throws SystemException, Bug 115 { 116 return (InterceptionPoint) getObjectWithId(InterceptionPointImpl.class, interceptionPointId, db); 117 } 118 119 public InterceptionPointVO getInterceptionPointVOWithId(Integer interceptionPointId) throws SystemException, Bug 120 { 121 return (InterceptionPointVO) getVOWithId(InterceptionPointImpl.class, interceptionPointId); 122 } 123 124 public List getInterceptionPointVOList() throws SystemException, Bug 125 { 126 return getAllVOObjects(InterceptionPointImpl.class, "interceptionPointId"); 127 } 128 129 public List getSortedInterceptionPointVOList() throws SystemException, Bug 130 { 131 return getAllVOObjects(InterceptionPointImpl.class, "category", "asc"); 132 } 133 134 public List getInterceptorsVOList(Integer interceptionPointId) throws SystemException, Bug 135 { 136 List interceptorVOList = null; 137 138 Database db = CastorDatabaseService.getDatabase(); 139 140 try 141 { 142 beginTransaction(db); 143 144 interceptorVOList = getInterceptorsVOList(interceptionPointId, db); 145 146 commitTransaction(db); 147 } 148 catch (Exception e) 149 { 150 logger.info("An error occurred so we should not complete the transaction:" + e); 151 rollbackTransaction(db); 152 throw new SystemException(e.getMessage()); 153 } 154 155 return interceptorVOList; 156 } 157 158 167 168 public List getInterceptorsVOList(Integer interceptionPointId, Database db) throws SystemException, Bug 169 { 170 String key = "" + interceptionPointId; 171 logger.info("key:" + key); 172 List cachedInterceptorVOList = (List )CacheController.getCachedObject("interceptorsCache", key); 173 if(cachedInterceptorVOList != null) 174 { 175 logger.info("There was an cached InterceptorVOList:" + cachedInterceptorVOList.size()); 176 return cachedInterceptorVOList; 177 } 178 179 List interceptorsVOList = null; 180 181 InterceptionPoint interceptionPoint = this.getInterceptionPointWithId(interceptionPointId, db); 182 183 Collection interceptors = interceptionPoint.getInterceptors(); 184 185 interceptorsVOList = toVOList(interceptors); 186 187 CacheController.cacheObject("interceptorsCache", key, interceptorsVOList); 188 189 return interceptorsVOList; 190 } 191 192 193 public InterceptionPointVO getInterceptionPointVOWithName(String interceptorPointName) throws SystemException, Bug 194 { 195 InterceptionPointVO interceptionPointVO = null; 196 197 Database db = CastorDatabaseService.getDatabase(); 198 199 try 200 { 201 beginTransaction(db); 202 203 InterceptionPoint interceptionPoint = getInterceptionPointWithName(interceptorPointName, db); 204 if(interceptionPoint != null) 205 interceptionPointVO = interceptionPoint.getValueObject(); 206 207 commitTransaction(db); 208 } 209 catch (Exception e) 210 { 211 logger.info("An error occurred so we should not complete the transaction:" + e); 212 rollbackTransaction(db); 213 throw new SystemException(e.getMessage()); 214 } 215 216 return interceptionPointVO; 217 } 218 219 public InterceptionPointVO getInterceptionPointVOWithName(String interceptorPointName, Database db) throws SystemException, Bug 220 { 221 String key = "" + interceptorPointName; 222 logger.info("key:" + key); 223 224 InterceptionPointVO interceptionPointVO = null; 225 226 Object object = CacheController.getCachedObject("interceptionPointCache", key); 227 228 if(object instanceof NullObject) 229 { 230 return null; 231 } 232 else if(object != null) 233 { 234 interceptionPointVO = (InterceptionPointVO)object; 235 } 236 else 237 { 238 239 249 InterceptionPoint interceptorPoint = null; 250 251 try 252 { 253 OQLQuery oql = db.getOQLQuery("SELECT f FROM org.infoglue.cms.entities.management.impl.simple.InterceptionPointImpl f WHERE f.name = $1"); 254 oql.bind(interceptorPointName); 255 256 QueryResults results = oql.execute(Database.ReadOnly); 257 if(results.hasMore()) 258 { 259 interceptorPoint = (InterceptionPoint)results.next(); 260 interceptionPointVO = interceptorPoint.getValueObject(); 261 262 CacheController.cacheObject("interceptionPointCache", key, interceptionPointVO); 263 } 265 else 266 { 267 CacheController.cacheObject("interceptionPointCache", key, new NullObject()); 268 } 269 270 results.close(); 271 oql.close(); 272 } 273 catch(Exception e) 274 { 275 throw new SystemException("An error occurred when we tried to fetch an InterceptionPointVO. Reason:" + e.getMessage(), e); 276 } 277 } 278 279 return interceptionPointVO; 280 } 281 282 283 public InterceptionPoint getInterceptionPointWithName(String interceptorPointName, Database db) throws SystemException, Bug 284 { 285 InterceptionPoint interceptorPoint = null; 286 287 try 288 { 289 OQLQuery oql = db.getOQLQuery("SELECT f FROM org.infoglue.cms.entities.management.impl.simple.InterceptionPointImpl f WHERE f.name = $1"); 290 oql.bind(interceptorPointName); 291 292 QueryResults results = oql.execute(); 293 this.logger.info("Fetching entity in read/write mode:" + interceptorPointName); 294 if(results.hasMore()) 295 { 296 interceptorPoint = (InterceptionPoint)results.next(); 297 } 298 299 results.close(); 300 oql.close(); 301 } 302 catch(Exception e) 303 { 304 throw new SystemException("An error occurred when we tried to fetch an InterceptionPointVO. Reason:" + e.getMessage(), e); 305 } 306 307 return interceptorPoint; 308 } 309 310 311 public List getInterceptionPointVOList(String category) throws SystemException, Bug 312 { 313 List interceptionPointVOList = null; 314 315 Database db = CastorDatabaseService.getDatabase(); 316 317 try 318 { 319 beginTransaction(db); 320 321 interceptionPointVOList = toVOList(getInterceptionPointList(category, db)); 322 323 commitTransaction(db); 324 } 325 catch (Exception e) 326 { 327 logger.info("An error occurred so we should not complete the transaction:" + e); 328 rollbackTransaction(db); 329 throw new SystemException(e.getMessage()); 330 } 331 332 return interceptionPointVOList; 333 } 334 335 336 public List getInterceptionPointList(String category, Database db) throws SystemException, Bug 337 { 338 List interceptionPoints = new ArrayList (); 339 340 try 341 { 342 OQLQuery oql = db.getOQLQuery("SELECT f FROM org.infoglue.cms.entities.management.impl.simple.InterceptionPointImpl f WHERE f.category = $1"); 343 oql.bind(category); 344 345 QueryResults results = oql.execute(); 346 this.logger.info("Fetching entity in read/write mode:" + category); 347 348 while(results.hasMore()) 349 { 350 InterceptionPoint interceptionPoint = (InterceptionPoint)results.next(); 351 interceptionPoints.add(interceptionPoint); 352 } 353 354 results.close(); 355 oql.close(); 356 } 357 catch(Exception e) 358 { 359 throw new SystemException("An error occurred when we tried to fetch an InterceptionPointVO. Reason:" + e.getMessage(), e); 360 } 361 362 return interceptionPoints; 363 } 364 365 373 374 public InterceptionPointVO create(InterceptionPointVO interceptionPointVO) throws ConstraintException, SystemException 375 { 376 InterceptionPointVO newInterceptionPointVO = null; 377 378 Database db = CastorDatabaseService.getDatabase(); 379 380 try 381 { 382 beginTransaction(db); 383 384 newInterceptionPointVO = create(interceptionPointVO, db); 385 386 commitTransaction(db); 387 } 388 catch (Exception e) 389 { 390 logger.info("An error occurred so we should not complete the transaction:" + e); 391 rollbackTransaction(db); 392 throw new SystemException(e.getMessage()); 393 } 394 395 return newInterceptionPointVO; 396 } 397 398 406 407 public InterceptionPointVO create(InterceptionPointVO interceptionPointVO, Database db) throws SystemException, Exception 408 { 409 InterceptionPoint interceptionPoint = new InterceptionPointImpl(); 410 interceptionPoint.setValueObject(interceptionPointVO); 411 412 db.create(interceptionPoint); 413 414 return interceptionPoint.getValueObject(); 415 } 416 417 418 public InterceptionPointVO update(InterceptionPointVO interceptionPointVO) throws ConstraintException, SystemException 419 { 420 return (InterceptionPointVO) updateEntity(InterceptionPointImpl.class, interceptionPointVO); 421 } 422 423 424 public void update(InterceptionPointVO interceptionPointVO, String [] values) throws ConstraintException, SystemException 425 { 426 Database db = CastorDatabaseService.getDatabase(); 427 428 try 429 { 430 beginTransaction(db); 431 432 ConstraintExceptionBuffer ceb = interceptionPointVO.validate(); 433 ceb.throwIfNotEmpty(); 434 435 InterceptionPoint interceptionPoint = this.getInterceptionPointWithId(interceptionPointVO.getInterceptionPointId(), db); 436 437 interceptionPoint.setValueObject(interceptionPointVO); 438 439 Collection interceptors = interceptionPoint.getInterceptors(); 440 Iterator interceptorsIterator = interceptors.iterator(); 441 while(interceptorsIterator.hasNext()) 442 { 443 Interceptor interceptor = (Interceptor)interceptorsIterator.next(); 444 interceptor.getInterceptionPoints().remove(interceptor); 445 } 446 447 interceptionPoint.getInterceptors().clear(); 448 449 if(values != null) 450 { 451 for(int i=0; i<values.length; i++) 452 { 453 String interceptorId = values[i]; 454 Interceptor interceptor = InterceptorController.getController().getInterceptorWithId(new Integer (interceptorId), db); 455 interceptionPoint.getInterceptors().add(interceptor); 456 interceptor.getInterceptionPoints().add(interceptionPoint); 457 } 458 } 459 460 logger.info("Interceptors:" + interceptionPoint.getInterceptors().size()); 461 462 commitTransaction(db); 463 } 464 catch (Exception e) 465 { 466 logger.info("An error occurred so we should not complete the transaction:" + e); 467 rollbackTransaction(db); 468 throw new SystemException(e.getMessage()); 469 } 470 } 471 472 473 public void delete(InterceptionPointVO interceptionPointVO) throws ConstraintException, SystemException 474 { 475 Database db = CastorDatabaseService.getDatabase(); 476 477 beginTransaction(db); 478 479 try 480 { 481 InterceptionPoint interceptionPoint = this.getInterceptionPointWithId(interceptionPointVO.getInterceptionPointId(), db); 482 483 List accessRights = AccessRightController.getController().getAccessRightList(interceptionPoint.getInterceptionPointId(), db); 484 Iterator accessRightsIterator = accessRights.iterator(); 485 while(accessRightsIterator.hasNext()) 486 { 487 AccessRight accessRight = (AccessRight)accessRightsIterator.next(); 488 489 Iterator groupIterator = accessRight.getGroups().iterator(); 490 while(groupIterator.hasNext()) 491 { 492 AccessRightGroup group = (AccessRightGroup)groupIterator.next(); 493 groupIterator.remove(); 494 db.remove(group); 495 } 496 497 Iterator roleIterator = accessRight.getRoles().iterator(); 498 while(roleIterator.hasNext()) 499 { 500 AccessRightRole role = (AccessRightRole)roleIterator.next(); 501 roleIterator.remove(); 502 db.remove(role); 503 } 504 505 Iterator userIterator = accessRight.getUsers().iterator(); 506 while(userIterator.hasNext()) 507 { 508 AccessRightUser user = (AccessRightUser)userIterator.next(); 509 userIterator.remove(); 510 db.remove(user); 511 } 512 513 db.remove(accessRight); 514 accessRightsIterator.remove(); 515 } 516 517 db.remove(interceptionPoint); 518 519 commitTransaction(db); 520 } 521 catch(Exception e) 522 { 523 logger.error("An error occurred so we should not complete the transaction:" + e, e); 524 rollbackTransaction(db); 525 throw new SystemException(e.getMessage()); 526 } 527 528 } 529 530 543 544 548 549 public BaseEntityVO getNewVO() 550 { 551 return new InterceptionPointVO(); 552 } 553 554 } 555 556 | Popular Tags |