details: /erp/devel/pi/rev/01959b3e59bd
changeset: 9441:01959b3e59bd
user: Martin Taal <martin.taal <at> openbravo.com>
date: Tue Dec 28 16:10:23 2010 +0100
summary: Fixes issue 15535: Importing client with anonymous references to
tabs with views results in NPE
diffstat:
src/org/openbravo/dal/xml/EntityResolver.java | 27 +++++++++++-
src/org/openbravo/service/db/ClientImportEntityResolver.java | 12 ++++-
src/org/openbravo/service/db/DataImportService.java | 4 +-
3 files changed, 37 insertions(+), 6 deletions(-)
diffs (141 lines):
diff -r bd225d714fa8 -r 01959b3e59bd
src/org/openbravo/dal/xml/EntityResolver.java
--- a/src/org/openbravo/dal/xml/EntityResolver.java Tue Dec 28 11:47:52
2010 +0100
+++ b/src/org/openbravo/dal/xml/EntityResolver.java Tue Dec 28 16:10:23
2010 +0100
@@ -80,6 +80,7 @@
// keeps track of the mapping from id's to objects
private Map<Object, BaseOBObject> data = new HashMap<Object, BaseOBObject>();
+ private Map<String, BaseOBObject> originalIdObjectMapping = new
HashMap<String, BaseOBObject>();
private Map<BaseOBObject, String> objectOriginalIdMapping = new
HashMap<BaseOBObject, String>();
private Client clientZero;
private Organization organizationZero;
@@ -87,7 +88,6 @@
private Client client;
private Organization organization;
private String[] orgNaturalTree;
- private String[] orgIdTree;
private ResolvingMode resolvingMode = ResolvingMode.ALLOW_NOT_EXIST;
private OrganizationStructureProvider organizationStructureProvider;
@@ -96,6 +96,7 @@
void clear() {
data.clear();
+ originalIdObjectMapping.clear();
objectOriginalIdMapping.clear();
}
@@ -131,13 +132,25 @@
if (result != null) {
return result;
}
+ if (result != null) {
+ return result;
+ }
result = searchInstance(entity, id);
}
+ // search using the id if it is a view, note can be wrong as there can
+ // be duplicates in id for older id values, but is the best we can do
+ // at the moment
+ if (result == null && entity.isView()) {
+ result = getObjectUsingOriginalId(id);
+ }
+
if (result != null) {
// found, cache it for future use
data.put(getKey(entityName, id), result);
+ objectOriginalIdMapping.put(result, id);
+ originalIdObjectMapping.put(id, result);
} else {
if (referenced && !isOptionCreateReferencedIfNotFound()) {
throw new EntityNotFoundException("Entity " + entityName + " with id "
+ id + " not found");
@@ -153,6 +166,7 @@
// keep the relation so that ad_ref_data_loaded can be filled
// later
objectOriginalIdMapping.put(result, id);
+ originalIdObjectMapping.put(id, result);
// check if we can keep the id for this one
if (!OBDal.getInstance().exists(entityName, id)) {
@@ -170,6 +184,12 @@
return result;
}
+ protected void addObjectToCaches(String id, String entityName, BaseOBObject
bob) {
+ data.put(getKey(entityName, id), bob);
+ objectOriginalIdMapping.put(bob, id);
+ originalIdObjectMapping.put(id, bob);
+ }
+
protected void setClientOrganization(BaseOBObject bob) {
setClientOrganizationZero();
@@ -258,6 +278,10 @@
return objectOriginalIdMapping.get(bob);
}
+ public BaseOBObject getObjectUsingOriginalId(String id) {
+ return originalIdObjectMapping.get(id);
+ }
+
protected BaseOBObject searchSystem(String id, Entity entity) {
return doSearch(id, entity, "0", "0");
}
@@ -385,7 +409,6 @@
}
protected void setOrganization(Organization organization) {
- orgIdTree = new String[] { organization.getId() };
final Set<String> orgs =
organizationStructureProvider.getNaturalTree(organization.getId());
orgNaturalTree = orgs.toArray(new String[orgs.size()]);
this.organization = organization;
diff -r bd225d714fa8 -r 01959b3e59bd
src/org/openbravo/service/db/ClientImportEntityResolver.java
--- a/src/org/openbravo/service/db/ClientImportEntityResolver.java Tue Dec
28 11:47:52 2010 +0100
+++ b/src/org/openbravo/service/db/ClientImportEntityResolver.java Tue Dec
28 16:10:23 2010 +0100
@@ -91,11 +91,17 @@
result = searchInstance(entity, id);
}
+ // search using the id if it is a view, note can be wrong as there can
+ // be duplicates in id for older id values, but is the best we can do
+ // at the moment
+ if (result == null && entity.isView()) {
+ result = getObjectUsingOriginalId(id);
+ }
+
if (result != null) {
// found, cache it for future use
- getData().put(getKey(entityName, id), result);
+ addObjectToCaches(id, entityName, result);
} else {
-
// not found create a new one
result = (BaseOBObject) OBProvider.getInstance().get(entityName);
@@ -110,7 +116,7 @@
}
// keep it here so it can be found later
- getData().put(getKey(entityName, id), result);
+ addObjectToCaches(id, entityName, result);
}
setClientOrganization(result);
}
diff -r bd225d714fa8 -r 01959b3e59bd
src/org/openbravo/service/db/DataImportService.java
--- a/src/org/openbravo/service/db/DataImportService.java Tue Dec 28
11:47:52 2010 +0100
+++ b/src/org/openbravo/service/db/DataImportService.java Tue Dec 28
16:10:23 2010 +0100
@@ -320,9 +320,11 @@
if (value != null && !value.equals("0")) {
final Entity entity = PrimitiveReferenceHandler.getInstance()
.getPrimitiveReferencedEntity(objectToRepair, p);
+
final BaseOBObject referencedBob = (BaseOBObject)
entityResolver.resolve(
entity.getName(), value, true);
- if (referencedBob == null) {
+
+ if (referencedBob == null || referencedBob.getId() == null) {
if (ir.getErrorMessages() == null) {
ir.setErrorMessages("The object " + objectToRepair
+ " references an object (entity: " + entity + ") with id "
+ value
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits