diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactBundle.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactBundle.java index db6c4dcb0..4c208bcbb 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactBundle.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericContactBundle.java @@ -34,27 +34,27 @@ public class GenericContactBundle setContentType(primary.getContentType()); addInstance(primary); - super.setName(primary.getName()); + super.setName(primary.getName()); } public GenericContactBundle(final OID oid) throws DataObjectNotFoundException { - super(oid); + super(oid); } public GenericContactBundle(final BigDecimal id) throws DataObjectNotFoundException { - super(new OID(BASE_DATA_OBJECT_TYPE, id)); + super(new OID(BASE_DATA_OBJECT_TYPE, id)); } public GenericContactBundle(final DataObject dobj) { - super(dobj); + super(dobj); } public GenericContactBundle(final String type) { super(type); } - + /** *

Copy association properties. These are for example the associations * between GenericPerson and GenericContact, or between @@ -76,7 +76,6 @@ public class GenericContactBundle (GenericContactBundle) source; if (PERSON.equals(attribute)) { - final DataCollection persons = (DataCollection) contactBundle. get(PERSON); @@ -85,7 +84,16 @@ public class GenericContactBundle } return true; - } else { + } else if ("organizationalunit".equals(attribute)) { + final DataCollection orgaunits = (DataCollection) contactBundle. + get("organizationalunit"); + + while (orgaunits.next()) { + createOrgaUnitAssoc(orgaunits); + } + + return true; + } else { return super.copyProperty(source, property, copier); } } else { @@ -114,6 +122,28 @@ public class GenericContactBundle } } + private void createOrgaUnitAssoc(final DataCollection orgaunits) { + final GenericOrganizationalUnitBundle draftOrga = + (GenericOrganizationalUnitBundle) DomainObjectFactory. + newInstance(orgaunits.getDataObject()); + final GenericOrganizationalUnitBundle liveOrga = + (GenericOrganizationalUnitBundle) draftOrga. + getLiveVersion(); + + if (liveOrga != null) { + final DataObject link = add("organizationalunit", liveOrga); + + link.set(GenericOrganizationalUnitContactCollection.CONTACT_TYPE, + orgaunits.get( + GenericOrganizationalUnitContactCollection.LINK_CONTACT_TYPE)); + link.set(GenericOrganizationalUnitContactCollection.CONTACT_ORDER, + orgaunits.get( + GenericOrganizationalUnitContactCollection.LINK_CONTACT_ORDER)); + + link.save(); + } + } + public GenericPerson getPerson() { DataCollection collection;