diff --git a/ccm-core/src/main/java/org/libreccm/api/pagemodels/dto/ComponentModelDto.java b/ccm-core/src/main/java/org/libreccm/api/pagemodels/dto/ComponentModelDto.java
new file mode 100644
index 000000000..04f3ddeca
--- /dev/null
+++ b/ccm-core/src/main/java/org/libreccm/api/pagemodels/dto/ComponentModelDto.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2020 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.libreccm.api.pagemodels.dto;
+
+import org.libreccm.pagemodel.ComponentModel;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class ComponentModelDto {
+
+ private long componentModelId;
+ private String uuid;
+ private String modelUuid;
+
+ private String key;
+
+ private String type;
+
+ private String idAttribute;
+
+ private String classAttribute;
+
+ private String styleAttribute;
+
+ ComponentModelDto() {
+ // Nothing
+ }
+
+ ComponentModelDto(final ComponentModel fromComponentModel) {
+ this.componentModelId =fromComponentModel.getComponentModelId();
+ this.uuid = fromComponentModel.getUuid();
+ this.modelUuid = fromComponentModel.getModelUuid();
+ this.key = fromComponentModel.getKey();
+ this.idAttribute = fromComponentModel.getIdAttribute();
+ this.classAttribute = fromComponentModel.getClassAttribute();
+ this.styleAttribute = fromComponentModel.getStyleAttribute();
+ }
+
+ public long getComponentModelId() {
+ return componentModelId;
+ }
+
+ public void setComponentModelId(final long componentModelId) {
+ this.componentModelId = componentModelId;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(final String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getModelUuid() {
+ return modelUuid;
+ }
+
+ public void setModelUuid(final String modelUuid) {
+ this.modelUuid = modelUuid;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(final String key) {
+ this.key = key;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getIdAttribute() {
+ return idAttribute;
+ }
+
+ public void setIdAttribute(final String idAttribute) {
+ this.idAttribute = idAttribute;
+ }
+
+ public String getClassAttribute() {
+ return classAttribute;
+ }
+
+ public void setClassAttribute(final String classAttribute) {
+ this.classAttribute = classAttribute;
+ }
+
+ public String getStyleAttribute() {
+ return styleAttribute;
+ }
+
+ public void setStyleAttribute(final String styleAttribute) {
+ this.styleAttribute = styleAttribute;
+ }
+
+
+
+}
diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModel.java b/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModel.java
index af8248378..e9b14c497 100644
--- a/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModel.java
+++ b/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModel.java
@@ -53,11 +53,24 @@ import javax.persistence.Table;
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "PAGE_MODEL_COMPONENT_MODELS", schema = CoreConstants.DB_SCHEMA)
@NamedQueries({
- @NamedQuery(name = "ComponentModel.findComponentByContainerAndKey",
- query = "SELECT c "
- + "FROM ComponentModel c "
- + "WHERE c.container = :container "
- + "AND c.key = :key")
+ @NamedQuery(
+ name = "ComponentModel.findComponentsOfContainer",
+ query = "SELECT c FROM ComponentModel c "
+ + "WHERE c.container = :container "
+ + "ORDER BY c.key"
+ ),
+ @NamedQuery(
+ name = "ComponentModel.countComponentsOfContainer",
+ query = "SELECT COUNT(c) FROM ComponentModel c "
+ + "WHERE c.container = :container"
+ ),
+ @NamedQuery(
+ name = "ComponentModel.findComponentByContainerAndKey",
+ query = "SELECT c "
+ + "FROM ComponentModel c "
+ + "WHERE c.container = :container "
+ + "AND c.key = :key"
+ )
})
public class ComponentModel implements Serializable {
diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModelRepository.java b/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModelRepository.java
index 763ff92fe..cc7a905d3 100644
--- a/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModelRepository.java
+++ b/ccm-core/src/main/java/org/libreccm/pagemodel/ComponentModelRepository.java
@@ -24,6 +24,7 @@ import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -32,6 +33,7 @@ import javax.enterprise.context.RequestScoped;
import javax.transaction.Transactional;
import java.util.UUID;
+import java.util.stream.Stream;
import javax.persistence.EntityGraph;
import javax.persistence.NoResultException;
@@ -162,20 +164,68 @@ public class ComponentModelRepository
}
}
+ @Transactional(Transactional.TxType.REQUIRED)
+ public List findComponentsOfContainerAsList(
+ final ContainerModel containerModel,
+ final int limit,
+ final int offset
+ ) {
+ return getEntityManager()
+ .createNamedQuery(
+ "ComponentModel.findComponentsOfContainer",
+ ComponentModel.class
+ )
+ .setParameter("container", containerModel)
+ .setFirstResult(offset)
+ .setMaxResults(limit)
+ .getResultList();
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ public Stream findComponentsOfContainerAsStream(
+ final ContainerModel containerModel,
+ final int limit,
+ final int offset
+ ) {
+ return getEntityManager()
+ .createNamedQuery(
+ "ComponentModel.findComponentsOfContainer",
+ ComponentModel.class
+ )
+ .setParameter("container", containerModel)
+ .setFirstResult(offset)
+ .setMaxResults(limit)
+ .getResultStream();
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ public long countComponentsOfContainer(
+ final ContainerModel containerModel,
+ final int limit,
+ final int offset
+ ) {
+ return getEntityManager()
+ .createNamedQuery(
+ "ComponentModel.countComponentsOfContainer", Long.class
+ )
+ .setParameter("container", containerModel)
+ .getSingleResult();
+ }
+
@Transactional(Transactional.TxType.REQUIRED)
public Optional findComponentByContainerAndKey(
final ContainerModel containerModel,
final String componentKey) {
final TypedQuery query = getEntityManager()
- .createNamedQuery("ComponentModel.findComponentByContainerAndKey",
- ComponentModel.class);
+ .createNamedQuery("ComponentModel.findComponentByContainerAndKey",
+ ComponentModel.class);
query.setParameter("container", containerModel);
query.setParameter("key", componentKey);
-
+
try {
return Optional.of(query.getSingleResult());
- } catch(NoResultException ex) {
+ } catch (NoResultException ex) {
return Optional.empty();
}
}
diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/ContainerModel.java b/ccm-core/src/main/java/org/libreccm/pagemodel/ContainerModel.java
index b05bfbdd2..748d799b5 100644
--- a/ccm-core/src/main/java/org/libreccm/pagemodel/ContainerModel.java
+++ b/ccm-core/src/main/java/org/libreccm/pagemodel/ContainerModel.java
@@ -61,7 +61,9 @@ import javax.xml.bind.annotation.XmlTransient;
@NamedQueries({
@NamedQuery(
name = "ContainerModel.findContainersOfPageModel",
- query = "SELECT c FROM ContainerModel c WHERE c.pageModel = :pageModel"
+ query = "SELECT c FROM ContainerModel c "
+ + "WHERE c.pageModel = :pageModel "
+ + "ORDER BY c.key"
),
@NamedQuery(
name = "ContainerModel.countContainersOfPageModel",