public static Map<String,Object> runPullEntitySync(DispatchContext dctx,Map<String,Object> context){
  LocalDispatcher dispatcher=dctx.getDispatcher();
  Locale locale=(Locale)context.get("locale");
  String entitySyncId=(String)context.get("entitySyncId");
  String remotePullAndReportEntitySyncDataName=(String)context.get("remotePullAndReportEntitySyncDataName");
  Debug.logInfo("Running runPullEntitySync for entitySyncId=" + context.get("entitySyncId"),module);
  boolean gotMoreData=true;
  Timestamp startDate=null;
  Long toCreateInserted=null;
  Long toCreateUpdated=null;
  Long toCreateNotUpdated=null;
  Long toStoreInserted=null;
  Long toStoreUpdated=null;
  Long toStoreNotUpdated=null;
  Long toRemoveDeleted=null;
  Long toRemoveAlreadyDeleted=null;
  while (gotMoreData) {
    gotMoreData=false;
    Map<String,Object> remoteCallContext=new HashMap<String,Object>();
    remoteCallContext.put("entitySyncId",entitySyncId);
    remoteCallContext.put("delegatorName",context.get("remoteDelegatorName"));
    remoteCallContext.put("userLogin",context.get("userLogin"));
    remoteCallContext.put("startDate",startDate);
    remoteCallContext.put("toCreateInserted",toCreateInserted);
    remoteCallContext.put("toCreateUpdated",toCreateUpdated);
    remoteCallContext.put("toCreateNotUpdated",toCreateNotUpdated);
    remoteCallContext.put("toStoreInserted",toStoreInserted);
    remoteCallContext.put("toStoreUpdated",toStoreUpdated);
    remoteCallContext.put("toStoreNotUpdated",toStoreNotUpdated);
    remoteCallContext.put("toRemoveDeleted",toRemoveDeleted);
    remoteCallContext.put("toRemoveAlreadyDeleted",toRemoveAlreadyDeleted);
    try {
      Map<String,Object> result=dispatcher.runSync(remotePullAndReportEntitySyncDataName,remoteCallContext);
      if (ServiceUtil.isError(result)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource,"EntityExtErrorCallingRemotePull",UtilMisc.toMap("remotePullAndReportEntitySyncDataName",remotePullAndReportEntitySyncDataName),locale),null,null,result);
      }
      startDate=(Timestamp)result.get("startDate");
      try {
        if (startDate != null && (!UtilValidate.isEmpty(result.get("valuesToCreate")) || !UtilValidate.isEmpty(result.get("valuesToStore")) || !UtilValidate.isEmpty(result.get("keysToRemove")))) {
          gotMoreData=true;
          List<GenericValue> valuesToCreate=checkList(result.get("valuesToCreate"),GenericValue.class);
          if (valuesToCreate == null)           valuesToCreate=Collections.emptyList();
          List<GenericValue> valuesToStore=checkList(result.get("valuesToStore"),GenericValue.class);
          if (valuesToStore == null)           valuesToStore=Collections.emptyList();
          List<GenericEntity> keysToRemove=checkList(result.get("keysToRemove"),GenericEntity.class);
          if (keysToRemove == null)           keysToRemove=Collections.emptyList();
          Map<String,Object> callLocalStoreContext=UtilMisc.toMap("entitySyncId",entitySyncId,"delegatorName",context.get("localDelegatorName"),"valuesToCreate",valuesToCreate,"valuesToStore",valuesToStore,"keysToRemove",keysToRemove);
          callLocalStoreContext.put("userLogin",context.get("userLogin"));
          Map<String,Object> storeResult=dispatcher.runSync("storeEntitySyncData",callLocalStoreContext);
          if (ServiceUtil.isError(storeResult)) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource,"EntityExtErrorCallingService",locale),null,null,storeResult);
          }
          toCreateInserted=(Long)storeResult.get("toCreateInserted");
          toCreateUpdated=(Long)storeResult.get("toCreateUpdated");
          toCreateNotUpdated=(Long)storeResult.get("toCreateNotUpdated");
          toStoreInserted=(Long)storeResult.get("toStoreInserted");
          toStoreUpdated=(Long)storeResult.get("toStoreUpdated");
          toStoreNotUpdated=(Long)storeResult.get("toStoreNotUpdated");
          toRemoveDeleted=(Long)storeResult.get("toRemoveDeleted");
          toRemoveAlreadyDeleted=(Long)storeResult.get("toRemoveAlreadyDeleted");
        }
      }
 catch (      GenericServiceException e) {
        Debug.logError(e,"Error calling service to store data locally: " + e.toString(),module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource,"EntityExtErrorCallingService",locale) + e.toString());
      }
    }
 catch (    GenericServiceException e) {
      Debug.logError(e,"Exception calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName + "; "+ e.toString(),module);
      return ServiceUtil.returnError(UtilProperties.getMessage(resource,"EntityExtErrorCallingRemotePull",UtilMisc.toMap("remotePullAndReportEntitySyncDataName",remotePullAndReportEntitySyncDataName),locale) + e.toString());
    }
catch (    Throwable t) {
      Debug.logError(t,"Error calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName + "; "+ t.toString(),module);
      return ServiceUtil.returnError(UtilProperties.getMessage(resource,"EntityExtErrorCallingRemotePull",UtilMisc.toMap("remotePullAndReportEntitySyncDataName",remotePullAndReportEntitySyncDataName),locale) + t.toString());
    }
  }
  return ServiceUtil.returnSuccess();
}

public static Map < String , Object > runPullEntitySync ( DispatchContext dctx , Map < String , Object > context ) { LocalDispatcher dispatcher = dctx . getDispatcher ( ) ; Locale locale = ( Locale ) context . get ( "locale" ) ; String entitySyncId = ( String ) context . get ( "entitySyncId" ) ; String remotePullAndReportEntitySyncDataName = ( String ) context . get ( "remotePullAndReportEntitySyncDataName" ) ; Debug . logInfo ( "Running runPullEntitySync for entitySyncId=" + context . get ( "entitySyncId" ) , module ) ; boolean gotMoreData = true ; Timestamp startDate = null ; Long toCreateInserted = null ; Long toCreateUpdated = null ; Long toCreateNotUpdated = null ; Long toStoreInserted = null ; Long toStoreUpdated = null ; Long toStoreNotUpdated = null ; Long toRemoveDeleted = null ; Long toRemoveAlreadyDeleted = null ; while ( gotMoreData ) { gotMoreData = false ; Map < String , Object > remoteCallContext = new HashMap < String , Object > ( ) ; remoteCallContext . put ( "entitySyncId" , entitySyncId ) ; remoteCallContext . put ( "delegatorName" , context . get ( "remoteDelegatorName" ) ) ; remoteCallContext . put ( "userLogin" , context . get ( "userLogin" ) ) ; remoteCallContext . put ( "startDate" , startDate ) ; remoteCallContext . put ( "toCreateInserted" , toCreateInserted ) ; remoteCallContext . put ( "toCreateUpdated" , toCreateUpdated ) ; remoteCallContext . put ( "toCreateNotUpdated" , toCreateNotUpdated ) ; remoteCallContext . put ( "toStoreInserted" , toStoreInserted ) ; remoteCallContext . put ( "toStoreUpdated" , toStoreUpdated ) ; remoteCallContext . put ( "toStoreNotUpdated" , toStoreNotUpdated ) ; remoteCallContext . put ( "toRemoveDeleted" , toRemoveDeleted ) ; remoteCallContext . put ( "toRemoveAlreadyDeleted" , toRemoveAlreadyDeleted ) ; try { Map < String , Object > result = dispatcher . runSync ( remotePullAndReportEntitySyncDataName , remoteCallContext ) ; if ( ServiceUtil . isError ( result ) ) { return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "EntityExtErrorCallingRemotePull" , UtilMisc . toMap ( "remotePullAndReportEntitySyncDataName" , remotePullAndReportEntitySyncDataName ) , locale ) , null , null , result ) ; } startDate = ( Timestamp ) result . get ( "startDate" ) ; try { if ( startDate != null && ( ! UtilValidate . isEmpty ( result . get ( "valuesToCreate" ) ) || ! UtilValidate . isEmpty ( result . get ( "valuesToStore" ) ) || ! UtilValidate . isEmpty ( result . get ( "keysToRemove" ) ) ) ) { gotMoreData = true ; List < GenericValue > valuesToCreate = checkList ( result . get ( "valuesToCreate" ) , GenericValue . class ) ; if ( valuesToCreate == null ) valuesToCreate = Collections . emptyList ( ) ; List < GenericValue > valuesToStore = checkList ( result . get ( "valuesToStore" ) , GenericValue . class ) ; if ( valuesToStore == null ) valuesToStore = Collections . emptyList ( ) ; List < GenericEntity > keysToRemove = checkList ( result . get ( "keysToRemove" ) , GenericEntity . class ) ; if ( keysToRemove == null ) keysToRemove = Collections . emptyList ( ) ; Map < String , Object > callLocalStoreContext = UtilMisc . toMap ( "entitySyncId" , entitySyncId , "delegatorName" , context . get ( "localDelegatorName" ) , "valuesToCreate" , valuesToCreate , "valuesToStore" , valuesToStore , "keysToRemove" , keysToRemove ) ; callLocalStoreContext . put ( "userLogin" , context . get ( "userLogin" ) ) ; Map < String , Object > storeResult = dispatcher . runSync ( "storeEntitySyncData" , callLocalStoreContext ) ; if ( ServiceUtil . isError ( storeResult ) ) { return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "EntityExtErrorCallingService" , locale ) , null , null , storeResult ) ; } toCreateInserted = ( Long ) storeResult . get ( "toCreateInserted" ) ; toCreateUpdated = ( Long ) storeResult . get ( "toCreateUpdated" ) ; toCreateNotUpdated = ( Long ) storeResult . get ( "toCreateNotUpdated" ) ; toStoreInserted = ( Long ) storeResult . get ( "toStoreInserted" ) ; toStoreUpdated = ( Long ) storeResult . get ( "toStoreUpdated" ) ; toStoreNotUpdated = ( Long ) storeResult . get ( "toStoreNotUpdated" ) ; toRemoveDeleted = ( Long ) storeResult . get ( "toRemoveDeleted" ) ; toRemoveAlreadyDeleted = ( Long ) storeResult . get ( "toRemoveAlreadyDeleted" ) ; } } catch ( GenericServiceException e ) { Debug . logError ( e , "Error calling service to store data locally: " + e . toString ( ) , module ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "EntityExtErrorCallingService" , locale ) + e . toString ( ) ) ; } } catch ( GenericServiceException e ) { Debug . logError ( e , "Exception calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName + "; " + e . toString ( ) , module ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "EntityExtErrorCallingRemotePull" , UtilMisc . toMap ( "remotePullAndReportEntitySyncDataName" , remotePullAndReportEntitySyncDataName ) , locale ) + e . toString ( ) ) ; } catch ( Throwable t ) { Debug . logError ( t , "Error calling remote pull and report EntitySync service with name: " + remotePullAndReportEntitySyncDataName + "; " + t . toString ( ) , module ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "EntityExtErrorCallingRemotePull" , UtilMisc . toMap ( "remotePullAndReportEntitySyncDataName" , remotePullAndReportEntitySyncDataName ) , locale ) + t . toString ( ) ) ; } } return ServiceUtil . returnSuccess ( ) ; }
run pull entity sync - pull from remote
