CCM NG: Some repository classes for ccm-cms
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4187 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
9166673585
commit
1b3479a1e8
|
|
@ -36,6 +36,8 @@ import javax.persistence.Inheritance;
|
||||||
import javax.persistence.InheritanceType;
|
import javax.persistence.InheritanceType;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.JoinTable;
|
import javax.persistence.JoinTable;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
@ -48,6 +50,17 @@ import static org.librecms.CmsConstants.*;
|
||||||
@Table(schema = DB_SCHEMA, name = "ASSETS")
|
@Table(schema = DB_SCHEMA, name = "ASSETS")
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
@Audited
|
@Audited
|
||||||
|
@NamedQueries({
|
||||||
|
@NamedQuery(name = "Asset.findByUuid",
|
||||||
|
query = "SELECT a FROM Asset a WHERE a.uuid = :uuid"),
|
||||||
|
@NamedQuery(name = "Asset.findByType",
|
||||||
|
query = "SELECT a FROM Asset a "
|
||||||
|
+ "WHERE TYPE(a) = :type"),
|
||||||
|
@NamedQuery(name = "Asset.findByUuidAndType",
|
||||||
|
query = "SELECT a FROM Asset a "
|
||||||
|
+ "WHERE a.uuid = :uuid "
|
||||||
|
+ "AND TYPE(a) = :type")
|
||||||
|
})
|
||||||
public class Asset implements Identifiable, Serializable {
|
public class Asset implements Identifiable, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -3499741368562653529L;
|
private static final long serialVersionUID = -3499741368562653529L;
|
||||||
|
|
@ -75,7 +88,7 @@ public class Asset implements Identifiable, Serializable {
|
||||||
public Asset() {
|
public Asset() {
|
||||||
title = new LocalizedString();
|
title = new LocalizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getAssetId() {
|
public long getAssetId() {
|
||||||
return assetId;
|
return assetId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.auditing.AbstractAuditedEntityRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class AssetRepository
|
||||||
|
extends AbstractAuditedEntityRepository<Long, Asset> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getEntityId(final Asset asset) {
|
||||||
|
return asset.getAssetId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Asset> getEntityClass() {
|
||||||
|
return Asset.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNew(final Asset asset) {
|
||||||
|
return asset.getAssetId() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Asset> findByUuid(final String uuid) {
|
||||||
|
final TypedQuery<Asset> query = entityManager.createNamedQuery(
|
||||||
|
"Asset.findByUuid", Asset.class);
|
||||||
|
query.setParameter("uuid", uuid);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Optional.of(query.getSingleResult());
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Asset> findByUuidAndType(
|
||||||
|
final String uuid, final Class<? extends Asset> clazz) {
|
||||||
|
|
||||||
|
final TypedQuery<Asset> query = entityManager.createNamedQuery(
|
||||||
|
"Asset.findByUuidAndType", Asset.class);
|
||||||
|
query.setParameter("uuid", uuid);
|
||||||
|
query.setParameter("type", clazz.getName());
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Optional.of(query.getSingleResult());
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Asset> findByType(
|
||||||
|
final String uuid, final Class<? extends Asset> clazz) {
|
||||||
|
|
||||||
|
final TypedQuery<Asset> query = entityManager.createNamedQuery(
|
||||||
|
"Asset.findByType", Asset.class);
|
||||||
|
query.setParameter("type", clazz.getName());
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Optional.of(query.getSingleResult());
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.contentsection;
|
||||||
|
|
||||||
|
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
import org.libreccm.core.CcmObjectRepository;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class ContentItemRepository
|
||||||
|
extends AbstractAuditedEntityRepository<Long, ContentItem>{
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CcmObjectRepository ccmObjectRepo;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getEntityId(final ContentItem item) {
|
||||||
|
return item.getObjectId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<ContentItem> getEntityClass() {
|
||||||
|
return ContentItem.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNew(final ContentItem item) {
|
||||||
|
return ccmObjectRepo.isNew(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentItem findById(final long itemId) {
|
||||||
|
final CcmObject result = ccmObjectRepo.findObjectById(itemId);
|
||||||
|
if (result instanceof ContentItem) {
|
||||||
|
return (ContentItem) result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentItem findByUuid(final String uuid) {
|
||||||
|
final CcmObject result = ccmObjectRepo.findObjectByUuid(uuid);
|
||||||
|
if (result instanceof ContentItem) {
|
||||||
|
return (ContentItem) result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//ToDo: Methods for finding items by name, path, content type etc.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.contentsection;
|
||||||
|
|
||||||
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class ContentSectionRepository
|
||||||
|
extends AbstractEntityRepository<Long, ContentSection> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<ContentSection> getEntityClass() {
|
||||||
|
return ContentSection.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNew(final ContentSection section) {
|
||||||
|
return section.getObjectId() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -79,6 +79,7 @@ public class ContentType extends CcmObject implements Serializable {
|
||||||
private ContentItemMode mode;
|
private ContentItemMode mode;
|
||||||
|
|
||||||
//ToDo references for authoring kit etc
|
//ToDo references for authoring kit etc
|
||||||
|
|
||||||
public String getContentItemClass() {
|
public String getContentItemClass() {
|
||||||
return contentItemClass;
|
return contentItemClass;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ import org.hibernate.envers.Audited;
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "CcmObject.findById",
|
@NamedQuery(name = "CcmObject.findById",
|
||||||
query = "SELECT o FROM CcmObject o WHERE o.objectId = :id")
|
query = "SELECT o FROM CcmObject o WHERE o.objectId = :id"),
|
||||||
|
@NamedQuery(name = "CcmObject.findByUuid",
|
||||||
|
query = "SELECT o FROM CcmObject o WHERE o.uuid = :uuid")
|
||||||
})
|
})
|
||||||
@XmlRootElement(name = "ccm-object", namespace = CORE_XML_NS)
|
@XmlRootElement(name = "ccm-object", namespace = CORE_XML_NS)
|
||||||
//False warning (?). Because this class has been migrated from the old PDL style
|
//False warning (?). Because this class has been migrated from the old PDL style
|
||||||
|
|
|
||||||
|
|
@ -69,5 +69,17 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CcmObject findObjectByUuid(final String uuid) {
|
||||||
|
final TypedQuery<CcmObject> query = getEntityManager().createNamedQuery(
|
||||||
|
"CcmObject.findByUuid", CcmObject.class);
|
||||||
|
query.setParameter("uuid", uuid);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return query.getSingleResult();
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue