From c307489d854456b4ade9b6993ff85eae9a1435f8 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 6 Nov 2021 13:56:19 +0100 Subject: [PATCH] Model for RelatedLink asset. --- .../pages/models/RelatedLinkModel.java | 74 +++++++++++++++++++ .../pages/models/RelatedLinkModelBuilder.java | 67 +++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModel.java create mode 100644 ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModelBuilder.java diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModel.java new file mode 100644 index 000000000..5b05bdbe7 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModel.java @@ -0,0 +1,74 @@ +/* + * 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.RelatedLink; + +/** + * + * @author Jens Pelzetter + */ +public class RelatedLinkModel extends AbstractAssetModel { + + @Override + public String getType() { + return RelatedLink.class.getName(); + } + + private boolean externalLink; + + private String targetUrl; + + private String targetItemUuid; + + private String targetItemPath; + + public boolean isExternalLink() { + return externalLink; + } + + public void setExternalLink(final boolean externalLink) { + this.externalLink = externalLink; + } + + public String getTargetUrl() { + return targetUrl; + } + + public void setTargetUrl(final String targetUrl) { + this.targetUrl = targetUrl; + } + + public String getTargetItemUuid() { + return targetItemUuid; + } + + public void setTargetItemUuid(final String targetItemUuid) { + this.targetItemUuid = targetItemUuid; + } + + public String getTargetItemPath() { + return targetItemPath; + } + + public void setTargetItemPath(final String targetItemPath) { + this.targetItemPath = targetItemPath; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModelBuilder.java new file mode 100644 index 000000000..2e08124bb --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/RelatedLinkModelBuilder.java @@ -0,0 +1,67 @@ +/* + * 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.RelatedLink; +import org.librecms.contentsection.ContentItemManager; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class RelatedLinkModelBuilder + extends AbstractAssetModelBuilder { + + @Inject + private ContentItemManager itemManager; + + @Override + public Class buildsAssetModelFor() { + return RelatedLink.class; + } + + @Override + protected RelatedLinkModel buildModel() { + return new RelatedLinkModel(); + } + + @Transactional(Transactional.TxType.REQUIRED) + @Override + protected void addProperties( + final RelatedLink relatedLink, final RelatedLinkModel model + ) { + if (relatedLink.getBookmark() == null) { + // Internal Link + model.setExternalLink(false); + model.setTargetItemUuid(relatedLink.getTargetItem().getUuid()); + model.setTargetItemPath( + itemManager.getItemPath(relatedLink.getTargetItem()) + ); + } else { + model.setExternalLink(true); + model.setTargetUrl(relatedLink.getBookmark().getUrl()); + } + } + +}