Überarbeitete Assoziation GenericContact <-> GenericPerson

git-svn-id: https://svn.libreccm.org/ccm/trunk@1482 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-01-30 18:36:20 +00:00
parent 503d7519c2
commit ab0e27cf33
9 changed files with 271 additions and 51 deletions

View File

@ -11,7 +11,7 @@
classname="com.arsdigita.cms.contenttypes.Contact"> classname="com.arsdigita.cms.contenttypes.Contact">
<ctd:authoring-kit <ctd:authoring-kit
createComponent="com.arsdigita.cms.ui.authoring.PageCreate"> createComponent="com.arsdigita.cms.contenttypes.ui.GenericContactCreate">
<ctd:authoring-step <ctd:authoring-step
labelKey="cms.contenttypes.shared.basic_properties.title" labelKey="cms.contenttypes.shared.basic_properties.title"

View File

@ -34,6 +34,10 @@ object type GenericContact extends ContentPage {
reference key ( cms_contacts.contact_id ); reference key ( cms_contacts.contact_id );
} }
object type GenericContactBundle extends ContentBundle {
reference key (cms_contact_bundles.bundle_id);
}
object type GenericContactEntry extends ContentItem { object type GenericContactEntry extends ContentItem {
String[1..1] key = cms_contactEntries.key VARCHAR(100); String[1..1] key = cms_contactEntries.key VARCHAR(100);
@ -46,18 +50,18 @@ object type GenericContactEntry extends ContentItem {
association { association {
GenericPerson[0..n] person = join cms_contacts.contact_id GenericPersonBundle[0..n] person = join cms_contact_bundles.bundle_id
to cms_person_contact_map.contact_id, to cms_person_contact_map.contact_id,
join cms_person_contact_map.person_id join cms_person_contact_map.person_id
to cms_persons.person_id; to cms_person_bundles.bundle_id;
GenericContact[0..n] contacts = join cms_persons.person_id GenericContactBundle[0..n] contacts = join cms_person_bundles.bundle_id
to cms_person_contact_map.person_id, to cms_person_contact_map.person_id,
join cms_person_contact_map.contact_id join cms_person_contact_map.contact_id
to cms_contacts.contact_id; to cms_contact_bundles.bundle_id;
// Link Attribute // Link Attribute
BigDecimal[0..1] link_order = cms_person_contact_map.link_order INTEGER; BigDecimal[0..1] linkOrder = cms_person_contact_map.link_order INTEGER;
String[0..1] link_key = cms_person_contact_map.link_key VARCHAR(100); String[0..1] linkKey = cms_person_contact_map.link_key VARCHAR(100);
} }

View File

@ -12,7 +12,7 @@
mode="hidden"> mode="hidden">
<ctd:authoring-kit <ctd:authoring-kit
createComponent="com.arsdigita.cms.ui.authoring.PageCreate"> createComponent="com.arsdigita.cms.contenttypes.ui.GenericContactCreate">
<ctd:authoring-step <ctd:authoring-step
labelKey="cms.contenttypes.shared.basic_properties.title" labelKey="cms.contenttypes.shared.basic_properties.title"

View File

@ -98,11 +98,15 @@ public class GenericContact extends ContentPage implements
return s_config; return s_config;
} }
public GenericContactBundle getGenericContactBundle() {
return (GenericContactBundle) getContentBundle();
}
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// 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);
@ -118,14 +122,15 @@ public class GenericContact extends ContentPage implements
collection.close(); collection.close();
return (GenericPerson) DomainObjectFactory.newInstance(dobj); return (GenericPerson) DomainObjectFactory.newInstance(dobj);
} }*/
//return (GenericPerson) DomainObjectFactory.newInstance((DataObject)get(PERSON));
return getGenericContactBundle().getPerson();
} }
// 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) { /*if (getPerson() != null) {
unsetPerson(); unsetPerson();
} }
@ -135,7 +140,9 @@ public class GenericContact extends ContentPage implements
link.set(GenericPerson.CONTACTS_KEY, contactType); link.set(GenericPerson.CONTACTS_KEY, contactType);
link.set(GenericPerson.CONTACTS_ORDER, new BigDecimal(person.getContacts().size())); link.set(GenericPerson.CONTACTS_ORDER, new BigDecimal(person.getContacts().size()));
link.save(); link.save();
} }*/
getGenericContactBundle().setPerson(person, contactType);
} }
// // Get the type for this contact // // Get the type for this contact
@ -150,11 +157,13 @@ 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; /*GenericPerson oldPerson;
oldPerson = getPerson(); oldPerson = getPerson();
if (oldPerson != null) { if (oldPerson != null) {
remove(PERSON, oldPerson); remove(PERSON, oldPerson);
} }*/
getGenericContactBundle().unsetPerson();
} }
// Get the address for this contact // Get the address for this contact

View File

@ -0,0 +1,100 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
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;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class GenericContactBundle extends ContentBundle {
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.GenericContactBundle";
public static final String PERSON = "person";
public GenericContactBundle(final ContentItem primary) {
super(BASE_DATA_OBJECT_TYPE);
Assert.exists(primary, ContentItem.class);
setDefaultLanguage(primary.getLanguage());
setContentType(primary.getContentType());
addInstance(primary);
super.setName(primary.getName());
}
public GenericContactBundle(final OID oid) throws
DataObjectNotFoundException {
super(oid);
}
public GenericContactBundle(final BigDecimal id) throws
DataObjectNotFoundException {
super(new OID(BASE_DATA_OBJECT_TYPE, id));
}
public GenericContactBundle(final DataObject dobj) {
super(dobj);
}
public GenericContactBundle(final String type) {
super(type);
}
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();
final GenericPersonBundle bundle =
(GenericPersonBundle) DomainObjectFactory.
newInstance(dobj);
return (GenericPerson) bundle.getPrimaryInstance();
}
}
public void setPerson(GenericPerson person, String contactType) {
if (getPerson() != null) {
unsetPerson();
}
if (person != null) {
Assert.exists(person, GenericPerson.class);
DataObject link = add(PERSON, person.getGenericPersonBundle());
link.set(GenericPerson.CONTACTS_KEY, contactType);
link.set(GenericPerson.CONTACTS_ORDER, new BigDecimal(person.
getContacts().size()));
link.save();
}
}
public void unsetPerson() {
GenericPerson oldPerson;
oldPerson = getPerson();
if (oldPerson != null) {
remove(PERSON, oldPerson.getGenericPersonBundle());
}
}
}

View File

@ -50,8 +50,8 @@ public class GenericPerson extends ContentPage implements
public static final String BIRTHDATE = "birthdate"; public static final String BIRTHDATE = "birthdate";
public static final String GENDER = "gender"; public static final String GENDER = "gender";
public static final String CONTACTS = "contacts"; public static final String CONTACTS = "contacts";
public static final String CONTACTS_KEY = "link_key"; public static final String CONTACTS_KEY = "linkKey";
public static final String CONTACTS_ORDER = "link_order"; public static final String CONTACTS_ORDER = "linkOrder";
public static final String ALIAS = "alias"; public static final String ALIAS = "alias";
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 =
@ -212,24 +212,28 @@ public class GenericPerson extends ContentPage implements
// Get all contacts for this person // Get all contacts for this person
public GenericPersonContactCollection getContacts() { public GenericPersonContactCollection getContacts() {
return new GenericPersonContactCollection( //return new GenericPersonContactCollection(
(DataCollection) get(CONTACTS)); // (DataCollection) get(CONTACTS));
return getGenericPersonBundle().getContacts();
} }
// Add a contact for this person // Add a contact for this person
public void addContact(GenericContact contact, String contactType) { public void addContact(final GenericContact contact,
Assert.exists(contact, GenericContact.class); final String contactType) {
/* Assert.exists(contact, GenericContact.class);
DataObject link = add(CONTACTS, contact); DataObject link = add(CONTACTS, contact);
link.set(CONTACTS_KEY, contactType); link.set(CONTACTS_KEY, contactType);
link.set(CONTACTS_ORDER, BigDecimal.valueOf(getContacts().size())); link.set(CONTACTS_ORDER, BigDecimal.valueOf(getContacts().size()));*/
getGenericPersonBundle().addContact(contact, contactType);
} }
// Remove a contact for this person // Remove a contact for this person
public void removeContact(GenericContact contact) { public void removeContact(final GenericContact contact) {
Assert.exists(contact, GenericContact.class); //Assert.exists(contact, GenericContact.class);
remove(CONTACTS, contact); //remove(CONTACTS, contact);
getGenericPersonBundle().removeContact(contact);
} }
public boolean hasContacts() { public boolean hasContacts() {

View File

@ -3,6 +3,7 @@ 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.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
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;
@ -15,7 +16,11 @@ import java.math.BigDecimal;
*/ */
public class GenericPersonBundle extends ContentBundle { public class GenericPersonBundle extends ContentBundle {
public final static String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericPersonBundle"; public final static String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.GenericPersonBundle";
public static final String CONTACTS = "contacts";
public static final String CONTACTS_KEY = "linkKey";
public static final String CONTACTS_ORDER = "linkOrder";
public GenericPersonBundle(final ContentItem primary) { public GenericPersonBundle(final ContentItem primary) {
super(BASE_DATA_OBJECT_TYPE); super(BASE_DATA_OBJECT_TYPE);
@ -33,7 +38,8 @@ public class GenericPersonBundle extends ContentBundle {
super(oid); super(oid);
} }
public GenericPersonBundle(final BigDecimal id) throws DataObjectNotFoundException { public GenericPersonBundle(final BigDecimal id) throws
DataObjectNotFoundException {
super(new OID(BASE_DATA_OBJECT_TYPE, id)); super(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
@ -45,6 +51,29 @@ public class GenericPersonBundle extends ContentBundle {
super(type); super(type);
} }
public GenericPersonContactCollection getContacts() {
return new GenericPersonContactCollection(
(DataCollection) get(CONTACTS));
}
// 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.getContentBundle());
link.set(CONTACTS_KEY, contactType);
link.set(CONTACTS_ORDER, BigDecimal.valueOf(getContacts().size()));
}
// Remove a contact for this person
public void removeContact(GenericContact contact) {
Assert.exists(contact, GenericContact.class);
remove(CONTACTS, contact.getContentBundle());
}
public boolean hasContacts() {
return !this.getContacts().isEmpty();
}
} }

View File

@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes;
import com.arsdigita.domain.DomainCollection; import com.arsdigita.domain.DomainCollection;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataObject;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -48,10 +49,10 @@ public class GenericPersonContactCollection extends DomainCollection {
public void setContactOrder(BigDecimal order) { public void setContactOrder(BigDecimal order) {
DataObject link = (DataObject) this.get("link"); DataObject link = (DataObject) this.get("link");
link.set(CONTACTS_ORDER, order); link.set("linkOrder", order);
} }
public void swapWithNext(GenericContact contact) { public void swapWithNext(final GenericContact contact) {
int currentPos = 0; int currentPos = 0;
int currentIndex = 0; int currentIndex = 0;
int nextIndex = 0; int nextIndex = 0;
@ -93,7 +94,7 @@ public class GenericPersonContactCollection extends DomainCollection {
this.rewind(); this.rewind();
} }
public void swapWithPrevious(GenericContact contact) { public void swapWithPrevious(final GenericContact contact) {
int previousPos = 0; int previousPos = 0;
int previousIndex = 0; int previousIndex = 0;
int currentPos = 0; int currentPos = 0;
@ -139,7 +140,19 @@ public class GenericPersonContactCollection extends DomainCollection {
} }
public GenericContact getContact() { public GenericContact getContact() {
return new GenericContact(m_dataCollection.getDataObject()); final GenericContactBundle bundle =
(GenericContactBundle) DomainObjectFactory.
newInstance(m_dataCollection.getDataObject());
return (GenericContact) bundle.getInstance(GlobalizationHelper.
getNegotiatedLocale().getLanguage());
//return new GenericContact(m_dataCollection.getDataObject());
}
public GenericContact getContact(final String language) {
final GenericContactBundle bundle =
(GenericContactBundle) DomainObjectFactory.
newInstance(m_dataCollection.getDataObject());
return (GenericContact) bundle.getInstance(language);
} }
public GenericPerson getPerson() { public GenericPerson getPerson() {
@ -159,19 +172,28 @@ public class GenericPersonContactCollection extends DomainCollection {
// Close Collection to prevent an open ResultSet // Close Collection to prevent an open ResultSet
collection.close(); collection.close();
return (GenericPerson) DomainObjectFactory.newInstance(dobj); GenericContactBundle bundle =
(GenericContactBundle) DomainObjectFactory.
newInstance(dobj);
return (GenericPerson) bundle.getPrimaryInstance();
} }
} }
public GenericAddress getAddress() { public GenericAddress getAddress() {
return (GenericAddress) DomainObjectFactory.newInstance((DataObject) m_dataCollection. /*
getDataObject().get( * return (GenericAddress) DomainObjectFactory.newInstance((DataObject)
* m_dataCollection. getDataObject().get(
GenericContact.ADDRESS)); GenericContact.ADDRESS));
*/
return getContact().getAddress();
} }
public GenericContactEntryCollection getContactEntries() { public GenericContactEntryCollection getContactEntries() {
return new GenericContactEntryCollection((DataCollection) m_dataCollection. /*
getDataObject().get( * return new GenericContactEntryCollection((DataCollection)
* m_dataCollection. getDataObject().get(
GenericContact.CONTACT_ENTRIES)); GenericContact.CONTACT_ENTRIES));
*/
return getContact().getContactEntries();
} }
} }

View File

@ -0,0 +1,52 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.GenericContactBundle;
import com.arsdigita.cms.ui.authoring.CreationSelector;
import com.arsdigita.cms.ui.authoring.PageCreate;
import java.util.Date;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class GenericContactCreate extends PageCreate {
public GenericContactCreate(final ItemSelectionModel itemModel,
final CreationSelector parent) {
super(itemModel, parent);
}
@Override
public void process(final FormSectionEvent fse) throws FormProcessException {
final FormData data = fse.getFormData();
final PageState state = fse.getPageState();
final ContentSection section = m_parent.getContentSection(state);
final Folder folder = m_parent.getFolder(state);
final ContentPage item = createContentPage(state);
item.setLanguage((String) data.get(LANGUAGE));
item.setName((String) data.get(NAME));
item.setTitle((String) data.get(TITLE));
if (!ContentSection.getConfig().getHideLaunchDate()) {
item.setLaunchDate((Date) data.get(LAUNCH_DATE));
}
final GenericContactBundle bundle = new GenericContactBundle(item);
bundle.setParent(folder);
bundle.setContentSection(section);
bundle.save();
m_workflowSection.applyWorkflow(state, item);
m_parent.editItem(state, item);
}
}