svn commit: r1804786 - in /ofbiz/ofbiz-framework/trunk/framework: service/dtd/ service/src/main/java/org/apache/ofbiz/service/ webtools/config/ webtools/groovyScripts/service/ webtools/template/service/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

svn commit: r1804786 - in /ofbiz/ofbiz-framework/trunk/framework: service/dtd/ service/src/main/java/org/apache/ofbiz/service/ webtools/config/ webtools/groovyScripts/service/ webtools/template/service/

nmalin
Author: nmalin
Date: Fri Aug 11 12:41:22 2017
New Revision: 1804786

URL: http://svn.apache.org/viewvc?rev=1804786&view=rev
Log:
Implemented: Manage deprecated service in the ModelService (OFBIZ-9558)
When you want to remove a service we add a new xml element <deprecated/> that you can put on the service definition like this

<service name="oldService" ...>
    <deprecated use-instead="newService" since="theReleaseXXX">The reason to move it as deprecated</deprecated>
    <implements service="newService"/>
</service>

A deprecated service generate a warning log each time it is called
When you navigate on webtools a deprecated service is strike in the service list and display deprecated reason on the service definition detail page.

Thanks to Scott, Deepak, Taher and Jacques for sharing on this subject

Modified:
    ofbiz/ofbiz-framework/trunk/framework/service/dtd/services.xsd
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java
    ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml
    ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy
    ofbiz/ofbiz-framework/trunk/framework/webtools/template/service/AvailableServices.ftl

Modified: ofbiz/ofbiz-framework/trunk/framework/service/dtd/services.xsd
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/dtd/services.xsd?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/dtd/services.xsd (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/dtd/services.xsd Fri Aug 11 12:41:22 2017
@@ -44,6 +44,7 @@ under the License.
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="required-permissions"/>
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="implements"/>
                 <xs:element minOccurs="0" ref="metric"/>
+                <xs:element minOccurs="0" maxOccurs="1" ref="deprecated"/>
                 <xs:choice maxOccurs="1" minOccurs="0">
                     <xs:choice minOccurs="0" maxOccurs="unbounded">
                         <xs:element ref="auto-attributes"/>
@@ -448,6 +449,19 @@ under the License.
             </xs:simpleType>
         </xs:attribute>
     </xs:attributeGroup>
+    <xs:element name="deprecated">
+        <xs:complexType>
+            <xs:attributeGroup ref="attlist.deprecated"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.deprecated">
+        <xs:attribute name="use-instead" type="xs:string" use="required">
+            <xs:annotation><xs:documentation>Precise the service who replace now the current</xs:documentation></xs:annotation>
+        </xs:attribute>
+        <xs:attribute name="since" type="xs:string" use="optional">
+            <xs:annotation><xs:documentation>Precise the ofbiz release when this service has been set to deprecated</xs:documentation></xs:annotation>
+        </xs:attribute>
+    </xs:attributeGroup>
     <xs:element name="override">
         <xs:complexType>
             <xs:sequence>

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java Fri Aug 11 12:41:22 2017
@@ -198,6 +198,11 @@ public class ModelService extends Abstra
     /** Internal Service Group */
     public GroupModel internalGroup = null;
 
+    /**Deprecated information*/
+    public String deprecatedUseInstead = null;
+    public String deprecatedSince = null;
+    public String deprecatedReason = null;
+
     /** Context Information, a Map of parameters used by the service, contains ModelParam objects */
     protected Map<String, ModelParam> contextInfo = new LinkedHashMap<String, ModelParam>();
 
@@ -1215,6 +1220,23 @@ public class ModelService extends Abstra
         }
     }
 
+    /**
+     * if the service is declare as deprecated, create a log warning with the reason
+     */
+    public void informIfDeprecated() {
+        if (this.deprecatedUseInstead != null) {
+            StringBuilder informMsg = new StringBuilder("DEPRECATED: the service ")
+                    .append(name).append( " has been deprecated and replaced by ").append(deprecatedUseInstead);
+            if (this.deprecatedSince != null) {
+                informMsg.append(", since ").append(deprecatedSince);
+            }
+            if (deprecatedReason != null) {
+                informMsg.append(" because '").append(deprecatedReason).append("'");
+            }
+            Debug.logWarning(informMsg.toString(), module);
+        }
+    }
+
     public Document toWSDL(String locationURI) throws WSDLException {
         WSDLFactory factory = WSDLFactory.newInstance();
         Definition def = factory.newDefinition();

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java Fri Aug 11 12:41:22 2017
@@ -282,6 +282,7 @@ public class ModelServiceReader implemen
         this.createAutoAttrDefs(serviceElement, service);
         this.createAttrDefs(serviceElement, service);
         this.createOverrideDefs(serviceElement, service);
+        this.createDeprecated(serviceElement, service);
         // Get metrics.
         Element metricsElement = UtilXml.firstChildElement(serviceElement, "metric");
         if (metricsElement != null) {
@@ -686,6 +687,16 @@ public class ModelServiceReader implemen
         }
     }
 
+    private void createDeprecated(Element baseElement, ModelService service) {
+        Element deprecated = UtilXml.firstChildElement(baseElement, "deprecated");
+        if (deprecated != null) {
+            service.deprecatedUseInstead = deprecated.getAttribute("use-instead");
+            service.deprecatedSince = deprecated.getAttribute("since");
+            service.deprecatedReason = UtilXml.elementValue(deprecated);
+            service.informIfDeprecated();
+        }
+    }
+
     private void addValidators(Element attribute, ModelParam param) {
         List<? extends Element> validateElements = UtilXml.childElementList(attribute, "type-validate");
         if (UtilValidate.isNotEmpty(validateElements)) {

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java Fri Aug 11 12:41:22 2017
@@ -290,6 +290,7 @@ public class ServiceDispatcher {
             eventMap = ServiceEcaUtil.getServiceEventMap(modelService.name);
             engine = this.getGenericEngine(modelService.engineName);
 
+            modelService.informIfDeprecated();
 
             // set IN attributes with default-value as applicable
             modelService.updateDefaultValues(context, ModelService.IN_PARAM);

Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/config/WebtoolsUiLabels.xml Fri Aug 11 12:41:22 2017
@@ -1623,6 +1623,14 @@
         <value xml:lang="zh">删除这个值</value>
         <value xml:lang="zh-TW">刪除這個值</value>
     </property>
+    <property key="WebtoolsDeprecated">
+        <value xml:lang="en">Deprecated</value>
+        <value xml:lang="fr">Périmé</value>
+    </property>
+    <property key="WebtoolsDeprecatedUseInstead">
+        <value xml:lang="en">Use instead</value>
+        <value xml:lang="fr">Utilisez en remplacement</value>
+    </property>
     <property key="WebtoolsDispatcherName">
         <value xml:lang="de">Dispatcher-Name</value>
         <value xml:lang="en">Dispatcher Name</value>

Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy Fri Aug 11 12:41:22 2017
@@ -408,6 +408,9 @@ if (selectedService) {
         curServiceMap.implServices = implServices
         curServiceMap.useTrans = useTrans
         curServiceMap.maxRetry = maxRetry
+        curServiceMap.deprecatedUseInstead = curServiceModel.deprecatedUseInstead
+        curServiceMap.deprecatedSince = curServiceModel.deprecatedSince
+        curServiceMap.deprecatedReason = curServiceModel.deprecatedReason
 
         allParamsList = new ArrayList(3)
 
@@ -563,6 +566,7 @@ if (!selectedService) {
             curServiceMap.location = location
             curServiceMap.definitionLocation = curServiceModel.definitionLocation.replaceFirst("file:/" + System.getProperty("ofbiz.home") + "/", "")
             curServiceMap.requireNewTransaction = requireNewTransaction
+            curServiceMap.deprecated = curServiceModel.deprecatedUseInstead
 
             servicesList.add(curServiceMap)
             servicesFoundCount++

Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/template/service/AvailableServices.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/service/AvailableServices.ftl?rev=1804786&r1=1804785&r2=1804786&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/template/service/AvailableServices.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/template/service/AvailableServices.ftl Fri Aug 11 12:41:22 2017
@@ -92,6 +92,26 @@ under the License.
       </div>
     </div>
 
+    <#if selectedServiceMap.deprecatedUseInstead?has_content>
+    <div class="screenlet">
+      <div class="screenlet-title-bar">
+        <h3>${uiLabelMap.WebtoolsWarningLogLevel?upper_case} : ${uiLabelMap.WebtoolsDeprecated}</h3>
+      </div>
+        <table class="basic-table" cellspacing='0'>
+          <tr>
+            <td class="label">${uiLabelMap.WebtoolsDeprecatedUseInstead}</td>
+            <td>${selectedServiceMap.deprecatedUseInstead}</td>
+            <td class="label">${uiLabelMap.CommonSince}</td>
+            <td>${selectedServiceMap.deprecatedSince}</td>
+          </tr>
+          <tr>
+            <td class="label">${uiLabelMap.CommonReason}</td>
+            <td colspan="3">${selectedServiceMap.deprecatedReason}</td>
+          </tr>
+        </table>
+    </div>
+    </#if>
+
     <div class="screenlet">
       <div class="screenlet-title-bar">
         <h3>${uiLabelMap.SecurityGroups}</h3>
@@ -360,7 +380,7 @@ under the License.
         <#assign alt_row = false>
         <#list servicesList as service>
           <tr<#if alt_row> class="alternate-row"</#if>>
-            <td><a href='<@ofbizUrl>${url}?sel_service_name=${service.serviceName}</@ofbizUrl>'>${service.serviceName}</a></td>
+            <td><#if service.deprecated?has_content><strike></#if><a href='<@ofbizUrl>${url}?sel_service_name=${service.serviceName}</@ofbizUrl>'>${service.serviceName}</a><#if service.deprecated?has_content></strike> @deprecated</#if></td>
             <td><a href='<@ofbizUrl>${url}?constraint=engine_name@${service.engineName?default(uiLabelMap.CommonNA)}</@ofbizUrl>'>${service.engineName}</a></td>
             <td><a href='<@ofbizUrl>${url}?constraint=default_entity_name@${service.defaultEntityName?default(uiLabelMap.CommonNA)}</@ofbizUrl>'>${service.defaultEntityName}</a></td>
             <td>${service.invoke}</td>


Loading...