ContactableEntity Asset, Organization Asset
* Migrations for ContactEntryKey * More work on the form for managing assets of these types git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@6149 8810af33-2d31-482b-a856-94f89814c4df
parent
6b7bd96e60
commit
6fda965f86
|
|
@ -69,21 +69,29 @@ public abstract class AbstractAssetForm<T extends Asset>
|
|||
FormSubmissionListener {
|
||||
|
||||
private static final String ASSET_TITLE = "asset-name";
|
||||
|
||||
private static final String ASSET_NAME = "asset-title";
|
||||
|
||||
private final AssetPane assetPane;
|
||||
|
||||
private final SingleSelectionModel<Long> selectionModel;
|
||||
|
||||
private BoxPanel showLocalePanel;
|
||||
|
||||
private SingleSelect showLocaleSelect;
|
||||
|
||||
private Submit showLocaleSubmit;
|
||||
|
||||
private BoxPanel addLocalePanel;
|
||||
|
||||
private SingleSelect addLocaleSelect;
|
||||
|
||||
private Submit addLocaleSubmit;
|
||||
|
||||
private TextField name;
|
||||
|
||||
private TextField title;
|
||||
|
||||
private SaveCancelSection saveCancelSection;
|
||||
|
||||
public AbstractAssetForm(final AssetPane assetPane) {
|
||||
|
|
@ -130,13 +138,13 @@ public abstract class AbstractAssetForm<T extends Asset>
|
|||
final SingleSelect target = (SingleSelect) event
|
||||
.getTarget();
|
||||
|
||||
target.clearOptions();;
|
||||
target.clearOptions();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AssetL10NManager l10nManager = cdiUtil
|
||||
.findBean(AssetL10NManager.class);
|
||||
final List<Locale> availableLocales = new ArrayList<>(
|
||||
l10nManager.availableLocales(selectedAsset.get()));
|
||||
final AbstractAssetFormController controller = cdiUtil
|
||||
.findBean(AbstractAssetFormController.class);
|
||||
final List<Locale> availableLocales = controller
|
||||
.availableLocales(selectedAsset.get());
|
||||
availableLocales.sort((locale1, locale2) -> {
|
||||
return locale1.toString().compareTo(locale2
|
||||
.toString());
|
||||
|
|
@ -206,10 +214,11 @@ public abstract class AbstractAssetForm<T extends Asset>
|
|||
target.clearOptions();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AssetL10NManager l10nManager = cdiUtil
|
||||
.findBean(AssetL10NManager.class);
|
||||
final List<Locale> creatableLocales = new ArrayList<>(
|
||||
l10nManager.creatableLocales(selectedAsset.get()));
|
||||
final AbstractAssetFormController controller = cdiUtil
|
||||
.findBean(AbstractAssetFormController.class);
|
||||
|
||||
final List<Locale> creatableLocales = controller
|
||||
.creatableLocales(selectedAsset.get());
|
||||
creatableLocales.sort((locale1, locale2) -> {
|
||||
return locale1
|
||||
.toString()
|
||||
|
|
@ -298,14 +307,15 @@ public abstract class AbstractAssetForm<T extends Asset>
|
|||
|
||||
if (selectedAsset.isPresent()) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AbstractAssetFormController controller = cdiUtil
|
||||
.findBean(AbstractAssetFormController.class);
|
||||
showLocaleSelect.setValue(state,
|
||||
getSelectedLocale(state));
|
||||
|
||||
title.setValue(state,
|
||||
selectedAsset
|
||||
.get()
|
||||
.getTitle()
|
||||
.getValue(getSelectedLocale(state)));
|
||||
controller.getTitle(selectedAsset.get(),
|
||||
getSelectedLocale(state)));
|
||||
} else {
|
||||
showLocaleSelect.setValue(state,
|
||||
KernelConfig
|
||||
|
|
@ -345,11 +355,13 @@ public abstract class AbstractAssetForm<T extends Asset>
|
|||
.get()
|
||||
.getDisplayName());
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AbstractAssetFormController controller = cdiUtil
|
||||
.findBean(AbstractAssetFormController.class);
|
||||
|
||||
title.setValue(state,
|
||||
selectedAsset
|
||||
.get()
|
||||
.getTitle()
|
||||
.getValue(getSelectedLocale(state)));
|
||||
controller.getTitle(selectedAsset.get(),
|
||||
getSelectedLocale(state)));
|
||||
showLocale(state);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (C) 2019 LibreCCM Foundation.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets;
|
||||
|
||||
import org.librecms.assets.AssetL10NManager;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class AbstractAssetFormController {
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Inject
|
||||
private AssetL10NManager l10nManager;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String getTitle(final Asset asset, final Locale locale) {
|
||||
|
||||
Objects.requireNonNull(asset, "Can't get title from asset null.");
|
||||
Objects.requireNonNull(locale,
|
||||
"Can't title from asset for locale null");
|
||||
|
||||
final Asset result = assetRepository
|
||||
.findById(asset.getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format("No asset with ID %d found.",
|
||||
asset.getObjectId())
|
||||
)
|
||||
);
|
||||
|
||||
return result.getTitle().getValue(locale);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Locale> availableLocales(final Asset asset) {
|
||||
|
||||
Objects.requireNonNull(asset,
|
||||
"Can't get available locales from asset null.");
|
||||
|
||||
final Asset result = assetRepository
|
||||
.findById(asset.getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format("No asset with ID %d found.",
|
||||
asset.getObjectId())
|
||||
)
|
||||
);
|
||||
|
||||
return new ArrayList<>(l10nManager.availableLocales(result));
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Locale> creatableLocales(final Asset asset) {
|
||||
|
||||
Objects.requireNonNull(asset,
|
||||
"Can't get creatable locales from asset null.");
|
||||
|
||||
final Asset result = assetRepository
|
||||
.findById(asset.getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format("No asset with ID %d found.",
|
||||
asset.getObjectId())
|
||||
)
|
||||
);
|
||||
|
||||
return new ArrayList<>(l10nManager.creatableLocales(result));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,8 +23,14 @@ import com.arsdigita.bebop.Component;
|
|||
import com.arsdigita.bebop.ControlLink;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
|
|
@ -45,14 +51,20 @@ import com.arsdigita.globalization.GlobalizedMessage;
|
|||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.ContactEntry;
|
||||
import org.librecms.assets.ContactEntryKeyByLabelComparator;
|
||||
import org.librecms.assets.ContactEntryKey;
|
||||
import org.librecms.assets.ContactEntryKeyRepository;
|
||||
import org.librecms.assets.ContactableEntity;
|
||||
import org.librecms.assets.PostalAddress;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
|
|
@ -72,6 +84,8 @@ public abstract class AbstractContactableEntityForm<T extends ContactableEntity>
|
|||
|
||||
private final AssetPane assetPane;
|
||||
|
||||
private SimpleContainer contactEntriesContainer;
|
||||
|
||||
private Table contactEntriesTable;
|
||||
|
||||
private SingleSelect contactEntryKeySelect;
|
||||
|
|
@ -94,27 +108,97 @@ public abstract class AbstractContactableEntityForm<T extends ContactableEntity>
|
|||
|
||||
addPropertyWidgets();
|
||||
|
||||
contactEntriesContainer = new SimpleContainer() {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
return getSelectedAsset(state) != null;
|
||||
}
|
||||
|
||||
};
|
||||
add(contactEntriesContainer);
|
||||
|
||||
contactEntriesTable = buildContactEntriesTable();
|
||||
add(contactEntriesTable);
|
||||
contactEntriesContainer.add(contactEntriesTable);
|
||||
|
||||
contactEntryKeySelect = new SingleSelect(new StringParameter(
|
||||
"contactentry-key"));
|
||||
add(contactEntryKeySelect);
|
||||
try {
|
||||
contactEntryKeySelect
|
||||
.addPrintListener(new ContactEntryKeySelectPrintListener());
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
contactEntriesContainer.add(new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.key",
|
||||
CMS_BUNDLE))
|
||||
);
|
||||
contactEntriesContainer.add(contactEntryKeySelect);
|
||||
|
||||
contactEntryValueField = new TextField("contact-entry-value");
|
||||
contactEntriesContainer.add(new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.value",
|
||||
CMS_BUNDLE))
|
||||
);
|
||||
contactEntriesContainer.add(contactEntryValueField);
|
||||
|
||||
addContactEntryLink = new ActionLink(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.add",
|
||||
CMS_BUNDLE)
|
||||
);
|
||||
addContactEntryLink
|
||||
.addActionListener(new AddContactEntryActionListener());
|
||||
contactEntriesContainer.add(addContactEntryLink);
|
||||
|
||||
contactEntriesContainer.add(new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.postaladdress",
|
||||
CMS_BUNDLE))
|
||||
);
|
||||
postalAddressSearchWidget = new AssetSearchWidget(
|
||||
"contactable-postaladdress", PostalAddress.class
|
||||
);
|
||||
contactEntriesContainer.add(postalAddressSearchWidget);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
super.init(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Optional<T> selected = getSelectedAsset(state);
|
||||
|
||||
if (selected.isPresent()) {
|
||||
// ToDo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final Page page) {
|
||||
|
||||
super.register(page);
|
||||
|
||||
// page.addComponent(addContactEntryLink);
|
||||
}
|
||||
|
||||
protected abstract void addPropertyWidgets();
|
||||
|
||||
private Table buildContactEntriesTable() {
|
||||
|
||||
final Table table = new Table() {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
return getSelectedAsset(state).isPresent();
|
||||
}
|
||||
|
||||
};
|
||||
final Table table = new Table();
|
||||
// {
|
||||
|
||||
// @Override
|
||||
// public boolean isVisible(final PageState state) {
|
||||
// return getSelectedAsset(state).isPresent();
|
||||
// }
|
||||
// };
|
||||
final TableColumnModel columnModel = table.getColumnModel();
|
||||
columnModel.add(new TableColumn(
|
||||
COL_CONTACT_ENTRIES_KEY,
|
||||
|
|
@ -168,8 +252,9 @@ public abstract class AbstractContactableEntityForm<T extends ContactableEntity>
|
|||
final Integer rowKey = (Integer) event.getRowKey();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContactableEntityFormController controller = cdiUtil
|
||||
.findBean(ContactableEntityFormController.class);
|
||||
final AbstractContactableEntityFormController controller
|
||||
= cdiUtil
|
||||
.findBean(AbstractContactableEntityFormController.class);
|
||||
final Optional<T> selected = getSelectedAsset(event
|
||||
.getPageState());
|
||||
if (selected.isPresent()) {
|
||||
|
|
@ -199,8 +284,11 @@ public abstract class AbstractContactableEntityForm<T extends ContactableEntity>
|
|||
.orElseThrow(
|
||||
() -> new IllegalStateException("No asset selected")
|
||||
);
|
||||
final List<ContactEntry> contactEntries = selected
|
||||
.getContactEntries();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AbstractContactableEntityFormController controller = cdiUtil
|
||||
.findBean(AbstractContactableEntityFormController.class);
|
||||
final List<ContactEntry> contactEntries = controller
|
||||
.getContactEntries(selected);
|
||||
return new ContactEntriesTableModel(contactEntries);
|
||||
}
|
||||
|
||||
|
|
@ -295,8 +383,33 @@ public abstract class AbstractContactableEntityForm<T extends ContactableEntity>
|
|||
);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContactEntryKeyRepository keyRepo = cdiUtil
|
||||
.findBean(ContactEntryKeyRepository.class);
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||
.findBean(GlobalizationHelper.class);
|
||||
final List<ContactEntryKey> keys = keyRepo
|
||||
.findAll()
|
||||
.stream()
|
||||
.sorted(new ContactEntryKeyByLabelComparator(globalizationHelper
|
||||
.getNegotiatedLocale()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (final ContactEntryKey key : keys) {
|
||||
|
||||
final Text label = new Text(
|
||||
globalizationHelper
|
||||
.getValueFromLocalizedString(key.getLabel()));
|
||||
|
||||
target.addOption(new Option(key.getEntryKey(), label));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AddContactEntryActionListener implements ActionListener {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ package com.arsdigita.cms.ui.assets.forms;
|
|||
import org.librecms.assets.ContactEntry;
|
||||
import org.librecms.assets.ContactableEntity;
|
||||
import org.librecms.assets.ContactableEntityManager;
|
||||
import org.librecms.assets.ContactableEntityRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -31,11 +36,36 @@ import javax.transaction.Transactional;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class ContactableEntityFormController {
|
||||
public class AbstractContactableEntityFormController {
|
||||
|
||||
@Inject
|
||||
private ContactableEntityRepository contactableEntityRepository;
|
||||
|
||||
@Inject
|
||||
private ContactableEntityManager contactableEntityManager;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<ContactEntry> getContactEntries(
|
||||
final ContactableEntity contactable) {
|
||||
|
||||
Objects.requireNonNull(contactable,
|
||||
"Can't get contact entries from null.");
|
||||
|
||||
final ContactableEntity entity = contactableEntityRepository
|
||||
.findById(contactable.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContactEntity with ID %d found.",
|
||||
contactable.getObjectId())));
|
||||
|
||||
final List<ContactEntry> entries = new ArrayList<>();
|
||||
for(final ContactEntry entry : entity.getContactEntries()) {
|
||||
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void addContactEntry(final ContactEntry contactEntry,
|
||||
final ContactableEntity toContactableEntity) {
|
||||
|
|
@ -31,6 +31,7 @@ import org.librecms.assets.Organization;
|
|||
import org.librecms.contentsection.Asset;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -45,6 +46,21 @@ public class OrganizationForm extends AbstractContactableEntityForm<Organization
|
|||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
super.init(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Optional<Organization> selected = getSelectedAsset(state);
|
||||
|
||||
if (selected.isPresent()) {
|
||||
|
||||
organizationName.setValue(state, selected.get().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPropertyWidgets() {
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
|
@ -58,8 +60,10 @@ public class ContactEntry implements Serializable {
|
|||
/**
|
||||
* Key used to identify the entry.
|
||||
*/
|
||||
@Column(name = "ENTRY_KEY", length = 255, nullable = false)
|
||||
private String key;
|
||||
// @Column(name = "ENTRY_KEY", length = 255, nullable = false)
|
||||
@OneToOne
|
||||
@JoinColumn(name = "CONTACT_ENTRY_KEY_ID")
|
||||
private ContactEntryKey key;
|
||||
|
||||
/**
|
||||
* The value of the entry.
|
||||
|
|
@ -89,11 +93,21 @@ public class ContactEntry implements Serializable {
|
|||
this.order = order;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
// public String getKey() {
|
||||
// return key;
|
||||
// }
|
||||
//
|
||||
// public void setKey(final String key) {
|
||||
// this.key = key;
|
||||
// }
|
||||
|
||||
public ContactEntryKey getKey() {
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(final String key) {
|
||||
public void setKey(final ContactEntryKey key) {
|
||||
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +119,8 @@ public class ContactEntry implements Serializable {
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
|
|
@ -158,13 +174,13 @@ public class ContactEntry implements Serializable {
|
|||
return String.format("%s{ "
|
||||
+ "contactEntryId = %d, "
|
||||
+ "order = %d"
|
||||
+ "key = \"%s\", "
|
||||
+ "key = %s, "
|
||||
+ "value = \"%s\"%s"
|
||||
+ " }",
|
||||
super.toString(),
|
||||
contactEntryId,
|
||||
order,
|
||||
key,
|
||||
Objects.toString(key),
|
||||
value,
|
||||
data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -39,8 +40,10 @@ import static org.librecms.CmsConstants.*;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONTACT_ENTRY_KEYS")
|
||||
public class ContactEntryKey implements Serializable {
|
||||
@Audited
|
||||
@Table(name = "CONTACT_ENTRY_KEYS", schema = DB_SCHEMA)
|
||||
public class ContactEntryKey
|
||||
implements Comparable<ContactEntryKey>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
@ -94,6 +97,12 @@ public class ContactEntryKey implements Serializable {
|
|||
this.label = Objects.requireNonNull(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ContactEntryKey other) {
|
||||
|
||||
return entryKey.compareTo(other.getEntryKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (C) 2019 LibreCCM Foundation.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContactEntryKeyByLabelComparator
|
||||
implements Comparator<ContactEntryKey> {
|
||||
|
||||
private final Locale locale;
|
||||
|
||||
private final Locale defaultLocale;
|
||||
|
||||
public ContactEntryKeyByLabelComparator(final Locale locale) {
|
||||
|
||||
this.locale = locale;
|
||||
defaultLocale = KernelConfig.getConfig().getDefaultLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(final ContactEntryKey key1, final ContactEntryKey key2) {
|
||||
|
||||
final LocalizedString label1 = key1.getLabel();
|
||||
final LocalizedString label2 = key2.getLabel();
|
||||
|
||||
final String localized1 = getLocalizedValue(label1);
|
||||
final String localized2 = getLocalizedValue(label2);
|
||||
|
||||
return localized1.compareTo(localized2);
|
||||
}
|
||||
|
||||
private String getLocalizedValue(final LocalizedString source) {
|
||||
|
||||
if (source.hasValue(locale)) {
|
||||
return source.getValue(locale);
|
||||
} else if (source.hasValue(defaultLocale)) {
|
||||
return source.getValue(defaultLocale);
|
||||
} else {
|
||||
return source.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2019 LibreCCM Foundation.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class ContactableEntityRepository
|
||||
extends AbstractEntityRepository<Long, ContactableEntity>{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Class<ContactableEntity> getEntityClass() {
|
||||
return ContactableEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdAttributeName() {
|
||||
return "objectId";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIdOfEntity(final ContactableEntity entity) {
|
||||
|
||||
return entity.getObjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(final ContactableEntity entity) {
|
||||
|
||||
return entity.getObjectId() == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
alter table CCM_CMS.CONTACT_ENTRIES add column CONTACT_ENTRY_KEY_ID bigint;
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEY_LABELS (
|
||||
KEY_ID bigint not null,
|
||||
LOCALIZED_VALUE varchar(2147483647),
|
||||
LOCALE varchar(255) not null,
|
||||
primary key (KEY_ID, LOCALE)
|
||||
);
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEY_LABELS_AUD (
|
||||
REV integer not null,
|
||||
KEY_ID bigint not null,
|
||||
LOCALIZED_VALUE varchar(2147483647) not null,
|
||||
LOCALE varchar(255) not null,
|
||||
REVTYPE tinyint,
|
||||
REVEND integer,
|
||||
primary key (REV, KEY_ID, LOCALIZED_VALUE, LOCALE)
|
||||
);
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEYS (
|
||||
KEY_ID bigint not null,
|
||||
ENTRY_KEY varchar(255),
|
||||
primary key (KEY_ID)
|
||||
);
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEYS_AUD (
|
||||
KEY_ID bigint not null,
|
||||
REV integer not null,
|
||||
REVTYPE tinyint,
|
||||
REVEND integer,
|
||||
ENTRY_KEY varchar(255),
|
||||
primary key (KEY_ID, REV)
|
||||
);
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRIES
|
||||
add constraint FKirtfj8sm4y5myworl5hvs1l78
|
||||
foreign key (CONTACT_ENTRY_KEY_ID)
|
||||
references CCM_CMS.CONTACT_ENTRY_KEYS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEY_LABELS
|
||||
add constraint FK243nk3buqm0pskkr5ifjqfxn5
|
||||
foreign key (KEY_ID)
|
||||
references CCM_CMS.CONTACT_ENTRY_KEYS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEY_LABELS_AUD
|
||||
add constraint FK6n995k5gao6v63gfcga3yaxcw
|
||||
foreign key (REV)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEY_LABELS_AUD
|
||||
add constraint FKdr8ujdpn1ej8l6omlxq8bsxbd
|
||||
foreign key (REVEND)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEYS_AUD
|
||||
add constraint FKcvn2b1h1d4uvvmtbf4qf81l0y
|
||||
foreign key (REV)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEYS_AUD
|
||||
add constraint FKkyy4v3tax8w5htnpkmmt8aec1
|
||||
foreign key (REVEND)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
|
@ -0,0 +1 @@
|
|||
alter table CCM_CMS.CONTACT_ENTRIES_AUD add column CONTACT_ENTRY_KEY_ID bigint;
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
alter table CCM_CMS.CONTACT_ENTRIES add column CONTACT_ENTRY_KEY_ID int8;
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEY_LABELS (
|
||||
KEY_ID int8 not null,
|
||||
LOCALIZED_VALUE text,
|
||||
LOCALE varchar(255) not null,
|
||||
primary key (KEY_ID, LOCALE)
|
||||
);
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEY_LABELS_AUD (
|
||||
REV int4 not null,
|
||||
KEY_ID int8 not null,
|
||||
LOCALIZED_VALUE text not null,
|
||||
LOCALE varchar(255) not null,
|
||||
REVTYPE int2,
|
||||
REVEND int4,
|
||||
primary key (REV, KEY_ID, LOCALIZED_VALUE, LOCALE)
|
||||
);
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEYS (
|
||||
KEY_ID int8 not null,
|
||||
ENTRY_KEY varchar(255),
|
||||
primary key (KEY_ID)
|
||||
);
|
||||
|
||||
create table CCM_CMS.CONTACT_ENTRY_KEYS_AUD (
|
||||
KEY_ID int8 not null,
|
||||
REV int4 not null,
|
||||
REVTYPE int2,
|
||||
REVEND int4,
|
||||
ENTRY_KEY varchar(255),
|
||||
primary key (KEY_ID, REV)
|
||||
);
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRIES
|
||||
add constraint FKirtfj8sm4y5myworl5hvs1l78
|
||||
foreign key (CONTACT_ENTRY_KEY_ID)
|
||||
references CCM_CMS.CONTACT_ENTRY_KEYS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEY_LABELS
|
||||
add constraint FK243nk3buqm0pskkr5ifjqfxn5
|
||||
foreign key (KEY_ID)
|
||||
references CCM_CMS.CONTACT_ENTRY_KEYS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEY_LABELS_AUD
|
||||
add constraint FK6n995k5gao6v63gfcga3yaxcw
|
||||
foreign key (REV)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEY_LABELS_AUD
|
||||
add constraint FKdr8ujdpn1ej8l6omlxq8bsxbd
|
||||
foreign key (REVEND)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEYS_AUD
|
||||
add constraint FKcvn2b1h1d4uvvmtbf4qf81l0y
|
||||
foreign key (REV)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
||||
alter table CCM_CMS.CONTACT_ENTRY_KEYS_AUD
|
||||
add constraint FKkyy4v3tax8w5htnpkmmt8aec1
|
||||
foreign key (REVEND)
|
||||
references CCM_CORE.CCM_REVISIONS;
|
||||
|
|
@ -0,0 +1 @@
|
|||
alter table CCM_CMS.CONTACT_ENTRIES_AUD add column CONTACT_ENTRY_KEY_ID int8;
|
||||
Loading…
Reference in New Issue