Publizieren der Assoziation zwischen GenericPerson(Bundle) und GenericContact(Bundle) nach neuer Methodik.
git-svn-id: https://svn.libreccm.org/ccm/trunk@1548 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
cf4118ee01
commit
a0efd5c1f8
|
|
@ -1,14 +0,0 @@
|
|||
//$Id$
|
||||
|
||||
model com.arsdigita.cms;
|
||||
|
||||
object type PublishedAssociation {
|
||||
composite ContentItem[1..1] draftA = join cms_published_associations.draft_a to cms_items.item_id;
|
||||
composite ContentItem[1..1] draftB = join cms_published_associations.draft_b to cms_items.item_id;
|
||||
String[1..1] propertyA = cms_published_associations.property_a VARCHAR(100);
|
||||
String[1..1] propertyB = cms_published_associations.property_b VARCHAR(100);
|
||||
//composite ContentItem[1..1] pendingA = join cms_published_associations.pending_a to cms_items.item_id;
|
||||
//composite ContentItem[1..1] pendingB = join cms_published_associations.pending_b to cms_items.item_id;
|
||||
Blob[0..1] associationAttributes = cms_published_associations.association_attributes BLOB;
|
||||
object key (draftA, draftB, propertyA, propertyB);
|
||||
}
|
||||
|
|
@ -10,10 +10,11 @@ import com.arsdigita.persistence.metadata.Property;
|
|||
*/
|
||||
public interface AssociationCopier {
|
||||
|
||||
boolean handlesProperty(Property property);
|
||||
void copy(DomainObject source,
|
||||
DomainObject target,
|
||||
DomainObject value,
|
||||
Property property);
|
||||
boolean copyReverseProperty(CustomCopy source,
|
||||
DomainObject target,
|
||||
Property property,
|
||||
DomainObject value,
|
||||
ItemCopier copier);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,104 +0,0 @@
|
|||
package com.arsdigita.cms;
|
||||
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AssociationCopierDefaultImpl implements AssociationCopier {
|
||||
|
||||
final Map<String, HandledProperty> handledProperties =
|
||||
new HashMap<String, HandledProperty>();
|
||||
|
||||
public void addHandledProperty(final String name,
|
||||
final String type,
|
||||
final String reverse,
|
||||
final String reverseType) {
|
||||
final HandledProperty prop = new HandledProperty();
|
||||
prop.setName(name);
|
||||
prop.setType(type);
|
||||
prop.setReverse(reverse);
|
||||
prop.setReverseType(reverseType);
|
||||
handledProperties.put(name, prop);
|
||||
}
|
||||
|
||||
public boolean handlesProperty(final Property property) {
|
||||
return handledProperties.containsKey(property.getName());
|
||||
}
|
||||
|
||||
public void copy(final DomainObject source,
|
||||
final DomainObject target,
|
||||
final DomainObject value,
|
||||
final Property property) {
|
||||
final HandledProperty propData = handledProperties.get(
|
||||
property.getName());
|
||||
if (propData == null) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Illegal call for this method. Property '%s' is not handled"
|
||||
+ "by this AssociationCopier.", property.getName()));
|
||||
}
|
||||
|
||||
//Create PublishedAssociation here.
|
||||
final HandledProperty handledProperty = handledProperties.get(property.
|
||||
getName());
|
||||
if (handledProperty == null) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Property '%s' "
|
||||
+ "is not handled by this AssociationCopier.",
|
||||
property.getName()));
|
||||
}
|
||||
|
||||
final ContentItem sourceItem = (ContentItem) source;
|
||||
final ContentItem valueItem = (ContentItem) value;
|
||||
|
||||
PublishedAssociation.create(sourceItem,
|
||||
valueItem,
|
||||
property.getName(),
|
||||
handledProperty.getReverse());
|
||||
}
|
||||
|
||||
private class HandledProperty {
|
||||
|
||||
private String name;
|
||||
private String type;
|
||||
private String reverse;
|
||||
private String reverseType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getReverse() {
|
||||
return reverse;
|
||||
}
|
||||
|
||||
public void setReverse(String reverse) {
|
||||
this.reverse = reverse;
|
||||
}
|
||||
|
||||
public String getReverseType() {
|
||||
return reverseType;
|
||||
}
|
||||
|
||||
public void setReverseType(String reverseType) {
|
||||
this.reverseType = reverseType;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -371,7 +371,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
|
||||
/**
|
||||
* @return the base PDL object type for this item. Child classes should
|
||||
* override this method to return the correct value
|
||||
* override this method to return the correct value
|
||||
*/
|
||||
@Override
|
||||
public String getBaseDataObjectType() {
|
||||
|
|
@ -382,6 +382,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* Publicized getter method for use by metadata forms.
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -392,8 +393,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
/**
|
||||
* Public setter method for use by metadata forms.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param key param value
|
||||
*/
|
||||
@Override
|
||||
public void set(final String key, final Object value) {
|
||||
|
|
@ -403,8 +403,8 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
/**
|
||||
* Public add for use by metadata forms.
|
||||
*
|
||||
* @param propertyName
|
||||
* @param dobj
|
||||
* @param propertyName param dobj
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -415,8 +415,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
/**
|
||||
* Public remove for use by metadata forms
|
||||
*
|
||||
* @param propertyName
|
||||
* @param dobj
|
||||
* @param propertyName param dobj
|
||||
*/
|
||||
@Override
|
||||
public void remove(String propertyName, DomainObject dobj) {
|
||||
|
|
@ -694,6 +693,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
*
|
||||
* @param includeSelf a
|
||||
* <code>boolean</code> value.
|
||||
*
|
||||
* @return the items on the path to the root folder.
|
||||
*/
|
||||
public ItemCollection getPathInfo(boolean includeSelf) {
|
||||
|
|
@ -761,8 +761,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* <code>true</code> if this item is a
|
||||
* <code>DRAFT</code> version.
|
||||
*
|
||||
* @return
|
||||
* <code>true</code> if this item is a
|
||||
* @return < code>true</code> if this item is a
|
||||
* <code>DRAFT</code> version
|
||||
*/
|
||||
public boolean isDraftVersion() {
|
||||
|
|
@ -800,6 +799,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
*
|
||||
* @return the working version representation of the
|
||||
* <code>ContentItem</code>, possibly this item
|
||||
*
|
||||
* @deprecated use {@link #getDraftVersion()} instead
|
||||
*/
|
||||
public ContentItem getWorkingVersion() {
|
||||
|
|
@ -811,8 +811,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* <code>true</code> if this item is a
|
||||
* <code>PENDING</code> version.
|
||||
*
|
||||
* @return
|
||||
* <code>true</code> if
|
||||
* @return < code>true</code> if
|
||||
* <code>this</code> is one of the pending versions
|
||||
*/
|
||||
public boolean isPendingVersion() {
|
||||
|
|
@ -915,8 +914,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* <code>true</code> if this item is a
|
||||
* <code>LIVE</code> version.
|
||||
*
|
||||
* @return
|
||||
* <code>true</code> if
|
||||
* @return < code>true</code> if
|
||||
* <code>this</code> is the live version
|
||||
*/
|
||||
public boolean isLiveVersion() {
|
||||
|
|
@ -1067,8 +1065,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* not necessarily the live version nor is this method to be confused with
|
||||
* isPublished.
|
||||
*
|
||||
* @return
|
||||
* <code>true<code> if this content item has a live
|
||||
* @return < code>true<code> if this content item has a live
|
||||
* version, or if it <em>is</em> the live version
|
||||
*/
|
||||
public boolean isLive() {
|
||||
|
|
@ -1079,7 +1076,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* Makes an item live or not live.
|
||||
*
|
||||
* @param version the version which should become live, null to make the
|
||||
* item non-live
|
||||
* item non-live
|
||||
*/
|
||||
public void setLive(final ContentItem version) {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
|
|
@ -1143,7 +1140,6 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
|
||||
oldVersion.delete();
|
||||
PublishedLink.refreshOnUnpublish(this);
|
||||
PublishedAssociation.refreshOnUnPublish(this);
|
||||
}
|
||||
|
||||
if (parent instanceof ContentBundle || parent instanceof Folder) {
|
||||
|
|
@ -1172,7 +1168,6 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
save();
|
||||
|
||||
PublishedLink.updateLiveLinks(version);
|
||||
PublishedAssociation.updateLiveAssociations(version);
|
||||
save();
|
||||
|
||||
// publish item (as template or html pages) to the file
|
||||
|
|
@ -1186,9 +1181,9 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
/**
|
||||
* Schedules an item for publication.
|
||||
*
|
||||
* @param cycleDef The lifecycle definition
|
||||
* @param cycleDef The lifecycle definition
|
||||
* @param startDate The time to schedule the start of the lifecycle. If
|
||||
* null, use the current time as the start date.
|
||||
* null, use the current time as the start date.
|
||||
*
|
||||
* @return the new pending version
|
||||
*/
|
||||
|
|
@ -1546,6 +1541,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* 'non-finalness' of this method should be considered deprecated.
|
||||
*
|
||||
* @return the live version for this item
|
||||
*
|
||||
* @see #copyServicesFrom(ContentItem)
|
||||
*/
|
||||
public ContentItem copy() {
|
||||
|
|
@ -1561,10 +1557,11 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* associations from the copy to point to the copies of original items. <p>
|
||||
* NOTE: This method will save the item and all of its unpublished subitems.
|
||||
*
|
||||
* @param newParent The new parent item for this item
|
||||
* @param newParent The new parent item for this item
|
||||
* @param copyServices Copy services if true
|
||||
*
|
||||
* @return the new copy of the item
|
||||
*
|
||||
* @see #copyServicesFrom(ContentItem)
|
||||
*/
|
||||
final public ContentItem copy(final ContentItem newParent,
|
||||
|
|
@ -1617,6 +1614,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* language of the copy.
|
||||
*
|
||||
* @param language
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected ContentItem makeCopy(String language) {
|
||||
|
|
@ -1645,6 +1643,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
*
|
||||
* @param source the
|
||||
* <code>ContentItem</code> whose services will be copied
|
||||
*
|
||||
* @see #copy()
|
||||
*/
|
||||
public void copyServicesFrom(final ContentItem source) {
|
||||
|
|
@ -1660,7 +1659,8 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* subitems.
|
||||
*
|
||||
* @param cycle the lifecycle to use. A null cycle implies that a live
|
||||
* version should be created.
|
||||
* version should be created.
|
||||
*
|
||||
* @return the new pending version for this item
|
||||
*/
|
||||
protected ContentItem createPendingVersion(final Lifecycle cycle) {
|
||||
|
|
@ -1705,10 +1705,12 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
}
|
||||
|
||||
setLive(pending);
|
||||
|
||||
ContentBundle draftBundle = getBundle();
|
||||
ContentBundle liveBundle = pending.getBundle();
|
||||
if (draftBundle != null && liveBundle != null && !liveBundle.
|
||||
isLiveVersion()) {
|
||||
if ((draftBundle != null)
|
||||
&& (liveBundle != null)
|
||||
&& (!liveBundle.isLiveVersion())) {
|
||||
draftBundle.promotePendingVersion(liveBundle);
|
||||
}
|
||||
|
||||
|
|
@ -1842,12 +1844,13 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* <code>false</code> to indicate that the copier should continue to handle
|
||||
* the association normally.
|
||||
*
|
||||
* @param source the source CustomCopy item
|
||||
* @param source the source CustomCopy item
|
||||
* @param property the property to copy
|
||||
* @param copier a temporary class that is able to copy a child item
|
||||
* correctly.
|
||||
* @param copier a temporary class that is able to copy a child item
|
||||
* correctly.
|
||||
*
|
||||
* @return true if the property was copied; false to indicate that regular
|
||||
* metadata-driven methods should be used to copy the property.
|
||||
* metadata-driven methods should be used to copy the property.
|
||||
*/
|
||||
public boolean copyProperty(final CustomCopy source,
|
||||
final Property property,
|
||||
|
|
@ -1884,8 +1887,8 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
if (parent instanceof ContentBundle) {
|
||||
|
||||
final ContentBundle bundle = (ContentBundle) parent;
|
||||
final ContentBundle oldLiveBundle = (ContentBundle) bundle.
|
||||
getPublicVersion();
|
||||
final ContentBundle oldLiveBundle =
|
||||
(ContentBundle) bundle.getPublicVersion();
|
||||
//jensp 2012-03-07 Changes to the ContentBundle were not
|
||||
//published because the ContentBundle was not republished.
|
||||
//Moved the next lines out of the if below to enable
|
||||
|
|
@ -1925,7 +1928,8 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
final ItemCollection instances = oldLiveBundle.
|
||||
getInstances();
|
||||
while (instances.next()) {
|
||||
liveBundle.addInstance(instances.getContentItem());
|
||||
liveBundle.addInstance(
|
||||
instances.getContentItem());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1956,7 +1960,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* processing of services.
|
||||
*
|
||||
* @return true to tell the object copier to stop copying services for this
|
||||
* item, false otherwise
|
||||
* item, false otherwise
|
||||
*/
|
||||
public boolean copyServices(ContentItem srcItem) {
|
||||
return false;
|
||||
|
|
@ -2209,7 +2213,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
* generators returned by this method will may be null. </p>
|
||||
*
|
||||
* @return A list of all extra XML Generators for lists views of this
|
||||
* content item.
|
||||
* content item.
|
||||
*/
|
||||
public List<ExtraXMLGenerator> getExtraListXMLGenerators() {
|
||||
return new ArrayList<ExtraXMLGenerator>();
|
||||
|
|
|
|||
|
|
@ -1,233 +0,0 @@
|
|||
package com.arsdigita.cms;
|
||||
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.Session;
|
||||
import com.arsdigita.persistence.SessionManager;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PublishedAssociation extends DomainObject {
|
||||
|
||||
private static final String DRAFT_A = "draftA";
|
||||
private static final String DRAFT_B = "draftA";
|
||||
private static final String PROPERTY_A = "propertyA";
|
||||
private static final String PROPERTY_B = "propertyB";
|
||||
//private static final String PENDING_A = "pendingA";
|
||||
//private static final String PENDING_B = "pendingA";
|
||||
private static final String ATTRIBUTES = "associationAttributes";
|
||||
public static final String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.PublishedAssociation";
|
||||
|
||||
protected PublishedAssociation() {
|
||||
super(BASE_DATA_OBJECT_TYPE);
|
||||
}
|
||||
|
||||
protected PublishedAssociation(final DataObject dobj) {
|
||||
super(dobj);
|
||||
}
|
||||
|
||||
protected PublishedAssociation(final OID oid) {
|
||||
super(oid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBaseDataObjectType() {
|
||||
return BASE_DATA_OBJECT_TYPE;
|
||||
}
|
||||
|
||||
protected static PublishedAssociation create(final ContentItem draftA,
|
||||
final ContentItem draftB,
|
||||
final String propertyA,
|
||||
final String propertyB) {
|
||||
//Check if the association is already saved.
|
||||
final Session session = SessionManager.getSession();
|
||||
final DataCollection assocsA = session.retrieve(BASE_DATA_OBJECT_TYPE);
|
||||
assocsA.addEqualsFilter(DRAFT_A + ".id", draftA.getID());
|
||||
assocsA.addEqualsFilter(DRAFT_B + ".id", draftB.getID());
|
||||
assocsA.addEqualsFilter(PROPERTY_A, propertyA);
|
||||
assocsA.addEqualsFilter(PROPERTY_B, propertyB);
|
||||
|
||||
if (assocsA.size() == 1) {
|
||||
assocsA.next();
|
||||
final DataObject dobj = assocsA.getDataObject();
|
||||
assocsA.close();
|
||||
return new PublishedAssociation(dobj);
|
||||
} else if (assocsA.size() > 1) {
|
||||
throw new UncheckedWrapperException(
|
||||
"Something very strange has occurred. There is more than "
|
||||
+ "one PublishedAssociation for a association.");
|
||||
}
|
||||
|
||||
//Maybe draftA and draftB are switched
|
||||
final DataCollection assocsB = session.retrieve(BASE_DATA_OBJECT_TYPE);
|
||||
assocsB.addEqualsFilter(DRAFT_A + ".id", draftB.getID());
|
||||
assocsB.addEqualsFilter(DRAFT_B + ".id", draftA.getID());
|
||||
assocsB.addEqualsFilter(PROPERTY_A, propertyB);
|
||||
assocsB.addEqualsFilter(PROPERTY_B, propertyA);
|
||||
|
||||
if (assocsB.size() == 1) {
|
||||
assocsB.next();
|
||||
final DataObject dobj = assocsB.getDataObject();
|
||||
assocsB.close();
|
||||
return new PublishedAssociation(dobj);
|
||||
} else if (assocsB.size() > 1) {
|
||||
throw new UncheckedWrapperException(
|
||||
"Something very strange has occurred. There is more than "
|
||||
+ "one PublishedAssociation for a association.");
|
||||
}
|
||||
|
||||
//No existing entry found, crate new one.
|
||||
|
||||
final PublishedAssociation assoc = new PublishedAssociation();
|
||||
assoc.set(DRAFT_A, draftA);
|
||||
assoc.set(DRAFT_B, draftB);
|
||||
assoc.set(PROPERTY_A, propertyA);
|
||||
assoc.set(PROPERTY_B, PROPERTY_B);
|
||||
|
||||
if (draftA.getObjectType().getProperty(propertyA).isCollection()) {
|
||||
final DataCollection coll = (DataCollection) draftA.get(
|
||||
propertyA + "@link");
|
||||
|
||||
while (coll.next()) {
|
||||
DataObject linkObj = coll.getDataObject();
|
||||
|
||||
if (draftB.getOID().equals(((DataObject) linkObj.getOID().get(
|
||||
propertyA)).getOID())) {
|
||||
assoc.saveAssociationAttributes(linkObj);
|
||||
coll.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assoc.save();
|
||||
|
||||
return assoc;
|
||||
}
|
||||
|
||||
protected static void updateLiveAssociations(final ContentItem item) {
|
||||
final Session session = SessionManager.getSession();
|
||||
final ContentItem draftItem = item.getDraftVersion();
|
||||
final ContentItem liveItem = draftItem.getLiveVersion();
|
||||
|
||||
final DataCollection assocsA = session.retrieve(BASE_DATA_OBJECT_TYPE);
|
||||
assocsA.addEqualsFilter(DRAFT_A + ".id", draftItem.getID());
|
||||
processAssociations(assocsA, liveItem);
|
||||
|
||||
final DataCollection assocsB = session.retrieve(BASE_DATA_OBJECT_TYPE);
|
||||
assocsB.addEqualsFilter(DRAFT_B + ".id", draftItem.getID());
|
||||
processAssociations(assocsB, liveItem);
|
||||
}
|
||||
|
||||
private static void processAssociations(final DataCollection associations,
|
||||
final ContentItem liveItem) {
|
||||
while (associations.next()) {
|
||||
processAssociation(new PublishedAssociation(
|
||||
associations.getDataObject()), liveItem);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processAssociation(
|
||||
final PublishedAssociation association,
|
||||
final ContentItem liveItem) {
|
||||
final ContentItem otherDraft = (ContentItem) association.get(DRAFT_B);
|
||||
final ContentItem otherLive = otherDraft.getLiveVersion();
|
||||
|
||||
if (otherLive != null) {
|
||||
createAssociation(liveItem,
|
||||
(String) association.get(PROPERTY_A),
|
||||
otherLive,
|
||||
(byte[]) association.get(ATTRIBUTES));
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAssociation(final ContentItem itemA,
|
||||
final String propertyA,
|
||||
final ContentItem itemB,
|
||||
final byte[] associationAttributes) {
|
||||
final DataObject association = itemA.add(propertyA, itemB);
|
||||
setAttributesForLiveAssociation(association, associationAttributes);
|
||||
}
|
||||
|
||||
protected static void refreshOnUnPublish(final ContentItem item) {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
private void saveAssociationAttributes(final DataObject assocObj) {
|
||||
final Iterator properties = assocObj.getObjectType().
|
||||
getDeclaredProperties();
|
||||
final Map<String, Object> assocAttrs = new HashMap<String, Object>();
|
||||
|
||||
while (properties.hasNext()) {
|
||||
processAttribute(assocObj, assocAttrs, (Property) properties.next());
|
||||
}
|
||||
|
||||
if (!assocAttrs.isEmpty()) {
|
||||
final ByteArrayOutputStream data = new ByteArrayOutputStream();
|
||||
try {
|
||||
final ObjectOutputStream out = new ObjectOutputStream(data);
|
||||
out.writeObject(assocAttrs);
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedWrapperException(ex);
|
||||
}
|
||||
|
||||
set(ATTRIBUTES, data.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void processAttribute(final DataObject assocObj,
|
||||
final Map<String, Object> assocAttrs,
|
||||
final Property property) {
|
||||
final String name = property.getName();
|
||||
|
||||
// Teste Property: Es darf kein Key und muß ein simples Attribute sein
|
||||
if (property.isAttribute() && !property.isKeyProperty()) {
|
||||
final Object value = assocObj.get(name);
|
||||
assocAttrs.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setAttributesForLiveAssociation(
|
||||
final DataObject association, byte[] attributes) {
|
||||
if (attributes != null) {
|
||||
final ByteArrayInputStream data;
|
||||
final ObjectInputStream in;
|
||||
final Map<String, Object> assocAttrs;
|
||||
|
||||
data = new ByteArrayInputStream(attributes);
|
||||
try {
|
||||
in = new ObjectInputStream(data);
|
||||
assocAttrs = (Map<String, Object>) in.readObject();
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedWrapperException(ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new UncheckedWrapperException(ex);
|
||||
}
|
||||
|
||||
if (assocAttrs != null) {
|
||||
for(Map.Entry<String, Object> entry : assocAttrs.entrySet()) {
|
||||
if(association.getObjectType().hasDeclaredProperty(entry.getKey())
|
||||
&& association.getSession() != null) {
|
||||
association.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ class VersionCopier extends ObjectCopier {
|
|||
* ContentItem)} in order to transfer the categories and other services.
|
||||
*
|
||||
* @param item the item to be copied
|
||||
*
|
||||
* @return a copy of the item
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -168,7 +169,7 @@ class VersionCopier extends ObjectCopier {
|
|||
* @param source the
|
||||
* <code>DomainObject</code> being copied
|
||||
* @param target the new copy
|
||||
* @param prop the
|
||||
* @param prop the
|
||||
* <code>Property</code> currently under consideration
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -196,56 +197,49 @@ class VersionCopier extends ObjectCopier {
|
|||
item.assertDraft();
|
||||
}
|
||||
|
||||
if ((item instanceof AssociationCopier)
|
||||
&& ((AssociationCopier) item).handlesProperty(prop)) {
|
||||
final AssociationCopier assocCopier = (AssociationCopier) item;
|
||||
assocCopier.copy(source, target, target, prop);
|
||||
|
||||
|
||||
if (prop.isComponent()) {
|
||||
s_log.debug("The property is a component; creating a "
|
||||
+ "live or pending version");
|
||||
|
||||
final ContentItem copy = createVersion(item);
|
||||
|
||||
m_trace.exit("copy", copy);
|
||||
|
||||
return copy;
|
||||
} else if (m_traversedComponents.contains(object)) {
|
||||
final DomainObject copy = copy(object);
|
||||
|
||||
m_trace.exit("copy", copy);
|
||||
|
||||
return copy;
|
||||
} else if (prop.isRequired()) {
|
||||
Assert.fail(
|
||||
"1..1 associations to non-component top-level ContentItems are not allowed");
|
||||
return null;
|
||||
} else {
|
||||
s_log.debug("The property is not a component; creating "
|
||||
+ "PublishedLink for the item");
|
||||
|
||||
if (prop.isComponent()) {
|
||||
s_log.debug("The property is a component; creating a "
|
||||
+ "live or pending version");
|
||||
|
||||
final ContentItem copy = createVersion(item);
|
||||
|
||||
m_trace.exit("copy", copy);
|
||||
|
||||
return copy;
|
||||
} else if (m_traversedComponents.contains(object)) {
|
||||
final DomainObject copy = copy(object);
|
||||
|
||||
m_trace.exit("copy", copy);
|
||||
|
||||
return copy;
|
||||
} else if (prop.isRequired()) {
|
||||
Assert.fail(
|
||||
"1..1 associations to non-component top-level ContentItems are not allowed");
|
||||
return null;
|
||||
if (source instanceof ContentItem) {
|
||||
PublishedLink.create(
|
||||
(ContentItem) getCopy(m_topLevelSourceOID),
|
||||
target,
|
||||
prop.getName(),
|
||||
item,
|
||||
(ContentItem) source);
|
||||
} else {
|
||||
s_log.debug("The property is not a component; creating "
|
||||
+ "PublishedLink for the item");
|
||||
|
||||
if (source instanceof ContentItem) {
|
||||
PublishedLink.create(
|
||||
(ContentItem) getCopy(m_topLevelSourceOID),
|
||||
target,
|
||||
prop.getName(),
|
||||
item,
|
||||
(ContentItem) source);
|
||||
} else {
|
||||
PublishedLink.create(
|
||||
(ContentItem) getCopy(m_topLevelSourceOID),
|
||||
target,
|
||||
prop.getName(),
|
||||
item,
|
||||
null);
|
||||
}
|
||||
m_trace.exit("copy", null);
|
||||
|
||||
return null;
|
||||
PublishedLink.create(
|
||||
(ContentItem) getCopy(m_topLevelSourceOID),
|
||||
target,
|
||||
prop.getName(),
|
||||
item,
|
||||
null);
|
||||
}
|
||||
m_trace.exit("copy", null);
|
||||
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
s_log.debug("The property is not a content item; using "
|
||||
|
|
|
|||
|
|
@ -39,27 +39,31 @@ public class GenericContact extends ContentPage implements
|
|||
RelationAttributeInterface {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(GenericContact.class);
|
||||
/** PDL property names */
|
||||
/**
|
||||
* PDL property names
|
||||
*/
|
||||
public static final String PERSON = "person";
|
||||
// public static final String CONTACT_TYPE = "";
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String CONTACT_ENTRIES = "contactentries";
|
||||
public static final String CONTACTS_KEY = GenericPersonContactCollection.CONTACTS_KEY;
|
||||
|
||||
private static final String RELATION_ATTRIBUTES = "person.link_key:GenericContactTypes;contactentries.key:GenericContactEntryKeys";
|
||||
|
||||
public static final String CONTACTS_KEY =
|
||||
GenericPersonContactCollection.CONTACTS_KEY;
|
||||
private static final String RELATION_ATTRIBUTES =
|
||||
"person.link_key:GenericContactTypes;contactentries.key:GenericContactEntryKeys";
|
||||
// Config
|
||||
private static final GenericContactConfig s_config =
|
||||
new GenericContactConfig();
|
||||
new GenericContactConfig();
|
||||
|
||||
static {
|
||||
logger.debug("Static initializer is starting...");
|
||||
s_config.load();
|
||||
logger.debug("Static initializer finished");
|
||||
}
|
||||
/** Data object type for this domain object */
|
||||
/**
|
||||
* Data object type for this domain object
|
||||
*/
|
||||
public static final String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.contenttypes.GenericContact";
|
||||
"com.arsdigita.cms.contenttypes.GenericContact";
|
||||
|
||||
public GenericContact() {
|
||||
super(BASE_DATA_OBJECT_TYPE);
|
||||
|
|
@ -106,23 +110,20 @@ public class GenericContact extends ContentPage implements
|
|||
// accessors
|
||||
// Get the person for this contact
|
||||
public GenericPerson getPerson() {
|
||||
/*DataCollection collection;
|
||||
|
||||
collection = (DataCollection) get(PERSON);
|
||||
|
||||
if (collection.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
DataObject dobj;
|
||||
|
||||
collection.next();
|
||||
dobj = collection.getDataObject();
|
||||
|
||||
// Close Collection to prevent an open ResultSet
|
||||
collection.close();
|
||||
|
||||
return (GenericPerson) DomainObjectFactory.newInstance(dobj);
|
||||
}*/
|
||||
/*
|
||||
* DataCollection collection;
|
||||
*
|
||||
* collection = (DataCollection) get(PERSON);
|
||||
*
|
||||
* if (collection.size() == 0) { return null; } else { DataObject dobj;
|
||||
*
|
||||
* collection.next(); dobj = collection.getDataObject();
|
||||
*
|
||||
* // Close Collection to prevent an open ResultSet collection.close();
|
||||
*
|
||||
* return (GenericPerson) DomainObjectFactory.newInstance(dobj);
|
||||
}
|
||||
*/
|
||||
|
||||
return getGenericContactBundle().getPerson();
|
||||
}
|
||||
|
|
@ -130,17 +131,16 @@ public class GenericContact extends ContentPage implements
|
|||
// Set the person for this contact
|
||||
public void setPerson(GenericPerson person, String contactType) {
|
||||
//set(PERSON, person);
|
||||
/*if (getPerson() != null) {
|
||||
unsetPerson();
|
||||
/*
|
||||
* if (getPerson() != null) { unsetPerson(); }
|
||||
*
|
||||
* if (person != null) { Assert.exists(person, GenericPerson.class);
|
||||
* DataObject link = add(PERSON, person);
|
||||
* link.set(GenericPerson.CONTACTS_KEY, contactType);
|
||||
* link.set(GenericPerson.CONTACTS_ORDER, new
|
||||
* BigDecimal(person.getContacts().size())); link.save();
|
||||
}
|
||||
|
||||
if (person != null) {
|
||||
Assert.exists(person, GenericPerson.class);
|
||||
DataObject link = add(PERSON, person);
|
||||
link.set(GenericPerson.CONTACTS_KEY, contactType);
|
||||
link.set(GenericPerson.CONTACTS_ORDER, new BigDecimal(person.getContacts().size()));
|
||||
link.save();
|
||||
}*/
|
||||
*/
|
||||
|
||||
getGenericContactBundle().setPerson(person, contactType);
|
||||
}
|
||||
|
|
@ -157,11 +157,11 @@ public class GenericContact extends ContentPage implements
|
|||
// Unset the address for this contact
|
||||
public void unsetPerson() {
|
||||
//set(PERSON, null);
|
||||
/*GenericPerson oldPerson;
|
||||
oldPerson = getPerson();
|
||||
if (oldPerson != null) {
|
||||
remove(PERSON, oldPerson);
|
||||
}*/
|
||||
/*
|
||||
* GenericPerson oldPerson; oldPerson = getPerson(); if (oldPerson !=
|
||||
* null) { remove(PERSON, oldPerson);
|
||||
}
|
||||
*/
|
||||
|
||||
getGenericContactBundle().unsetPerson();
|
||||
}
|
||||
|
|
@ -204,8 +204,8 @@ public class GenericContact extends ContentPage implements
|
|||
|
||||
GenericPerson person = getPerson();
|
||||
|
||||
if(person != null) {
|
||||
GenericPersonContactCollection collection = person.getContacts();
|
||||
if (person != null) {
|
||||
GenericPersonContactCollection collection = person.getContacts();
|
||||
collection.next();
|
||||
String contactType = (String) collection.getContactType();
|
||||
|
||||
|
|
@ -221,8 +221,8 @@ public class GenericContact extends ContentPage implements
|
|||
public void setContactType(String contactType) {
|
||||
|
||||
GenericPerson person = getPerson();
|
||||
if(person != null) {
|
||||
GenericPersonContactCollection collection = person.getContacts();
|
||||
if (person != null) {
|
||||
GenericPersonContactCollection collection = person.getContacts();
|
||||
collection.next();
|
||||
DataObject link = (DataObject) collection.get("link");
|
||||
link.set(CONTACTS_KEY, contactType);
|
||||
|
|
@ -249,9 +249,9 @@ public class GenericContact extends ContentPage implements
|
|||
@Override
|
||||
public boolean hasRelationAttributeProperty(String propertyName) {
|
||||
StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
||||
while(strTok.hasMoreTokens()) {
|
||||
while (strTok.hasMoreTokens()) {
|
||||
String token = strTok.nextToken();
|
||||
if(token.startsWith(propertyName + ".")) {
|
||||
if (token.startsWith(propertyName + ".")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -266,10 +266,11 @@ public class GenericContact extends ContentPage implements
|
|||
@Override
|
||||
public String getRelationAttributeKeyName(String propertyName) {
|
||||
StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
||||
while(strTok.hasMoreTokens()) {
|
||||
while (strTok.hasMoreTokens()) {
|
||||
String token = strTok.nextToken();
|
||||
if(token.startsWith(propertyName + ".")) {
|
||||
return token.substring(token.indexOf(".") + 1, token.indexOf(":"));
|
||||
if (token.startsWith(propertyName + ".")) {
|
||||
return token.substring(token.indexOf(".") + 1,
|
||||
token.indexOf(":"));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -278,9 +279,9 @@ public class GenericContact extends ContentPage implements
|
|||
@Override
|
||||
public String getRelationAttributeName(String propertyName) {
|
||||
StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
||||
while(strTok.hasMoreTokens()) {
|
||||
while (strTok.hasMoreTokens()) {
|
||||
String token = strTok.nextToken();
|
||||
if(token.startsWith(propertyName + ".")) {
|
||||
if (token.startsWith(propertyName + ".")) {
|
||||
return token.substring(token.indexOf(":") + 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -291,5 +292,4 @@ public class GenericContact extends ContentPage implements
|
|||
public String getRelationAttributeKey(String propertyName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,14 @@ package com.arsdigita.cms.contenttypes;
|
|||
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.CustomCopy;
|
||||
import com.arsdigita.cms.ItemCopier;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import com.arsdigita.util.Assert;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
|
@ -15,7 +18,8 @@ import java.math.BigDecimal;
|
|||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GenericContactBundle extends ContentBundle {
|
||||
public class GenericContactBundle
|
||||
extends ContentBundle {
|
||||
|
||||
public static final String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.contenttypes.GenericContactBundle";
|
||||
|
|
@ -51,6 +55,65 @@ public class GenericContactBundle extends ContentBundle {
|
|||
super(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Copy association properties. These are for example the associations
|
||||
* between GenericPerson and GenericContact, or between
|
||||
* GenericOrganizationalUnit and GenericPerson. </p>
|
||||
*
|
||||
* @param source param property param copier
|
||||
* @param property
|
||||
* @param copier
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean copyProperty(final CustomCopy source,
|
||||
final Property property,
|
||||
final ItemCopier copier) {
|
||||
final String attribute = property.getName();
|
||||
if (copier.getCopyType() == ItemCopier.VERSION_COPY) {
|
||||
final GenericContactBundle contactBundle =
|
||||
(GenericContactBundle) source;
|
||||
|
||||
if (PERSON.equals(attribute)) {
|
||||
|
||||
final DataCollection persons = (DataCollection) contactBundle.
|
||||
get(PERSON);
|
||||
|
||||
while (persons.next()) {
|
||||
createPersonAssoc(persons);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return super.copyProperty(source, property, copier);
|
||||
}
|
||||
} else {
|
||||
return super.copyProperty(source, property, copier);
|
||||
}
|
||||
}
|
||||
|
||||
private void createPersonAssoc(final DataCollection persons) {
|
||||
final GenericPersonBundle draftPerson =
|
||||
(GenericPersonBundle) DomainObjectFactory.
|
||||
newInstance(
|
||||
persons.getDataObject());
|
||||
final GenericPersonBundle livePerson =
|
||||
(GenericPersonBundle) draftPerson.
|
||||
getLiveVersion();
|
||||
|
||||
if (livePerson != null) {
|
||||
final DataObject link = add(PERSON, livePerson);
|
||||
|
||||
link.set(GenericPerson.CONTACTS_KEY,
|
||||
persons.get(GenericPersonContactCollection.CONTACTS_KEY));
|
||||
link.set(GenericPerson.CONTACTS_ORDER,
|
||||
persons.get(GenericPersonContactCollection.CONTACTS_ORDER));
|
||||
|
||||
link.save();
|
||||
}
|
||||
}
|
||||
|
||||
public GenericPerson getPerson() {
|
||||
DataCollection collection;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,19 +18,18 @@
|
|||
*/
|
||||
package com.arsdigita.cms.contenttypes;
|
||||
|
||||
import com.arsdigita.cms.ContentType;
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentType;
|
||||
import com.arsdigita.cms.LanguageInvariantContentItem;
|
||||
import com.arsdigita.cms.RelationAttributeInterface;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.util.Assert;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Date;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Basic GenericPerson Contenttype for OpenCCM.
|
||||
|
|
@ -56,13 +55,17 @@ public class GenericPerson extends ContentPage implements
|
|||
public static final String DABIN_ID = "dabinId";
|
||||
private static final String RELATION_ATTRIBUTES =
|
||||
"contacts.link_key:GenericContactType";
|
||||
/** Data object type for this domain object */
|
||||
/**
|
||||
* Data object type for this domain object
|
||||
*/
|
||||
public static final String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.contenttypes.GenericPerson";
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor. This creates a new (empty) GenericPerson.
|
||||
**/
|
||||
*
|
||||
*/
|
||||
public GenericPerson() {
|
||||
this(BASE_DATA_OBJECT_TYPE);
|
||||
}
|
||||
|
|
@ -94,7 +97,9 @@ public class GenericPerson extends ContentPage implements
|
|||
Assert.exists(getContentType(), ContentType.class);
|
||||
}
|
||||
|
||||
/* accessors *****************************************************/
|
||||
/*
|
||||
* accessors ****************************************************
|
||||
*/
|
||||
public String getSurname() {
|
||||
return (String) get(SURNAME);
|
||||
}
|
||||
|
|
@ -148,7 +153,8 @@ public class GenericPerson extends ContentPage implements
|
|||
}
|
||||
|
||||
public GenericPerson getAlias() {
|
||||
return (GenericPerson) DomainObjectFactory.newInstance((DataObject) get(ALIAS));
|
||||
return (GenericPerson) DomainObjectFactory.newInstance((DataObject) get(
|
||||
ALIAS));
|
||||
}
|
||||
|
||||
public void setAlias(final GenericPerson alias) {
|
||||
|
|
@ -160,7 +166,7 @@ public class GenericPerson extends ContentPage implements
|
|||
}
|
||||
|
||||
public Integer getDabinId() {
|
||||
return (Integer)get(DABIN_ID);
|
||||
return (Integer) get(DABIN_ID);
|
||||
}
|
||||
|
||||
public void setDabinId(final Integer dabinId) {
|
||||
|
|
@ -213,19 +219,21 @@ public class GenericPerson extends ContentPage implements
|
|||
// Get all contacts for this person
|
||||
public GenericPersonContactCollection getContacts() {
|
||||
//return new GenericPersonContactCollection(
|
||||
// (DataCollection) get(CONTACTS));
|
||||
// (DataCollection) get(CONTACTS));
|
||||
return getGenericPersonBundle().getContacts();
|
||||
}
|
||||
|
||||
// Add a contact for this person
|
||||
public void addContact(final GenericContact contact,
|
||||
final String contactType) {
|
||||
/* Assert.exists(contact, GenericContact.class);
|
||||
|
||||
DataObject link = add(CONTACTS, contact);
|
||||
|
||||
link.set(CONTACTS_KEY, contactType);
|
||||
link.set(CONTACTS_ORDER, BigDecimal.valueOf(getContacts().size()));*/
|
||||
/*
|
||||
* Assert.exists(contact, GenericContact.class);
|
||||
*
|
||||
* DataObject link = add(CONTACTS, contact);
|
||||
*
|
||||
* link.set(CONTACTS_KEY, contactType); link.set(CONTACTS_ORDER,
|
||||
* BigDecimal.valueOf(getContacts().size()));
|
||||
*/
|
||||
getGenericPersonBundle().addContact(contact, contactType);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,15 @@ package com.arsdigita.cms.contenttypes;
|
|||
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.CustomCopy;
|
||||
import com.arsdigita.cms.ItemCopier;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import com.arsdigita.util.Assert;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
|
@ -14,7 +19,8 @@ import java.math.BigDecimal;
|
|||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GenericPersonBundle extends ContentBundle {
|
||||
public class GenericPersonBundle
|
||||
extends ContentBundle {
|
||||
|
||||
public final static String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.contenttypes.GenericPersonBundle";
|
||||
|
|
@ -76,4 +82,49 @@ public class GenericPersonBundle extends ContentBundle {
|
|||
public boolean hasContacts() {
|
||||
return !this.getContacts().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyProperty(final CustomCopy source,
|
||||
final Property property,
|
||||
final ItemCopier copier) {
|
||||
final String attribute = property.getName();
|
||||
final GenericPersonBundle personBundle =
|
||||
(GenericPersonBundle) source;
|
||||
if (copier.getCopyType() == ItemCopier.VERSION_COPY) {
|
||||
if (CONTACTS.equals(attribute)) {
|
||||
final DataCollection contacts = (DataCollection) personBundle.
|
||||
get(CONTACTS);
|
||||
|
||||
while (contacts.next()) {
|
||||
createContactAssoc(contacts);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return super.copyProperty(source, property, copier);
|
||||
}
|
||||
} else {
|
||||
return super.copyProperty(source, property, copier);
|
||||
}
|
||||
}
|
||||
|
||||
private void createContactAssoc(final DataCollection contacts) {
|
||||
final GenericContactBundle draftContact =
|
||||
(GenericContactBundle) DomainObjectFactory.
|
||||
newInstance(contacts.getDataObject());
|
||||
final GenericContactBundle liveContact =
|
||||
(GenericContactBundle) draftContact.
|
||||
getLiveVersion();
|
||||
|
||||
if (liveContact != null) {
|
||||
final DataObject link = add(CONTACTS, liveContact);
|
||||
|
||||
link.set(GenericPersonContactCollection.CONTACTS_KEY, contacts.get(
|
||||
CONTACTS_KEY));
|
||||
link.set(GenericPersonContactCollection.CONTACTS_ORDER,
|
||||
contacts.get(CONTACTS_ORDER));
|
||||
|
||||
link.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,20 +180,11 @@ public class GenericPersonContactCollection extends DomainCollection {
|
|||
}
|
||||
|
||||
public GenericAddress getAddress() {
|
||||
/*
|
||||
* return (GenericAddress) DomainObjectFactory.newInstance((DataObject)
|
||||
* m_dataCollection. getDataObject().get(
|
||||
GenericContact.ADDRESS));
|
||||
*/
|
||||
|
||||
return getContact().getAddress();
|
||||
}
|
||||
|
||||
public GenericContactEntryCollection getContactEntries() {
|
||||
/*
|
||||
* return new GenericContactEntryCollection((DataCollection)
|
||||
* m_dataCollection. getDataObject().get(
|
||||
GenericContact.CONTACT_ENTRIES));
|
||||
*/
|
||||
return getContact().getContactEntries();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue