Better exceptio handling
parent
161eff594d
commit
72ee9fe032
|
|
@ -23,8 +23,11 @@ import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.NonUniqueResultException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to resolve {@link CcmObject}s based on their UUIDs when importing and
|
* Used to resolve {@link CcmObject}s based on their UUIDs when importing and
|
||||||
* exporting them.
|
* exporting them.
|
||||||
|
|
@ -49,6 +52,7 @@ public class CcmObjectIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
|
try {
|
||||||
return CdiUtil
|
return CdiUtil
|
||||||
.createCdiUtil()
|
.createCdiUtil()
|
||||||
.findBean(CcmObjectRepository.class)
|
.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
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue