public static Map<String,Object> findRelatedContent(DispatchContext dctx,Map<String,? extends Object> context){
  LocalDispatcher dispatcher=dctx.getDispatcher();
  Map<String,Object> results=FastMap.newInstance();
  GenericValue currentContent=(GenericValue)context.get("currentContent");
  String fromDate=(String)context.get("fromDate");
  String thruDate=(String)context.get("thruDate");
  String toFrom=(String)context.get("toFrom");
  Locale locale=(Locale)context.get("locale");
  if (toFrom == null) {
    toFrom="TO";
  }
 else {
    toFrom=toFrom.toUpperCase();
  }
  List<String> assocTypes=UtilGenerics.checkList(context.get("contentAssocTypeList"));
  List<String> targetOperations=UtilGenerics.checkList(context.get("targetOperationList"));
  List<String> contentTypes=UtilGenerics.checkList(context.get("contentTypeList"));
  List<GenericValue> contentList=null;
  try {
    contentList=ContentWorker.getAssociatedContent(currentContent,toFrom,assocTypes,contentTypes,fromDate,thruDate);
  }
 catch (  GenericEntityException e) {
    return ServiceUtil.returnError(UtilProperties.getMessage(resource,"ContentAssocRetrievingError",UtilMisc.toMap("errorString",e.toString()),locale));
  }
  if (UtilValidate.isEmpty(targetOperations)) {
    results.put("contentList",contentList);
    return results;
  }
  Map<String,Object> serviceInMap=FastMap.newInstance();
  serviceInMap.put("userLogin",context.get("userLogin"));
  serviceInMap.put("targetOperationList",targetOperations);
  serviceInMap.put("entityOperation",context.get("entityOperation"));
  List<GenericValue> permittedList=FastList.newInstance();
  Map<String,Object> permResults=null;
  for (  GenericValue content : contentList) {
    serviceInMap.put("currentContent",content);
    try {
      permResults=dispatcher.runSync("checkContentPermission",serviceInMap);
    }
 catch (    GenericServiceException e) {
      Debug.logError(e,"Problem checking permissions","ContentServices");
      return ServiceUtil.returnError(UtilProperties.getMessage(resource,"ContentPermissionNotGranted",locale));
    }
    String permissionStatus=(String)permResults.get("permissionStatus");
    if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) {
      permittedList.add(content);
    }
  }
  results.put("contentList",permittedList);
  return results;
}

public static Map < String , Object > findRelatedContent ( DispatchContext dctx , Map < String , ? extends Object > context ) { LocalDispatcher dispatcher = dctx . getDispatcher ( ) ; Map < String , Object > results = FastMap . newInstance ( ) ; GenericValue currentContent = ( GenericValue ) context . get ( "currentContent" ) ; String fromDate = ( String ) context . get ( "fromDate" ) ; String thruDate = ( String ) context . get ( "thruDate" ) ; String toFrom = ( String ) context . get ( "toFrom" ) ; Locale locale = ( Locale ) context . get ( "locale" ) ; if ( toFrom == null ) { toFrom = "TO" ; } else { toFrom = toFrom . toUpperCase ( ) ; } List < String > assocTypes = UtilGenerics . checkList ( context . get ( "contentAssocTypeList" ) ) ; List < String > targetOperations = UtilGenerics . checkList ( context . get ( "targetOperationList" ) ) ; List < String > contentTypes = UtilGenerics . checkList ( context . get ( "contentTypeList" ) ) ; List < GenericValue > contentList = null ; try { contentList = ContentWorker . getAssociatedContent ( currentContent , toFrom , assocTypes , contentTypes , fromDate , thruDate ) ; } catch ( GenericEntityException e ) { return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "ContentAssocRetrievingError" , UtilMisc . toMap ( "errorString" , e . toString ( ) ) , locale ) ) ; } if ( UtilValidate . isEmpty ( targetOperations ) ) { results . put ( "contentList" , contentList ) ; return results ; } Map < String , Object > serviceInMap = FastMap . newInstance ( ) ; serviceInMap . put ( "userLogin" , context . get ( "userLogin" ) ) ; serviceInMap . put ( "targetOperationList" , targetOperations ) ; serviceInMap . put ( "entityOperation" , context . get ( "entityOperation" ) ) ; List < GenericValue > permittedList = FastList . newInstance ( ) ; Map < String , Object > permResults = null ; for ( GenericValue content : contentList ) { serviceInMap . put ( "currentContent" , content ) ; try { permResults = dispatcher . runSync ( "checkContentPermission" , serviceInMap ) ; } catch ( GenericServiceException e ) { Debug . logError ( e , "Problem checking permissions" , "ContentServices" ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "ContentPermissionNotGranted" , locale ) ) ; } String permissionStatus = ( String ) permResults . get ( "permissionStatus" ) ; if ( permissionStatus != null && permissionStatus . equalsIgnoreCase ( "granted" ) ) { permittedList . add ( content ) ; } } results . put ( "contentList" , permittedList ) ; return results ; }
findrelatedcontent finds the related
