59 lines
1.6 KiB
Java
59 lines
1.6 KiB
Java
package org.scientificcms.publications;
|
|
|
|
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
|
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
|
import org.libreccm.cdi.utils.CdiUtil;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import javax.enterprise.context.RequestScoped;
|
|
|
|
/**
|
|
*
|
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
*/
|
|
@RequestScoped
|
|
public class PublicationIdResolver implements Serializable, ObjectIdResolver {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@Override
|
|
public void bindItem(
|
|
final ObjectIdGenerator.IdKey idKey,
|
|
final Object object
|
|
) {
|
|
// According to the Jackson JavaDoc, this method can be used to keep
|
|
// track of objects directly in a resolver implementation. We don't need
|
|
// this here therefore this method is empty.
|
|
}
|
|
|
|
@Override
|
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
|
return CdiUtil
|
|
.createCdiUtil()
|
|
.findBean(PublicationRepository.class)
|
|
.findByUuid(id.key.toString())
|
|
.orElseThrow(
|
|
() -> new IllegalArgumentException(
|
|
String.format(
|
|
"No Publiation with UUID %s found in database.",
|
|
id.key.toString()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
@Override
|
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
|
return new PublicationIdResolver();
|
|
}
|
|
|
|
@Override
|
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
|
return resolverType instanceof PublicationIdResolver;
|
|
}
|
|
|
|
|
|
|
|
}
|