Setting/resetting the index item of a category only worked for the root category, now works for all categories.

pull/20/head
Jens Pelzetter 2022-02-26 17:55:16 +01:00
parent 35ce5479fd
commit f5d3481c9a
2 changed files with 40 additions and 29 deletions

View File

@ -524,7 +524,7 @@
<td class="actions-setindex-col">
<c:choose>
<c:when test="#{object.indexObject}">
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/categorysystems/#{CategorySystemModel.selectedCategorySystem.context}/categories#{category.path}/@index-element/reset"
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/categorysystems/#{CategorySystemModel.selectedCategorySystem.context}/categories#{CategorySystemModel.selectedCategory.path}/@index-element/reset"
method="post">
<button class="btn btn-danger"
type="submit">
@ -534,7 +534,7 @@
</form>
</c:when>
<c:otherwise>
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/categorysystems/#{CategorySystemModel.selectedCategorySystem.context}/categories#{category.path}/@index-element/#{object.objectUuid}"
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/categorysystems/#{CategorySystemModel.selectedCategorySystem.context}/categories#{CategorySystemModel.selectedCategory.path}/@index-element/#{object.objectUuid}"
method="post">
<button class="btn btn-info"
type="submit">

View File

@ -47,7 +47,7 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
private static final long serialVersionUID = 8462548002420023652L;
protected static final String FETCH_GRAPH_HINT_KEY
= "javax.persistence.fetchgraph";
= "javax.persistence.fetchgraph";
/**
* The {@link EntityManager} instance to use. Provided by the container via
@ -113,7 +113,8 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
@SuppressWarnings("unchecked")
public EntityGraph<E> createEntityGraph(final String entityGraphName) {
return (EntityGraph<E>) entityManager.createEntityGraph(
entityGraphName);
entityGraphName
);
}
/**
@ -153,16 +154,18 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
*/
@Transactional(Transactional.TxType.REQUIRED)
public Optional<E> findById(final K entityId) {
Objects.requireNonNull(entityId);
return Optional.ofNullable(entityManager.find(getEntityClass(),
entityId));
return Optional.ofNullable(
entityManager.find(
getEntityClass(),
entityId
)
);
}
@Transactional(Transactional.TxType.REQUIRED)
public Optional<E> findById(final K entityId, final String entityGraphName) {
Objects.requireNonNull(entityId);
Objects.requireNonNull(entityGraphName);
@ -175,15 +178,18 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
@Transactional(Transactional.TxType.REQUIRED)
public Optional<E> findById(final K entityId,
final EntityGraph<E> entityGraph) {
Objects.requireNonNull(entityId);
Objects.requireNonNull(entityGraph);
final Map<String, Object> hints = new HashMap<>();
hints.put(FETCH_GRAPH_HINT_KEY, entityGraph);
return Optional.ofNullable(entityManager.find(getEntityClass(),
entityId,
hints));
return Optional.ofNullable(
entityManager.find(
getEntityClass(),
entityId,
hints
)
);
}
/**
@ -206,16 +212,18 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
Objects.requireNonNull(entityId);
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
final CriteriaQuery<E> criteriaQuery = builder
.createQuery(getEntityClass());
final CriteriaQuery<E> criteriaQuery = builder.createQuery(
getEntityClass()
);
final Root<E> from = criteriaQuery.from(getEntityClass());
criteriaQuery.from(getEntityClass());
for (final String fetchJoin : fetchJoins) {
from.fetch(fetchJoin);
}
criteriaQuery
.where(builder.equal(from.get(getIdAttributeName()), entityId));
criteriaQuery.where(
builder.equal(from.get(getIdAttributeName()), entityId)
);
final TypedQuery<E> query = entityManager.createQuery(criteriaQuery);
try {
@ -229,10 +237,15 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
public E reload(final E entity, final String... fetchJoins) {
return findById(getIdOfEntity(entity), fetchJoins)
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Entity of type \"%s\" with ID %s in the database.",
getEntityClass().getName(),
Objects.toString(getIdOfEntity(entity)))));
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Entity of type \"%s\" with ID %s in the database.",
getEntityClass().getName(),
Objects.toString(getIdOfEntity(entity))
)
)
);
}
/**
@ -273,7 +286,8 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
final CriteriaBuilder criteriaBuilder = entityManager
.getCriteriaBuilder();
final CriteriaQuery<E> criteriaQuery = criteriaBuilder.createQuery(
getEntityClass());
getEntityClass()
);
final Root<E> root = criteriaQuery.from(getEntityClass());
return criteriaQuery.select(root);
}
@ -303,8 +317,7 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
final String graphName) {
@SuppressWarnings("unchecked")
final EntityGraph<E> entityGraph = (EntityGraph< E>) entityManager
.getEntityGraph(
graphName);
.getEntityGraph(graphName);
return executeCriteriaQuery(criteriaQuery, entityGraph);
}
@ -334,7 +347,6 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
*/
@Transactional(Transactional.TxType.REQUIRED)
public void save(final E entity) {
Objects.requireNonNull(entity, "Can't save null.");
if (isNew(entity)) {
@ -363,12 +375,11 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
*/
@Transactional(Transactional.TxType.REQUIRED)
public void delete(final E entity) {
Objects.requireNonNull(
entity, "Can't delete a null entity."
);
Objects.requireNonNull(entity,
"Can't delete a null entity.");
//We need to make sure we use a none detached entity, therefore the merge
entityManager.remove(entityManager.merge(entity));
entityManager.remove(entity);
}
}