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.JoinColumn;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.OrderBy;
|
||||
|
|
@ -49,6 +51,12 @@ import static org.librecms.CmsConstants.*;
|
|||
@Entity
|
||||
@Audited
|
||||
@Table(name = "CONTACTABLE_ENTITIES", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "ContactableEntity.findByUuid",
|
||||
query = "SELECT c FROM ContactableEntity c WHERE c.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
@JsonIdentityInfo(
|
||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
resolver = ContactableEntityIdResolver.class,
|
||||
|
|
|
|||
|
|
@ -51,11 +51,8 @@ public class ContactableEntityIdResolver implements Serializable,
|
|||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
return CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(AssetRepository.class)
|
||||
.findByUuidAndType(
|
||||
id.key.toString(),
|
||||
ContactableEntity.class
|
||||
)
|
||||
.findBean(ContactableEntityRepository.class)
|
||||
.findByUuid(id.key.toString())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
|
|
|
|||
|
|
@ -20,15 +20,18 @@ package org.librecms.assets;
|
|||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class ContactableEntityRepository
|
||||
extends AbstractEntityRepository<Long, ContactableEntity>{
|
||||
public class ContactableEntityRepository
|
||||
extends AbstractEntityRepository<Long, ContactableEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
@ -44,14 +47,30 @@ public class ContactableEntityRepository
|
|||
|
||||
@Override
|
||||
public Long getIdOfEntity(final ContactableEntity entity) {
|
||||
|
||||
|
||||
return entity.getObjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(final ContactableEntity entity) {
|
||||
|
||||
|
||||
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