From 2b951c981c1350937ccbbf284b9e652a14c71446 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 6 Nov 2021 16:39:32 +0100 Subject: [PATCH] Model for ContactableEntity asset --- ...AbstractContactableEntityModelBuilder.java | 83 +++++++++++++++++++ .../pages/models/ContactEntryModel.java | 57 +++++++++++++ .../pages/models/ContactableEntityModel.java | 62 ++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 ccm-cms/src/main/java/org/librecms/pages/models/AbstractContactableEntityModelBuilder.java create mode 100644 ccm-cms/src/main/java/org/librecms/pages/models/ContactEntryModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/pages/models/ContactableEntityModel.java diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/AbstractContactableEntityModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/AbstractContactableEntityModelBuilder.java new file mode 100644 index 000000000..aea1e5104 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/AbstractContactableEntityModelBuilder.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2021 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.pages.models; + +import org.libreccm.l10n.GlobalizationHelper; +import org.librecms.assets.ContactEntry; +import org.librecms.assets.ContactableEntity; + +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.transaction.Transactional; + +/** + * + * @author Jens Pelzetter + * @param + * @param + */ +public abstract class AbstractContactableEntityModelBuilder + extends AbstractAssetModelBuilder { + + @Inject + private GlobalizationHelper globalizationHelper; + + @Inject + private PostalAddressModelBuilder postalAddressModelBuilder; + + @Transactional(Transactional.TxType.REQUIRED) + @Override + protected void addProperties(final T contactableEntity, final M model) { + super.addProperties(contactableEntity, model); + model.setContactEntries( + contactableEntity + .getContactEntries() + .stream() + .map(this::buildContactEntryModel) + .collect( + Collectors.toMap( + ContactEntryModel::getKey, + contactEntry -> contactEntry + ) + ) + ); + model.setPostalAddress( + postalAddressModelBuilder.buildAssetModel( + contactableEntity.getPostalAddress() + ) + ); + } + + private ContactEntryModel buildContactEntryModel( + final ContactEntry contactEntry + ) { + final ContactEntryModel model = new ContactEntryModel(); + model.setKey(contactEntry.getKey().getEntryKey()); + model.setKeyLabel( + globalizationHelper.getValueFromLocalizedString( + contactEntry.getKey().getLabel() + ) + ); + model.setValue(contactEntry.getValue()); + + return model; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/ContactEntryModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/ContactEntryModel.java new file mode 100644 index 000000000..9e2a21b1a --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/ContactEntryModel.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2021 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.pages.models; + +/** + * + * @author Jens Pelzetter + */ +public class ContactEntryModel { + + private String key; + + private String keyLabel; + + private String value; + + public String getKey() { + return key; + } + + public void setKey(final String key) { + this.key = key; + } + + public String getKeyLabel() { + return keyLabel; + } + + public void setKeyLabel(final String keyLabel) { + this.keyLabel = keyLabel; + } + + public String getValue() { + return value; + } + + public void setValue(final String value) { + this.value = value; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/ContactableEntityModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/ContactableEntityModel.java new file mode 100644 index 000000000..4c25a08c1 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/ContactableEntityModel.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2021 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.pages.models; + +import org.librecms.assets.ContactableEntity; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + */ +public class ContactableEntityModel extends AbstractAssetModel { + + private Map contactEntries; + + private PostalAddressModel postalAddress; + + @Override + public String getType() { + return ContactableEntity.class.getName(); + } + + public Map getContactEntries() { + return Collections.unmodifiableMap(contactEntries); + } + + public void setContactEntries( + final Map contactEntries + ) { + this.contactEntries = new HashMap<>(contactEntries); + } + + public PostalAddressModel getPostalAddress() { + return postalAddress; + } + + public void setPostalAddress(final PostalAddressModel postalAddress) { + this.postalAddress = postalAddress; + } + + + +}