Assoziation Publication <-> GenericPerson optimiert, Ticket 1115)

git-svn-id: https://svn.libreccm.org/ccm/trunk@1567 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-04-05 08:01:36 +00:00
parent d6839274b0
commit 9e72a3b58b
7 changed files with 278 additions and 42 deletions

View File

@ -1947,17 +1947,32 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
}
}
final AssociationCopierLoader assocCopierLoader =
/*final AssociationCopierLoader assocCopierLoader =
AssociationCopierLoader.getInstance();
final AssociationCopier assocCopier = assocCopierLoader.
getAssociationCopierFor(property, source);
if (assocCopier != null) {
return assocCopier.copyProperty(source, property, copier);
}*/
if (handlesReverseProperties()) {
return copyReverseProperty(source, this, property, copier);
}
return false;
}
public boolean handlesReverseProperties() {
return false;
}
public boolean copyReverseProperty(final CustomCopy source,
final ContentItem liveItem,
final Property property,
final ItemCopier copier) {
return false;
}
/**
* Copy services from the source item. This method is the analogue of the {@link #copyProperty}
* method above. The object copier will call this method whenever an item

View File

@ -20,14 +20,10 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.contenttypes.ui.GenericOrganizationalUnitSubordinateOrgaUnitAddForm;
import com.arsdigita.cms.contenttypes.ui.GenericOrganizationalUnitSubordinateOrgaUnitsTable;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.domain.DataObjectNotFoundException;
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 org.apache.log4j.Logger;

View File

@ -71,7 +71,8 @@ public class GenericOrganizationalUnitPersonCollection extends DomainCollection
public GenericPerson getPerson() {
/*return (GenericPerson) DomainObjectFactory.newInstance(m_dataCollection.
getDataObject());*/
final ContentBundle bundle = (ContentBundle) DomainObjectFactory.newInstance(m_dataCollection.getDataObject());
final ContentBundle bundle = (ContentBundle) DomainObjectFactory.
newInstance(m_dataCollection.getDataObject());
return (GenericPerson) bundle.getPrimaryInstance();
}

View File

@ -20,6 +20,7 @@
model com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentBundle;
//PDL definition for the basic attributes of publication.
object type Publication extends ContentPage {
@ -44,18 +45,23 @@ object type Publication extends ContentPage {
reference key (ct_publications.publication_id);
}
object type PublicationBundle extends ContentBundle {
reference key (ct_publication_bundles.bundle_id);
}
//Assoication for the authors
association {
Publication[0..n] publication = join cms_persons.person_id
PublicationBundle[0..n] publication = join cms_person_bundles.bundle_id
to ct_publications_authorship.person_id,
join ct_publications_authorship.publication_id
to ct_publications.publication_id;
to ct_publication_bundles.bundle_id;
GenericPerson[0..n] authors = join ct_publications.publication_id
GenericPersonBundle[0..n] authors = join ct_publication_bundles.bundle_id
to ct_publications_authorship.publication_id,
join ct_publications_authorship.person_id
to cms_persons.person_id;
to cms_person_bundles.bundle_id;
// Additional attributes
Boolean[0..1] editor = ct_publications_authorship.editor BIT;

View File

@ -18,7 +18,9 @@
*/
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.domain.DomainCollection;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
import org.apache.log4j.Logger;
@ -172,17 +174,22 @@ public class AuthorshipCollection extends DomainCollection {
this.rewind();
}
public GenericPerson getAuthor() {
//return new GenericPerson(m_dataCollection.getDataObject());
final ContentBundle bundle = (ContentBundle) DomainObjectFactory.
newInstance(m_dataCollection.getDataObject());
return (GenericPerson) bundle.getPrimaryInstance();
}
public String getSurname() {
return (String) m_dataCollection.getDataObject().get(
GenericPerson.SURNAME);
//return (String) m_dataCollection.getDataObject().get(
// GenericPerson.SURNAME);
return getAuthor().getSurname();
}
public String getGivenName() {
return (String) m_dataCollection.getDataObject().get(
GenericPerson.GIVENNAME);
}
public GenericPerson getAuthor() {
return new GenericPerson(m_dataCollection.getDataObject());
//return (String) m_dataCollection.getDataObject().get(
// GenericPerson.GIVENNAME);
return getAuthor().getGivenName();
}
}

View File

@ -69,7 +69,7 @@ public class Publication extends ContentPage {
public final static String ABSTRACT = "abstract";
public final static String MISC = "misc";
public final static String AUTHORS = "authors";
private final static String AUTHORS_STR = "authorsStr"; //authorsStr is an interal field only for use in data queries, and is updated automatically
protected final static String AUTHORS_STR = "authorsStr"; //authorsStr is an interal field only for use in data queries, and is updated automatically
public final static String EDITOR = "editor";
public final static String AUTHOR_ORDER = "authorOrder";
public final static String SERIES = "series";
@ -109,6 +109,10 @@ public class Publication extends ContentPage {
return config;
}
public PublicationBundle getPublicationBundle() {
return (PublicationBundle) getContentBundle();
}
/**
* Gets the year of publications.
*
@ -179,7 +183,8 @@ public class Publication extends ContentPage {
* @return Collection of the authors of the publication.
*/
public AuthorshipCollection getAuthors() {
return new AuthorshipCollection((DataCollection) get(AUTHORS));
//return new AuthorshipCollection((DataCollection) get(AUTHORS));
return getPublicationBundle().getAuthors();
}
/**
@ -190,14 +195,16 @@ public class Publication extends ContentPage {
* @param editor Is the author an editor?
*/
public void addAuthor(final GenericPerson author, final Boolean editor) {
Assert.exists(author, GenericPerson.class);
//Assert.exists(author, GenericPerson.class);
DataObject link = add(AUTHORS, author);
//DataObject link = add(AUTHORS, author);
link.set(EDITOR, editor);
link.set(AUTHOR_ORDER, Integer.valueOf((int) getAuthors().size()));
//link.set(EDITOR, editor);
//link.set(AUTHOR_ORDER, Integer.valueOf((int) getAuthors().size()));
updateAuthorsStr();
//updateAuthorsStr();
getPublicationBundle().addAuthor(author, editor);
}
/**
@ -206,10 +213,11 @@ public class Publication extends ContentPage {
* @param author The author to remove.
*/
public void removeAuthor(final GenericPerson author) {
Assert.exists(author, GenericPerson.class);
remove(AUTHORS, author);
//Assert.exists(author, GenericPerson.class);
//remove(AUTHORS, author);
updateAuthorsStr();
//updateAuthorsStr();
getPublicationBundle().removeAuthor(author);
}
public void swapWithPreviousAuthor(final GenericPerson author) {

View File

@ -0,0 +1,203 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.AssociationCopier;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.CustomCopy;
import com.arsdigita.cms.ItemCollection;
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;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class PublicationBundle extends ContentBundle {
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contentttypes.PublicationBundle";
public static final String AUTHORS = "authors";
public final static String AUTHOR_ORDER = "authorOrder";
public final static String EDITOR = "editor";
public PublicationBundle(final ContentItem primary) {
super(BASE_DATA_OBJECT_TYPE);
Assert.exists(primary, ContentItem.class);
setDefaultLanguage(primary.getLanguage());
setContentType(primary.getContentType());
addInstance(primary);
setName(primary.getName());
}
public PublicationBundle(final OID oid) throws DataObjectNotFoundException {
super(oid);
}
public PublicationBundle(final BigDecimal id)
throws DataObjectNotFoundException {
super(new OID(BASE_DATA_OBJECT_TYPE, id));
}
public PublicationBundle(final DataObject dobj) {
super(dobj);
}
public PublicationBundle(final String type) {
super(type);
}
@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 Publication pubBundle = (Publication) source;
if (AUTHORS.equals(attribute)) {
final DataCollection authors = (DataCollection) pubBundle.get(
AUTHORS);
while (authors.next()) {
createAuthorAssoc(authors);
}
return true;
} else {
return super.copyProperty(source, property, copier);
}
} else {
return super.copyProperty(source, property, copier);
}
}
@Override
public boolean handlesReverseProperties() {
return true;
}
@Override
public boolean copyReverseProperty(final CustomCopy source,
final ContentItem liveItem,
final Property property,
final ItemCopier copier) {
final String attribute = property.getName();
if (copier.getCopyType() == ItemCopier.VERSION_COPY) {
if (("publication".equals(attribute))
&& (source instanceof GenericPersonBundle)) {
final GenericPersonBundle authorBundle =
(GenericPersonBundle) source;
final DataCollection publications =
(DataCollection) authorBundle.get(
"publication");
while (publications.next()) {
createAuthorPublicationAssoc(publications,
(GenericPersonBundle) liveItem);
}
return true;
} else {
return super.copyReverseProperty(source, liveItem, property,
copier);
}
} else {
return super.copyReverseProperty(source, liveItem, property, copier);
}
}
private void createAuthorAssoc(final DataCollection authors) {
final GenericPersonBundle draftAuthor =
(GenericPersonBundle) DomainObjectFactory.
newInstance(authors.getDataObject());
final GenericPersonBundle liveAuthor =
(GenericPersonBundle) draftAuthor.
getLiveVersion();
if (liveAuthor != null) {
final DataObject link = add(AUTHORS, liveAuthor);
link.set(EDITOR, authors.get(AuthorshipCollection.LINKEDITOR));
link.set(AUTHOR_ORDER, authors.get(AuthorshipCollection.LINKORDER));
link.save();
}
}
private void createAuthorPublicationAssoc(final DataCollection publications,
final GenericPersonBundle author) {
final PublicationBundle draftPublication =
(PublicationBundle) DomainObjectFactory.
newInstance(publications.getDataObject());
final PublicationBundle livePublication =
(PublicationBundle) draftPublication.
getLiveVersion();
if (livePublication != null) {
final DataObject link = author.add("publication", livePublication);
link.set(EDITOR, publications.get(AuthorshipCollection.LINKEDITOR));
link.set(AUTHOR_ORDER, publications.get(AuthorshipCollection.LINKORDER));
link.save();
}
}
public AuthorshipCollection getAuthors() {
return new AuthorshipCollection((DataCollection) get(AUTHORS));
}
public void addAuthor(final GenericPerson author, final Boolean editor) {
Assert.exists(author, GenericPerson.class);
final DataObject link = add(AUTHORS, author);
link.set(EDITOR, editor);
link.set(AUTHOR_ORDER, Integer.valueOf((int) getAuthors().size()));
updateAuthorsStr();
}
public void removeAuthor(final GenericPerson author) {
Assert.exists(author, GenericPerson.class);
remove(AUTHORS, author);
updateAuthorsStr();
}
protected void updateAuthorsStr() {
final AuthorshipCollection authors = getAuthors();
StringBuilder builder = new StringBuilder();
while (authors.next()) {
if (builder.length() > 0) {
builder.append("; ");
}
builder.append(authors.getSurname());
builder.append(", ");
builder.append(authors.getGivenName());
}
final String authorsStr = builder.toString();
final ItemCollection instances = getInstances();
Publication publication;
while (instances.next()) {
publication = (Publication) instances.getDomainObject();
publication.set(Publication.AUTHORS_STR, authorsStr);
}
}
}