svn commit: r630428 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/model/ModelEntity.java webtools/src/org/ofbiz/webtools/WebToolsServices.java

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

svn commit: r630428 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/model/ModelEntity.java webtools/src/org/ofbiz/webtools/WebToolsServices.java

jonesde
Author: jonesde
Date: Sat Feb 23 05:10:50 2008
New Revision: 630428

URL: http://svn.apache.org/viewvc?rev=630428&view=rev
Log:
A number of fixes and improvements to get the EOModelBundle stuff to be loadable in OmniGraffle, now pretty much functional

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
    ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java

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=630428&r1=630427&r2=630428&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 Sat Feb 23 05:10:50 2008
@@ -1393,7 +1393,7 @@
      * @param entityPrefix
      * @param helperName
      */
-    public void writeEoModelText(PrintWriter writer, String entityPrefix, String helperName) {
+    public void writeEoModelText(PrintWriter writer, String entityPrefix, String helperName, Set<String> entityNameIncludeSet) {
         int indent = 4;
         StringBuffer indentStrBuf = new StringBuffer();
         for (int i = 0; i < indent; i++) indentStrBuf.append(' ');
@@ -1467,7 +1467,24 @@
             writer.print(indentString);
             writer.print(indentString);
             writer.print("externalType = ");
-            writer.print(fieldType.getSqlType());
+            String sqlType = fieldType.getSqlType();
+            if (sqlType.indexOf("(") >= 0) {
+                writer.print(sqlType.substring(0, sqlType.indexOf("(")));
+                writer.println(";");
+                
+                // since there is a field length set that
+                writer.print(indentString);
+                writer.print(indentString);
+                writer.print("width = ");
+                String widthStr = sqlType.substring(sqlType.indexOf("(") + 1, sqlType.indexOf(")"));
+                // if there is a comma remove it; the format doesn't seem to support this sort of detail
+                if (widthStr.indexOf(",") >= 0) {
+                    widthStr = widthStr.substring(0, widthStr.indexOf(","));
+                }
+                writer.print(widthStr);
+            } else {
+                writer.print(sqlType);
+            }
             writer.println(";");
             
             writer.print(indentString);
@@ -1505,94 +1522,110 @@
         }
         writer.println(");");
 
-        // attributes
-        writer.print(indentString);
-        writer.println("relationships = (");
-        Iterator<ModelRelation> relRelationshipIter = this.getRelationsIterator();
-        while (relRelationshipIter.hasNext()) {
-            ModelRelation relationship = relRelationshipIter.next();
-
-            writer.print(indentString);
-            writer.println("{");
-            
-            writer.print(indentString);
-            writer.print(indentString);
-            writer.print("name = ");
-            writer.print(relationship.getCombinedName());
-            writer.println(";");
-            
-            writer.print(indentString);
-            writer.print(indentString);
-            writer.print("destination = ");
-            writer.print(relationship.getRelEntityName());
-            writer.println(";");
+        // relationships
+        List<ModelRelation> relRelationshipList = FastList.newInstance();
+        Iterator<ModelRelation> buildRelationshipIter = this.getRelationsIterator();
+        while (buildRelationshipIter.hasNext()) {
+            ModelRelation relationship = buildRelationshipIter.next();
             
-            writer.print(indentString);
-            writer.print(indentString);
-            if ("many".equals(relationship.getType())) {
-                writer.println("isToMany = Y;");
-            } else {
-                writer.println("isToMany = N;");
+            if (entityNameIncludeSet.contains(relationship.getRelEntityName())) {
+                relRelationshipList.add(relationship);
             }
-
-            /* nothing in OFBiz entity models for this yet, but might be nice to add in the future
-            writer.print(indentString);
-            writer.print(indentString);
-            writer.print("isMandatory = ");
-            writer.print();
-            writer.println(";");
-            */
-            
-            writer.print(indentString);
-            writer.print(indentString);
-            writer.println("joinSemantic = EOInnerJoin;");
-            
-            writer.print(indentString);
+        }
+        
+        if (relRelationshipList.size() > 0) {
             writer.print(indentString);
-            writer.println("joins = (");
-            Iterator<ModelKeyMap> keyMapIter = relationship.getKeyMapsIterator();
-            while (keyMapIter.hasNext()) {
-                ModelKeyMap keyMap = keyMapIter.next();
+            writer.println("relationships = (");
+            Iterator<ModelRelation> relRelationshipIter = relRelationshipList.iterator();
+            while (relRelationshipIter.hasNext()) {
+                ModelRelation relationship = relRelationshipIter.next();
+                
+                if (!entityNameIncludeSet.contains(relationship.getRelEntityName())) {
+                    continue;
+                }
 
                 writer.print(indentString);
-                writer.print(indentString);
                 writer.println("{");
                 
                 writer.print(indentString);
                 writer.print(indentString);
+                writer.print("name = ");
+                writer.print(relationship.getCombinedName());
+                writer.println(";");
+                
+                writer.print(indentString);
                 writer.print(indentString);
-                writer.print("sourceAttribute = ");
-                writer.print(keyMap.getFieldName());
+                writer.print("destination = ");
+                writer.print(relationship.getRelEntityName());
                 writer.println(";");
-
+                
                 writer.print(indentString);
                 writer.print(indentString);
+                if ("many".equals(relationship.getType())) {
+                    writer.println("isToMany = Y;");
+                } else {
+                    writer.println("isToMany = N;");
+                }
+
+                /* nothing in OFBiz entity models for this yet, but might be nice to add in the future
+                writer.print(indentString);
                 writer.print(indentString);
-                writer.print("destinationAttribute = ");
-                writer.print(keyMap.getRelFieldName());
+                writer.print("isMandatory = ");
+                writer.print();
                 writer.println(";");
-
+                */
+                
                 writer.print(indentString);
                 writer.print(indentString);
-                if (keyMapIter.hasNext()) {
+                writer.println("joinSemantic = EOInnerJoin;");
+                
+                writer.print(indentString);
+                writer.print(indentString);
+                writer.println("joins = (");
+                Iterator<ModelKeyMap> keyMapIter = relationship.getKeyMapsIterator();
+                while (keyMapIter.hasNext()) {
+                    ModelKeyMap keyMap = keyMapIter.next();
+
+                    writer.print(indentString);
+                    writer.print(indentString);
+                    writer.println("{");
+                    
+                    writer.print(indentString);
+                    writer.print(indentString);
+                    writer.print(indentString);
+                    writer.print("sourceAttribute = ");
+                    writer.print(keyMap.getFieldName());
+                    writer.println(";");
+
+                    writer.print(indentString);
+                    writer.print(indentString);
+                    writer.print(indentString);
+                    writer.print("destinationAttribute = ");
+                    writer.print(keyMap.getRelFieldName());
+                    writer.println(";");
+
+                    writer.print(indentString);
+                    writer.print(indentString);
+                    if (keyMapIter.hasNext()) {
+                        writer.println("},");
+                    } else {
+                        writer.println("}");
+                    }
+                }
+                writer.print(indentString);
+                writer.print(indentString);
+                writer.println(");");
+                
+                writer.print(indentString);
+                if (relRelationshipIter.hasNext()) {
                     writer.println("},");
                 } else {
                     writer.println("}");
                 }
             }
             writer.print(indentString);
-            writer.print(indentString);
             writer.println(");");
-            
-            writer.print(indentString);
-            if (relRelationshipIter.hasNext()) {
-                writer.println("},");
-            } else {
-                writer.println("}");
-            }
         }
-        writer.print(indentString);
-        writer.println(");");
         
         writer.println("}");
     }

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=630428&r1=630427&r2=630428&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Sat Feb 23 05:10:50 2008
@@ -823,6 +823,16 @@
             } else {
                 entityNames.addAll(reader.getEntityNames());
             }
+
+            // remove all view-entity
+            Iterator<String> filterEntityNameIter = entityNames.iterator();
+            while (filterEntityNameIter.hasNext()) {
+                String entityName = filterEntityNameIter.next();
+                ModelEntity modelEntity = reader.getModelEntity(entityName);
+                if (modelEntity instanceof ModelViewEntity) {
+                    filterEntityNameIter.remove();
+                }
+            }
             
             // write the index.eomodeld file
             PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, "index.eomodeld")), "UTF-8")));
@@ -848,7 +858,7 @@
             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);
+                modelEntity.writeEoModelText(entityWriter, entityNamePrefix, datasourceName, entityNames);
                 entityWriter.close();
             }
         } catch (UnsupportedEncodingException e) {