1 24 package org.ofbiz.content; 25 26 import java.sql.Timestamp ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Collections ; 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 import java.util.Set ; 35 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpSession ; 38 39 import org.ofbiz.base.util.Debug; 40 import org.ofbiz.base.util.GeneralException; 41 import org.ofbiz.base.util.StringUtil; 42 import org.ofbiz.base.util.UtilHttp; 43 import org.ofbiz.base.util.UtilMisc; 44 import org.ofbiz.base.util.UtilValidate; 45 import org.ofbiz.base.util.collections.LifoSet; 46 import org.ofbiz.content.content.ContentServicesComplex; 47 import org.ofbiz.entity.GenericDelegator; 48 import org.ofbiz.entity.GenericEntity; 49 import org.ofbiz.entity.GenericEntityException; 50 import org.ofbiz.entity.GenericPK; 51 import org.ofbiz.entity.GenericValue; 52 import org.ofbiz.entity.condition.EntityCondition; 53 import org.ofbiz.entity.condition.EntityConditionList; 54 import org.ofbiz.entity.condition.EntityExpr; 55 import org.ofbiz.entity.condition.EntityOperator; 56 import org.ofbiz.entity.util.EntityUtil; 57 import org.ofbiz.entityext.permission.EntityPermissionChecker; 58 import org.ofbiz.minilang.MiniLangException; 59 import org.ofbiz.security.Security; 60 61 62 69 public class ContentManagementWorker { 70 71 public static final String module = ContentManagementWorker.class.getName(); 72 public static Map cachedWebSitePublishPoints = new HashMap (); 73 public static Map cachedStaticValues = new HashMap (); 74 75 public static void mruAdd(HttpServletRequest request, GenericEntity pk, String suffix ) { 76 HttpSession session = request.getSession(); 77 mruAdd(session, pk); 78 } 79 80 public static void mruAdd(HttpServletRequest request, GenericEntity pk ) { 81 HttpSession session = request.getSession(); 82 mruAdd(session, pk); 83 } 84 85 public static void mruAdd(HttpSession session, GenericEntity pk) { 86 87 if (pk == null) return; 88 89 Map lookupCaches = (Map )session.getAttribute("lookupCaches"); 90 if(lookupCaches == null){ 91 lookupCaches = new HashMap (); 92 session.setAttribute("lookupCaches", lookupCaches); 93 } 94 String entityName = pk.getEntityName(); 95 96 mruAddByEntityName( entityName, pk, lookupCaches); 97 return; 98 } 99 100 108 public static void mruAddByEntityName(String entityName, GenericEntity pk, Map lookupCaches) { 109 110 String cacheEntityName = entityName; 111 LifoSet lkupCache = (LifoSet)lookupCaches.get(cacheEntityName); 112 if(lkupCache == null){ 113 lkupCache = new LifoSet(); 114 lookupCaches.put(cacheEntityName, lkupCache); 115 } 116 117 lkupCache.add(pk.getPrimaryKey()); 118 if (Debug.infoOn()) Debug.logInfo("in mruAddByEntityName, entityName:" + entityName + " lifoSet.size()" + lkupCache.size(), module); 119 return; 120 } 121 122 public static Iterator mostRecentlyViewedIterator(String entityName, Map lookupCaches) { 123 124 String cacheEntityName = entityName; 125 LifoSet lkupCache = (LifoSet)lookupCaches.get(cacheEntityName); 126 if(lkupCache == null){ 127 lkupCache = new LifoSet(); 128 lookupCaches.put(cacheEntityName, lkupCache); 129 } 130 131 Iterator mrvIterator = lkupCache.iterator(); 132 return mrvIterator; 133 } 134 135 136 142 public static String buildPKSig( GenericEntity pk, String suffix ) { 143 144 String sig = ""; 145 Collection keyColl = pk.getPrimaryKey().getAllKeys(); 146 List keyList = new ArrayList (keyColl); 147 Collections.sort(keyList); 148 Iterator it = keyList.iterator(); 149 while (it.hasNext()) { 150 String ky = (String )it.next(); 151 String val = (String )pk.get(ky); 152 if (val != null && val.length() > 0) { 153 if (sig.length() > 0) sig += "_"; 154 sig += val; 155 } 156 } 157 if (suffix != null && suffix.length() > 0) { 158 if (sig.length() > 0) sig += "_"; 159 sig += suffix; 160 } 161 return sig; 162 } 163 164 165 public static void setCurrentEntityMap(HttpServletRequest request, GenericEntity ent) { 166 167 String entityName = ent.getEntityName(); 168 setCurrentEntityMap(request, entityName, ent); 169 } 170 171 public static void setCurrentEntityMap(HttpServletRequest request, 172 String entityName, GenericEntity ent) { 173 HttpSession session = request.getSession(); 174 Map currentEntityMap = (Map )session.getAttribute("currentEntityMap"); 175 if(currentEntityMap == null){ 176 currentEntityMap = new HashMap (); 177 session.setAttribute("currentEntityMap", currentEntityMap); 178 } 179 180 currentEntityMap.put(entityName, ent); 181 } 182 183 public static String getFromSomewhere(String name, Map paramMap, HttpServletRequest request, Map context) { 185 186 String ret = null; 187 if (paramMap != null) 188 ret = (String )paramMap.get(name); 189 190 if (UtilValidate.isEmpty(ret)) { 191 Object obj = request.getAttribute(name); 192 if (obj != null) { 193 ret = obj.toString(); 194 } else { 195 obj = context.get(name); 196 if (obj != null) { 197 ret = obj.toString(); 198 } 199 } 200 } 201 return ret; 202 } 203 204 public static String getFromSomewhere(String name, Map paramMap, HttpServletRequest request, org.jpublish.JPublishContext context) { 206 207 String ret = null; 208 if (paramMap != null) 209 ret = (String )paramMap.get(name); 210 211 if (UtilValidate.isEmpty(ret)) { 212 Object obj = request.getAttribute(name); 213 if (obj != null) { 214 ret = obj.toString(); 215 } else { 216 obj = context.get(name); 217 if (obj != null) { 218 ret = obj.toString(); 219 } 220 } 221 } 222 return ret; 223 } 224 225 public static void getCurrentValue(HttpServletRequest request, GenericDelegator delegator) { 226 227 228 HttpSession session = request.getSession(); 229 Map currentEntityMap = (Map )session.getAttribute("currentEntityMap"); 230 if(currentEntityMap == null){ 231 currentEntityMap = new HashMap (); 232 session.setAttribute("currentEntityMap", currentEntityMap); 233 } 234 Map paramMap = UtilHttp.getParameterMap(request); 235 String entityName = (String )paramMap.get("entityName"); 236 if (UtilValidate.isEmpty(entityName)) 237 entityName = (String )request.getAttribute("entityName"); 238 GenericPK cachedPK = null; 239 if (UtilValidate.isNotEmpty(entityName)) 240 cachedPK = (GenericPK)currentEntityMap.get(entityName); 241 getCurrentValueWithCachedPK( request, delegator, cachedPK, entityName); 242 GenericPK currentPK = (GenericPK)request.getAttribute("currentPK"); 243 currentEntityMap.put(entityName, currentPK); 244 return; 245 } 246 247 public static void getCurrentValueWithCachedPK(HttpServletRequest request, GenericDelegator delegator, GenericPK cachedPK, String entityName) { 248 249 Map paramMap = UtilHttp.getParameterMap(request); 250 GenericValue v = delegator.makeValue(entityName, null); 252 GenericPK passedPK = v.getPrimaryKey(); 253 Collection keyColl = passedPK.getAllKeys(); 254 Iterator keyIt = keyColl.iterator(); 255 while (keyIt.hasNext()) { 256 String attrName = (String )keyIt.next(); 257 String attrVal = (String )request.getAttribute(attrName); 258 if (UtilValidate.isEmpty(attrVal)) { 259 attrVal = (String )paramMap.get(attrName); 260 } 261 if (UtilValidate.isNotEmpty(attrVal)) { 262 passedPK.put(attrName,attrVal); 263 } 264 } 265 266 boolean useCached = false; 270 boolean usePassed = true; 271 if(cachedPK != null ) { 272 useCached = true; 273 keyColl = cachedPK.getPrimaryKey().getAllKeys(); 274 keyIt = keyColl.iterator(); 275 while(keyIt.hasNext()) { 276 String sCached = null; 277 String sPassed = null; 278 Object oPassed = null; 279 Object oCached = null; 280 String ky = (String )keyIt.next(); 281 oPassed = passedPK.get(ky); 282 if(oPassed != null) { 283 sPassed = oPassed.toString(); 284 if(UtilValidate.isEmpty(sPassed)){ 285 usePassed = false; 287 } else { 288 oCached = cachedPK.get(ky); 289 if(oCached != null) { 290 sCached = oCached.toString(); 291 if(UtilValidate.isEmpty(sCached)){ 292 useCached = false; 293 } else { 294 } 295 } else { 296 useCached = false; 297 } 298 } 299 } else { 300 usePassed = false; 302 } 303 } 304 } 305 306 GenericPK currentPK = null; 307 if (usePassed && useCached) { 308 currentPK = passedPK; 309 } else if (usePassed && !useCached) { 310 currentPK = passedPK; 311 } else if (!usePassed && useCached) { 312 currentPK = cachedPK; 313 } 314 315 if (currentPK != null) { 316 request.setAttribute("currentPK", currentPK); 317 GenericValue currentValue = null; 318 try { 319 currentValue = delegator.findByPrimaryKey(currentPK.getPrimaryKey()); 320 } catch(GenericEntityException e) { 321 } 322 request.setAttribute("currentValue", currentValue); 323 } 324 325 } 326 327 public static List getPermittedPublishPoints(GenericDelegator delegator, List allPublishPoints, GenericValue userLogin, Security security, String permittedAction, String permittedOperations, String passedRoles) throws GeneralException { 328 329 List permittedPublishPointList = new ArrayList (); 330 331 Iterator it = allPublishPoints.iterator(); 333 while(it.hasNext()) { 334 GenericValue webSitePP = (GenericValue)it.next(); 335 String contentId = (String )webSitePP.get("contentId"); 336 String templateTitle = (String )webSitePP.get("templateTitle"); 337 GenericValue content = delegator.makeValue("Content", UtilMisc.toMap("contentId", contentId)); 338 String statusId = null; 339 String entityAction = permittedAction; 340 if (entityAction == null) 341 entityAction = "_ADMIN"; 342 List passedPurposes = UtilMisc.toList("ARTICLE"); 343 List roles = StringUtil.split(passedRoles, "|"); 344 List targetOperationList = new ArrayList (); 345 if (UtilValidate.isEmpty(permittedOperations)) { 346 targetOperationList.add("CONTENT" + entityAction); 347 } else { 348 targetOperationList = StringUtil.split(permittedOperations, "|"); 349 } 350 Map results = null; 351 results = EntityPermissionChecker.checkPermission(content, statusId, userLogin, passedPurposes, targetOperationList, roles, delegator, security, entityAction); 353 String permissionStatus = (String )results.get("permissionStatus"); 354 if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) { 355 String [] arr = {contentId,templateTitle}; 356 permittedPublishPointList.add(arr); 357 } 358 } 359 return permittedPublishPointList; 360 } 361 362 368 public static List getAllPublishPoints(GenericDelegator delegator, String parentPubPt) throws GeneralException { 369 370 GenericValue rootContent = null; 371 List relatedPubPts = null; 372 try { 373 rootContent = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", parentPubPt)); 374 relatedPubPts = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentIdTo", parentPubPt, "contentAssocTypeId", "SUBSITE")); 376 377 } catch(GenericEntityException e) { 378 throw new GeneralException(e.getMessage()); 379 } 380 List allPublishPoints = new ArrayList (); 381 GenericValue webSitePublishPoint = null; 382 GenericValue rootWebSitePublishPoint = null; 383 GenericValue currentWebSitePublishPoint = null; 384 GenericValue contentAssoc = null; 385 Iterator it = relatedPubPts.iterator(); 386 while (it.hasNext()) { 387 contentAssoc = (GenericValue)it.next(); 388 String pub = (String )contentAssoc.get("contentId"); 389 webSitePublishPoint = getWebSitePublishPoint(delegator, pub, false); 391 allPublishPoints.add(webSitePublishPoint); 392 } 393 return allPublishPoints; 394 } 395 396 public static Map getPublishPointMap(GenericDelegator delegator, String pubPtId ) throws GeneralException { 397 398 List publishPointList = getAllPublishPoints( delegator, pubPtId ); 399 Map publishPointMap = new HashMap (); 400 Iterator it = publishPointList.iterator(); 401 while (it.hasNext()) { 402 GenericValue webSitePublishPoint = (GenericValue)it.next(); 403 String pub = (String )webSitePublishPoint.get("contentId"); 404 publishPointMap.put(pub, webSitePublishPoint); 405 } 406 return publishPointMap; 407 } 408 409 410 public static void getAllPublishPointMap(GenericDelegator delegator, String pubPtId, Map publishPointMap ) throws GeneralException { 411 412 List publishPointList = getAllPublishPoints( delegator, pubPtId ); 413 Iterator it = publishPointList.iterator(); 414 while (it.hasNext()) { 415 GenericValue webSitePublishPoint = (GenericValue)it.next(); 416 String pub = (String )webSitePublishPoint.get("contentId"); 417 publishPointMap.put(pub, webSitePublishPoint); 418 getAllPublishPointMap(delegator, pub, publishPointMap); 419 } 420 return; 421 } 422 423 public static Map getPublishPointMap(GenericDelegator delegator, List publishPointList ) { 424 425 Map publishPointMap = new HashMap (); 426 Iterator it = publishPointList.iterator(); 427 while (it.hasNext()) { 428 GenericValue webSitePublishPoint = (GenericValue)it.next(); 429 String pub = (String )webSitePublishPoint.get("contentId"); 430 publishPointMap.put(pub, webSitePublishPoint); 431 } 432 return publishPointMap; 433 } 434 435 public static List getStaticValues(GenericDelegator delegator, String parentPlaceholderId, List permittedPublishPointList) throws GeneralException { 436 437 List assocValueList = null; 438 try { 439 assocValueList = delegator.findByAndCache("Content", UtilMisc.toMap("contentTypeId", parentPlaceholderId)); 440 } catch(GenericEntityException e) { 441 throw new GeneralException(e.getMessage()); 442 } 443 444 List staticValueList = new ArrayList (); 445 Iterator it = assocValueList.iterator(); 446 int counter = 0; 447 while(it.hasNext()) { 448 GenericValue content = (GenericValue)it.next(); 449 String contentId = (String )content.get("contentId"); 450 String contentName = (String )content.get("contentName"); 451 String description = (String )content.get("description"); 452 Map map = new HashMap (); 453 map.put("contentId", contentId); 454 map.put("contentName", contentName); 455 map.put("description", description); 456 Iterator it2 = permittedPublishPointList.iterator(); 457 while (it2.hasNext()) { 458 String [] publishPointArray = (String [])it2.next(); 459 String publishPointId = (String )publishPointArray[0]; 460 String fieldName = publishPointId; 462 List contentAssocList = content.getRelatedByAnd("ToContentAssoc", UtilMisc.toMap("contentId", publishPointId)); 463 List filteredList = EntityUtil.filterByDate(contentAssocList); 464 if (filteredList.size() > 0) { 465 map.put(fieldName, "Y"); 466 GenericValue assoc = (GenericValue)filteredList.get(0); 467 Timestamp fromDate = (Timestamp )assoc.get("fromDate"); 468 map.put(fieldName + "FromDate", fromDate); 469 } else { 470 map.put(fieldName, "N"); 471 } 472 } 473 staticValueList.add(map); 474 counter++; 475 } 476 return staticValueList; 477 } 478 479 public static GenericValue getWebSitePublishPoint(GenericDelegator delegator, String contentId) throws GenericEntityException { 480 return getWebSitePublishPoint(delegator, contentId, false); 481 } 482 483 public static GenericValue getWebSitePublishPoint(GenericDelegator delegator, String contentId, boolean ignoreCache) throws GenericEntityException { 484 GenericValue webSitePublishPoint = null; 485 if (!ignoreCache) 486 webSitePublishPoint = (GenericValue)cachedWebSitePublishPoints.get(contentId); 487 488 if (webSitePublishPoint == null) { 489 webSitePublishPoint = delegator.findByPrimaryKey("WebSitePublishPoint", UtilMisc.toMap("contentId", contentId)); 490 if (webSitePublishPoint == null) { 492 webSitePublishPoint = delegator.makeValue("WebSitePublishPoint", UtilMisc.toMap("contentId", contentId)); 493 } 494 webSitePublishPoint = overrideWebSitePublishPoint(delegator, webSitePublishPoint); 496 cachedWebSitePublishPoints.put(contentId, webSitePublishPoint); 497 } 498 return webSitePublishPoint; 499 } 500 501 public static GenericValue overrideWebSitePublishPoint(GenericDelegator delegator, GenericValue passedValue) throws GenericEntityException { 502 String contentId = passedValue.getString("contentId"); 503 GenericValue webSitePublishPoint = passedValue; 504 String contentIdTo = getParentWebSitePublishPointId(delegator, contentId); 505 if (contentIdTo != null) { 507 webSitePublishPoint = delegator.findByPrimaryKeyCache("WebSitePublishPoint", UtilMisc.toMap("contentId", contentIdTo)); 509 if (webSitePublishPoint != null) { 510 webSitePublishPoint = GenericValue.create(webSitePublishPoint); 511 webSitePublishPoint = overrideWebSitePublishPoint(delegator, webSitePublishPoint); 512 webSitePublishPoint.setNonPKFields(passedValue, false); 513 webSitePublishPoint.setPKFields(passedValue, false); 514 passedValue.setNonPKFields(webSitePublishPoint); 515 } 516 } 517 return webSitePublishPoint; 518 } 519 520 public static GenericValue getParentWebSitePublishPointValue(GenericDelegator delegator, String contentId) throws GenericEntityException { 521 522 String contentIdTo = getParentWebSitePublishPointId(delegator, contentId); 523 GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentIdTo)); 524 return content; 525 } 526 527 public static String getParentWebSitePublishPointId(GenericDelegator delegator, String contentId) throws GenericEntityException { 528 529 530 String contentIdTo = null; 531 List contentAssocList = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", contentId, "contentAssocTypeId", "SUBSITE")); 532 List filteredContentAssocList = EntityUtil.filterByDate(contentAssocList); 533 if (filteredContentAssocList.size() > 0) { 534 GenericValue contentAssoc = (GenericValue)filteredContentAssocList.get(0); 535 if (contentAssoc != null) 536 contentIdTo = contentAssoc.getString("contentIdTo"); 537 } 538 return contentIdTo; 539 } 540 541 public static GenericValue getStaticValue(GenericDelegator delegator, String parentPlaceholderId, String webSitePublishPointId, boolean ignoreCache) throws GenericEntityException { 542 GenericValue webSitePublishPoint = null; 543 GenericValue staticValue = null; 544 if (!ignoreCache) { 545 Map subStaticValueMap = (GenericValue)cachedStaticValues.get(parentPlaceholderId); 546 if (subStaticValueMap == null) { 547 subStaticValueMap = new HashMap (); 548 cachedStaticValues.put(parentPlaceholderId, subStaticValueMap); 549 } 550 } 552 553 564 return webSitePublishPoint; 565 } 566 567 568 public static List getPublishedLinks(GenericDelegator delegator, String targContentId, String rootPubId, GenericValue userLogin, Security security, String permittedAction, String permittedOperations , String passedRoles) throws GeneralException { 569 570 List allPublishPointList = getAllPublishPoints( delegator, rootPubId ); 573 List publishPointList = getPermittedPublishPoints( delegator, allPublishPointList, userLogin, security , permittedAction, permittedOperations, passedRoles ); 575 Map publishPointMap = new HashMap (); 576 Map publishPointMapAll = new HashMap (); 577 Iterator it = publishPointList.iterator(); 578 while (it.hasNext()) { 579 String [] arr = (String [])it.next(); 583 String contentId = (String )arr[0]; 584 String description = (String )arr[1]; 585 List subPointList = new ArrayList (); 586 Object nullObj = null; 587 Object [] subArr = {contentId, subPointList, description, nullObj}; 588 publishPointMap.put(contentId, subArr); 589 publishPointMapAll.put(contentId, contentId); 590 List subPublishPointList = getAllPublishPoints( delegator, contentId ); 591 Iterator it2 = subPublishPointList.iterator(); 592 while (it2.hasNext()) { 593 GenericValue webSitePublishPoint2 = (GenericValue)it2.next(); 597 String contentId2 = (String )webSitePublishPoint2.get("contentId"); 598 String description2 = (String )webSitePublishPoint2.get("templateTitle"); 599 publishPointMapAll.put(contentId2, contentId); 600 Timestamp obj = null; 601 Object [] subArr2 = {contentId2, description2, obj}; 602 subPointList.add(subArr2); 603 } 604 } 605 606 List assocValueList = null; 607 try { 608 List rawAssocValueList = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", targContentId, "contentAssocTypeId", "PUBLISH_LINK")); 609 assocValueList = EntityUtil.filterByDate(rawAssocValueList); 610 } catch(GenericEntityException e) { 611 throw new GeneralException(e.getMessage()); 612 } 613 Map publishedLinkMap = new HashMap (); 614 Iterator it4 = assocValueList.iterator(); 615 while (it4.hasNext()) { 616 GenericValue contentAssoc = (GenericValue)it4.next(); 617 String contentIdTo = contentAssoc.getString("contentIdTo"); 618 String topContentId = (String )publishPointMapAll.get(contentIdTo); 619 Object [] subArr = (Object [])publishPointMap.get(topContentId); 620 if (contentIdTo.equals(topContentId)) { 622 subArr[3] = contentAssoc.get("fromDate"); 623 } else { 624 if (subArr != null) { 625 List subPointList = (List )subArr[1]; 626 Iterator it5 = subPointList.iterator(); 627 Object [] subArr2 = null; 628 while (it5.hasNext()) { 629 subArr2 = (Object [])it5.next(); 630 String contentId5 = (String )subArr2[0]; 631 if (contentId5.equals(contentIdTo)) 632 break; 633 } 634 subArr2[2] = contentAssoc.get("fromDate"); 635 } 636 } 637 } 638 639 List publishedLinkList = new ArrayList (); 640 Set keySet = publishPointMap.keySet(); 641 Iterator it3 = keySet.iterator(); 642 while (it3.hasNext()) { 643 String contentId = (String )it3.next(); 644 Object [] subPointArr = (Object [])publishPointMap.get(contentId); 645 publishedLinkList.add(subPointArr); 646 } 647 return publishedLinkList; 648 } 649 650 public static GenericValue getAuthorContent(GenericDelegator delegator, String contentId) { 651 652 GenericValue authorContent = null; 653 try { 654 List assocTypes = UtilMisc.toList("AUTHOR"); 655 List contentTypes = null; 656 String fromDate = null; 657 String thruDate = null; 658 Map results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, contentId, null, "To", null, null, assocTypes, contentTypes, new Boolean (true), null); 659 List valueList = (List )results.get("entityList"); 660 if (valueList.size() > 0) { 661 GenericValue value = (GenericValue)valueList.get(0); 662 authorContent = delegator.makeValue("Content", null); 663 authorContent.setPKFields(value); 664 authorContent.setNonPKFields(value); 665 } 667 } catch(GenericEntityException e) { 668 } catch(MiniLangException e2) { 669 } 670 671 return authorContent; 672 } 673 674 public static List getPermittedDepartmentPoints(GenericDelegator delegator, List allDepartmentPoints, GenericValue userLogin, Security security, String permittedAction, String permittedOperations, String passedRoles) throws GeneralException { 675 676 List permittedDepartmentPointList = new ArrayList (); 677 678 Iterator it = allDepartmentPoints.iterator(); 680 while(it.hasNext()) { 681 GenericValue content = (GenericValue)it.next(); 682 String contentId = (String )content.get("contentId"); 683 String contentName = (String )content.get("contentName"); 684 String statusId = null; 685 String entityAction = permittedAction; 686 if (entityAction == null) 687 entityAction = "_ADMIN"; 688 List passedPurposes = UtilMisc.toList("ARTICLE"); 689 List roles = StringUtil.split(passedRoles, "|"); 690 List targetOperationList = new ArrayList (); 691 if (UtilValidate.isEmpty(permittedOperations)) { 692 targetOperationList.add("CONTENT" + entityAction); 693 } else { 694 targetOperationList = StringUtil.split(permittedOperations, "|"); 695 } 696 Map results = null; 697 results = EntityPermissionChecker.checkPermission(content, statusId, userLogin, passedPurposes, targetOperationList, roles, delegator, security, entityAction); 699 String permissionStatus = (String )results.get("permissionStatus"); 700 if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) { 701 String [] arr = {contentId,contentName}; 702 permittedDepartmentPointList.add(arr); 703 } 704 } 705 return permittedDepartmentPointList; 706 } 707 708 714 public static List getAllDepartmentContent(GenericDelegator delegator, String parentPubPt) throws GeneralException { 715 716 GenericValue rootContent = null; 717 List relatedPubPts = null; 718 try { 719 rootContent = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", parentPubPt)); 720 relatedPubPts = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentIdTo", parentPubPt, "contentAssocTypeId", "DEPARTMENT")); 722 723 } catch(GenericEntityException e) { 724 throw new GeneralException(e.getMessage()); 725 } 726 List allDepartmentPoints = new ArrayList (); 727 GenericValue departmentContent = null; 728 GenericValue contentAssoc = null; 729 Iterator it = relatedPubPts.iterator(); 730 while (it.hasNext()) { 731 contentAssoc = (GenericValue)it.next(); 732 String pub = (String )contentAssoc.get("contentId"); 733 departmentContent = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", pub)); 734 allDepartmentPoints.add(departmentContent); 735 } 736 return allDepartmentPoints; 737 } 738 739 public static String getUserName(HttpServletRequest request, String userLoginId) throws GenericEntityException { 740 741 String userName = null; 742 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 743 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); 744 GenericValue person = userLogin.getRelatedOneCache("Person"); 745 userName = person.getString("firstName") + " " + person.getString("lastName"); 746 return userName; 747 } 748 749 public static int updateStatsTopDown(GenericDelegator delegator, String contentId, List typeList) throws GenericEntityException { 750 int subLeafCount = 0; 751 GenericValue thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); 752 if (thisContent == null) 753 throw new RuntimeException ("No entity found for id=" + contentId); 754 755 List condList = new ArrayList (); 756 Iterator iterType = typeList.iterator(); 757 while (iterType.hasNext()) { 758 String type = (String )iterType.next(); 759 condList.add(new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, type)); 760 } 761 762 EntityCondition conditionMain = null; 763 if (condList.size() > 0 ) { 764 EntityCondition conditionType = new EntityConditionList(condList, EntityOperator.OR); 765 conditionMain = new EntityConditionList(UtilMisc.toList( new EntityExpr("contentIdTo", EntityOperator.EQUALS, contentId), conditionType), EntityOperator.AND); 766 } else { 767 conditionMain = new EntityExpr("contentIdTo", EntityOperator.EQUALS, contentId); 768 } 769 List listAll = delegator.findByConditionCache("ContentAssoc", conditionMain, null, null); 770 List listFiltered = EntityUtil.filterByDate(listAll); 771 Iterator iter = listFiltered.iterator(); 772 while (iter.hasNext()) { 773 GenericValue contentAssoc = (GenericValue)iter.next(); 774 String subContentId = contentAssoc.getString("contentId"); 775 subLeafCount += updateStatsTopDown(delegator, subContentId, typeList); 776 } 777 778 if (subLeafCount == 0) 780 subLeafCount = 1; 781 thisContent.put("childBranchCount", new Long (listFiltered.size())); 782 thisContent.put("childLeafCount", new Long (subLeafCount)); 783 thisContent.store(); 784 785 return subLeafCount; 786 } 787 788 public static void updateStatsBottomUp(GenericDelegator delegator, String contentId, List typeList, int branchChangeAmount, int leafChangeAmount) throws GenericEntityException { 789 GenericValue thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); 790 if (thisContent == null) 791 throw new RuntimeException ("No entity found for id=" + contentId); 792 793 List condList = new ArrayList (); 794 Iterator iterType = typeList.iterator(); 795 while (iterType.hasNext()) { 796 String type = (String )iterType.next(); 797 condList.add(new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, type)); 798 } 799 800 EntityCondition conditionType = new EntityConditionList(condList, EntityOperator.OR); 801 EntityCondition conditionMain = new EntityConditionList(UtilMisc.toList( new EntityExpr("contentId", EntityOperator.EQUALS, contentId), conditionType), EntityOperator.AND); 802 List listAll = delegator.findByConditionCache("ContentAssoc", conditionMain, null, null); 803 List listFiltered = EntityUtil.filterByDate(listAll); 804 Iterator iter = listFiltered.iterator(); 805 while (iter.hasNext()) { 806 GenericValue contentAssoc = (GenericValue)iter.next(); 807 String contentIdTo = contentAssoc.getString("contentIdTo"); 808 GenericValue contentTo = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentIdTo)); 809 int intLeafCount = 0; 810 Long leafCount = (Long )contentTo.get("childLeafCount"); 811 if (leafCount != null) { 812 intLeafCount = leafCount.intValue(); 813 } 814 contentTo.set("childLeafCount", new Long (intLeafCount + leafChangeAmount)); 815 816 if (branchChangeAmount != 0) { 817 int intBranchCount = 0; 818 Long branchCount = (Long )contentTo.get("childBranchCount"); 819 if (branchCount != null) { 820 intBranchCount = branchCount.intValue(); 821 } 822 contentTo.set("childBranchCount", new Long (intBranchCount + branchChangeAmount)); 823 } 824 contentTo.store(); 825 updateStatsBottomUp(delegator, contentIdTo, typeList, 0, leafChangeAmount); 826 } 827 828 829 return ; 830 } 831 832 } 833 | Popular Tags |