Model for RelatedLink asset.
parent
9e57ec4cd5
commit
c307489d85
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class RelatedLinkModelBuilder
|
||||||
|
extends AbstractAssetModelBuilder<RelatedLink, RelatedLinkModel> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentItemManager itemManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<RelatedLink> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue