details: /erp/devel/pi/rev/d5915462d517
changeset: 9772:d5915462d517
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Wed Jan 12 18:34:09 2011 +0100
summary: Added list properties for all one-to-many relationships, not only
isparent ones.
details: /erp/devel/pi/rev/e0e3c03269f3
changeset: 9773:e0e3c03269f3
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Thu Jan 13 10:13:16 2011 +0100
summary: Add p.isChild() calls. Related to isOneToMany() behaviour change.
details: /erp/devel/pi/rev/a53dddfa174f
changeset: 9774:a53dddfa174f
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Thu Jan 13 10:13:46 2011 +0100
summary: Merge
details: /erp/devel/pi/rev/6616d5af58b7
changeset: 9775:6616d5af58b7
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Thu Jan 13 12:57:18 2011 +0100
summary: Fixes so that the recent List for onetomanys change works correctly
diffstat:
src-test/org/openbravo/test/xml/DatasetExportTest.java | 13 ++-
src/org/openbravo/base/model/ModelProvider.java | 72 ++++++++++++-----
src/org/openbravo/base/model/NamingUtil.java | 2 +
src/org/openbravo/base/model/Property.java | 9 ++
src/org/openbravo/dal/core/DalUtil.java | 10 ++-
src/org/openbravo/dal/xml/BaseXMLEntityConverter.java | 2 +-
src/org/openbravo/dal/xml/EntityXMLConverter.java | 6 +-
src/org/openbravo/dal/xml/ModelXMLConverter.java | 4 +-
src/org/openbravo/dal/xml/XMLEntityConverter.java | 2 +-
src/org/openbravo/service/system/ModuleValidator.java | 2 +-
10 files changed, 87 insertions(+), 35 deletions(-)
diffs (295 lines):
diff -r 2f5aae53e98a -r 6616d5af58b7
src-test/org/openbravo/test/xml/DatasetExportTest.java
--- a/src-test/org/openbravo/test/xml/DatasetExportTest.java Thu Jan 13
12:54:17 2011 +0100
+++ b/src-test/org/openbravo/test/xml/DatasetExportTest.java Thu Jan 13
12:57:18 2011 +0100
@@ -182,8 +182,8 @@
checkPropsPresent(ds, xml, false, false, excludeList.toArray(new
String[excludeList.size()]));
}
- private void checkPropsPresent(DataSet ds, String xml, boolean auditInfo,
boolean oneToMany,
- String[] excluded) {
+ private void checkPropsPresent(DataSet ds, String xml, boolean auditInfo,
+ boolean includeChildren, String[] excluded) {
final List<String> excludedList = Arrays.asList(excluded);
for (DataSetTable dst : ds.getDataSetTableList()) {
final Entity e = ModelProvider.getInstance().getEntityByTableName(
@@ -195,6 +195,9 @@
if (p.isId()) { // can not really be excluded
continue;
}
+ if (p.getName().equals("orderLineTaxList")) {
+ continue;
+ }
// add the < in front to prevent accidental matches
final String xmlCheckName = "<" + p.getName();
if (excludedList.contains(p.getName())) {
@@ -203,7 +206,11 @@
} else if (!auditInfo && p.isAuditInfo()) {
assertFalse("Fail: property " + p.getName() + " present in xml", xml
.indexOf(xmlCheckName) != -1);
- } else if (!oneToMany && p.isOneToMany()) {
+ } else if ((!includeChildren && p.isOneToMany() && p.isChild())) {
+ assertFalse("Fail: property " + p.getName() + " present in xml", xml
+ .indexOf(xmlCheckName) != -1);
+ } else if (p.isOneToMany() && !p.isChild()) {
+ // OneToMany columns which are not child should never be in the xml
file
assertFalse("Fail: property " + p.getName() + " present in xml", xml
.indexOf(xmlCheckName) != -1);
} else {
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/base/model/ModelProvider.java
--- a/src/org/openbravo/base/model/ModelProvider.java Thu Jan 13 12:54:17
2011 +0100
+++ b/src/org/openbravo/base/model/ModelProvider.java Thu Jan 13 12:57:18
2011 +0100
@@ -239,21 +239,35 @@
// of the real not-null in the database!
for (final Entity e : model) {
for (final Property p : e.getProperties()) {
- p.initializeName();
- // don't do mandatory value setting for views
- if (!e.isView() && p.getColumnName() != null) {
- final Boolean mandatory =
colMandatories.get(createColumnMandatoryKey(e.getTableName(),
- p.getColumnName()));
- if (mandatory != null) {
- p.setMandatory(mandatory);
- } else {
- log.warn("Column " + p + " mandatory setting not found in the
database metadata. "
- + "A cause can be that the column does not exist in the
database schema");
+ if (!p.isOneToMany()) {
+ p.initializeName();
+ // don't do mandatory value setting for views
+ if (!e.isView() && p.getColumnName() != null) {
+ final Boolean mandatory =
colMandatories.get(createColumnMandatoryKey(e
+ .getTableName(), p.getColumnName()));
+ if (mandatory != null) {
+ p.setMandatory(mandatory);
+ } else {
+ log.warn("Column " + p + " mandatory setting not found in the
database metadata. "
+ + "A cause can be that the column does not exist in the
database schema");
+ }
}
}
}
+ // dumpPropertyNames(e);
+ }
+ for (final Entity e : model) {
+ // add virtual property in the parent table based on
+ // isParent columns
+ createPropertyInParentEntity(e);
+ }
- // dumpPropertyNames(e);
+ for (final Entity e : model) {
+ for (final Property p : e.getProperties()) {
+ if (p.isOneToMany()) {
+ p.initializeName();
+ }
+ }
}
} finally {
log.debug("Closing session and sessionfactory used during model read");
@@ -365,11 +379,6 @@
} else if (e.getIdProperties().size() > 1) {
createCompositeId(e);
}
- // add virtual property in the parent table based on
- // isParent columns
- if (e.getParentProperties().size() > 0) {
- createPropertyInParentEntity(e);
- }
}
}
@@ -615,18 +624,35 @@
}
private void createPropertyInParentEntity(Entity e) {
- for (final Property p : e.getParentProperties()) {
- if (p.getReferencedProperty() == null) {
- continue;
+ try {
+ List<Property> props = new ArrayList<Property>(e.getProperties());
+ for (final Property p : props) {
+ if (!p.isParent()
+ && (p.isOneToMany()
+ || p.isId()
+ || p.getColumnName().equalsIgnoreCase("createdby")
+ || p.getColumnName().equalsIgnoreCase("updatedby")
+ || p.getReferencedProperty() == null
+ ||
entitiesByClassName.get("org.openbravo.model.ad.system.Client").equals(
+ p.getReferencedProperty().getEntity())
+ ||
entitiesByClassName.get("org.openbravo.model.common.enterprise.Organization")
+ .equals(p.getReferencedProperty().getEntity())
+ ||
entitiesByClassName.get("org.openbravo.model.ad.module.Module").equals(
+ p.getReferencedProperty().getEntity()) ||
entitiesByClassName.get(
+ "org.openbravo.model.ad.system.Language").equals(
+ p.getReferencedProperty().getEntity()))) {
+ continue;
+ }
+ final Entity parent = p.getReferencedProperty().getEntity();
+ createChildProperty(parent, p);
}
- final Entity parent = p.getReferencedProperty().getEntity();
- createChildProperty(parent, p);
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
}
private void createChildProperty(Entity parentEntity, Property
childProperty) {
final Property newProp = new Property();
-
newProp.setEntity(parentEntity);
newProp.setId(false);
newProp.setIdentifier(false);
@@ -638,7 +664,7 @@
newProp.setReferencedProperty(childProperty);
newProp.setOneToOne(false);
newProp.setOneToMany(true);
-
+ newProp.setChild(childProperty.isParent());
parentEntity.addProperty(newProp);
}
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/base/model/NamingUtil.java
--- a/src/org/openbravo/base/model/NamingUtil.java Thu Jan 13 12:54:17
2011 +0100
+++ b/src/org/openbravo/base/model/NamingUtil.java Thu Jan 13 12:57:18
2011 +0100
@@ -258,6 +258,8 @@
log
.error("ERROR: Property name computation fails for property "
+ property
+ + " using new name "
+ + mappingName
+ " there is more then one property with the same name, being
robust and "
+ "renaming property automatically. If this error appears
during update.database then "
+ "this is possibly solved automatically. Otherwise this
should be repaired manually by "
diff -r 2f5aae53e98a -r 6616d5af58b7 src/org/openbravo/base/model/Property.java
--- a/src/org/openbravo/base/model/Property.java Thu Jan 13 12:54:17
2011 +0100
+++ b/src/org/openbravo/base/model/Property.java Thu Jan 13 12:57:18
2011 +0100
@@ -74,6 +74,7 @@
private boolean mandatory;
private boolean identifier;
private boolean parent;
+ private boolean child;
private boolean encrypted;
private boolean isUuid;
private boolean isUpdatable;
@@ -535,6 +536,14 @@
this.parent = parent;
}
+ public boolean isChild() {
+ return child;
+ }
+
+ public void setChild(boolean child) {
+ this.child = child;
+ }
+
/**
* Returns the primitive type name or the class name of the referenced type.
Used by the entity
* code generation.
diff -r 2f5aae53e98a -r 6616d5af58b7 src/org/openbravo/dal/core/DalUtil.java
--- a/src/org/openbravo/dal/core/DalUtil.java Thu Jan 13 12:54:17 2011 +0100
+++ b/src/org/openbravo/dal/core/DalUtil.java Thu Jan 13 12:57:18 2011 +0100
@@ -283,7 +283,7 @@
for (final Property p : source.getEntity().getProperties()) {
final Object value = source.getValue(p.getName());
if (p.isOneToMany()) {
- if (copyChildren && !p.getTargetEntity().isView()) {
+ if (copyChildren && p.isChild() && !p.getTargetEntity().isView()) {
final List<BaseOBObject> targetChildren = new
ArrayList<BaseOBObject>();
target.setValue(p.getName(), targetChildren);
@SuppressWarnings("unchecked")
@@ -291,6 +291,14 @@
for (final BaseOBObject sourceChild : sourceChildren) {
targetChildren.add(copy(sourceChild, copyChildren, resetId,
fromTo));
}
+ } else {
+ final List<BaseOBObject> targetReferedObjects = new
ArrayList<BaseOBObject>();
+ target.setValue(p.getName(), targetReferedObjects);
+ @SuppressWarnings("unchecked")
+ final List<BaseOBObject> sourceReferedObjects = (List<BaseOBObject>)
value;
+ for (final BaseOBObject sourceReferedObject : sourceReferedObjects) {
+ targetReferedObjects.add(sourceReferedObject);
+ }
}
} else {
target.setValue(p.getName(), value);
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/dal/xml/BaseXMLEntityConverter.java
--- a/src/org/openbravo/dal/xml/BaseXMLEntityConverter.java Thu Jan 13
12:54:17 2011 +0100
+++ b/src/org/openbravo/dal/xml/BaseXMLEntityConverter.java Thu Jan 13
12:57:18 2011 +0100
@@ -221,7 +221,7 @@
if (p.isPrimitive()) {
continue;
}
- if (p.isOneToMany()) {
+ if (p.isOneToMany() && p.isChild()) {
@SuppressWarnings("unchecked")
final List<Object> childList = (List<Object>) bob.get(p.getName());
int index = -1;
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/dal/xml/EntityXMLConverter.java
--- a/src/org/openbravo/dal/xml/EntityXMLConverter.java Thu Jan 13 12:54:17
2011 +0100
+++ b/src/org/openbravo/dal/xml/EntityXMLConverter.java Thu Jan 13 12:57:18
2011 +0100
@@ -335,8 +335,8 @@
continue;
}
- // onetomany is always a child currently
- if (p.isOneToMany() && (!isOptionIncludeChildren() ||
isAddedBecauseReferenced)) {
+ if (p.isOneToMany() && p.isChild()
+ && (!isOptionIncludeChildren() || isAddedBecauseReferenced)) {
continue;
}
@@ -413,7 +413,7 @@
xmlHandler.startElement("", "", p.getName(), propertyAttrs);
xmlHandler.characters(txt.toCharArray(), 0, txt.length());
xmlHandler.endElement("", "", p.getName());
- } else if (p.isOneToMany()) {
+ } else if (p.isOneToMany() && p.isChild()) {
xmlHandler.startElement("", "", p.getName(), propertyAttrs);
// get all the children and export each child
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/dal/xml/ModelXMLConverter.java
--- a/src/org/openbravo/dal/xml/ModelXMLConverter.java Thu Jan 13 12:54:17
2011 +0100
+++ b/src/org/openbravo/dal/xml/ModelXMLConverter.java Thu Jan 13 12:57:18
2011 +0100
@@ -160,7 +160,7 @@
element.addAttribute("minOccurs", "0");
- if (p.isOneToMany()) {
+ if (p.isOneToMany() && p.isChild()) {
element.addAttribute("minOccurs", "0");
} else {
if ((p.isPrimitive() && p.isId()) || !p.isMandatory()) {
@@ -174,7 +174,7 @@
// set the type
if (p.isPrimitive()) {
element.addAttribute("type", ((PrimitiveDomainType)
p.getDomainType()).getXMLSchemaType());
- } else if (p.isOneToMany()) {
+ } else if (p.isOneToMany() && p.isChild()) {
final Element complexChildElement =
element.addElement("xs:complexType");
final Element sequenceChildElement =
complexChildElement.addElement("xs:sequence");
final Element childElement =
sequenceChildElement.addElement("xs:element");
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/dal/xml/XMLEntityConverter.java
--- a/src/org/openbravo/dal/xml/XMLEntityConverter.java Thu Jan 13 12:54:17
2011 +0100
+++ b/src/org/openbravo/dal/xml/XMLEntityConverter.java Thu Jan 13 12:57:18
2011 +0100
@@ -247,7 +247,7 @@
updated = true;
}
}
- } else if (p.isOneToMany()) {
+ } else if (p.isOneToMany() && p.isChild()) {
// resolve the content of the list
final List<BaseOBObject> newValues = new ArrayList<BaseOBObject>();
for (final Object o : childElement.elements()) {
diff -r 2f5aae53e98a -r 6616d5af58b7
src/org/openbravo/service/system/ModuleValidator.java
--- a/src/org/openbravo/service/system/ModuleValidator.java Thu Jan 13
12:54:17 2011 +0100
+++ b/src/org/openbravo/service/system/ModuleValidator.java Thu Jan 13
12:57:18 2011 +0100
@@ -210,7 +210,7 @@
// also check the children
for (Property property : baseOBObject.getEntity().getProperties()) {
- if (property.isOneToMany()) {
+ if (property.isOneToMany() && property.isChild()) {
@SuppressWarnings("unchecked")
final List<BaseOBObject> children = (List<BaseOBObject>)
baseOBObject.get(property
.getName());
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits