- Association between GenericContact and GenericAddress is now modeled like other associations (necessary to work around limitations in the publication process and of PDL). Solves Ticket #2039.
- Is was not possible to remove a address from a contact. See #2017. Attention: Database Upgrade ccm-cms-6.6.10-6.6.11 required for existing databases! git-svn-id: https://svn.libreccm.org/ccm/trunk@2547 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
4aed32729b
commit
1b23384b47
|
|
@ -1,6 +1,6 @@
|
||||||
model com.arsdigita.cms.contenttypes;
|
model com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentPage;
|
import com.arsdigita.cms.*;
|
||||||
|
|
||||||
// Address object
|
// Address object
|
||||||
object type GenericAddress extends ContentPage {
|
object type GenericAddress extends ContentPage {
|
||||||
|
|
@ -14,3 +14,7 @@ object type GenericAddress extends ContentPage {
|
||||||
reference key ( cms_addresses.address_id );
|
reference key ( cms_addresses.address_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object type GenericAddressBundle extends ContentBundle {
|
||||||
|
reference key (cms_address_bundles.bundle_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,6 @@ import com.arsdigita.cms.*;
|
||||||
// Contact Object
|
// Contact Object
|
||||||
object type GenericContact extends ContentPage {
|
object type GenericContact extends ContentPage {
|
||||||
|
|
||||||
GenericAddress [0..1] address = join cms_contacts.address_id
|
|
||||||
to cms_addresses.address_id;
|
|
||||||
|
|
||||||
component GenericContactEntry [0..n] contactentries = join cms_contacts.contact_id
|
component GenericContactEntry [0..n] contactentries = join cms_contacts.contact_id
|
||||||
to cms_contactEntries.contact_id;
|
to cms_contactEntries.contact_id;
|
||||||
|
|
||||||
|
|
@ -50,18 +47,36 @@ object type GenericContactEntry extends ContentItem {
|
||||||
|
|
||||||
association {
|
association {
|
||||||
|
|
||||||
GenericPersonBundle[0..n] person = join cms_contact_bundles.bundle_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_person_bundles.bundle_id;
|
to cms_person_bundles.bundle_id;
|
||||||
|
|
||||||
GenericContactBundle[0..n] contacts = join cms_person_bundles.bundle_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_contact_bundles.bundle_id;
|
to cms_contact_bundles.bundle_id;
|
||||||
|
|
||||||
// Link Attribute
|
// Link Attribute
|
||||||
BigDecimal[0..1] linkOrder = cms_person_contact_map.link_order INTEGER;
|
BigDecimal[0..1] linkOrder = cms_person_contact_map.link_order INTEGER;
|
||||||
String[0..1] linkKey = cms_person_contact_map.link_key VARCHAR(100);
|
String[0..1] linkKey = cms_person_contact_map.link_key VARCHAR(100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
association {
|
||||||
|
|
||||||
|
GenericAddressBundle[0..n] address = join cms_contact_bundles.bundle_id
|
||||||
|
to cms_contact_address_map.contact_id,
|
||||||
|
join cms_contact_address_map.address_id
|
||||||
|
to cms_address_bundles.bundle_id;
|
||||||
|
|
||||||
|
GenericContactBundle[0..n] contacts = join cms_address_bundles.bundle_id
|
||||||
|
to cms_contact_address_map.address_id,
|
||||||
|
join cms_contact_address_map.contact_id
|
||||||
|
to cms_contact_bundles.bundle_id;
|
||||||
|
|
||||||
|
//We don't need for UI purposes but other the ContentItem#add method does not return a link
|
||||||
|
//object if an association has no attributes...
|
||||||
|
BigDecimal[0..1] linkOrder = cms_contact_address_map.link_order INTEGER;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.GenericAddressCreate">
|
||||||
|
|
||||||
<ctd:authoring-step
|
<ctd:authoring-step
|
||||||
labelKey="cms.contenttypes.shared.basic_properties.title"
|
labelKey="cms.contenttypes.shared.basic_properties.title"
|
||||||
|
|
|
||||||
|
|
@ -80,5 +80,8 @@
|
||||||
<version from="6.6.10" to="6.6.11">
|
<version from="6.6.10" to="6.6.11">
|
||||||
<!-- Add stacktrace column for cms_publish_lock -->
|
<!-- Add stacktrace column for cms_publish_lock -->
|
||||||
<script sql="ccm-cms/upgrade/::database::-6.6.10-6.6.11.sql"/>
|
<script sql="ccm-cms/upgrade/::database::-6.6.10-6.6.11.sql"/>
|
||||||
|
<!-- Refactor the association between GenericContact and GenericAddress to the model used by
|
||||||
|
similar assocs -->
|
||||||
|
<script class="com.arsdigita.cms.contenttypes.upgrades.Upgrade6610to6611ContactAddressAssoc"/>
|
||||||
</version>
|
</version>
|
||||||
</upgrade>
|
</upgrade>
|
||||||
|
|
|
||||||
|
|
@ -172,3 +172,4 @@ cms.contenttypes.ui.genericorgaunit.persons.status=Status
|
||||||
cms.ui.edit_assoc=Edit
|
cms.ui.edit_assoc=Edit
|
||||||
cms.contenttypes.ui.person.contact.type=Contact Type
|
cms.contenttypes.ui.person.contact.type=Contact Type
|
||||||
cms.contenttypes.ui.person.contact.title=Title
|
cms.contenttypes.ui.person.contact.title=Title
|
||||||
|
cms.contenttypes.ui.contact.person.confirm_remove=Remove address
|
||||||
|
|
|
||||||
|
|
@ -182,3 +182,4 @@ cms.contenttypes.ui.genericorgaunit.persons.status=Status
|
||||||
cms.ui.edit_assoc=Bearbeiten
|
cms.ui.edit_assoc=Bearbeiten
|
||||||
cms.contenttypes.ui.person.contact.type=Art des Kontaktes
|
cms.contenttypes.ui.person.contact.type=Art des Kontaktes
|
||||||
cms.contenttypes.ui.person.contact.title=Titel
|
cms.contenttypes.ui.person.contact.title=Titel
|
||||||
|
cms.contenttypes.ui.contact.person.confirm_remove=Addresse l\u00f6schen
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,10 @@ public class GenericAddress extends ContentPage {
|
||||||
set(STATE, state);
|
set(STATE, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericAddressBundle getGenericAddressBundle() {
|
||||||
|
return (GenericAddressBundle) getContentBundle();
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the iso country code to country names using the current locale
|
// Convert the iso country code to country names using the current locale
|
||||||
public static String getCountryNameFromIsoCode(String isoCountryCode) {
|
public static String getCountryNameFromIsoCode(String isoCountryCode) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Jens Pelzetter
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
*/
|
||||||
|
public class GenericAddressBundle extends ContentBundle {
|
||||||
|
|
||||||
|
public static final String BASE_DATA_OBJECT_TYPE
|
||||||
|
= "com.arsdigita.cms.contenttypes.GenericAddressBundle";
|
||||||
|
private static final String CONTACTS = "contacts";
|
||||||
|
|
||||||
|
public GenericAddressBundle(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 GenericAddressBundle(final OID oid) throws DataObjectNotFoundException {
|
||||||
|
super(oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericAddressBundle(final BigDecimal id) throws DataObjectNotFoundException {
|
||||||
|
super(new OID(BASE_DATA_OBJECT_TYPE, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericAddressBundle(final DataObject dobj) {
|
||||||
|
super(dobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericAddressBundle(final String type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean copyProperty(final CustomCopy source,
|
||||||
|
final Property property,
|
||||||
|
final ItemCopier copier) {
|
||||||
|
final String attribute = property.getName();
|
||||||
|
final GenericAddressBundle addressBundle = (GenericAddressBundle) source;
|
||||||
|
if (copier.getCopyType() == ItemCopier.VERSION_COPY) {
|
||||||
|
if (CONTACTS.equals(attribute)) {
|
||||||
|
final DataCollection contacts = (DataCollection) addressBundle.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.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -28,7 +28,6 @@ import com.arsdigita.cms.ContentType;
|
||||||
import com.arsdigita.cms.ContentPage;
|
import com.arsdigita.cms.ContentPage;
|
||||||
import com.arsdigita.cms.ExtraXMLGenerator;
|
import com.arsdigita.cms.ExtraXMLGenerator;
|
||||||
import com.arsdigita.cms.RelationAttributeInterface;
|
import com.arsdigita.cms.RelationAttributeInterface;
|
||||||
import com.arsdigita.domain.DomainObjectFactory;
|
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
|
|
@ -42,9 +41,9 @@ import org.apache.log4j.Logger;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GenericContact extends ContentPage implements
|
public class GenericContact extends ContentPage implements
|
||||||
RelationAttributeInterface, ExtraXMLGenerator {
|
RelationAttributeInterface, ExtraXMLGenerator {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(GenericContact.class);
|
private static final Logger LOGGER = Logger.getLogger(GenericContact.class);
|
||||||
/**
|
/**
|
||||||
* PDL property names
|
* PDL property names
|
||||||
*/
|
*/
|
||||||
|
|
@ -52,47 +51,44 @@ public class GenericContact extends ContentPage implements
|
||||||
// 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 =
|
public static final String CONTACTS_KEY = GenericPersonContactCollection.CONTACTS_KEY;
|
||||||
GenericPersonContactCollection.CONTACTS_KEY;
|
private static final String RELATION_ATTRIBUTES
|
||||||
private static final String RELATION_ATTRIBUTES =
|
= "person.link_key:GenericContactTypes;contactentries.key:GenericContactEntryKeys";
|
||||||
"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();
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
logger.debug("Static initializer is starting...");
|
LOGGER.debug("Static initializer is starting...");
|
||||||
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";
|
||||||
|
|
||||||
public GenericContact() {
|
public GenericContact() {
|
||||||
super(BASE_DATA_OBJECT_TYPE);
|
super(BASE_DATA_OBJECT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericContact(BigDecimal id)
|
public GenericContact(final BigDecimal id)
|
||||||
throws DataObjectNotFoundException {
|
throws DataObjectNotFoundException {
|
||||||
this(new OID(BASE_DATA_OBJECT_TYPE, id));
|
this(new OID(BASE_DATA_OBJECT_TYPE, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericContact(OID id)
|
public GenericContact(final OID id)
|
||||||
throws DataObjectNotFoundException {
|
throws DataObjectNotFoundException {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericContact(DataObject obj) {
|
public GenericContact(final DataObject obj) {
|
||||||
super(obj);
|
super(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericContact(String type) {
|
public GenericContact(final String type) {
|
||||||
super(type);
|
super(type);
|
||||||
//unsetPerson();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -104,6 +100,8 @@ public class GenericContact extends ContentPage implements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the current configuration
|
* Retrieves the current configuration
|
||||||
|
*
|
||||||
|
* @return The Config for GenericContact
|
||||||
*/
|
*/
|
||||||
public static final GenericContactConfig getConfig() {
|
public static final GenericContactConfig getConfig() {
|
||||||
return s_config;
|
return s_config;
|
||||||
|
|
@ -117,121 +115,80 @@ 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;
|
|
||||||
*
|
|
||||||
* 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();
|
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);
|
|
||||||
/*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
getGenericContactBundle().setPerson(person, contactType);
|
getGenericContactBundle().setPerson(person, contactType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Get the type for this contact
|
|
||||||
// public String getContactType() {
|
|
||||||
// return get(CONTACT_TYPE));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Set the type for this contact
|
|
||||||
// public void setContactType(String type) {
|
|
||||||
// set(CONTACT_TYPE, type);
|
|
||||||
// }
|
|
||||||
// Unset the address for this contact
|
// Unset the address for this contact
|
||||||
public void unsetPerson() {
|
public void unsetPerson() {
|
||||||
//set(PERSON, null);
|
|
||||||
/*
|
|
||||||
* GenericPerson oldPerson; oldPerson = getPerson(); if (oldPerson !=
|
|
||||||
* null) { remove(PERSON, oldPerson);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
getGenericContactBundle().unsetPerson();
|
getGenericContactBundle().unsetPerson();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the address for this contact
|
// Get the address for this contact
|
||||||
public GenericAddress getAddress() {
|
public GenericAddress getAddress() {
|
||||||
return (GenericAddress) DomainObjectFactory.newInstance((DataObject) get(
|
// return (GenericAddress) DomainObjectFactory.newInstance((DataObject) get(
|
||||||
ADDRESS));
|
// ADDRESS));
|
||||||
|
return getGenericContactBundle().getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the address for this contact
|
// Set the address for this contact
|
||||||
public void setAddress(GenericAddress address) {
|
public void setAddress(final GenericAddress address) {
|
||||||
set(ADDRESS, address);
|
//set(ADDRESS, address);
|
||||||
|
getGenericContactBundle().setAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset the address for this contact
|
// Unset the address for this contact
|
||||||
public void unsetAddress() {
|
public void unsetAddress() {
|
||||||
set(ADDRESS, null);
|
//set(ADDRESS, null);
|
||||||
|
getGenericContactBundle().unsetAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all contact entries for this contact, p. ex. phone number, type of contact etc.
|
// Get all contact entries for this contact, p. ex. phone number, type of contact etc.
|
||||||
public GenericContactEntryCollection getContactEntries() {
|
public GenericContactEntryCollection getContactEntries() {
|
||||||
return new GenericContactEntryCollection((DataCollection) get(
|
return new GenericContactEntryCollection((DataCollection) get(
|
||||||
CONTACT_ENTRIES));
|
CONTACT_ENTRIES));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a contact entry for this contact
|
// Add a contact entry for this contact
|
||||||
public void addContactEntry(GenericContactEntry contactEntry) {
|
public void addContactEntry(final GenericContactEntry contactEntry) {
|
||||||
Assert.exists(contactEntry, GenericContactEntry.class);
|
Assert.exists(contactEntry, GenericContactEntry.class);
|
||||||
add(CONTACT_ENTRIES, contactEntry);
|
add(CONTACT_ENTRIES, contactEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a contect entry for this contact
|
// Remove a contect entry for this contact
|
||||||
public void removeContactEntry(GenericContactEntry contactEntry) {
|
public void removeContactEntry(final GenericContactEntry contactEntry) {
|
||||||
Assert.exists(contactEntry, GenericContactEntry.class);
|
Assert.exists(contactEntry, GenericContactEntry.class);
|
||||||
remove(CONTACT_ENTRIES, contactEntry);
|
remove(CONTACT_ENTRIES, contactEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContactType() {
|
public String getContactType() {
|
||||||
|
final GenericPerson person = getPerson();
|
||||||
|
|
||||||
GenericPerson person = getPerson();
|
if (person == null) {
|
||||||
|
return null;
|
||||||
if (person != null) {
|
} else {
|
||||||
GenericPersonContactCollection collection = person.getContacts();
|
final GenericPersonContactCollection collection = person.getContacts();
|
||||||
collection.next();
|
collection.next();
|
||||||
String contactType = (String) collection.getContactType();
|
final String contactType = collection.getContactType();
|
||||||
|
|
||||||
// Close Collection to prevent open ResultSet
|
// Close Collection to prevent open ResultSet
|
||||||
collection.close();
|
collection.close();
|
||||||
|
|
||||||
return contactType;
|
return contactType;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactType(String contactType) {
|
public void setContactType(final String contactType) {
|
||||||
|
|
||||||
GenericPerson person = getPerson();
|
final GenericPerson person = getPerson();
|
||||||
if (person != null) {
|
if (person != null) {
|
||||||
GenericPersonContactCollection collection = person.getContacts();
|
final GenericPersonContactCollection collection = person.getContacts();
|
||||||
collection.next();
|
collection.next();
|
||||||
DataObject link = (DataObject) collection.get("link");
|
final DataObject link = (DataObject) collection.get("link");
|
||||||
link.set(CONTACTS_KEY, contactType);
|
link.set(CONTACTS_KEY, contactType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -254,10 +211,10 @@ public class GenericContact extends ContentPage implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasRelationAttributeProperty(String propertyName) {
|
public boolean hasRelationAttributeProperty(final String propertyName) {
|
||||||
StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
final StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
||||||
while (strTok.hasMoreTokens()) {
|
while (strTok.hasMoreTokens()) {
|
||||||
String token = strTok.nextToken();
|
final String token = strTok.nextToken();
|
||||||
if (token.startsWith(propertyName + ".")) {
|
if (token.startsWith(propertyName + ".")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -271,71 +228,108 @@ public class GenericContact extends ContentPage implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRelationAttributeKeyName(String propertyName) {
|
public String getRelationAttributeKeyName(final String propertyName) {
|
||||||
StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
final StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
||||||
while (strTok.hasMoreTokens()) {
|
while (strTok.hasMoreTokens()) {
|
||||||
String token = strTok.nextToken();
|
final String token = strTok.nextToken();
|
||||||
if (token.startsWith(propertyName + ".")) {
|
if (token.startsWith(propertyName + ".")) {
|
||||||
return token.substring(token.indexOf(".") + 1,
|
return token.substring(token.indexOf('.') + 1,
|
||||||
token.indexOf(":"));
|
token.indexOf(':'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRelationAttributeName(String propertyName) {
|
public String getRelationAttributeName(final String propertyName) {
|
||||||
StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
final StringTokenizer strTok = new StringTokenizer(RELATION_ATTRIBUTES, ";");
|
||||||
while (strTok.hasMoreTokens()) {
|
while (strTok.hasMoreTokens()) {
|
||||||
String token = strTok.nextToken();
|
final String token = strTok.nextToken();
|
||||||
if (token.startsWith(propertyName + ".")) {
|
if (token.startsWith(propertyName + ".")) {
|
||||||
return token.substring(token.indexOf(":") + 1);
|
return token.substring(token.indexOf(':') + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRelationAttributeKey(String propertyName) {
|
public String getRelationAttributeKey(final String propertyName) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateXML(ContentItem item, Element element, PageState state) {
|
public void generateXML(final ContentItem item, final Element element, final PageState state) {
|
||||||
if (getPerson() != null) {
|
if (getPerson() != null) {
|
||||||
Element personElem = element.newChildElement("person");
|
final Element personElem = element.newChildElement("person");
|
||||||
GenericPerson person = getPerson();
|
GenericPerson person = getPerson();
|
||||||
|
|
||||||
if ((person.getSurname() != null) && !person.getSurname().isEmpty()) {
|
if ((person.getSurname() != null) && !person.getSurname().isEmpty()) {
|
||||||
Element surnameElem = personElem.newChildElement("surname");
|
final Element surnameElem = personElem.newChildElement("surname");
|
||||||
surnameElem.setText(person.getSurname());
|
surnameElem.setText(person.getSurname());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((person.getGivenName() != null) && !person.getGivenName().isEmpty()) {
|
if ((person.getGivenName() != null) && !person.getGivenName().isEmpty()) {
|
||||||
Element givenNameElem = personElem.newChildElement("givenname");
|
final Element givenNameElem = personElem.newChildElement("givenname");
|
||||||
givenNameElem.setText(person.getGivenName());
|
givenNameElem.setText(person.getGivenName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((person.getTitlePre() != null) && !person.getTitlePre().isEmpty()) {
|
if ((person.getTitlePre() != null) && !person.getTitlePre().isEmpty()) {
|
||||||
Element titlePreElem = personElem.newChildElement("titlepre");
|
final Element titlePreElem = personElem.newChildElement("titlepre");
|
||||||
titlePreElem.setText(person.getTitlePre());
|
titlePreElem.setText(person.getTitlePre());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((person.getTitlePost() != null) && !person.getTitlePost().isEmpty()) {
|
if ((person.getTitlePost() != null) && !person.getTitlePost().isEmpty()) {
|
||||||
Element titlePostElem = personElem.newChildElement("titlepost");
|
final Element titlePostElem = personElem.newChildElement("titlepost");
|
||||||
titlePostElem.setText(person.getTitlePost());
|
titlePostElem.setText(person.getTitlePost());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTokenizer keys = s_config.getContactEntryKeys();
|
final StringTokenizer keys = s_config.getContactEntryKeys();
|
||||||
Element contactKeysElem = element.newChildElement("contactEntryKeys");
|
final Element contactKeysElem = element.newChildElement("contactEntryKeys");
|
||||||
while (keys.hasMoreElements()) {
|
while (keys.hasMoreElements()) {
|
||||||
contactKeysElem.newChildElement("entryKey").setText(keys.nextToken());
|
contactKeysElem.newChildElement("entryKey").setText(keys.nextToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getAddress() != null) {
|
||||||
|
final Element addressElem = element.newChildElement("address");
|
||||||
|
final GenericAddress address = getAddress();
|
||||||
|
|
||||||
|
if ((address.getAddress() != null) && !address.getAddress().isEmpty()) {
|
||||||
|
final Element addressAdrElem = addressElem.newChildElement("address");
|
||||||
|
addressAdrElem.setText(address.getAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((address.getPostalCode() != null) && !address.getPostalCode().isEmpty()) {
|
||||||
|
final Element postalCodeElem = addressElem.newChildElement("postalCode");
|
||||||
|
postalCodeElem.setText(address.getPostalCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((address.getCity() != null) && !address.getCity().isEmpty()) {
|
||||||
|
final Element cityElem = addressElem.newChildElement("city");
|
||||||
|
cityElem.setText(address.getCity());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((address.getState() != null) && !address.getState().isEmpty()) {
|
||||||
|
final Element stateElem = addressElem.newChildElement("state");
|
||||||
|
stateElem.setText(address.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((address.getIsoCountryCode() != null) && !address.getIsoCountryCode().isEmpty()) {
|
||||||
|
final Element isoCodeElem = addressElem.newChildElement("isoCountryCode");
|
||||||
|
isoCodeElem.setText(address.getIsoCountryCode());
|
||||||
|
|
||||||
|
final Element countryElem = addressElem.newChildElement("country");
|
||||||
|
countryElem.setText(GenericAddress.getCountryNameFromIsoCode(address.
|
||||||
|
getIsoCountryCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final Element titleElem = element.newChildElement("title");
|
||||||
|
titleElem.setText(address.getTitle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGlobalStateParams(Page p) {
|
public void addGlobalStateParams(final Page page) {
|
||||||
//Nothing
|
//Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,7 +340,7 @@ public class GenericContact extends ContentPage implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ExtraXMLGenerator> getExtraXMLGenerators() {
|
public List<ExtraXMLGenerator> getExtraXMLGenerators() {
|
||||||
List<ExtraXMLGenerator> generators = super.getExtraXMLGenerators();
|
final List<ExtraXMLGenerator> generators = super.getExtraXMLGenerators();
|
||||||
generators.add(this);
|
generators.add(this);
|
||||||
return generators;
|
return generators;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ public class GenericContactBundle
|
||||||
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";
|
||||||
public static final String PERSON = "person";
|
public static final String PERSON = "person";
|
||||||
|
public static final String ADDRESS = "address";
|
||||||
|
public static final String ADDRESS_ORDER = "linkOrder";
|
||||||
|
|
||||||
public GenericContactBundle(final ContentItem primary) {
|
public GenericContactBundle(final ContentItem primary) {
|
||||||
super(BASE_DATA_OBJECT_TYPE);
|
super(BASE_DATA_OBJECT_TYPE);
|
||||||
|
|
@ -93,6 +95,15 @@ public class GenericContactBundle
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else if(ADDRESS.equals(attribute)) {
|
||||||
|
final DataCollection addresses = (DataCollection) contactBundle.get(ADDRESS);
|
||||||
|
|
||||||
|
while(addresses.next()) {
|
||||||
|
createAddressAssoc(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return super.copyProperty(source, property, copier);
|
return super.copyProperty(source, property, copier);
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +133,17 @@ public class GenericContactBundle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createAddressAssoc(final DataCollection addresses) {
|
||||||
|
final GenericAddressBundle draftAddress = (GenericAddressBundle) DomainObjectFactory.newInstance(addresses.getDataObject());
|
||||||
|
final GenericAddressBundle liveAddress = (GenericAddressBundle) draftAddress.getLiveVersion();
|
||||||
|
|
||||||
|
if (liveAddress != null) {
|
||||||
|
final DataObject link = add(ADDRESS, liveAddress);
|
||||||
|
|
||||||
|
link.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createOrgaUnitAssoc(final DataCollection orgaunits) {
|
private void createOrgaUnitAssoc(final DataCollection orgaunits) {
|
||||||
final GenericOrganizationalUnitBundle draftOrga =
|
final GenericOrganizationalUnitBundle draftOrga =
|
||||||
(GenericOrganizationalUnitBundle) DomainObjectFactory.
|
(GenericOrganizationalUnitBundle) DomainObjectFactory.
|
||||||
|
|
@ -168,7 +190,7 @@ public class GenericContactBundle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPerson(GenericPerson person, String contactType) {
|
public void setPerson(final GenericPerson person, final String contactType) {
|
||||||
if (getPerson() != null) {
|
if (getPerson() != null) {
|
||||||
unsetPerson();
|
unsetPerson();
|
||||||
}
|
}
|
||||||
|
|
@ -190,4 +212,47 @@ public class GenericContactBundle
|
||||||
remove(PERSON, oldPerson.getGenericPersonBundle());
|
remove(PERSON, oldPerson.getGenericPersonBundle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericAddress getAddress() {
|
||||||
|
DataCollection collection;
|
||||||
|
|
||||||
|
collection = (DataCollection) get(ADDRESS);
|
||||||
|
|
||||||
|
if (collection.size() == 0) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
DataObject dobj;
|
||||||
|
|
||||||
|
collection.next();
|
||||||
|
dobj = collection.getDataObject();
|
||||||
|
|
||||||
|
//Close collection to prevent an open ResultSet
|
||||||
|
collection.close();
|
||||||
|
|
||||||
|
final GenericAddressBundle bundle = (GenericAddressBundle) DomainObjectFactory.newInstance(dobj);
|
||||||
|
|
||||||
|
return (GenericAddress) bundle.getPrimaryInstance();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(final GenericAddress address) {
|
||||||
|
if (getAddress() != null) {
|
||||||
|
unsetAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (address != null) {
|
||||||
|
Assert.exists(address, GenericAddress.class);
|
||||||
|
final DataObject link = add(ADDRESS, address.getGenericAddressBundle());
|
||||||
|
link.set(ADDRESS_ORDER, new BigDecimal("1"));
|
||||||
|
link.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsetAddress() {
|
||||||
|
final GenericAddress oldAddress = getAddress();
|
||||||
|
if (oldAddress != null) {
|
||||||
|
remove(ADDRESS, oldAddress.getGenericAddressBundle());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
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.GenericAddressBundle;
|
||||||
|
import static com.arsdigita.cms.ui.authoring.BasicPageForm.*;
|
||||||
|
import com.arsdigita.cms.ui.authoring.CreationSelector;
|
||||||
|
import com.arsdigita.cms.ui.authoring.PageCreate;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special create step for GenericAddress, creating a {@link GenericAddressBundle} instead of a
|
||||||
|
* Content Bundle
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class GenericAddressCreate extends PageCreate {
|
||||||
|
|
||||||
|
public GenericAddressCreate(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 GenericAddressBundle bundle = new GenericAddressBundle(item);
|
||||||
|
bundle.setParent(folder);
|
||||||
|
bundle.setContentSection(section);
|
||||||
|
bundle.save();
|
||||||
|
|
||||||
|
m_workflowSection.applyWorkflow(state, item);
|
||||||
|
|
||||||
|
m_parent.editItem(state, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -33,152 +33,237 @@ public class GenericContactAddressPropertiesStep extends SimpleEditStep {
|
||||||
public static final String EDIT_ADDRESS_SHEET_NAME = "editAddress";
|
public static final String EDIT_ADDRESS_SHEET_NAME = "editAddress";
|
||||||
public static final String CHANGE_ADDRESS_SHEET_NAME = "changeAddress";
|
public static final String CHANGE_ADDRESS_SHEET_NAME = "changeAddress";
|
||||||
public static final String DELETE_ADDRESS_SHEET_NAME = "deleteAddress";
|
public static final String DELETE_ADDRESS_SHEET_NAME = "deleteAddress";
|
||||||
private ItemSelectionModel itemModel;
|
//private ItemSelectionModel itemModel;
|
||||||
|
private final WorkflowLockedComponentAccess addAddress;
|
||||||
|
|
||||||
/** Creates a new instance of GenericContactAddressPropertiesStep */
|
/**
|
||||||
public GenericContactAddressPropertiesStep(ItemSelectionModel itemModel,
|
* Creates a new instance of GenericContactAddressPropertiesStep
|
||||||
AuthoringKitWizard parent) {
|
*/
|
||||||
|
public GenericContactAddressPropertiesStep(final ItemSelectionModel itemModel,
|
||||||
|
final AuthoringKitWizard parent) {
|
||||||
this(itemModel, parent, "");
|
this(itemModel, parent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericContactAddressPropertiesStep(ItemSelectionModel itemModel,
|
public GenericContactAddressPropertiesStep(final ItemSelectionModel itemModel,
|
||||||
AuthoringKitWizard parent,
|
final AuthoringKitWizard parent,
|
||||||
String prefix) {
|
final String prefix) {
|
||||||
super(itemModel, parent, prefix);
|
super(itemModel, parent, prefix);
|
||||||
|
|
||||||
this.itemModel = itemModel;
|
final BasicPageForm addAddressSheet = new GenericContactAttachAddressPropertyForm(itemModel,
|
||||||
|
this);
|
||||||
BasicPageForm attachAddressSheet =
|
addAddress = new WorkflowLockedComponentAccess(addAddressSheet, itemModel);
|
||||||
new GenericContactAttachAddressPropertyForm(itemModel,
|
|
||||||
this);
|
|
||||||
BasicPageForm reattachAddressSheet =
|
|
||||||
new GenericContactAttachAddressPropertyForm(itemModel,
|
|
||||||
this);
|
|
||||||
BasicPageForm editAddressSheet =
|
|
||||||
new GenericContactEditAddressPropertyForm(itemModel, this);
|
|
||||||
BasicPageForm deleteAddressSheet = new GenericContactDeleteAddressForm(
|
|
||||||
itemModel, this);
|
|
||||||
|
|
||||||
add(ADD_ADDRESS_SHEET_NAME,
|
add(ADD_ADDRESS_SHEET_NAME,
|
||||||
ContenttypesGlobalizationUtil.globalize(
|
ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.attach_address"),
|
||||||
"cms.contenttypes.ui.contact.attach_address"),
|
addAddress,
|
||||||
new AttachAddressWorkflowLockedComponentAccess(attachAddressSheet,
|
addAddressSheet.getSaveCancelSection().getCancelButton());
|
||||||
itemModel),
|
|
||||||
attachAddressSheet.getSaveCancelSection().getCancelButton());
|
|
||||||
add(CHANGE_ADDRESS_SHEET_NAME,
|
|
||||||
ContenttypesGlobalizationUtil.globalize(
|
|
||||||
"cms.contenttypes.ui.contact.reattach_address"),
|
|
||||||
new EditAddressWorkflowLockedComponentAccess(reattachAddressSheet,
|
|
||||||
itemModel),
|
|
||||||
reattachAddressSheet.getSaveCancelSection().getCancelButton());
|
|
||||||
/*add(EDIT_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil.
|
|
||||||
globalize("cms.contenttypes.ui.contact.edit_address").localize(),
|
|
||||||
new EditAddressWorkflowLockedComponentAccess(editAddressSheet,
|
|
||||||
itemModel),
|
|
||||||
editAddressSheet.getSaveCancelSection().getCancelButton());*/
|
|
||||||
add(DELETE_ADDRESS_SHEET_NAME,
|
|
||||||
ContenttypesGlobalizationUtil.globalize(
|
|
||||||
"cms.contenttypes.ui.contact.delete_address"),
|
|
||||||
new EditAddressWorkflowLockedComponentAccess(deleteAddressSheet,
|
|
||||||
itemModel),
|
|
||||||
deleteAddressSheet.getSaveCancelSection().getCancelButton());
|
|
||||||
|
|
||||||
/* Set the displayComponent for this step */
|
|
||||||
setDisplayComponent(getAddressPropertySheet(itemModel));
|
setDisplayComponent(getAddressPropertySheet(itemModel));
|
||||||
|
|
||||||
|
// this.itemModel = itemModel;
|
||||||
|
//
|
||||||
|
// BasicPageForm attachAddressSheet = new GenericContactAttachAddressPropertyForm(itemModel,
|
||||||
|
// this);
|
||||||
|
// BasicPageForm reattachAddressSheet = new GenericContactAttachAddressPropertyForm(itemModel,
|
||||||
|
// this);
|
||||||
|
// BasicPageForm editAddressSheet = new GenericContactEditAddressPropertyForm(itemModel, this);
|
||||||
|
// BasicPageForm deleteAddressSheet = new GenericContactDeleteAddressForm(
|
||||||
|
// itemModel, this);
|
||||||
|
//
|
||||||
|
// add(ADD_ADDRESS_SHEET_NAME,
|
||||||
|
// ContenttypesGlobalizationUtil.globalize(
|
||||||
|
// "cms.contenttypes.ui.contact.attach_address"),
|
||||||
|
// new AttachAddressWorkflowLockedComponentAccess(attachAddressSheet,
|
||||||
|
// itemModel),
|
||||||
|
// attachAddressSheet.getSaveCancelSection().getCancelButton());
|
||||||
|
// add(CHANGE_ADDRESS_SHEET_NAME,
|
||||||
|
// ContenttypesGlobalizationUtil.globalize(
|
||||||
|
// "cms.contenttypes.ui.contact.reattach_address"),
|
||||||
|
// new EditAddressWorkflowLockedComponentAccess(reattachAddressSheet,
|
||||||
|
// itemModel),
|
||||||
|
// reattachAddressSheet.getSaveCancelSection().getCancelButton());
|
||||||
|
//
|
||||||
|
// add(DELETE_ADDRESS_SHEET_NAME,
|
||||||
|
// ContenttypesGlobalizationUtil.globalize(
|
||||||
|
// "cms.contenttypes.ui.contact.delete_address"),
|
||||||
|
// new EditAddressWorkflowLockedComponentAccess(deleteAddressSheet,
|
||||||
|
// itemModel),
|
||||||
|
// deleteAddressSheet.getSaveCancelSection().getCancelButton());
|
||||||
|
//
|
||||||
|
// /* Set the displayComponent for this step */
|
||||||
|
// setDisplayComponent(getAddressPropertySheet(itemModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component getAddressPropertySheet(final ItemSelectionModel itemModel) {
|
||||||
|
final GenericContactAddressSheet sheet = new GenericContactAddressSheet(itemModel);
|
||||||
|
return sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param itemModel
|
* @param itemModel
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Component getAddressPropertySheet(ItemSelectionModel itemModel) {
|
// public static Component getAddressPropertySheet(ItemSelectionModel itemModel) {
|
||||||
|
//
|
||||||
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
|
// DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
|
||||||
itemModel);
|
// itemModel);
|
||||||
|
//
|
||||||
sheet.add(ContenttypesGlobalizationUtil.globalize(
|
// sheet.add(ContenttypesGlobalizationUtil.globalize(
|
||||||
"cms.contenttypes.ui.address.address"),
|
// "cms.contenttypes.ui.address.address"),
|
||||||
"address." + GenericAddress.ADDRESS);
|
// "address." + GenericAddress.ADDRESS,
|
||||||
if (!GenericContact.getConfig().getHideAddressPostalCode()) {
|
// new DomainObjectPropertySheet.AttributeFormatter() {
|
||||||
sheet.add(ContenttypesGlobalizationUtil.globalize(
|
//
|
||||||
"cms.contenttypes.ui.address.postal_code"),
|
// @Override
|
||||||
"address." + GenericAddress.POSTAL_CODE);
|
// public String format(final DomainObject obj,
|
||||||
}
|
// final String attribute,
|
||||||
sheet.add(ContenttypesGlobalizationUtil.globalize(
|
// final PageState state) {
|
||||||
"cms.contenttypes.ui.address.city"),
|
// final GenericAddress address = ((GenericContact) obj).getAddress();
|
||||||
"address." + GenericAddress.CITY);
|
// if ((address == null) || (address.getAddress() == null)) {
|
||||||
if (!GenericContact.getConfig().getHideAddressState()) {
|
// return (String) GlobalizationUtil.globalize(
|
||||||
sheet.add(ContenttypesGlobalizationUtil.globalize(
|
// "cms.ui.unknown").localize();
|
||||||
"cms.contenttypes.ui.address.state"),
|
// } else {
|
||||||
"address." + GenericAddress.STATE);
|
// return address.getAddress();
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
if (!GenericContact.getConfig().getHideAddressCountry()) {
|
// }
|
||||||
sheet.add(ContenttypesGlobalizationUtil.globalize(
|
//
|
||||||
"cms.contenttypes.ui.address.iso_country_code"),
|
// });
|
||||||
"address." + GenericAddress.ISO_COUNTRY_CODE,
|
// if (!GenericContact.getConfig().getHideAddressPostalCode()) {
|
||||||
new DomainObjectPropertySheet.AttributeFormatter() {
|
// sheet.add(ContenttypesGlobalizationUtil.globalize(
|
||||||
|
// "cms.contenttypes.ui.address.postal_code"),
|
||||||
@Override
|
// "address." + GenericAddress.POSTAL_CODE,
|
||||||
public String format(DomainObject item,
|
// new DomainObjectPropertySheet.AttributeFormatter() {
|
||||||
String attribute,
|
//
|
||||||
PageState state) {
|
// @Override
|
||||||
GenericAddress Address =
|
// public String format(final DomainObject obj,
|
||||||
((GenericContact) item).getAddress();
|
// final String attribute,
|
||||||
if (Address != null && Address.getIsoCountryCode() != null) {
|
// final PageState state) {
|
||||||
return GenericAddress.getCountryNameFromIsoCode(Address.
|
// final GenericAddress address = ((GenericContact) obj).getAddress();
|
||||||
getIsoCountryCode());
|
// if ((address == null) || (address.getPostalCode() == null)) {
|
||||||
} else {
|
// return (String) GlobalizationUtil.globalize(
|
||||||
return (String) GlobalizationUtil.globalize(
|
// "cms.ui.unknown").localize();
|
||||||
"cms.ui.unknown").localize();
|
// } else {
|
||||||
}
|
// return address.getPostalCode();
|
||||||
}
|
//
|
||||||
});
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
return sheet;
|
//
|
||||||
|
// });
|
||||||
}
|
// }
|
||||||
|
// sheet.add(ContenttypesGlobalizationUtil.globalize(
|
||||||
public static Component getEmptyBaseAddressPropertySheet(
|
// "cms.contenttypes.ui.address.city"),
|
||||||
ItemSelectionModel itemModel) {
|
// "address." + GenericAddress.CITY,
|
||||||
return new Label(
|
// new DomainObjectPropertySheet.AttributeFormatter() {
|
||||||
(ContenttypesGlobalizationUtil.globalize(
|
//
|
||||||
"cms.contenttypes.ui.contact.emptyAddress")));
|
// @Override
|
||||||
}
|
// public String format(final DomainObject obj,
|
||||||
|
// final String attribute,
|
||||||
private class EditAddressWorkflowLockedComponentAccess
|
// final PageState state) {
|
||||||
extends WorkflowLockedComponentAccess {
|
// final GenericAddress address = ((GenericContact) obj).getAddress();
|
||||||
|
// if ((address == null) || (address.getCity() == null)) {
|
||||||
public EditAddressWorkflowLockedComponentAccess(Component c,
|
// return (String) GlobalizationUtil.globalize(
|
||||||
ItemSelectionModel i) {
|
// "cms.ui.unknown").localize();
|
||||||
super(c, i);
|
// } else {
|
||||||
}
|
// return address.getCity();
|
||||||
|
//
|
||||||
@Override
|
// }
|
||||||
public boolean isVisible(PageState state) {
|
//
|
||||||
GenericContact contact = (GenericContact) itemModel.
|
// }
|
||||||
getSelectedObject(state);
|
//
|
||||||
|
// });
|
||||||
return contact.hasAddress();
|
// if (!GenericContact.getConfig().getHideAddressState()) {
|
||||||
}
|
// sheet.add(ContenttypesGlobalizationUtil.globalize(
|
||||||
}
|
// "cms.contenttypes.ui.address.state"),
|
||||||
|
// "address." + GenericAddress.STATE,
|
||||||
private class AttachAddressWorkflowLockedComponentAccess extends WorkflowLockedComponentAccess {
|
// new DomainObjectPropertySheet.AttributeFormatter() {
|
||||||
|
//
|
||||||
public AttachAddressWorkflowLockedComponentAccess(Component c,
|
// @Override
|
||||||
ItemSelectionModel i) {
|
// public String format(final DomainObject obj,
|
||||||
super(c, i);
|
// final String attribute,
|
||||||
}
|
// final PageState state) {
|
||||||
|
// final GenericAddress address = ((GenericContact) obj).getAddress();
|
||||||
@Override
|
// if ((address == null) || (address.getState() == null)) {
|
||||||
public boolean isVisible(PageState state) {
|
// return (String) GlobalizationUtil.globalize(
|
||||||
GenericContact contact = (GenericContact) itemModel.
|
// "cms.ui.unknown").localize();
|
||||||
getSelectedObject(state);
|
// } else {
|
||||||
|
// return address.getState();
|
||||||
return !contact.hasAddress();
|
//
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!GenericContact.getConfig().getHideAddressCountry()) {
|
||||||
|
// sheet.add(ContenttypesGlobalizationUtil.globalize(
|
||||||
|
// "cms.contenttypes.ui.address.iso_country_code"),
|
||||||
|
// "address." + GenericAddress.ISO_COUNTRY_CODE,
|
||||||
|
// new DomainObjectPropertySheet.AttributeFormatter() {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public String format(DomainObject item,
|
||||||
|
// String attribute,
|
||||||
|
// PageState state) {
|
||||||
|
// GenericAddress address = ((GenericContact) item).getAddress();
|
||||||
|
// if (address != null && address.getIsoCountryCode() != null) {
|
||||||
|
// return GenericAddress.getCountryNameFromIsoCode(address.
|
||||||
|
// getIsoCountryCode());
|
||||||
|
// } else {
|
||||||
|
// return (String) GlobalizationUtil.globalize(
|
||||||
|
// "cms.ui.unknown").localize();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return sheet;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static Component getEmptyBaseAddressPropertySheet(
|
||||||
|
// ItemSelectionModel itemModel) {
|
||||||
|
// return new Label(
|
||||||
|
// (ContenttypesGlobalizationUtil.globalize(
|
||||||
|
// "cms.contenttypes.ui.contact.emptyAddress")));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private class EditAddressWorkflowLockedComponentAccess
|
||||||
|
// extends WorkflowLockedComponentAccess {
|
||||||
|
//
|
||||||
|
// public EditAddressWorkflowLockedComponentAccess(Component c,
|
||||||
|
// ItemSelectionModel i) {
|
||||||
|
// super(c, i);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public boolean isVisible(PageState state) {
|
||||||
|
// GenericContact contact = (GenericContact) itemModel.
|
||||||
|
// getSelectedObject(state);
|
||||||
|
//
|
||||||
|
// return contact.hasAddress();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private class AttachAddressWorkflowLockedComponentAccess extends WorkflowLockedComponentAccess {
|
||||||
|
//
|
||||||
|
// public AttachAddressWorkflowLockedComponentAccess(Component c,
|
||||||
|
// ItemSelectionModel i) {
|
||||||
|
// super(c, i);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public boolean isVisible(PageState state) {
|
||||||
|
// GenericContact contact = (GenericContact) itemModel.
|
||||||
|
// getSelectedObject(state);
|
||||||
|
//
|
||||||
|
// return !contact.hasAddress();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,239 @@
|
||||||
|
package com.arsdigita.cms.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.ControlLink;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.Link;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.event.TableActionEvent;
|
||||||
|
import com.arsdigita.bebop.event.TableActionListener;
|
||||||
|
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||||
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
|
import com.arsdigita.bebop.table.TableColumnModel;
|
||||||
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
|
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.cms.ContentSection;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.cms.contenttypes.GenericAddress;
|
||||||
|
import com.arsdigita.cms.contenttypes.GenericContact;
|
||||||
|
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
|
||||||
|
import com.arsdigita.cms.dispatcher.ItemResolver;
|
||||||
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class GenericContactAddressSheet extends Table implements TableActionListener {
|
||||||
|
|
||||||
|
private static final String TABLE_COL_EDIT = "table_col_edit";
|
||||||
|
private static final String TABLE_COL_DEL = "table_col_del";
|
||||||
|
private final ItemSelectionModel itemModel;
|
||||||
|
|
||||||
|
public GenericContactAddressSheet(final ItemSelectionModel itemModel) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.itemModel = itemModel;
|
||||||
|
|
||||||
|
setEmptyView(new Label(ContenttypesGlobalizationUtil.globalize(
|
||||||
|
"cms.contenttypes.ui.contact.emptyAddress")));
|
||||||
|
|
||||||
|
final TableColumnModel colModel = getColumnModel();
|
||||||
|
colModel.add(new TableColumn(
|
||||||
|
0,
|
||||||
|
new Label(""),
|
||||||
|
TABLE_COL_EDIT));
|
||||||
|
|
||||||
|
colModel.add(new TableColumn(
|
||||||
|
1,
|
||||||
|
new Label(""),
|
||||||
|
TABLE_COL_DEL));
|
||||||
|
|
||||||
|
setModelBuilder(new GenericContactAddressTableModelBuilder(itemModel));
|
||||||
|
|
||||||
|
colModel.get(0).setCellRenderer(new EditCellRenderer());
|
||||||
|
colModel.get(1).setCellRenderer(new DeleteCellRenderer());
|
||||||
|
|
||||||
|
addTableActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GenericContactAddressTableModelBuilder
|
||||||
|
extends LockableImpl
|
||||||
|
implements TableModelBuilder {
|
||||||
|
|
||||||
|
private ItemSelectionModel itemModel;
|
||||||
|
|
||||||
|
public GenericContactAddressTableModelBuilder(final ItemSelectionModel itemModel) {
|
||||||
|
this.itemModel = itemModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableModel makeModel(final Table table, final PageState state) {
|
||||||
|
table.getRowSelectionModel().clearSelection(state);
|
||||||
|
final GenericContact contact = (GenericContact) itemModel.getSelectedObject(state);
|
||||||
|
return new GenericContactAddressTableModel(table, state, contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GenericContactAddressTableModel implements TableModel {
|
||||||
|
|
||||||
|
private final Table table;
|
||||||
|
private final GenericAddress address;
|
||||||
|
private boolean done;
|
||||||
|
|
||||||
|
public GenericContactAddressTableModel(final Table table,
|
||||||
|
final PageState state,
|
||||||
|
final GenericContact contact) {
|
||||||
|
this.table = table;
|
||||||
|
address = contact.getAddress();
|
||||||
|
if (address == null) {
|
||||||
|
done = false;
|
||||||
|
} else {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return table.getColumnModel().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean nextRow() {
|
||||||
|
boolean ret;
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
ret = true;
|
||||||
|
done = false;
|
||||||
|
} else {
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(final int columnIndex) {
|
||||||
|
switch (columnIndex) {
|
||||||
|
case 0:
|
||||||
|
return address.getTitle();
|
||||||
|
case 1:
|
||||||
|
return ContenttypesGlobalizationUtil.globalize(
|
||||||
|
"cms.contenttypes.ui.contact.delete_address.button_label");
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getKeyAt(final int columnIndex) {
|
||||||
|
return address.getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class EditCellRenderer extends LockableImpl implements TableCellRenderer {
|
||||||
|
|
||||||
|
public EditCellRenderer() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getComponent(final Table table,
|
||||||
|
final PageState state,
|
||||||
|
final Object value,
|
||||||
|
final boolean isSelected,
|
||||||
|
final Object key,
|
||||||
|
final int row,
|
||||||
|
final int column) {
|
||||||
|
com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(state);
|
||||||
|
GenericContact contact = (GenericContact) itemModel.getSelectedObject(state);
|
||||||
|
|
||||||
|
boolean canEdit = securityManager.canAccess(
|
||||||
|
state.getRequest(),
|
||||||
|
com.arsdigita.cms.SecurityManager.EDIT_ITEM,
|
||||||
|
contact);
|
||||||
|
|
||||||
|
if (canEdit) {
|
||||||
|
final GenericAddress address;
|
||||||
|
|
||||||
|
try {
|
||||||
|
address = new GenericAddress((BigDecimal) key);
|
||||||
|
} catch (DataObjectNotFoundException ex) {
|
||||||
|
return new Label(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
final ContentSection section = address.getContentSection();
|
||||||
|
final ItemResolver resolver = section.getItemResolver();
|
||||||
|
|
||||||
|
return new Link(value.toString(),
|
||||||
|
resolver.generateItemURL(state,
|
||||||
|
address,
|
||||||
|
section,
|
||||||
|
address.getVersion()));
|
||||||
|
} else {
|
||||||
|
return new Label(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getComponent(Table table,
|
||||||
|
PageState state,
|
||||||
|
Object value,
|
||||||
|
boolean isSelected,
|
||||||
|
Object key,
|
||||||
|
int row,
|
||||||
|
int col) {
|
||||||
|
com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(state);
|
||||||
|
GenericContact contact = (GenericContact) itemModel.getSelectedObject(
|
||||||
|
state);
|
||||||
|
|
||||||
|
boolean canEdit = securityManager.canAccess(
|
||||||
|
state.getRequest(),
|
||||||
|
com.arsdigita.cms.SecurityManager.DELETE_ITEM,
|
||||||
|
contact);
|
||||||
|
|
||||||
|
if (canEdit) {
|
||||||
|
final ControlLink link = new ControlLink(new Label((GlobalizedMessage) value));
|
||||||
|
link.setConfirmation(ContenttypesGlobalizationUtil.globalize(
|
||||||
|
"cms.contenttypes.ui.contact.person.confirm_remove"));
|
||||||
|
return link;
|
||||||
|
} else {
|
||||||
|
Label label = new Label("");
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cellSelected(final TableActionEvent event) {
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
final GenericContact contact = (GenericContact) itemModel.getSelectedObject(state);
|
||||||
|
|
||||||
|
final TableColumn column = getColumnModel().get(event.getColumn().intValue());
|
||||||
|
|
||||||
|
if (TABLE_COL_DEL.equals(column.getHeaderKey().toString())) {
|
||||||
|
contact.unsetAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void headSelected(final TableActionEvent event) {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -36,6 +36,7 @@ public class GenericContactDeleteAddressForm extends BasicPageForm implements Fo
|
||||||
GenericContactDeleteAddressForm(ItemSelectionModel itemModel, GenericContactAddressPropertiesStep step) {
|
GenericContactDeleteAddressForm(ItemSelectionModel itemModel, GenericContactAddressPropertiesStep step) {
|
||||||
super(ID, itemModel);
|
super(ID, itemModel);
|
||||||
addSaveCancelSection();
|
addSaveCancelSection();
|
||||||
|
addProcessListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(FormSectionEvent fse) {
|
public void init(FormSectionEvent fse) {
|
||||||
|
|
|
||||||
|
|
@ -247,13 +247,13 @@ public class GenericContactEntriesTable extends Table implements TableActionList
|
||||||
SecurityManager.DELETE_ITEM,
|
SecurityManager.DELETE_ITEM,
|
||||||
contact);
|
contact);
|
||||||
if (canDelete) {
|
if (canDelete) {
|
||||||
ControlLink link = new ControlLink(value.toString());
|
ControlLink link = new ControlLink((Label)value);
|
||||||
link.setConfirmation(
|
link.setConfirmation(
|
||||||
ContenttypesGlobalizationUtil.globalize(
|
ContenttypesGlobalizationUtil.globalize(
|
||||||
"cms.contenttypes.ui.contact.confirm_delete"));
|
"cms.contenttypes.ui.contact.confirm_delete"));
|
||||||
return link;
|
return link;
|
||||||
} else {
|
} else {
|
||||||
return new Label(value.toString());
|
return (Label) value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ import com.arsdigita.cms.contenttypes.GenericContact;
|
||||||
import com.arsdigita.cms.contenttypes.GenericPerson;
|
import com.arsdigita.cms.contenttypes.GenericPerson;
|
||||||
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
|
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
|
||||||
import com.arsdigita.cms.dispatcher.ItemResolver;
|
import com.arsdigita.cms.dispatcher.ItemResolver;
|
||||||
//import com.arsdigita.cms.dispatcher.Utilities;
|
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -47,40 +46,40 @@ import java.math.BigDecimal;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Jens Pelzetter
|
* @author Jens Pelzetter
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class GenericContactPersonSheet
|
public class GenericContactPersonSheet extends Table implements TableActionListener {
|
||||||
extends Table
|
|
||||||
implements TableActionListener {
|
|
||||||
|
|
||||||
private final String TABLE_COL_EDIT = "table_col_edit";
|
private final String TABLE_COL_EDIT = "table_col_edit";
|
||||||
private final String TABLE_COL_DEL = "table_col_del";
|
private final String TABLE_COL_DEL = "table_col_del";
|
||||||
private ItemSelectionModel m_itemModel;
|
private final ItemSelectionModel m_itemModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
*
|
||||||
* @param itemModel
|
* @param itemModel
|
||||||
*/
|
*/
|
||||||
public GenericContactPersonSheet(ItemSelectionModel itemModel) {
|
public GenericContactPersonSheet(final ItemSelectionModel itemModel) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
m_itemModel = itemModel;
|
m_itemModel = itemModel;
|
||||||
|
|
||||||
setEmptyView(
|
setEmptyView(
|
||||||
new Label(ContenttypesGlobalizationUtil.globalize(
|
new Label(ContenttypesGlobalizationUtil.globalize(
|
||||||
"cms.contenttypes.ui.genericcontact.emptyPerson")));
|
"cms.contenttypes.ui.genericcontact.emptyPerson")));
|
||||||
|
|
||||||
TableColumnModel colModel = getColumnModel();
|
TableColumnModel colModel = getColumnModel();
|
||||||
colModel.add(new TableColumn(
|
colModel.add(new TableColumn(
|
||||||
0,
|
0,
|
||||||
new Label(ContenttypesGlobalizationUtil.globalize(
|
new Label(ContenttypesGlobalizationUtil.globalize(
|
||||||
// "cms.contenttypes.ui.contact.person").localize(),
|
// "cms.contenttypes.ui.contact.person").localize(),
|
||||||
"cms.contenttypes.ui.genericcontact.person")),
|
"cms.contenttypes.ui.genericcontact.person")),
|
||||||
TABLE_COL_EDIT));
|
TABLE_COL_EDIT));
|
||||||
colModel.add(new TableColumn(
|
colModel.add(new TableColumn(
|
||||||
1,
|
1,
|
||||||
new Label(ContenttypesGlobalizationUtil.globalize(
|
new Label(ContenttypesGlobalizationUtil.globalize(
|
||||||
"cms.contenttypes.ui.genericcontact.delete_person")),
|
"cms.contenttypes.ui.genericcontact.delete_person")),
|
||||||
TABLE_COL_DEL));
|
TABLE_COL_DEL));
|
||||||
|
|
||||||
setModelBuilder(new GenericContactPersonSheetModelBuilder(itemModel));
|
setModelBuilder(new GenericContactPersonSheetModelBuilder(itemModel));
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public class GenericContactPersonSheet
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private class GenericContactPersonSheetModelBuilder
|
private class GenericContactPersonSheetModelBuilder
|
||||||
extends LockableImpl
|
extends LockableImpl
|
||||||
implements TableModelBuilder {
|
implements TableModelBuilder {
|
||||||
|
|
||||||
private ItemSelectionModel m_itemModel;
|
private ItemSelectionModel m_itemModel;
|
||||||
|
|
||||||
public GenericContactPersonSheetModelBuilder(
|
public GenericContactPersonSheetModelBuilder(
|
||||||
ItemSelectionModel itemModel) {
|
ItemSelectionModel itemModel) {
|
||||||
m_itemModel = itemModel;
|
m_itemModel = itemModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,13 +116,13 @@ public class GenericContactPersonSheet
|
||||||
|
|
||||||
private class GenericContactPersonSheetModel implements TableModel {
|
private class GenericContactPersonSheetModel implements TableModel {
|
||||||
|
|
||||||
private Table m_table;
|
private final Table m_table;
|
||||||
private GenericPerson m_person;
|
private final GenericPerson m_person;
|
||||||
private boolean m_done;
|
private boolean m_done;
|
||||||
|
|
||||||
public GenericContactPersonSheetModel(Table table,
|
public GenericContactPersonSheetModel(final Table table,
|
||||||
PageState state,
|
final PageState state,
|
||||||
GenericContact contact) {
|
final GenericContact contact) {
|
||||||
m_table = table;
|
m_table = table;
|
||||||
m_person = contact.getPerson();
|
m_person = contact.getPerson();
|
||||||
if (m_person == null) {
|
if (m_person == null) {
|
||||||
|
|
@ -133,10 +132,12 @@ public class GenericContactPersonSheet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return m_table.getColumnModel().size();
|
return m_table.getColumnModel().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean nextRow() {
|
public boolean nextRow() {
|
||||||
boolean ret;
|
boolean ret;
|
||||||
|
|
||||||
|
|
@ -150,27 +151,27 @@ public class GenericContactPersonSheet
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getElementAt(int columnIndex) {
|
@Override
|
||||||
|
public Object getElementAt(final int columnIndex) {
|
||||||
switch (columnIndex) {
|
switch (columnIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
return m_person.getFullName();
|
return m_person.getFullName();
|
||||||
case 1:
|
case 1:
|
||||||
return ContenttypesGlobalizationUtil.globalize(
|
return ContenttypesGlobalizationUtil.globalize(
|
||||||
"cms.contenttypes.ui.genericcontact.delete_person").localize();
|
"cms.contenttypes.ui.genericcontact.delete_person").localize();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getKeyAt(int columnIndex) {
|
@Override
|
||||||
|
public Object getKeyAt(final int columnIndex) {
|
||||||
return m_person.getID();
|
return m_person.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EditCellRenderer
|
private class EditCellRenderer extends LockableImpl implements TableCellRenderer {
|
||||||
extends LockableImpl
|
|
||||||
implements TableCellRenderer {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getComponent(Table table,
|
public Component getComponent(Table table,
|
||||||
|
|
@ -181,14 +182,13 @@ public class GenericContactPersonSheet
|
||||||
int row,
|
int row,
|
||||||
int column) {
|
int column) {
|
||||||
|
|
||||||
com.arsdigita.cms.SecurityManager securityManager =
|
com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(state);
|
||||||
CMS.getSecurityManager(state);
|
|
||||||
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
|
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
|
||||||
|
|
||||||
boolean canEdit = securityManager.canAccess(
|
boolean canEdit = securityManager.canAccess(
|
||||||
state.getRequest(),
|
state.getRequest(),
|
||||||
com.arsdigita.cms.SecurityManager.EDIT_ITEM,
|
com.arsdigita.cms.SecurityManager.EDIT_ITEM,
|
||||||
contact);
|
contact);
|
||||||
|
|
||||||
if (canEdit) {
|
if (canEdit) {
|
||||||
GenericPerson person;
|
GenericPerson person;
|
||||||
|
|
@ -218,8 +218,8 @@ public class GenericContactPersonSheet
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DeleteCellRenderer
|
private class DeleteCellRenderer
|
||||||
extends LockableImpl
|
extends LockableImpl
|
||||||
implements TableCellRenderer {
|
implements TableCellRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getComponent(Table table,
|
public Component getComponent(Table table,
|
||||||
|
|
@ -231,18 +231,18 @@ public class GenericContactPersonSheet
|
||||||
int col) {
|
int col) {
|
||||||
SecurityManager securityManager = CMS.getSecurityManager(state);
|
SecurityManager securityManager = CMS.getSecurityManager(state);
|
||||||
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(
|
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(
|
||||||
state);
|
state);
|
||||||
|
|
||||||
boolean canEdit = securityManager.canAccess(
|
boolean canEdit = securityManager.canAccess(
|
||||||
state.getRequest(),
|
state.getRequest(),
|
||||||
SecurityManager.DELETE_ITEM,
|
SecurityManager.DELETE_ITEM,
|
||||||
contact);
|
contact);
|
||||||
|
|
||||||
if (canEdit) {
|
if (canEdit) {
|
||||||
ControlLink link = new ControlLink(value.toString());
|
ControlLink link = new ControlLink(value.toString());
|
||||||
link.setConfirmation(ContenttypesGlobalizationUtil.globalize(
|
link.setConfirmation(ContenttypesGlobalizationUtil.globalize(
|
||||||
"cms.contenttypes.ui.contact.person"
|
"cms.contenttypes.ui.contact.person"
|
||||||
+ ".confirm_remove"));
|
+ ".confirm_remove"));
|
||||||
return link;
|
return link;
|
||||||
} else {
|
} else {
|
||||||
Label label = new Label(value.toString());
|
Label label = new Label(value.toString());
|
||||||
|
|
@ -257,7 +257,7 @@ public class GenericContactPersonSheet
|
||||||
PageState state = event.getPageState();
|
PageState state = event.getPageState();
|
||||||
|
|
||||||
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(
|
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(
|
||||||
state);
|
state);
|
||||||
|
|
||||||
TableColumn column = getColumnModel().get(event.getColumn().intValue());
|
TableColumn column = getColumnModel().get(event.getColumn().intValue());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import com.arsdigita.xml.Element;
|
||||||
*/
|
*/
|
||||||
public class GenericPersonExtraXmlGenerator implements ExtraXMLGenerator {
|
public class GenericPersonExtraXmlGenerator implements ExtraXMLGenerator {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void generateXML(final ContentItem item,
|
public void generateXML(final ContentItem item,
|
||||||
final Element element,
|
final Element element,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
|
|
@ -73,6 +74,7 @@ public class GenericPersonExtraXmlGenerator implements ExtraXMLGenerator {
|
||||||
//System.err.printf("Generated XML for a contact in %d ms\n", (System.nanoTime() - start) / 1000000);
|
//System.err.printf("Generated XML for a contact in %d ms\n", (System.nanoTime() - start) / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addGlobalStateParams(final Page page) {
|
public void addGlobalStateParams(final Page page) {
|
||||||
//Nothing
|
//Nothing
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,324 @@
|
||||||
|
package com.arsdigita.cms.contenttypes.upgrades;
|
||||||
|
|
||||||
|
import com.arsdigita.runtime.RuntimeConfig;
|
||||||
|
import com.arsdigita.util.cmd.Program;
|
||||||
|
import com.arsdigita.util.jdbc.Connections;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class Upgrade6610to6611ContactAddressAssoc extends Program {
|
||||||
|
|
||||||
|
public Upgrade6610to6611ContactAddressAssoc() {
|
||||||
|
super("Upgrade-6.6.10-to-6.6.11_AddressAssoc", "1.0.0", "", true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doRun(final CommandLine cmdLine) {
|
||||||
|
upgradeBundles();
|
||||||
|
upgradeAssoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
new Upgrade6610to6611ContactAddressAssoc().run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeBundles() {
|
||||||
|
System.out.println("Starting upgrade part 1 of 2");
|
||||||
|
|
||||||
|
System.out.println("Trying to get JDBC connection...");
|
||||||
|
|
||||||
|
final Connection conn = Connections.acquire(RuntimeConfig.getConfig().
|
||||||
|
getJDBCURL());
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to configure JDBC connection.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.err.println("Creating new table 'cms_address_bundles...'");
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
stmt.addBatch("CREATE TABLE cms_address_bundles (bundle_id integer NOT NULL)");
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY cms_address_bundles "
|
||||||
|
+ "ADD CONSTRAINT cms_addr_bundl_bund_id_p_f_pvc "
|
||||||
|
+ "PRIMARY KEY (bundle_id)");
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY cms_address_bundles "
|
||||||
|
+ "ADD CONSTRAINT cms_addr_bundl_bund_id_f_n3leu "
|
||||||
|
+ "FOREIGN KEY (bundle_id) REFERENCES cms_bundles(bundle_id)");
|
||||||
|
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to create table 'cms_address_bundles'");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Filling new table 'cms_address_bundle' with data...");
|
||||||
|
final Statement queryAddressesStmt = conn.createStatement();
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
|
final ResultSet addressesRs = queryAddressesStmt.executeQuery(
|
||||||
|
"SELECT parent_id "
|
||||||
|
+ " FROM cms_items "
|
||||||
|
+ " JOIN cms_addresses "
|
||||||
|
+ " ON cms_items.item_id = cms_addresses.address_id");
|
||||||
|
|
||||||
|
while (addressesRs.next()) {
|
||||||
|
stmt.addBatch(String.
|
||||||
|
format("INSERT INTO cms_address_bundles(bundle_id) VALUES (%d)",
|
||||||
|
addressesRs.getInt(1)));
|
||||||
|
stmt.addBatch(String.format(
|
||||||
|
"UPDATE acs_objects "
|
||||||
|
+ "SET default_domain_class = 'com.arsdigita.cms.contenttypes.GenericAddressBundle',"
|
||||||
|
+ "object_type = 'com.arsdigita.cms.contenttypes.GenericAddressBundle'"
|
||||||
|
+ "WHERE object_id = %d",
|
||||||
|
addressesRs.getInt(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to fill tables.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.commit();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to commiting modifications.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeAssoc() {
|
||||||
|
System.out.println("Starting upgrade part 2 of 2");
|
||||||
|
|
||||||
|
System.out.println("Trying to get JDBC connection...");
|
||||||
|
|
||||||
|
final Connection conn = Connections.acquire(RuntimeConfig.getConfig().
|
||||||
|
getJDBCURL());
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to configure JDBC connection.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Retrieving old data...");
|
||||||
|
final List<ContactBundleAddressBundlePair> newAssocs
|
||||||
|
= new ArrayList<ContactBundleAddressBundlePair>();
|
||||||
|
try {
|
||||||
|
final Statement stmt = conn.createStatement();
|
||||||
|
final List<ContactAddressPair> oldAssocs = new ArrayList<ContactAddressPair>();
|
||||||
|
final ResultSet oldAssocResult = stmt.executeQuery(
|
||||||
|
"SELECT contact_id, address_id "
|
||||||
|
+ "FROM cms_contacts");
|
||||||
|
|
||||||
|
while (oldAssocResult.next()) {
|
||||||
|
ContactAddressPair pair = new ContactAddressPair();
|
||||||
|
pair.setContactId(oldAssocResult.getBigDecimal("contact_id"));
|
||||||
|
pair.setAddressId(oldAssocResult.getBigDecimal("address_id"));
|
||||||
|
|
||||||
|
oldAssocs.add(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.addBatch("CREATE TABLE cms_contact_address_map ("
|
||||||
|
+ "contact_id integer NOT NULL,"
|
||||||
|
+ "address_id integer NOT NULL,"
|
||||||
|
+ "link_order integer)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY cms_contact_address_map "
|
||||||
|
+ "ADD CONSTRAINT cms_con_add_map_add_id_p_r1p86 "
|
||||||
|
+ "PRIMARY KEY (contact_id, address_id)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY cms_contact_address_map "
|
||||||
|
+ "ADD CONSTRAINT cms_con_add_map_con_id_f_u7txu "
|
||||||
|
+ "FOREIGN KEY (contact_id) "
|
||||||
|
+ "REFERENCES cms_contact_bundles(bundle_id)");
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE ONLY cms_contact_address_map "
|
||||||
|
+ "ADD CONSTRAINT cms_con_add_map_add_id_f_92kx1 "
|
||||||
|
+ "FOREIGN KEY (address_id) "
|
||||||
|
+ "REFERENCES cms_address_bundles(bundle_id)");
|
||||||
|
|
||||||
|
for (ContactAddressPair pair : oldAssocs) {
|
||||||
|
if (pair.getAddressId() != null) {
|
||||||
|
ContactBundleAddressBundlePair assocPair = new ContactBundleAddressBundlePair();
|
||||||
|
System.out.printf(
|
||||||
|
"Executing SELECT parent_id FROM cms_items WHERE item_id = %s\n",
|
||||||
|
pair.getContactId().toString());
|
||||||
|
ResultSet contactBundleIdResult = stmt.executeQuery(
|
||||||
|
String.format("SELECT parent_id FROM cms_items WHERE item_id = %s",
|
||||||
|
pair.getContactId().toString()));
|
||||||
|
contactBundleIdResult.next();
|
||||||
|
assocPair.setContactBundleId(contactBundleIdResult.getBigDecimal("parent_id"));
|
||||||
|
System.out.printf(
|
||||||
|
"Executing SELECT parent_id FROM cms_items WHERE item_id = %s\n",
|
||||||
|
pair.getAddressId().toString());
|
||||||
|
ResultSet addressBundleIdResult = stmt.executeQuery(
|
||||||
|
String.format("SELECT parent_id FROM cms_items WHERE item_id = %s",
|
||||||
|
pair.getAddressId().toString()));
|
||||||
|
addressBundleIdResult.next();
|
||||||
|
assocPair.setAddressBundleId(addressBundleIdResult.
|
||||||
|
getBigDecimal("parent_id"));
|
||||||
|
|
||||||
|
System.out.println("Aadding to new assoc list...");
|
||||||
|
newAssocs.add(assocPair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Inserting data into new assoc table...");
|
||||||
|
for (ContactBundleAddressBundlePair pair : newAssocs) {
|
||||||
|
stmt.addBatch(String.format(
|
||||||
|
"INSERT INTO cms_contact_address_map "
|
||||||
|
+ "(contact_id, address_id, link_order)"
|
||||||
|
+ "VALUES (%s, %s, 1)",
|
||||||
|
pair.getContactBundleId().toString(),
|
||||||
|
pair.getAddressBundleId().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.addBatch("ALTER TABLE cms_contacts DROP COLUMN address_id");
|
||||||
|
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.
|
||||||
|
println("Failed to create table 'cms_address_bundles' and fill it with data.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.err.
|
||||||
|
println("Failed to create table 'cms_address_bundles' and fill it with data.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
close(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.commit();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to commiting modifications.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
rollback(conn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rollback(final Connection conn) {
|
||||||
|
try {
|
||||||
|
System.err.println("WARNING: Rollback.");
|
||||||
|
conn.rollback();
|
||||||
|
} catch (SQLException ex1) {
|
||||||
|
System.err.println("Rollback failed.");
|
||||||
|
ex1.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(final Connection conn) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Failed to close JDBC connection.");
|
||||||
|
printStackTrace(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printStackTrace(final SQLException ex) {
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
if (ex.getNextException() != null) {
|
||||||
|
printStackTrace(ex.getNextException());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printStackTrace(final Exception ex) {
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ContactAddressPair {
|
||||||
|
|
||||||
|
private BigDecimal contactId;
|
||||||
|
private BigDecimal addressId;
|
||||||
|
|
||||||
|
public ContactAddressPair() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContactId(final BigDecimal contactId) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAddressId() {
|
||||||
|
return addressId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddressId(final BigDecimal addressId) {
|
||||||
|
this.addressId = addressId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ContactBundleAddressBundlePair {
|
||||||
|
|
||||||
|
private BigDecimal contactBundleId;
|
||||||
|
private BigDecimal addressBundleId;
|
||||||
|
|
||||||
|
public ContactBundleAddressBundlePair() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getContactBundleId() {
|
||||||
|
return contactBundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContactBundleId(final BigDecimal contactBundleId) {
|
||||||
|
this.contactBundleId = contactBundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAddressBundleId() {
|
||||||
|
return addressBundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddressBundleId(final BigDecimal addressBundleId) {
|
||||||
|
this.addressBundleId = addressBundleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue