diff --git a/framework/webapp/config/WebappUiLabels.properties b/framework/webapp/config/WebappUiLabels.properties index 0282d92794..185f7d108b 100644 --- a/framework/webapp/config/WebappUiLabels.properties +++ b/framework/webapp/config/WebappUiLabels.properties @@ -39,8 +39,9 @@ coreEvents.invalid_format_time=Invalid format for SERVICE_TIME coreEvents.service_time_already_passed=SERVICE_TIME has already passed coreEvents.invalid_format_interval=Invalid format for SERVICE_INTERVAL coreEvents.invalid_format_count=Invalid format for SERVICE_COUNT -coreEvents.invalid_format_frequency=Invalid format for SERIVCE_FREQUENCY +coreEvents.invalid_format_frequency=Invalid format for SERVICE_FREQUENCY coreEvents.service_dispatcher_exception=Service dispatcher threw an exception +coreEvents.no_fields_in_session=No previous fields found in session coreEvents.service_scheduled=Service has been scheduled coreEvents.must_specify_service_name=You must specify a 'serviceName', and optionally a 'mode' (sync or async, defaults to sync) coreEvents.service_eventhandler_exception=ServiceEventHandler threw an exception diff --git a/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java b/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java index 56fc793081..81f25d6e64 100644 --- a/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java +++ b/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java @@ -23,13 +23,20 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Timestamp; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilHttp; @@ -37,6 +44,7 @@ import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.webapp.control.RequestHandler; import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericValue; import org.ofbiz.security.Security; import org.ofbiz.service.DispatchContext; @@ -397,20 +405,107 @@ public class CoreEvents { request.setAttribute("_ERROR_MESSAGE_", errorBuf.toString()); return "error"; } - + + Map syncServiceResult = null; // schedule service try { - dispatcher.schedule(jobName, poolName, serviceName, serviceContext, startTime, frequency, interval, count, endTime, maxRetry); + if(null!=request.getParameter("_RUN_SYNC_") && request.getParameter("_RUN_SYNC_").equals("Y")){ + syncServiceResult = dispatcher.runSync(serviceName, serviceContext); + }else{ + dispatcher.schedule(jobName, poolName, serviceName, serviceContext, startTime, frequency, interval, count, endTime, maxRetry); + } } catch (GenericServiceException e) { String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.service_dispatcher_exception", locale); request.setAttribute("_ERROR_MESSAGE_", "
  • " + errMsg + e.getMessage()); return "error"; } - + String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.service_scheduled", locale); request.setAttribute("_EVENT_MESSAGE_", errMsg); + if(null!=syncServiceResult){ + request.getSession().setAttribute("_RUN_SYNC_RESULT_", syncServiceResult); + return "sync_success"; + } return "success"; } + + public static String saveServiceResultsToSession(HttpServletRequest request, HttpServletResponse response) { + HttpSession session = request.getSession(); + Locale locale = UtilHttp.getLocale(request); + Map syncServiceResult = (Map)session.getAttribute("_RUN_SYNC_RESULT_"); + if(null==syncServiceResult){ + String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.no_fields_in_session", locale); + request.setAttribute("_ERROR_MESSAGE_", "
  • " + errMsg); + return "error"; + } + + if(null!=request.getParameter("_CLEAR_PREVIOUS_PARAMS_") && request.getParameter("_CLEAR_PREVIOUS_PARAMS_").equalsIgnoreCase("on")) + session.removeAttribute("_SAVED_SYNC_RESULT_"); + + Map serviceFieldsToSave = request.getParameterMap(); + Map savedFields = FastMap.newInstance(); + Set keys = serviceFieldsToSave.keySet(); + Iterator keysItr = keys.iterator(); + + while(keysItr.hasNext()){ + String key = (String)keysItr.next(); + if(null!=serviceFieldsToSave.get(key) && request.getParameter(key).equalsIgnoreCase("on") && !key.equals("_CLEAR_PREVIOUS_PARAMS_")){ + String[] servicePath = key.split("\\|\\|"); + String partialKey = servicePath[servicePath.length-1]; + savedFields.put(partialKey, getObjectFromServicePath(key ,syncServiceResult)); + } + } + if(null!=session.getAttribute("_SAVED_SYNC_RESULT_")){ + Map savedSyncResult = (Map)session.getAttribute("_SAVED_SYNC_RESULT_"); + savedSyncResult.putAll(savedFields); + savedFields = savedSyncResult; + } + session.setAttribute("_SAVED_SYNC_RESULT_", savedFields); + return "success"; + } + + //Tries to return a map, if Object is one of HashMap, GenericEntity, List + public static Object getObjectFromServicePath(String servicePath, Map serviceResult){ + String[] sp = servicePath.split("\\|\\|"); + Object servicePathObject = null; + Map servicePathMap = null; + for(int i=0;i + + + + + + + + + + + + + + + + + + + @@ -540,9 +559,12 @@ under the License. + + + diff --git a/framework/webtools/webapp/webtools/main.ftl b/framework/webtools/webapp/webtools/main.ftl index 21b877e4ff..ba660a089c 100644 --- a/framework/webtools/webapp/webtools/main.ftl +++ b/framework/webtools/webapp/webtools/main.ftl @@ -89,6 +89,7 @@ under the License.
    • ${uiLabelMap.WebtoolsServiceReference}
    • ${uiLabelMap.PageTitleScheduleJob} +
    • ${uiLabelMap.PageTitleRunService}
    • ${uiLabelMap.PageTitleJobList}
    • ${uiLabelMap.PageTitleThreadList}
    • ${uiLabelMap.WebtoolsServiceLog} diff --git a/framework/webtools/webapp/webtools/service/ServiceForms.xml b/framework/webtools/webapp/webtools/service/ServiceForms.xml index 00fe61e5d5..dfcb6089e4 100644 --- a/framework/webtools/webapp/webtools/service/ServiceForms.xml +++ b/framework/webtools/webapp/webtools/service/ServiceForms.xml @@ -44,4 +44,11 @@ under the License. + +
      + + + + +
      diff --git a/framework/webtools/webapp/webtools/service/serviceResult.ftl b/framework/webtools/webapp/webtools/service/serviceResult.ftl new file mode 100644 index 0000000000..643c6ffa09 --- /dev/null +++ b/framework/webtools/webapp/webtools/service/serviceResult.ftl @@ -0,0 +1,45 @@ +<#-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +
      + +
      parameter
      +
      value
      +
      save value?
      + + + <#list serviceResultList as srl> + + <#if srl.hasChild=="Y"> + + <#else> +
      ${srl.key?if_exists}
      + +
      ${srl.value?if_exists}
      +
      + + + + +
       
      +
      Clear previous params?
      +
      + + diff --git a/framework/webtools/webapp/webtools/service/setServiceParameter.ftl b/framework/webtools/webapp/webtools/service/setServiceParameter.ftl index f763abae71..e8c9b6efc1 100644 --- a/framework/webtools/webapp/webtools/service/setServiceParameter.ftl +++ b/framework/webtools/webapp/webtools/service/setServiceParameter.ftl @@ -28,7 +28,7 @@ under the License.
      ${serviceParameter.name} (${serviceParameter.type})
      - + <#if serviceParameter.optional == "N">(required)<#else>(optional) diff --git a/framework/webtools/widget/ServiceScreens.xml b/framework/webtools/widget/ServiceScreens.xml index 5347e419e1..3616ff68b3 100644 --- a/framework/webtools/widget/ServiceScreens.xml +++ b/framework/webtools/widget/ServiceScreens.xml @@ -129,6 +129,21 @@ under the License. + +
      + + +