You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2008/03/05 08:40:04 UTC

svn commit: r633783 - in /ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/ entity/src/org/ofbiz/entity/model/ service/src/org/ofbiz/service/ service/src/org/ofbiz/service/eca/ webtools/src/org/ofbiz/webtools/ webtools/src/org/ofbiz/webtools/ar...

Author: jonesde
Date: Tue Mar  4 23:40:02 2008
New Revision: 633783

URL: http://svn.apache.org/viewvc?rev=633783&view=rev
Log:
Changed plist export to use XML form, much more friendly to funny characters; a few fixes/improvements too

Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java
    ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java
    ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
    ofbiz/trunk/framework/webtools/widget/EntityForms.xml

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java Tue Mar  4 23:40:02 2008
@@ -557,9 +557,74 @@
         for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
         writer.println(");");
     }
-    public static void writePlistFile(Map<String, Object> eoModelMap, String eomodeldFullPath, String filename) throws FileNotFoundException, UnsupportedEncodingException {
+
+    public static void writePlistPropertyXml(String name, Object value, int indentLevel, PrintWriter writer) {
+        for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+        writer.print("<key>");
+        writer.print(name);
+        writer.println("</key>");
+        if (value instanceof Map) {
+            writePlistPropertyMapXml((Map<String, Object>) value, indentLevel, writer);
+        } else if (value instanceof List) {
+            writePlistPropertyValueListXml((List<Object>) value, indentLevel, writer);
+        } else {
+            for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+            writer.print("<string>");
+            writer.print(value);
+            writer.println("</string>");
+        }
+    }
+    public static void writePlistPropertyMapXml(Map<String, Object> propertyMap, int indentLevel, PrintWriter writer) {
+        for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+        writer.println("<dict>");
+        for (Map.Entry<String, Object> property: propertyMap.entrySet()) {
+            writePlistPropertyXml(property.getKey(), property.getValue(), indentLevel + 1, writer);
+        }
+        for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+        writer.println("</dict>");
+    }
+    public static void writePlistPropertyValueListXml(List<Object> propertyValueList, int indentLevel, PrintWriter writer) {
+        for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+        writer.println("<array>");
+        
+        indentLevel++;
+        Iterator<Object> propertyValueIter = propertyValueList.iterator();
+        while (propertyValueIter.hasNext()) {
+            Object propertyValue = propertyValueIter.next();
+            if (propertyValue instanceof Map) {
+                Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
+                writePlistPropertyMapXml(propertyMap, indentLevel, writer);
+            } else {
+                for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+                writer.print("<string>");
+                writer.print(propertyValue);
+                writer.println("</string>");
+            }
+        }
+        indentLevel--;
+        
+        for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
+        writer.println("</array>");
+    }
+    
+    /**
+     * Writes model information in the Apple EOModelBundle format. 
+     * 
+     * For document structure and definition see: http://developer.apple.com/documentation/InternetWeb/Reference/WO_BundleReference/Articles/EOModelBundle.html
+     * 
+     * @param eoModelMap
+     * @param eomodeldFullPath
+     * @param filename
+     * @throws FileNotFoundException
+     * @throws UnsupportedEncodingException
+     */
+    public static void writePlistFile(Map<String, Object> eoModelMap, String eomodeldFullPath, String filename, boolean useXml) throws FileNotFoundException, UnsupportedEncodingException {
         PrintWriter plistWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, filename)), "UTF-8")));
-        UtilFormatOut.writePlistPropertyMap(eoModelMap, 0, plistWriter, false);
+        if (useXml) {
+            UtilFormatOut.writePlistPropertyMapXml(eoModelMap, 0, plistWriter);
+        } else {
+            UtilFormatOut.writePlistPropertyMap(eoModelMap, 0, plistWriter, false);
+        }
         plistWriter.close();
     }
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Tue Mar  4 23:40:02 2008
@@ -1417,8 +1417,11 @@
         topLevelMap.put("classProperties", classPropertiesList);
         for (ModelField field: this.fields) {
             if (field.getIsAutoCreatedInternal()) continue;
-            
-            classPropertiesList.add(field.getName());
+            if (field.getIsPk()) {
+                classPropertiesList.add(field.getName() + "*");
+            } else {
+                classPropertiesList.add(field.getName());
+            }
         }
         for (ModelRelation relationship: this.relations) {
             if (!entityNameIncludeSet.contains(relationship.getRelEntityName())) continue;
@@ -1438,7 +1441,11 @@
             Map<String, Object> attributeMap = FastMap.newInstance();
             attributesList.add(attributeMap);
             
-            attributeMap.put("name", field.getName());
+            if (field.getIsPk()) {
+                attributeMap.put("name", field.getName() + "*");
+            } else {
+                attributeMap.put("name", field.getName());
+            }
             attributeMap.put("columnName", field.getColName());
             attributeMap.put("valueClassName", fieldType.getJavaType());
 

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java Tue Mar  4 23:40:02 2008
@@ -116,7 +116,7 @@
     }
     
     public String getShortDisplayDescription() {
-        return this.name + "[" + this.type + "," + this.mode + "]" + (optional ? "" : "*"); 
+        return this.name + "[" + this.type + "-" + this.mode + "]" + (optional ? "" : "*"); 
     }
     
     public Object getDefaultValue() {

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java Tue Mar  4 23:40:02 2008
@@ -81,7 +81,7 @@
     }
     
     public String getShortDisplayDescription() {
-        return this.serviceName + "[" + this.serviceMode + (this.persist ? ",persist" : "") + "]";
+        return this.serviceName + "[" + this.serviceMode + (this.persist ? "-persist" : "") + "]";
     }
 
     public boolean runAction(String selfService, DispatchContext dctx, Map<String, Object> context, Map<String, Object> result) throws GenericServiceException {

Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Tue Mar  4 23:40:02 2008
@@ -799,6 +799,8 @@
         String datasourceName = (String) context.get("datasourceName");
         String entityNamePrefix = (String) context.get("entityNamePrefix");
         
+        if (datasourceName == null) datasourceName = "localderby";
+        
         ModelReader reader = dctx.getDelegator().getModelReader();
         
         try {
@@ -857,16 +859,12 @@
                 entitiesMap.put("className", "EOGenericRecord");
                 entitiesMap.put("name", entityName);
             }
-            PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, "index.eomodeld")), "UTF-8")));
-            UtilFormatOut.writePlistPropertyMap(topLevelMap, 0, writer, false);
-            writer.close();
+            UtilFormatOut.writePlistFile(topLevelMap, eomodeldFullPath, "index.eomodeld", true);
             
             // write each <EntityName>.plist file
             for (String curEntityName: entityNames) {
                 ModelEntity modelEntity = reader.getModelEntity(curEntityName);
-                PrintWriter entityWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, curEntityName +".plist")), "UTF-8")));
-                modelEntity.writeEoModelText(entityWriter, entityNamePrefix, datasourceName, entityNames);
-                entityWriter.close();
+                UtilFormatOut.writePlistFile(modelEntity.createEoModelMap(entityNamePrefix, datasourceName, entityNames), eomodeldFullPath, curEntityName +".plist", true);
             }
             
             return ServiceUtil.returnSuccess("Exported eomodeld file for " + entityNames.size() + " entities to: " + eomodeldFullPath);

Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java Tue Mar  4 23:40:02 2008
@@ -237,10 +237,10 @@
         allDiagramEntitiesWithPrefixes.add(this.modelService.name);
         
         // all services that call this service
-        Set<ServiceArtifactInfo> callingServiceList = this.getServicesCallingService();
-        if (callingServiceList != null) {
+        Set<ServiceArtifactInfo> callingServiceSet = this.getServicesCallingService();
+        if (callingServiceSet != null) {
             // set the prefix and add to the all list
-            for (ServiceArtifactInfo callingService: callingServiceList) {
+            for (ServiceArtifactInfo callingService: callingServiceSet) {
                 callingService.setDisplayPrefix("Calling_");
                 allDiagramEntitiesWithPrefixes.add(callingService.getDisplayPrefixedName());
                 allServiceList.add(callingService);
@@ -248,9 +248,9 @@
         }
         
         // all services this service calls
-        Set<ServiceArtifactInfo> calledServiceList = this.getServicesCalledByService();
+        Set<ServiceArtifactInfo> calledServiceSet = this.getServicesCalledByService();
         
-        for (ServiceArtifactInfo calledService: calledServiceList) {
+        for (ServiceArtifactInfo calledService: calledServiceSet) {
             calledService.setDisplayPrefix("Called_");
             allDiagramEntitiesWithPrefixes.add(calledService.getDisplayPrefixedName());
             allServiceList.add(calledService);
@@ -286,20 +286,20 @@
             entitiesMap.put("className", "EOGenericRecord");
             entitiesMap.put("name", entityName);
         }
-        UtilFormatOut.writePlistFile(indexEoModelMap, eomodeldFullPath, "index.eomodeld");
+        UtilFormatOut.writePlistFile(indexEoModelMap, eomodeldFullPath, "index.eomodeld", true);
         
         // write this service description file
-        Map<String, Object> thisServiceEoModelMap = createEoModelMap(allServiceList, allServiceEcaList, useMoreDetailedNames);
-        UtilFormatOut.writePlistFile(thisServiceEoModelMap, eomodeldFullPath, this.getDisplayPrefixedName() + ".plist");
+        Map<String, Object> thisServiceEoModelMap = createEoModelMap(callingServiceSet, calledServiceSet, callingServiceEcaSet, calledServiceEcaSet, useMoreDetailedNames);
+        UtilFormatOut.writePlistFile(thisServiceEoModelMap, eomodeldFullPath, this.getDisplayPrefixedName() + ".plist", true);
 
         // write service description files
-        for (ServiceArtifactInfo callingService: callingServiceList) {
-            Map<String, Object> serviceEoModelMap = callingService.createEoModelMap(UtilMisc.toList(this), null, useMoreDetailedNames);
-            UtilFormatOut.writePlistFile(serviceEoModelMap, eomodeldFullPath, callingService.getDisplayPrefixedName() + ".plist");
-        }
-        for (ServiceArtifactInfo calledService: calledServiceList) {
-            Map<String, Object> serviceEoModelMap = calledService.createEoModelMap(UtilMisc.toList(this), null, useMoreDetailedNames);
-            UtilFormatOut.writePlistFile(serviceEoModelMap, eomodeldFullPath, calledService.getDisplayPrefixedName() + ".plist");
+        for (ServiceArtifactInfo callingService: callingServiceSet) {
+            Map<String, Object> serviceEoModelMap = callingService.createEoModelMap(null, UtilMisc.toSet(this), null, null, useMoreDetailedNames);
+            UtilFormatOut.writePlistFile(serviceEoModelMap, eomodeldFullPath, callingService.getDisplayPrefixedName() + ".plist", true);
+        }
+        for (ServiceArtifactInfo calledService: calledServiceSet) {
+            Map<String, Object> serviceEoModelMap = calledService.createEoModelMap(UtilMisc.toSet(this), null, null, null, useMoreDetailedNames);
+            UtilFormatOut.writePlistFile(serviceEoModelMap, eomodeldFullPath, calledService.getDisplayPrefixedName() + ".plist", true);
         }
         
         // write SECA description files
@@ -313,7 +313,7 @@
                 ecaCallingServiceSet.add(this);
                 
                 Map<String, Object> serviceEcaEoModelMap = callingServiceEca.createEoModelMap(ecaCallingServiceSet, useMoreDetailedNames);
-                UtilFormatOut.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, callingServiceEca.getDisplayPrefixedName() + ".plist");
+                UtilFormatOut.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, callingServiceEca.getDisplayPrefixedName() + ".plist", true);
             }
         }
         for (ServiceEcaArtifactInfo calledServiceEca: calledServiceEcaSet) {
@@ -325,13 +325,15 @@
             ecaCalledServiceSet.add(this);
             
             Map<String, Object> serviceEcaEoModelMap = calledServiceEca.createEoModelMap(ecaCalledServiceSet, useMoreDetailedNames);
-            UtilFormatOut.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, calledServiceEca.getDisplayPrefixedName() + ".plist");
+            UtilFormatOut.writePlistFile(serviceEcaEoModelMap, eomodeldFullPath, calledServiceEca.getDisplayPrefixedName() + ".plist", true);
         }
     }
 
-    public Map<String, Object> createEoModelMap(List<ServiceArtifactInfo> relatedServiceList, List<ServiceEcaArtifactInfo> relatedServiceEcaList, boolean useMoreDetailedNames) {
-        if (relatedServiceList == null) relatedServiceList = FastList.newInstance();
-        if (relatedServiceEcaList == null) relatedServiceEcaList = FastList.newInstance();
+    public Map<String, Object> createEoModelMap(Set<ServiceArtifactInfo> callingServiceSet, Set<ServiceArtifactInfo> calledServiceSet, Set<ServiceEcaArtifactInfo> callingServiceEcaSet, Set<ServiceEcaArtifactInfo> calledServiceEcaSet, boolean useMoreDetailedNames) {
+        if (callingServiceSet == null) callingServiceSet = FastSet.newInstance();
+        if (calledServiceSet == null) calledServiceSet = FastSet.newInstance();
+        if (callingServiceEcaSet == null) callingServiceEcaSet = FastSet.newInstance();
+        if (calledServiceEcaSet == null) calledServiceEcaSet = FastSet.newInstance();
         Map<String, Object> topLevelMap = FastMap.newInstance();
 
         topLevelMap.put("name", this.getDisplayPrefixedName());
@@ -347,10 +349,16 @@
                 classPropertiesList.add(param.name);
             }
         }
-        for (ServiceArtifactInfo sai: relatedServiceList) {
+        for (ServiceArtifactInfo sai: callingServiceSet) {
             classPropertiesList.add(sai.getDisplayPrefixedName());
         }
-        for (ServiceEcaArtifactInfo seai: relatedServiceEcaList) {
+        for (ServiceArtifactInfo sai: calledServiceSet) {
+            classPropertiesList.add(sai.getDisplayPrefixedName());
+        }
+        for (ServiceEcaArtifactInfo seai: callingServiceEcaSet) {
+            classPropertiesList.add(seai.getDisplayPrefixedName());
+        }
+        for (ServiceEcaArtifactInfo seai: calledServiceEcaSet) {
             classPropertiesList.add(seai.getDisplayPrefixedName());
         }
         
@@ -373,26 +381,54 @@
         // relationships
         List<Map<String, Object>> relationshipsMapList = FastList.newInstance();
         
-        for (ServiceArtifactInfo sai: relatedServiceList) {
+        for (ServiceArtifactInfo sai: callingServiceSet) {
             Map<String, Object> relationshipMap = FastMap.newInstance();
             relationshipsMapList.add(relationshipMap);
             
             relationshipMap.put("name", sai.getDisplayPrefixedName());
             relationshipMap.put("destination", sai.getDisplayPrefixedName());
+            relationshipMap.put("isToMany", "N");
+            relationshipMap.put("isMandatory", "Y");
             
             // not sure if we can use these, or need them, for this type of diagram
-            //relationshipMap.put("isToMany", "N");
             //relationshipMap.put("joinSemantic", "EOInnerJoin");
             //relationshipMap.put("joins", joinsMapList);
             //joinsMap.put("sourceAttribute", keyMap.getFieldName());
             //joinsMap.put("destinationAttribute", keyMap.getRelFieldName());
         }
-        for (ServiceEcaArtifactInfo seai: relatedServiceEcaList) {
+        for (ServiceArtifactInfo sai: calledServiceSet) {
+            Map<String, Object> relationshipMap = FastMap.newInstance();
+            relationshipsMapList.add(relationshipMap);
+            
+            relationshipMap.put("name", sai.getDisplayPrefixedName());
+            relationshipMap.put("destination", sai.getDisplayPrefixedName());
+            relationshipMap.put("isToMany", "Y");
+            relationshipMap.put("isMandatory", "Y");
+            
+            // not sure if we can use these, or need them, for this type of diagram
+            //relationshipMap.put("joinSemantic", "EOInnerJoin");
+            //relationshipMap.put("joins", joinsMapList);
+            //joinsMap.put("sourceAttribute", keyMap.getFieldName());
+            //joinsMap.put("destinationAttribute", keyMap.getRelFieldName());
+        }
+        
+        for (ServiceEcaArtifactInfo seai: callingServiceEcaSet) {
+            Map<String, Object> relationshipMap = FastMap.newInstance();
+            relationshipsMapList.add(relationshipMap);
+            
+            relationshipMap.put("name", seai.getDisplayPrefixedName());
+            relationshipMap.put("destination", seai.getDisplayPrefixedName());
+            relationshipMap.put("isToMany", "N");
+            relationshipMap.put("isMandatory", "Y");
+        }
+        for (ServiceEcaArtifactInfo seai: calledServiceEcaSet) {
             Map<String, Object> relationshipMap = FastMap.newInstance();
             relationshipsMapList.add(relationshipMap);
             
             relationshipMap.put("name", seai.getDisplayPrefixedName());
             relationshipMap.put("destination", seai.getDisplayPrefixedName());
+            relationshipMap.put("isToMany", "Y");
+            relationshipMap.put("isMandatory", "Y");
         }
         
         if (relationshipsMapList.size() > 0) {

Modified: ofbiz/trunk/framework/webtools/widget/EntityForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/widget/EntityForms.xml?rev=633783&r1=633782&r2=633783&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/widget/EntityForms.xml (original)
+++ ofbiz/trunk/framework/webtools/widget/EntityForms.xml Tue Mar  4 23:40:02 2008
@@ -23,6 +23,7 @@
 
     <form name="EntityEoModelBundle" type="single" target="exportEntityEoModelBundle" title="">
         <auto-fields-service service-name="exportEntityEoModelBundle"/>
+        <field name="eomodeldFullPath"><text size="100"/></field>
         <field name="entityGroupId">
             <drop-down allow-empty="true">
                 <entity-options entity-name="EntityGroup" description="${entityGroupName}">