Using correct query for retrieving ContactableEntity assets.
parent
28f5fd53f5
commit
9330316c49
|
|
@ -33,6 +33,8 @@ import java.util.Objects;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.OrderBy;
|
import javax.persistence.OrderBy;
|
||||||
|
|
@ -49,6 +51,12 @@ import static org.librecms.CmsConstants.*;
|
||||||
@Entity
|
@Entity
|
||||||
@Audited
|
@Audited
|
||||||
@Table(name = "CONTACTABLE_ENTITIES", schema = DB_SCHEMA)
|
@Table(name = "CONTACTABLE_ENTITIES", schema = DB_SCHEMA)
|
||||||
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "ContactableEntity.findByUuid",
|
||||||
|
query = "SELECT c FROM ContactableEntity c WHERE c.uuid = :uuid"
|
||||||
|
)
|
||||||
|
})
|
||||||
@JsonIdentityInfo(
|
@JsonIdentityInfo(
|
||||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
resolver = ContactableEntityIdResolver.class,
|
resolver = ContactableEntityIdResolver.class,
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,8 @@ public class ContactableEntityIdResolver implements Serializable,
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
return CdiUtil
|
return CdiUtil
|
||||||
.createCdiUtil()
|
.createCdiUtil()
|
||||||
.findBean(AssetRepository.class)
|
.findBean(ContactableEntityRepository.class)
|
||||||
.findByUuidAndType(
|
.findByUuid(id.key.toString())
|
||||||
id.key.toString(),
|
|
||||||
ContactableEntity.class
|
|
||||||
)
|
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
() -> new IllegalArgumentException(
|
() -> new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,18 @@ package org.librecms.assets;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class ContactableEntityRepository
|
public class ContactableEntityRepository
|
||||||
extends AbstractEntityRepository<Long, ContactableEntity>{
|
extends AbstractEntityRepository<Long, ContactableEntity> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
@ -44,14 +47,30 @@ public class ContactableEntityRepository
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getIdOfEntity(final ContactableEntity entity) {
|
public Long getIdOfEntity(final ContactableEntity entity) {
|
||||||
|
|
||||||
return entity.getObjectId();
|
return entity.getObjectId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNew(final ContactableEntity entity) {
|
public boolean isNew(final ContactableEntity entity) {
|
||||||
|
|
||||||
return entity.getObjectId() == 0;
|
return entity.getObjectId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<ContactableEntity> findByUuid(final String uuid) {
|
||||||
|
try {
|
||||||
|
return Optional.of(
|
||||||
|
getEntityManager()
|
||||||
|
.createNamedQuery(
|
||||||
|
"ContactableEntity.findByUuid",
|
||||||
|
ContactableEntity.class
|
||||||
|
)
|
||||||
|
.setParameter("uuid", uuid)
|
||||||
|
.getSingleResult()
|
||||||
|
);
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue