Optimizations for RESTful API for managing containers
parent
8472cb7e45
commit
96dae5876b
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -53,11 +53,24 @@ import javax.persistence.Table;
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
@Table(name = "PAGE_MODEL_COMPONENT_MODELS", schema = CoreConstants.DB_SCHEMA)
|
@Table(name = "PAGE_MODEL_COMPONENT_MODELS", schema = CoreConstants.DB_SCHEMA)
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "ComponentModel.findComponentByContainerAndKey",
|
@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 "
|
query = "SELECT c "
|
||||||
+ "FROM ComponentModel c "
|
+ "FROM ComponentModel c "
|
||||||
+ "WHERE c.container = :container "
|
+ "WHERE c.container = :container "
|
||||||
+ "AND c.key = :key")
|
+ "AND c.key = :key"
|
||||||
|
)
|
||||||
})
|
})
|
||||||
public class ComponentModel implements Serializable {
|
public class ComponentModel implements Serializable {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import org.libreccm.security.AuthorizationRequired;
|
||||||
import org.libreccm.security.RequiresPrivilege;
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -32,6 +33,7 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.persistence.EntityGraph;
|
import javax.persistence.EntityGraph;
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
|
|
@ -162,6 +164,54 @@ public class ComponentModelRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public List<ComponentModel> 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<ComponentModel> 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)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<ComponentModel> findComponentByContainerAndKey(
|
public Optional<ComponentModel> findComponentByContainerAndKey(
|
||||||
final ContainerModel containerModel,
|
final ContainerModel containerModel,
|
||||||
|
|
@ -175,7 +225,7 @@ public class ComponentModelRepository
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Optional.of(query.getSingleResult());
|
return Optional.of(query.getSingleResult());
|
||||||
} catch(NoResultException ex) {
|
} catch (NoResultException ex) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,9 @@ import javax.xml.bind.annotation.XmlTransient;
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContainerModel.findContainersOfPageModel",
|
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(
|
@NamedQuery(
|
||||||
name = "ContainerModel.countContainersOfPageModel",
|
name = "ContainerModel.countContainersOfPageModel",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue