From e8d61ef0b7ebade8ff4b1f025831cab9affe963d Mon Sep 17 00:00:00 2001 From: "David E. Jones" Date: Fri, 22 Feb 2008 18:17:21 +0000 Subject: [PATCH] Added initial implementation of entity EOModelBundle export, including various utility methods and refactoring and such git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@630279 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/ofbiz/entity/GenericEntity.java | 12 +- .../org/ofbiz/entity/model/ModelEntity.java | 220 +++++++++++++++++- .../org/ofbiz/entity/model/ModelReader.java | 43 ++++ .../org/ofbiz/entity/model/ModelRelation.java | 4 + .../org/ofbiz/entityext/EntityGroupUtil.java | 116 +++++++++ .../synchronization/EntitySyncContext.java | 65 +----- .../config/WebtoolsUiLabels.properties | 1 + framework/webtools/servicedef/services.xml | 16 ++ .../org/ofbiz/webtools/WebToolsServices.java | 88 ++++++- .../webapp/webtools/WEB-INF/controller.xml | 90 ++++--- framework/webtools/webapp/webtools/main.ftl | 8 +- framework/webtools/widget/EntityForms.xml | 35 +++ framework/webtools/widget/EntityScreens.xml | 17 ++ 13 files changed, 595 insertions(+), 120 deletions(-) create mode 100644 framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java create mode 100644 framework/webtools/widget/EntityForms.xml diff --git a/framework/entity/src/org/ofbiz/entity/GenericEntity.java b/framework/entity/src/org/ofbiz/entity/GenericEntity.java index 3f2128cce8..40c2cbd031 100644 --- a/framework/entity/src/org/ofbiz/entity/GenericEntity.java +++ b/framework/entity/src/org/ofbiz/entity/GenericEntity.java @@ -991,11 +991,14 @@ public class GenericEntity extends Observable implements Map, Lo *@param prefix A prefix to put in front of the entity name in the tag name */ public void writeXmlText(PrintWriter writer, String prefix) { - final int indent = 4; + int indent = 4; + StringBuffer indentStrBuf = new StringBuffer(); + for (int i = 0; i < indent; i++) indentStrBuf.append(' '); + String indentString = indentStrBuf.toString(); if (prefix == null) prefix = ""; - for (int i = 0; i < indent; i++) writer.print(' '); + writer.print(indentString); writer.print('<'); writer.print(prefix); writer.print(this.getEntityName()); @@ -1123,7 +1126,8 @@ public class GenericEntity extends Observable implements Map, Lo writer.println('>'); for (Map.Entry entry: cdataMap.entrySet()) { - for (int i = 0; i < (indent << 1); i++) writer.print(' '); + writer.print(indentString); + writer.print(indentString); writer.print('<'); writer.print(entry.getKey()); writer.print(">, Lo } // don't forget to close the entity. - for (int i = 0; i < indent; i++) writer.print(' '); + writer.print(indentString); writer.print(""); diff --git a/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java b/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java index 59a331da5d..a9a9686f13 100644 --- a/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java +++ b/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java @@ -18,6 +18,7 @@ *******************************************************************************/ package org.ofbiz.entity.model; +import java.io.PrintWriter; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; @@ -1378,6 +1379,221 @@ public class ModelEntity extends ModelInfo implements Comparable, S public Element toXmlElement(Document document) { return this.toXmlElement(document, this.getPackageName()); } + + /** + * Writes entity 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 + * + * For examples see the JavaRealEstate.framework and JavaBusinessLogic.framework packages which are in the /Library/Frameworks directory after installing the WebObjects Examples package (get latest version of WebObjects download for this). + * + * This is based on examples and documentation from WebObjects 5.4, downloaded 20080221. + * + * @param writer + * @param entityPrefix + * @param helperName + */ + public void writeEoModelText(PrintWriter writer, String entityPrefix, String helperName) { + int indent = 4; + StringBuffer indentStrBuf = new StringBuffer(); + for (int i = 0; i < indent; i++) indentStrBuf.append(' '); + String indentString = indentStrBuf.toString(); + + if (entityPrefix == null) entityPrefix = ""; + if (helperName == null) helperName = "localderby"; + ModelFieldTypeReader modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperName); + + writer.println('{'); + + writer.print(indentString); + writer.print("externalName = "); + writer.print(this.getTableName(helperName)); + writer.println(";"); + + writer.print(indentString); + writer.print("name = "); + writer.print(this.getEntityName()); + writer.println(";"); + + writer.print(indentString); + writer.println("className = EOGenericRecord;"); + + // for classProperties add field names AND relationship names to get a nice, complete chart + writer.print(indentString); + writer.print("classProperties = ("); + Iterator cpFieldIter = this.getFieldsIterator(); + while (cpFieldIter.hasNext()) { + ModelField field = cpFieldIter.next(); + writer.print(field.getName()); + if (cpFieldIter.hasNext()) writer.print(", "); + } + Iterator cpRelationshipIter = this.getRelationsIterator(); + // put these on a new line if there are any + if (cpRelationshipIter.hasNext()) { + writer.println(","); + writer.print(indentString); + writer.print(indentString); + } + while (cpRelationshipIter.hasNext()) { + ModelRelation relationship = cpRelationshipIter.next(); + writer.print(relationship.getCombinedName()); + if (cpRelationshipIter.hasNext()) writer.print(", "); + } + writer.println(");"); + + // attributes + writer.print(indentString); + writer.println("attributes = ("); + Iterator attrFieldIter = this.getFieldsIterator(); + while (attrFieldIter.hasNext()) { + ModelField field = attrFieldIter.next(); + ModelFieldType fieldType = modelFieldTypeReader.getModelFieldType(field.getType()); + + writer.print(indentString); + writer.println("{"); + + writer.print(indentString); + writer.print(indentString); + writer.print("name = "); + writer.print(field.getName()); + writer.println(";"); + + writer.print(indentString); + writer.print(indentString); + writer.print("columnName = "); + writer.print(field.getColName()); + writer.println(";"); + + writer.print(indentString); + writer.print(indentString); + writer.print("externalType = "); + writer.print(fieldType.getSqlType()); + writer.println(";"); + + writer.print(indentString); + writer.print(indentString); + writer.print("valueClassName = "); + writer.print(fieldType.getJavaType()); + writer.println(";"); + + /* maybe map this one later, probably not needed for diagramming help anyway + writer.print(indentString); + writer.print(indentString); + writer.print("valueType = "); + writer.print(??); + writer.println(";"); + */ + + writer.print(indentString); + if (attrFieldIter.hasNext()) { + writer.println("},"); + } else { + writer.println("}"); + } + } + writer.print(indentString); + writer.println(");"); + + // primaryKeyAttributes + writer.print(indentString); + writer.print("primaryKeyAttributes = ("); + Iterator pkFieldIter = this.getPksIterator(); + while (pkFieldIter.hasNext()) { + ModelField field = pkFieldIter.next(); + writer.print(field.getName()); + if (pkFieldIter.hasNext()) writer.print(", "); + } + writer.println(");"); + + // attributes + writer.print(indentString); + writer.println("relationships = ("); + Iterator 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(";"); + + 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("isMandatory = "); + writer.print(); + writer.println(";"); + */ + + writer.print(indentString); + writer.print(indentString); + writer.println("joinSemantic = EOInnerJoin;"); + + writer.print(indentString); + writer.print(indentString); + writer.println("joins = ("); + Iterator 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.println(");"); + + writer.println("}"); + } } - - diff --git a/framework/entity/src/org/ofbiz/entity/model/ModelReader.java b/framework/entity/src/org/ofbiz/entity/model/ModelReader.java index 1482e11552..a9bae601f0 100644 --- a/framework/entity/src/org/ofbiz/entity/model/ModelReader.java +++ b/framework/entity/src/org/ofbiz/entity/model/ModelReader.java @@ -36,6 +36,7 @@ import org.ofbiz.base.config.MainResourceHandler; import org.ofbiz.base.config.ResourceHandler; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilTimer; +import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntityConfException; @@ -485,6 +486,48 @@ public class ModelReader implements Serializable { } return ec.keySet(); } + + /** Get all entities, organized by package */ + public Map> getEntitiesByPackage(Set packageFilterSet, Set entityFilterSet) throws GenericEntityException { + Map> entitiesByPackage = FastMap.newInstance(); + + //put the entityNames TreeSets in a HashMap by packageName + Iterator ecIter = this.getEntityNames().iterator(); + while (ecIter.hasNext()) { + String entityName = (String) ecIter.next(); + ModelEntity entity = this.getModelEntity(entityName); + String packageName = entity.getPackageName(); + + if (UtilValidate.isNotEmpty(packageFilterSet)) { + boolean skipThis = false; + // does it match any of these? + for (String packageFilter: packageFilterSet) { + boolean foundMatch = false; + if (packageName.contains(packageFilter)) { + foundMatch = true; + } + if (!foundMatch) { + //Debug.logInfo("Not including entity " + entityName + " becuase it is not in the package set: " + packageFilterSet, module); + skipThis = true; + } + } + if (skipThis) continue; + } + if (UtilValidate.isNotEmpty(entityFilterSet) && !entityFilterSet.contains(entityName)) { + //Debug.logInfo("Not including entity " + entityName + " becuase it is not in the entity set: " + entityFilterSet, module); + continue; + } + + TreeSet entities = entitiesByPackage.get(entity.getPackageName()); + if (entities == null) { + entities = new TreeSet(); + entitiesByPackage.put(entity.getPackageName(), entities); + } + entities.add(entityName); + } + + return entitiesByPackage; + } ModelEntity createModelEntity(Element entityElement, UtilTimer utilTimer, ModelInfo def) { if (entityElement == null) return null; diff --git a/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java b/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java index a9908642be..96ca37205c 100644 --- a/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java +++ b/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java @@ -90,6 +90,10 @@ public class ModelRelation extends ModelChild { } } } + + public String getCombinedName() { + return this.title + this.relEntityName; + } /** the title, gives a name/description to the relation */ public String getTitle() { diff --git a/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java b/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java new file mode 100644 index 0000000000..8494a73b2d --- /dev/null +++ b/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * 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. + *******************************************************************************/ +package org.ofbiz.entityext; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javolution.util.FastList; +import javolution.util.FastSet; + +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.model.ModelViewEntity; + +/** + * EntityEcaUtil + */ +public class EntityGroupUtil { + + public static final String module = EntityGroupUtil.class.getName(); + + public static Set getEntityNamesByGroup(String entityGroupId, GenericDelegator delegator) throws GenericEntityException { + Set entityNames = FastSet.newInstance(); + + List entitySyncGroupIncludes = delegator.findByAnd("EntitySyncInclGrpDetailView", UtilMisc.toMap("entityGroupId", entityGroupId)); + + List modelEntities = getModelEntitiesFromRecords(entitySyncGroupIncludes, delegator); + for (ModelEntity modelEntity: modelEntities) { + entityNames.add(modelEntity.getEntityName()); + } + + return entityNames; + } + + public static List getModelEntitiesFromRecords(List entityGroupEntryValues, GenericDelegator delegator) throws GenericEntityException { + List entityModelToUseList = FastList.newInstance(); + + Iterator entityNameIter = delegator.getModelReader().getEntityNamesIterator(); + while (entityNameIter.hasNext()) { + String entityName = (String) entityNameIter.next(); + ModelEntity modelEntity = delegator.getModelEntity(entityName); + + // if view-entity, throw it out + if (modelEntity instanceof ModelViewEntity) { + continue; + } + + // if it doesn't have either or both of the two update stamp fields, throw it out + if (!modelEntity.isField(ModelEntity.STAMP_FIELD) || !modelEntity.isField(ModelEntity.STAMP_TX_FIELD)) { + continue; + } + + // if there are no includes records, always include; otherwise check each one to make sure at least one matches + if (entityGroupEntryValues.size() == 0) { + entityModelToUseList.add(modelEntity); + } else { + // we have different types of include applications: ESIA_INCLUDE, ESIA_EXCLUDE, ESIA_ALWAYS + // if we find an always we can break right there because this will always be include regardless of excludes, etc + // if we find an include or exclude we have to finish going through the rest of them just in case there is something that overrides it (ie an exclude for an include or an always for an exclude) + boolean matchesInclude = false; + boolean matchesExclude = false; + boolean matchesAlways = false; + Iterator entitySyncIncludeIter = entityGroupEntryValues.iterator(); + while (entitySyncIncludeIter.hasNext()) { + GenericValue entitySyncInclude = entitySyncIncludeIter.next(); + String entityOrPackage = entitySyncInclude.getString("entityOrPackage"); + boolean matches = false; + if (entityName.equals(entityOrPackage)) { + matches = true; + } else if (modelEntity.getPackageName().startsWith(entityOrPackage)) { + matches = true; + } + + if (matches) { + if ("ESIA_INCLUDE".equals(entitySyncInclude.getString("applEnumId"))) { + matchesInclude = true; + } else if ("ESIA_EXCLUDE".equals(entitySyncInclude.getString("applEnumId"))) { + matchesExclude = true; + } else if ("ESIA_ALWAYS".equals(entitySyncInclude.getString("applEnumId"))) { + matchesAlways = true; + break; + } + } + } + + if (matchesAlways || (matchesInclude && !matchesExclude)) { + // make sure this log message is not checked in uncommented: + //Debug.log("In runEntitySync adding [" + modelEntity.getEntityName() + "] to list of Entities to sync", module); + entityModelToUseList.add(modelEntity); + } + } + } + + return entityModelToUseList; + } +} diff --git a/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java b/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java index 50a96f1391..e6a3579a4f 100644 --- a/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java +++ b/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java @@ -49,6 +49,7 @@ import org.ofbiz.entity.serialize.XmlSerializer; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entityext.EntityGroupUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GeneralServiceException; import org.ofbiz.service.GenericServiceException; @@ -843,69 +844,13 @@ public class EntitySyncContext { } /** prepare a list of all entities we want to synchronize: remove all view-entities and all entities that don't match the patterns attached to this EntitySync */ - protected List makeEntityModelToUseList() throws GenericEntityException { - List entityModelToUseList = new LinkedList(); - List entitySyncIncludes = entitySync.getRelated("EntitySyncInclude"); - + protected List makeEntityModelToUseList() throws GenericEntityException { + List entitySyncIncludes = entitySync.getRelated("EntitySyncInclude"); // get these ones as well, and just add them to the main list, it will have an extra field but that shouldn't hurt anything in the code below - List entitySyncGroupIncludes = entitySync.getRelated("EntitySyncInclGrpDetailView"); + List entitySyncGroupIncludes = entitySync.getRelated("EntitySyncInclGrpDetailView"); entitySyncIncludes.addAll(entitySyncGroupIncludes); - Iterator entityNameIter = delegator.getModelReader().getEntityNamesIterator(); - while (entityNameIter.hasNext()) { - String entityName = (String) entityNameIter.next(); - ModelEntity modelEntity = delegator.getModelEntity(entityName); - - // if view-entity, throw it out - if (modelEntity instanceof ModelViewEntity) { - continue; - } - - // if it doesn't have either or both of the two update stamp fields, throw it out - if (!modelEntity.isField(ModelEntity.STAMP_FIELD) || !modelEntity.isField(ModelEntity.STAMP_TX_FIELD)) { - continue; - } - - // if there are no includes records, always include; otherwise check each one to make sure at least one matches - if (entitySyncIncludes.size() == 0) { - entityModelToUseList.add(modelEntity); - } else { - // we have different types of include applications: ESIA_INCLUDE, ESIA_EXCLUDE, ESIA_ALWAYS - // if we find an always we can break right there because this will always be include regardless of excludes, etc - // if we find an include or exclude we have to finish going through the rest of them just in case there is something that overrides it (ie an exclude for an include or an always for an exclude) - boolean matchesInclude = false; - boolean matchesExclude = false; - boolean matchesAlways = false; - Iterator entitySyncIncludeIter = entitySyncIncludes.iterator(); - while (entitySyncIncludeIter.hasNext()) { - GenericValue entitySyncInclude = (GenericValue) entitySyncIncludeIter.next(); - String entityOrPackage = entitySyncInclude.getString("entityOrPackage"); - boolean matches = false; - if (entityName.equals(entityOrPackage)) { - matches = true; - } else if (modelEntity.getPackageName().startsWith(entityOrPackage)) { - matches = true; - } - - if (matches) { - if ("ESIA_INCLUDE".equals(entitySyncInclude.getString("applEnumId"))) { - matchesInclude = true; - } else if ("ESIA_EXCLUDE".equals(entitySyncInclude.getString("applEnumId"))) { - matchesExclude = true; - } else if ("ESIA_ALWAYS".equals(entitySyncInclude.getString("applEnumId"))) { - matchesAlways = true; - break; - } - } - } - - if (matchesAlways || (matchesInclude && !matchesExclude)) { - // make sure this log message is not checked in uncommented: - //Debug.log("In runEntitySync adding [" + modelEntity.getEntityName() + "] to list of Entities to sync", module); - entityModelToUseList.add(modelEntity); - } - } - } + List entityModelToUseList = EntityGroupUtil.getModelEntitiesFromRecords(entitySyncIncludes, delegator); if (Debug.infoOn()) Debug.logInfo("In makeEntityModelToUseList for EntitySync with ID [" + entitySync.get("entitySyncId") + "] syncing " + entityModelToUseList.size() + " entities", module); return entityModelToUseList; diff --git a/framework/webtools/config/WebtoolsUiLabels.properties b/framework/webtools/config/WebtoolsUiLabels.properties index 0795d0a960..ddc2bfab22 100644 --- a/framework/webtools/config/WebtoolsUiLabels.properties +++ b/framework/webtools/config/WebtoolsUiLabels.properties @@ -143,6 +143,7 @@ WebtoolsExpireTime=Expire Time WebtoolsExport=Export WebtoolsExportable=Exportable WebtoolsExportFromDataSource=XML Export from DataSource(s) +WebtoolsExportEntityEoModelBundle=Export Entity EOModelBundle WebtoolsFatalLogLevel=Fatal WebtoolsFatalLogLevelTooltip=The Fatal level designates very severe error events that will presumably lead the application to abort. WebtoolsFieldName=Field Name diff --git a/framework/webtools/servicedef/services.xml b/framework/webtools/servicedef/services.xml index ebaf0a2e4d..34ad8181a6 100644 --- a/framework/webtools/servicedef/services.xml +++ b/framework/webtools/servicedef/services.xml @@ -90,17 +90,33 @@ under the License. + Gets the entity reference data - for the entity reference screen. See org.ofbiz.webtools.WebToolsServices.getEntityRefData(). + + Saves specified set of entities to an Apple EOModelBundle file. + See org.ofbiz.webtools.WebToolsServices.exportEoModelBundle(). + Specify either entityPackageName or entityGroupId, or leave both empty for ALL entities in the data model. + + + + + + + + + Performs an entity maintenance security check. Returns hasPermission=true if the user has the ENTITY_MAINT permission. + + Find Jobs diff --git a/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java b/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java index 8b9caa92ba..d082a6eab1 100644 --- a/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java +++ b/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java @@ -25,6 +25,7 @@ import java.util.LinkedList; import java.util.List; import java.util.ArrayList; import java.util.Collection; +import java.util.Set; import java.util.TreeSet; import java.util.Locale; import java.util.Map; @@ -40,6 +41,7 @@ import java.io.OutputStreamWriter; import java.io.FileOutputStream; import java.io.IOException; import java.io.FileNotFoundException; +import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.MalformedURLException; @@ -77,6 +79,7 @@ import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityFindOptions; +import org.ofbiz.entityext.EntityGroupUtil; import org.ofbiz.security.Security; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.LocalDispatcher; @@ -487,7 +490,6 @@ public class WebToolsServices { outdir.mkdir(); } if (outdir.isDirectory() && outdir.canWrite()) { - Iterator passedEntityNames = null; try { ModelReader reader = delegator.getModelReader(); @@ -619,7 +621,7 @@ public class WebToolsServices { Map resultMap = ServiceUtil.returnSuccess(); ModelReader reader = delegator.getModelReader(); - Map packages = FastMap.newInstance(); + Map> entitiesByPackage = FastMap.newInstance(); TreeSet packageNames = new TreeSet(); TreeSet tableNames = new TreeSet(); @@ -635,10 +637,10 @@ public class WebToolsServices { if (UtilValidate.isNotEmpty(ent.getPlainTableName())) { tableNames.add(ent.getPlainTableName()); } - TreeSet entities = (TreeSet) packages.get(ent.getPackageName()); + TreeSet entities = entitiesByPackage.get(ent.getPackageName()); if (entities == null) { entities = new TreeSet(); - packages.put(ent.getPackageName(), entities); + entitiesByPackage.put(ent.getPackageName(), entities); packageNames.add(ent.getPackageName()); } entities.add(eName); @@ -654,7 +656,7 @@ public class WebToolsServices { while (piter.hasNext()) { Map packageMap = FastMap.newInstance(); String pName = (String) piter.next(); - TreeSet entities = (TreeSet) packages.get(pName); + TreeSet entities = entitiesByPackage.get(pName); List> entitiesList = FastList.newInstance(); Iterator e = entities.iterator(); while (e.hasNext()) { @@ -783,6 +785,82 @@ public class WebToolsServices { resultMap.put("packagesList", packagesList); return resultMap; } + + public static Map exportEntityEoModelBundle(DispatchContext dctx, Map context) { + String eomodeldFullPath = (String) context.get("eomodeldFullPath"); + String entityPackageName = (String) context.get("entityPackageName"); + String entityGroupId = (String) context.get("entityGroupId"); + String datasourceName = (String) context.get("datasourceName"); + String entityNamePrefix = (String) context.get("entityNamePrefix"); + + ModelReader reader = dctx.getDelegator().getModelReader(); + + try { + if (!eomodeldFullPath.endsWith(".eomodeld")) { + eomodeldFullPath = eomodeldFullPath + ".eomodeld"; + } + + File outdir = new File(eomodeldFullPath); + if (!outdir.exists()) { + outdir.mkdir(); + } + if (!outdir.isDirectory()) { + return ServiceUtil.returnError("eomodel Full Path is not a directory: " + eomodeldFullPath); + } + if (!outdir.canWrite()) { + return ServiceUtil.returnError("eomodel Full Path is not write-able: " + eomodeldFullPath); + } + + Set entityNames = new TreeSet(); + if (UtilValidate.isNotEmpty(entityPackageName)) { + Map> entitiesByPackage = reader.getEntitiesByPackage(UtilMisc.toSet(entityPackageName), null); + Debug.logInfo("entitiesByPackage = " + entitiesByPackage, module); + if (entitiesByPackage.get(entityPackageName) != null) { + entityNames.addAll(entitiesByPackage.get(entityPackageName)); + } + } else if (UtilValidate.isNotEmpty(entityGroupId)) { + entityNames.addAll(EntityGroupUtil.getEntityNamesByGroup(entityGroupId, dctx.getDelegator())); + } else { + entityNames.addAll(reader.getEntityNames()); + } + + // write the index.eomodeld file + PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(eomodeldFullPath, "index.eomodeld")), "UTF-8"))); + writer.println("{"); + writer.println("EOModelVersion = \"2.1\";"); + writer.println("entities = ("); + Iterator entityNameIter = entityNames.iterator(); + while (entityNameIter.hasNext()) { + String entityName = entityNameIter.next(); + writer.print("{ className = EOGenericRecord; name = "); + writer.print(entityName); + if (entityNameIter.hasNext()) { + writer.println("; },"); + } else { + writer.println("; }"); + } + } + writer.println(");"); + writer.println("}"); + writer.close(); + + // write each .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); + entityWriter.close(); + } + } catch (UnsupportedEncodingException e) { + return ServiceUtil.returnError("ERROR saving file: " + e.toString()); + } catch (FileNotFoundException e) { + return ServiceUtil.returnError("ERROR: file/directory not found: " + e.toString()); + } catch (GenericEntityException e) { + return ServiceUtil.returnError("ERROR: getting entity names: " + e.toString()); + } + + return ServiceUtil.returnSuccess(); + } /** Performs an entity maintenance security check. Returns hasPermission=true * if the user has the ENTITY_MAINT permission. diff --git a/framework/webtools/webapp/webtools/WEB-INF/controller.xml b/framework/webtools/webapp/webtools/WEB-INF/controller.xml index 6fb8b353c3..3205820a53 100644 --- a/framework/webtools/webapp/webtools/WEB-INF/controller.xml +++ b/framework/webtools/webapp/webtools/WEB-INF/controller.xml @@ -126,21 +126,35 @@ under the License. - - - - - + + + + + + + + + + + + + + + + + + + + - @@ -156,95 +170,67 @@ under the License. - + - + - + - - - - - - - - - - - + + + - - - - - - - - - - - - + - - - - - - - - - @@ -252,11 +238,13 @@ under the License. + + @@ -266,6 +254,7 @@ under the License. + @@ -275,6 +264,7 @@ under the License. + @@ -299,6 +289,7 @@ under the License. + @@ -411,6 +402,7 @@ under the License. + @@ -418,7 +410,6 @@ under the License. - @@ -426,7 +417,6 @@ under the License. - @@ -434,7 +424,6 @@ under the License. - @@ -442,7 +431,15 @@ under the License. - + + + + + + + + + @@ -550,7 +547,8 @@ under the License. - + + diff --git a/framework/webtools/webapp/webtools/main.ftl b/framework/webtools/webapp/webtools/main.ftl index d49fbb2a53..78e8d98ed9 100644 --- a/framework/webtools/webapp/webtools/main.ftl +++ b/framework/webtools/webapp/webtools/main.ftl @@ -70,13 +70,15 @@ text-decoration: underline; <#if security.hasPermission("ENTITY_MAINT", session)>
  • ${uiLabelMap.WebtoolsEntityEngineTools}

  • ${uiLabelMap.WebtoolsEntityDataMaintenance}
  • -
  • ${uiLabelMap.WebtoolsEntityReference} - ${uiLabelMap.WebtoolsEntityReferenceStaticVersion}
  • -
  • ${uiLabelMap.WebtoolsEntityReferencePdf}
  • +
  • ${uiLabelMap.WebtoolsEntityReference} - Interactive
  • +
  • ${uiLabelMap.WebtoolsEntityReference} - ${uiLabelMap.WebtoolsEntityReferenceStaticVersion}
  • +
  • ${uiLabelMap.WebtoolsEntityReferencePdf}
  • ${uiLabelMap.PageTitleEntitySQLProcessor}
  • ${uiLabelMap.WebtoolsEntitySyncStatus}
  • ${uiLabelMap.WebtoolsInduceModelXMLFromDatabase}
  • +
  • ${uiLabelMap.WebtoolsExportEntityEoModelBundle}
  • ${uiLabelMap.WebtoolsCheckUpdateDatabase}
  • -
  • Minerva Connection Info
  • + <#-- not using Minerva by default any more
  • Minerva Connection Info
  • --> <#-- want to leave these out because they are only working so-so, and cause people more problems that they solve, IMHO
  • Edit Entity Definitions
  • Generate Entity Model XML (all in one)
  • diff --git a/framework/webtools/widget/EntityForms.xml b/framework/webtools/widget/EntityForms.xml new file mode 100644 index 0000000000..68432f3879 --- /dev/null +++ b/framework/webtools/widget/EntityForms.xml @@ -0,0 +1,35 @@ + + + + + +
    + + + + + + + + + + +
    diff --git a/framework/webtools/widget/EntityScreens.xml b/framework/webtools/widget/EntityScreens.xml index d405fc7b11..7a6e01b454 100644 --- a/framework/webtools/widget/EntityScreens.xml +++ b/framework/webtools/widget/EntityScreens.xml @@ -346,6 +346,23 @@ under the License. + + +
    + + + + + + + + + + + +
    +
    +