Better exceptio handling
parent
161eff594d
commit
72ee9fe032
|
|
@ -23,8 +23,11 @@ import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
|||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.NonUniqueResultException;
|
||||
|
||||
/**
|
||||
* Used to resolve {@link CcmObject}s based on their UUIDs when importing and
|
||||
* exporting them.
|
||||
|
|
@ -49,6 +52,7 @@ public class CcmObjectIdResolver implements Serializable, ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
try {
|
||||
return CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(CcmObjectRepository.class)
|
||||
|
|
@ -61,6 +65,15 @@ public class CcmObjectIdResolver implements Serializable, ObjectIdResolver {
|
|||
)
|
||||
)
|
||||
);
|
||||
} catch(NonUniqueResultException ex) {
|
||||
throw new UnexpectedErrorException(
|
||||
String.format(
|
||||
"Found more than one result for UUID %s.",
|
||||
id.key.toString()
|
||||
),
|
||||
ex
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue