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 {
|
public interface AssociationCopier {
|
||||||
|
|
||||||
boolean handlesProperty(Property property);
|
boolean copyReverseProperty(CustomCopy source,
|
||||||
void copy(DomainObject source,
|
|
||||||
DomainObject target,
|
DomainObject target,
|
||||||
|
Property property,
|
||||||
DomainObject value,
|
DomainObject value,
|
||||||
Property property);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -382,6 +382,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* Publicized getter method for use by metadata forms.
|
* Publicized getter method for use by metadata forms.
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -392,8 +393,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
/**
|
/**
|
||||||
* Public setter method for use by metadata forms.
|
* Public setter method for use by metadata forms.
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key param value
|
||||||
* @param value
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void set(final String key, final Object value) {
|
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.
|
* Public add for use by metadata forms.
|
||||||
*
|
*
|
||||||
* @param propertyName
|
* @param propertyName param dobj
|
||||||
* @param dobj
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -415,8 +415,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
/**
|
/**
|
||||||
* Public remove for use by metadata forms
|
* Public remove for use by metadata forms
|
||||||
*
|
*
|
||||||
* @param propertyName
|
* @param propertyName param dobj
|
||||||
* @param dobj
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void remove(String propertyName, DomainObject dobj) {
|
public void remove(String propertyName, DomainObject dobj) {
|
||||||
|
|
@ -694,6 +693,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
*
|
*
|
||||||
* @param includeSelf a
|
* @param includeSelf a
|
||||||
* <code>boolean</code> value.
|
* <code>boolean</code> value.
|
||||||
|
*
|
||||||
* @return the items on the path to the root folder.
|
* @return the items on the path to the root folder.
|
||||||
*/
|
*/
|
||||||
public ItemCollection getPathInfo(boolean includeSelf) {
|
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>true</code> if this item is a
|
||||||
* <code>DRAFT</code> version.
|
* <code>DRAFT</code> version.
|
||||||
*
|
*
|
||||||
* @return
|
* @return < code>true</code> if this item is a
|
||||||
* <code>true</code> if this item is a
|
|
||||||
* <code>DRAFT</code> version
|
* <code>DRAFT</code> version
|
||||||
*/
|
*/
|
||||||
public boolean isDraftVersion() {
|
public boolean isDraftVersion() {
|
||||||
|
|
@ -800,6 +799,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
*
|
*
|
||||||
* @return the working version representation of the
|
* @return the working version representation of the
|
||||||
* <code>ContentItem</code>, possibly this item
|
* <code>ContentItem</code>, possibly this item
|
||||||
|
*
|
||||||
* @deprecated use {@link #getDraftVersion()} instead
|
* @deprecated use {@link #getDraftVersion()} instead
|
||||||
*/
|
*/
|
||||||
public ContentItem getWorkingVersion() {
|
public ContentItem getWorkingVersion() {
|
||||||
|
|
@ -811,8 +811,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* <code>true</code> if this item is a
|
* <code>true</code> if this item is a
|
||||||
* <code>PENDING</code> version.
|
* <code>PENDING</code> version.
|
||||||
*
|
*
|
||||||
* @return
|
* @return < code>true</code> if
|
||||||
* <code>true</code> if
|
|
||||||
* <code>this</code> is one of the pending versions
|
* <code>this</code> is one of the pending versions
|
||||||
*/
|
*/
|
||||||
public boolean isPendingVersion() {
|
public boolean isPendingVersion() {
|
||||||
|
|
@ -915,8 +914,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* <code>true</code> if this item is a
|
* <code>true</code> if this item is a
|
||||||
* <code>LIVE</code> version.
|
* <code>LIVE</code> version.
|
||||||
*
|
*
|
||||||
* @return
|
* @return < code>true</code> if
|
||||||
* <code>true</code> if
|
|
||||||
* <code>this</code> is the live version
|
* <code>this</code> is the live version
|
||||||
*/
|
*/
|
||||||
public boolean isLiveVersion() {
|
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
|
* not necessarily the live version nor is this method to be confused with
|
||||||
* isPublished.
|
* isPublished.
|
||||||
*
|
*
|
||||||
* @return
|
* @return < code>true<code> if this content item has a live
|
||||||
* <code>true<code> if this content item has a live
|
|
||||||
* version, or if it <em>is</em> the live version
|
* version, or if it <em>is</em> the live version
|
||||||
*/
|
*/
|
||||||
public boolean isLive() {
|
public boolean isLive() {
|
||||||
|
|
@ -1143,7 +1140,6 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
|
|
||||||
oldVersion.delete();
|
oldVersion.delete();
|
||||||
PublishedLink.refreshOnUnpublish(this);
|
PublishedLink.refreshOnUnpublish(this);
|
||||||
PublishedAssociation.refreshOnUnPublish(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent instanceof ContentBundle || parent instanceof Folder) {
|
if (parent instanceof ContentBundle || parent instanceof Folder) {
|
||||||
|
|
@ -1172,7 +1168,6 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
save();
|
save();
|
||||||
|
|
||||||
PublishedLink.updateLiveLinks(version);
|
PublishedLink.updateLiveLinks(version);
|
||||||
PublishedAssociation.updateLiveAssociations(version);
|
|
||||||
save();
|
save();
|
||||||
|
|
||||||
// publish item (as template or html pages) to the file
|
// publish item (as template or html pages) to the file
|
||||||
|
|
@ -1546,6 +1541,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* 'non-finalness' of this method should be considered deprecated.
|
* 'non-finalness' of this method should be considered deprecated.
|
||||||
*
|
*
|
||||||
* @return the live version for this item
|
* @return the live version for this item
|
||||||
|
*
|
||||||
* @see #copyServicesFrom(ContentItem)
|
* @see #copyServicesFrom(ContentItem)
|
||||||
*/
|
*/
|
||||||
public ContentItem copy() {
|
public ContentItem copy() {
|
||||||
|
|
@ -1565,6 +1561,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* @param copyServices Copy services if true
|
* @param copyServices Copy services if true
|
||||||
*
|
*
|
||||||
* @return the new copy of the item
|
* @return the new copy of the item
|
||||||
|
*
|
||||||
* @see #copyServicesFrom(ContentItem)
|
* @see #copyServicesFrom(ContentItem)
|
||||||
*/
|
*/
|
||||||
final public ContentItem copy(final ContentItem newParent,
|
final public ContentItem copy(final ContentItem newParent,
|
||||||
|
|
@ -1617,6 +1614,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* language of the copy.
|
* language of the copy.
|
||||||
*
|
*
|
||||||
* @param language
|
* @param language
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected ContentItem makeCopy(String language) {
|
protected ContentItem makeCopy(String language) {
|
||||||
|
|
@ -1645,6 +1643,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
*
|
*
|
||||||
* @param source the
|
* @param source the
|
||||||
* <code>ContentItem</code> whose services will be copied
|
* <code>ContentItem</code> whose services will be copied
|
||||||
|
*
|
||||||
* @see #copy()
|
* @see #copy()
|
||||||
*/
|
*/
|
||||||
public void copyServicesFrom(final ContentItem source) {
|
public void copyServicesFrom(final ContentItem source) {
|
||||||
|
|
@ -1661,6 +1660,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
*
|
*
|
||||||
* @param cycle the lifecycle to use. A null cycle implies that a live
|
* @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
|
* @return the new pending version for this item
|
||||||
*/
|
*/
|
||||||
protected ContentItem createPendingVersion(final Lifecycle cycle) {
|
protected ContentItem createPendingVersion(final Lifecycle cycle) {
|
||||||
|
|
@ -1705,10 +1705,12 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
}
|
}
|
||||||
|
|
||||||
setLive(pending);
|
setLive(pending);
|
||||||
|
|
||||||
ContentBundle draftBundle = getBundle();
|
ContentBundle draftBundle = getBundle();
|
||||||
ContentBundle liveBundle = pending.getBundle();
|
ContentBundle liveBundle = pending.getBundle();
|
||||||
if (draftBundle != null && liveBundle != null && !liveBundle.
|
if ((draftBundle != null)
|
||||||
isLiveVersion()) {
|
&& (liveBundle != null)
|
||||||
|
&& (!liveBundle.isLiveVersion())) {
|
||||||
draftBundle.promotePendingVersion(liveBundle);
|
draftBundle.promotePendingVersion(liveBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1846,6 +1848,7 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
* @param property the property to copy
|
* @param property the property to copy
|
||||||
* @param copier a temporary class that is able to copy a child item
|
* @param copier a temporary class that is able to copy a child item
|
||||||
* correctly.
|
* correctly.
|
||||||
|
*
|
||||||
* @return true if the property was copied; false to indicate that regular
|
* @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.
|
||||||
*/
|
*/
|
||||||
|
|
@ -1884,8 +1887,8 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
if (parent instanceof ContentBundle) {
|
if (parent instanceof ContentBundle) {
|
||||||
|
|
||||||
final ContentBundle bundle = (ContentBundle) parent;
|
final ContentBundle bundle = (ContentBundle) parent;
|
||||||
final ContentBundle oldLiveBundle = (ContentBundle) bundle.
|
final ContentBundle oldLiveBundle =
|
||||||
getPublicVersion();
|
(ContentBundle) bundle.getPublicVersion();
|
||||||
//jensp 2012-03-07 Changes to the ContentBundle were not
|
//jensp 2012-03-07 Changes to the ContentBundle were not
|
||||||
//published because the ContentBundle was not republished.
|
//published because the ContentBundle was not republished.
|
||||||
//Moved the next lines out of the if below to enable
|
//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.
|
final ItemCollection instances = oldLiveBundle.
|
||||||
getInstances();
|
getInstances();
|
||||||
while (instances.next()) {
|
while (instances.next()) {
|
||||||
liveBundle.addInstance(instances.getContentItem());
|
liveBundle.addInstance(
|
||||||
|
instances.getContentItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
* ContentItem)} in order to transfer the categories and other services.
|
||||||
*
|
*
|
||||||
* @param item the item to be copied
|
* @param item the item to be copied
|
||||||
|
*
|
||||||
* @return a copy of the item
|
* @return a copy of the item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -196,13 +197,7 @@ class VersionCopier extends ObjectCopier {
|
||||||
item.assertDraft();
|
item.assertDraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item instanceof AssociationCopier)
|
|
||||||
&& ((AssociationCopier) item).handlesProperty(prop)) {
|
|
||||||
final AssociationCopier assocCopier = (AssociationCopier) item;
|
|
||||||
assocCopier.copy(source, target, target, prop);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (prop.isComponent()) {
|
if (prop.isComponent()) {
|
||||||
s_log.debug("The property is a component; creating a "
|
s_log.debug("The property is a component; creating a "
|
||||||
|
|
@ -246,7 +241,6 @@ class VersionCopier extends ObjectCopier {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
s_log.debug("The property is not a content item; using "
|
s_log.debug("The property is not a content item; using "
|
||||||
+ "domain object copier");
|
+ "domain object copier");
|
||||||
|
|
|
||||||
|
|
@ -39,15 +39,17 @@ public class GenericContact extends ContentPage implements
|
||||||
RelationAttributeInterface {
|
RelationAttributeInterface {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(GenericContact.class);
|
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 PERSON = "person";
|
||||||
// public static final String CONTACT_TYPE = "";
|
// public static final String CONTACT_TYPE = "";
|
||||||
public static final String ADDRESS = "address";
|
public static final String ADDRESS = "address";
|
||||||
public static final String CONTACT_ENTRIES = "contactentries";
|
public static final String CONTACT_ENTRIES = "contactentries";
|
||||||
public static final String CONTACTS_KEY = GenericPersonContactCollection.CONTACTS_KEY;
|
public static final String CONTACTS_KEY =
|
||||||
|
GenericPersonContactCollection.CONTACTS_KEY;
|
||||||
private static final String RELATION_ATTRIBUTES = "person.link_key:GenericContactTypes;contactentries.key:GenericContactEntryKeys";
|
private static final String RELATION_ATTRIBUTES =
|
||||||
|
"person.link_key:GenericContactTypes;contactentries.key:GenericContactEntryKeys";
|
||||||
// Config
|
// Config
|
||||||
private static final GenericContactConfig s_config =
|
private static final GenericContactConfig s_config =
|
||||||
new GenericContactConfig();
|
new GenericContactConfig();
|
||||||
|
|
@ -57,7 +59,9 @@ public class GenericContact extends ContentPage implements
|
||||||
s_config.load();
|
s_config.load();
|
||||||
logger.debug("Static initializer finished");
|
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 =
|
public static final String BASE_DATA_OBJECT_TYPE =
|
||||||
"com.arsdigita.cms.contenttypes.GenericContact";
|
"com.arsdigita.cms.contenttypes.GenericContact";
|
||||||
|
|
||||||
|
|
@ -106,23 +110,20 @@ public class GenericContact extends ContentPage implements
|
||||||
// accessors
|
// accessors
|
||||||
// Get the person for this contact
|
// Get the person for this contact
|
||||||
public GenericPerson getPerson() {
|
public GenericPerson getPerson() {
|
||||||
/*DataCollection collection;
|
/*
|
||||||
|
* DataCollection collection;
|
||||||
collection = (DataCollection) get(PERSON);
|
*
|
||||||
|
* collection = (DataCollection) get(PERSON);
|
||||||
if (collection.size() == 0) {
|
*
|
||||||
return null;
|
* if (collection.size() == 0) { return null; } else { DataObject dobj;
|
||||||
} else {
|
*
|
||||||
DataObject dobj;
|
* collection.next(); dobj = collection.getDataObject();
|
||||||
|
*
|
||||||
collection.next();
|
* // Close Collection to prevent an open ResultSet collection.close();
|
||||||
dobj = collection.getDataObject();
|
*
|
||||||
|
* return (GenericPerson) DomainObjectFactory.newInstance(dobj);
|
||||||
// Close Collection to prevent an open ResultSet
|
}
|
||||||
collection.close();
|
*/
|
||||||
|
|
||||||
return (GenericPerson) DomainObjectFactory.newInstance(dobj);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return getGenericContactBundle().getPerson();
|
return getGenericContactBundle().getPerson();
|
||||||
}
|
}
|
||||||
|
|
@ -130,17 +131,16 @@ public class GenericContact extends ContentPage implements
|
||||||
// Set the person for this contact
|
// Set the person for this contact
|
||||||
public void setPerson(GenericPerson person, String contactType) {
|
public void setPerson(GenericPerson person, String contactType) {
|
||||||
//set(PERSON, person);
|
//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);
|
getGenericContactBundle().setPerson(person, contactType);
|
||||||
}
|
}
|
||||||
|
|
@ -157,11 +157,11 @@ public class GenericContact extends ContentPage implements
|
||||||
// Unset the address for this contact
|
// Unset the address for this contact
|
||||||
public void unsetPerson() {
|
public void unsetPerson() {
|
||||||
//set(PERSON, null);
|
//set(PERSON, null);
|
||||||
/*GenericPerson oldPerson;
|
/*
|
||||||
oldPerson = getPerson();
|
* GenericPerson oldPerson; oldPerson = getPerson(); if (oldPerson !=
|
||||||
if (oldPerson != null) {
|
* null) { remove(PERSON, oldPerson);
|
||||||
remove(PERSON, oldPerson);
|
}
|
||||||
}*/
|
*/
|
||||||
|
|
||||||
getGenericContactBundle().unsetPerson();
|
getGenericContactBundle().unsetPerson();
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +269,8 @@ public class GenericContact extends ContentPage implements
|
||||||
while (strTok.hasMoreTokens()) {
|
while (strTok.hasMoreTokens()) {
|
||||||
String token = strTok.nextToken();
|
String token = strTok.nextToken();
|
||||||
if (token.startsWith(propertyName + ".")) {
|
if (token.startsWith(propertyName + ".")) {
|
||||||
return token.substring(token.indexOf(".") + 1, token.indexOf(":"));
|
return token.substring(token.indexOf(".") + 1,
|
||||||
|
token.indexOf(":"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -291,5 +292,4 @@ public class GenericContact extends ContentPage implements
|
||||||
public String getRelationAttributeKey(String propertyName) {
|
public String getRelationAttributeKey(String propertyName) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,14 @@ package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentBundle;
|
import com.arsdigita.cms.ContentBundle;
|
||||||
import com.arsdigita.cms.ContentItem;
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.CustomCopy;
|
||||||
|
import com.arsdigita.cms.ItemCopier;
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
import com.arsdigita.domain.DomainObjectFactory;
|
import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
import com.arsdigita.persistence.DataObject;
|
import com.arsdigita.persistence.DataObject;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
|
import com.arsdigita.persistence.metadata.Property;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
|
@ -15,7 +18,8 @@ import java.math.BigDecimal;
|
||||||
* @author Jens Pelzetter
|
* @author Jens Pelzetter
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class GenericContactBundle extends ContentBundle {
|
public class GenericContactBundle
|
||||||
|
extends ContentBundle {
|
||||||
|
|
||||||
public static final String BASE_DATA_OBJECT_TYPE =
|
public static final String BASE_DATA_OBJECT_TYPE =
|
||||||
"com.arsdigita.cms.contenttypes.GenericContactBundle";
|
"com.arsdigita.cms.contenttypes.GenericContactBundle";
|
||||||
|
|
@ -51,6 +55,65 @@ public class GenericContactBundle extends ContentBundle {
|
||||||
super(type);
|
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() {
|
public GenericPerson getPerson() {
|
||||||
DataCollection collection;
|
DataCollection collection;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.contenttypes;
|
package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentType;
|
|
||||||
import com.arsdigita.cms.ContentPage;
|
import com.arsdigita.cms.ContentPage;
|
||||||
|
import com.arsdigita.cms.ContentType;
|
||||||
import com.arsdigita.cms.LanguageInvariantContentItem;
|
import com.arsdigita.cms.LanguageInvariantContentItem;
|
||||||
import com.arsdigita.cms.RelationAttributeInterface;
|
import com.arsdigita.cms.RelationAttributeInterface;
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
import com.arsdigita.domain.DomainObjectFactory;
|
import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
|
||||||
import com.arsdigita.persistence.DataObject;
|
import com.arsdigita.persistence.DataObject;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.StringTokenizer;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic GenericPerson Contenttype for OpenCCM.
|
* Basic GenericPerson Contenttype for OpenCCM.
|
||||||
|
|
@ -56,13 +55,17 @@ public class GenericPerson extends ContentPage implements
|
||||||
public static final String DABIN_ID = "dabinId";
|
public static final String DABIN_ID = "dabinId";
|
||||||
private static final String RELATION_ATTRIBUTES =
|
private static final String RELATION_ATTRIBUTES =
|
||||||
"contacts.link_key:GenericContactType";
|
"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 =
|
public static final String BASE_DATA_OBJECT_TYPE =
|
||||||
"com.arsdigita.cms.contenttypes.GenericPerson";
|
"com.arsdigita.cms.contenttypes.GenericPerson";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor. This creates a new (empty) GenericPerson.
|
* Default constructor. This creates a new (empty) GenericPerson.
|
||||||
**/
|
*
|
||||||
|
*/
|
||||||
public GenericPerson() {
|
public GenericPerson() {
|
||||||
this(BASE_DATA_OBJECT_TYPE);
|
this(BASE_DATA_OBJECT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +97,9 @@ public class GenericPerson extends ContentPage implements
|
||||||
Assert.exists(getContentType(), ContentType.class);
|
Assert.exists(getContentType(), ContentType.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* accessors *****************************************************/
|
/*
|
||||||
|
* accessors ****************************************************
|
||||||
|
*/
|
||||||
public String getSurname() {
|
public String getSurname() {
|
||||||
return (String) get(SURNAME);
|
return (String) get(SURNAME);
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +153,8 @@ public class GenericPerson extends ContentPage implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericPerson getAlias() {
|
public GenericPerson getAlias() {
|
||||||
return (GenericPerson) DomainObjectFactory.newInstance((DataObject) get(ALIAS));
|
return (GenericPerson) DomainObjectFactory.newInstance((DataObject) get(
|
||||||
|
ALIAS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlias(final GenericPerson alias) {
|
public void setAlias(final GenericPerson alias) {
|
||||||
|
|
@ -220,12 +226,14 @@ public class GenericPerson extends ContentPage implements
|
||||||
// Add a contact for this person
|
// Add a contact for this person
|
||||||
public void addContact(final GenericContact contact,
|
public void addContact(final GenericContact contact,
|
||||||
final String contactType) {
|
final String contactType) {
|
||||||
/* Assert.exists(contact, GenericContact.class);
|
/*
|
||||||
|
* Assert.exists(contact, GenericContact.class);
|
||||||
DataObject link = add(CONTACTS, contact);
|
*
|
||||||
|
* DataObject link = add(CONTACTS, contact);
|
||||||
link.set(CONTACTS_KEY, contactType);
|
*
|
||||||
link.set(CONTACTS_ORDER, BigDecimal.valueOf(getContacts().size()));*/
|
* link.set(CONTACTS_KEY, contactType); link.set(CONTACTS_ORDER,
|
||||||
|
* BigDecimal.valueOf(getContacts().size()));
|
||||||
|
*/
|
||||||
getGenericPersonBundle().addContact(contact, contactType);
|
getGenericPersonBundle().addContact(contact, contactType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,15 @@ package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentBundle;
|
import com.arsdigita.cms.ContentBundle;
|
||||||
import com.arsdigita.cms.ContentItem;
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.CustomCopy;
|
||||||
|
import com.arsdigita.cms.ItemCopier;
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
|
import com.arsdigita.domain.DomainObject;
|
||||||
|
import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
import com.arsdigita.persistence.DataObject;
|
import com.arsdigita.persistence.DataObject;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
|
import com.arsdigita.persistence.metadata.Property;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
|
@ -14,7 +19,8 @@ import java.math.BigDecimal;
|
||||||
* @author Jens Pelzetter
|
* @author Jens Pelzetter
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class GenericPersonBundle extends ContentBundle {
|
public class GenericPersonBundle
|
||||||
|
extends ContentBundle {
|
||||||
|
|
||||||
public final static String BASE_DATA_OBJECT_TYPE =
|
public final static String BASE_DATA_OBJECT_TYPE =
|
||||||
"com.arsdigita.cms.contenttypes.GenericPersonBundle";
|
"com.arsdigita.cms.contenttypes.GenericPersonBundle";
|
||||||
|
|
@ -76,4 +82,49 @@ public class GenericPersonBundle extends ContentBundle {
|
||||||
public boolean hasContacts() {
|
public boolean hasContacts() {
|
||||||
return !this.getContacts().isEmpty();
|
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() {
|
public GenericAddress getAddress() {
|
||||||
/*
|
|
||||||
* return (GenericAddress) DomainObjectFactory.newInstance((DataObject)
|
|
||||||
* m_dataCollection. getDataObject().get(
|
|
||||||
GenericContact.ADDRESS));
|
|
||||||
*/
|
|
||||||
return getContact().getAddress();
|
return getContact().getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericContactEntryCollection getContactEntries() {
|
public GenericContactEntryCollection getContactEntries() {
|
||||||
/*
|
|
||||||
* return new GenericContactEntryCollection((DataCollection)
|
|
||||||
* m_dataCollection. getDataObject().get(
|
|
||||||
GenericContact.CONTACT_ENTRIES));
|
|
||||||
*/
|
|
||||||
return getContact().getContactEntries();
|
return getContact().getContactEntries();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue