Bei Publizieren eines Items mit einem RelatatedLink kam es zu einer ClassCastException, da RelatedLink Objekte sich nicht zu ContentItem casten lassen (letzter

Parameter von PublishedLink#create()). Korrigiert, indem in VersionCopier für Objekte, die nicht von ContentItem abgeleitet sind 'null' im Parameter sourceObject 
übergeben wird. In PublishedLink#create() wird nun geprüft, ob sourceObject 'null' ist. Wenn der Parameter nicht 'null' ist, werden LinkAttribute (dafür ist dieser 
Parameter erforderlich) kopiert. Falls der Parameter 'null' ist, wird dieser Methodenaufruf übersprungen (in diesem Fall wäre er auch sinnlos).


git-svn-id: https://svn.libreccm.org/ccm/trunk@634 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2010-11-25 08:00:27 +00:00
parent c5b1f1a405
commit 1a574abe70
2 changed files with 46 additions and 36 deletions

View File

@ -150,7 +150,7 @@ class PublishedLink extends DomainObject {
link = new PublishedLink(SessionManager.getSession().create(oid));
}
if (sourceObject.getObjectType().getProperty(propertyName).isCollection()) {
if ((sourceObject != null) && sourceObject.getObjectType().getProperty(propertyName).isCollection()) {
link.saveLinkAttributes((DataCollection) sourceObject.get(propertyName + "@link"));
}

View File

@ -21,6 +21,7 @@ package com.arsdigita.cms;
import com.arsdigita.cms.lifecycle.Lifecycle;
import com.arsdigita.cms.lifecycle.LifecycleService;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.persistence.OID;
import com.arsdigita.util.Assert;
@ -39,7 +40,6 @@ import java.util.HashSet;
class VersionCopier extends ObjectCopier {
private static Logger s_log = Logger.getLogger(VersionCopier.class);
private final Lifecycle m_lifecycle;
private boolean m_once = false;
private long m_start = 0;
@ -91,10 +91,10 @@ class VersionCopier extends ObjectCopier {
m_once = true;
}
m_topLevelSourceOID = item.getOID();
m_topLevelSourceOID = item.getOID();
final ContentItem version = createVersion(item);
//Assert.isTrue(m_topLevelSourceOID == null,
// "CopyItem should be called only once for a given copier instance");
//Assert.isTrue(m_topLevelSourceOID == null,
// "CopyItem should be called only once for a given copier instance");
if (m_lifecycle != null) {
LifecycleService.setLifecycle(version, m_lifecycle);
@ -108,9 +108,10 @@ class VersionCopier extends ObjectCopier {
}
if (s_log.isInfoEnabled()) {
s_log.info("Done publishing " + item + " (" +
(System.currentTimeMillis() - m_start) +
" millis)");
s_log.info("Done publishing " + item + " (" + (System.
currentTimeMillis()
- m_start)
+ " millis)");
}
return version;
@ -133,10 +134,10 @@ class VersionCopier extends ObjectCopier {
*/
@Override
public DomainObject copy(final DomainObject object) {
if (object != null) {
m_traversedComponents.add(object);
}
return super.copy(object);
if (object != null) {
m_traversedComponents.add(object);
}
return super.copy(object);
}
/**
@ -173,9 +174,9 @@ class VersionCopier extends ObjectCopier {
*/
@Override
protected DomainObject copy(final DomainObject source,
final DomainObject target,
final DomainObject object,
final Property prop) {
final DomainObject target,
final DomainObject object,
final Property prop) {
m_trace.enter("copy", object, prop);
if (s_log.isDebugEnabled()) {
@ -197,8 +198,8 @@ class VersionCopier extends ObjectCopier {
}
if (prop.isComponent()) {
s_log.debug("The property is a component; creating a " +
"live or pending version");
s_log.debug("The property is a component; creating a "
+ "live or pending version");
final ContentItem copy = createVersion(item);
@ -206,26 +207,35 @@ class VersionCopier extends ObjectCopier {
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");
final DomainObject copy = copy(object);
PublishedLink.create((ContentItem) getCopy(m_topLevelSourceOID), target, prop.getName(), item, (ContentItem) source);
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 (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;
}
} else {
s_log.debug("The property is not a content item; using " +
"domain object copier");
s_log.debug("The property is not a content item; using "
+ "domain object copier");
final DomainObject copy = super.copy(source, target, object, prop);
@ -244,11 +254,11 @@ class VersionCopier extends ObjectCopier {
final ContentItem version = (ContentItem) copy(item);
s_log.debug("The copy is pending; associating it with " +
"the draft item");
version.setVersion(ContentItem.PENDING);
item.addPendingVersion(version);
s_log.debug("The copy is pending; associating it with "
+ "the draft item");
version.setVersion(ContentItem.PENDING);
item.addPendingVersion(version);
version.copyServicesFrom(item);