Model for ContactableEntity asset
parent
37750c793d
commit
2b951c981c
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
* @param <M>
|
||||
*/
|
||||
public abstract class AbstractContactableEntityModelBuilder<T extends ContactableEntity, M extends ContactableEntityModel>
|
||||
extends AbstractAssetModelBuilder<T, M> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContactableEntityModel extends AbstractAssetModel {
|
||||
|
||||
private Map<String, ContactEntryModel> contactEntries;
|
||||
|
||||
private PostalAddressModel postalAddress;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return ContactableEntity.class.getName();
|
||||
}
|
||||
|
||||
public Map<String, ContactEntryModel> getContactEntries() {
|
||||
return Collections.unmodifiableMap(contactEntries);
|
||||
}
|
||||
|
||||
public void setContactEntries(
|
||||
final Map<String, ContactEntryModel> contactEntries
|
||||
) {
|
||||
this.contactEntries = new HashMap<>(contactEntries);
|
||||
}
|
||||
|
||||
public PostalAddressModel getPostalAddress() {
|
||||
return postalAddress;
|
||||
}
|
||||
|
||||
public void setPostalAddress(final PostalAddressModel postalAddress) {
|
||||
this.postalAddress = postalAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue