use of com.qcadoo.model.api.CopyException in project qcadoo by qcadoo.
the class DataAccessServiceImpl method copy.
@Override
@Transactional
@Monitorable
public List<Entity> copy(final InternalDataDefinition dataDefinition, final Long... entityIds) {
InternalDataDefinition dataDefinitionToCopy = getDataDefinitionByMasterModel(dataDefinition);
List<Entity> copiedEntities = new ArrayList<Entity>();
for (Long entityId : entityIds) {
Entity sourceEntity = get(dataDefinitionToCopy, entityId);
Entity targetEntity = copy(dataDefinitionToCopy, sourceEntity);
if (targetEntity == null) {
throw new IllegalStateException("Cannot copy " + sourceEntity);
}
LOG.debug(sourceEntity + " has been copied to " + targetEntity);
targetEntity = save(dataDefinitionToCopy, targetEntity);
if (!targetEntity.isValid()) {
throw new CopyException(targetEntity);
}
copiedEntities.add(targetEntity);
}
return copiedEntities;
}
use of com.qcadoo.model.api.CopyException in project qcadoo by qcadoo.
the class DefaultExceptionResolver method doResolveException.
@Override
protected ModelAndView doResolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception exception) {
ModelAndView mv = super.doResolveException(request, response, handler, exception);
if (mv == null) {
return mv;
}
String codeStr = mv.getViewName();
int code = Integer.parseInt(codeStr);
CustomTranslationMessage customExceptionMessage = getCustomExceptionMessage(exception);
if (LOG.isDebugEnabled()) {
LOG.debug("Adding exception message to view: " + customExceptionMessage);
}
String customExceptionMessageHeader = null;
String customExceptionMessageExplanation = null;
@SuppressWarnings("rawtypes") ExceptionInfoResolver exceptionInfoResolver = classResolversMap.get(exception.getClass());
if (exceptionInfoResolver != null) {
@SuppressWarnings("unchecked") ExceptionInfo info = exceptionInfoResolver.getExceptionInfo(exception);
customExceptionMessageHeader = translationService.translate(info.getMessageHeader(), LocaleContextHolder.getLocale());
customExceptionMessageExplanation = translationService.translate(info.getMessageExplanation(), LocaleContextHolder.getLocale(), info.getMessageExplanationArgs());
} else if (customExceptionMessage != null) {
customExceptionMessageHeader = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".header", LocaleContextHolder.getLocale());
if (customExceptionMessage.getEntityIdentifier() == null) {
if ("uploadException.maxSizeExceeded".equals(customExceptionMessage.getMessage())) {
customExceptionMessageExplanation = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".explanation", LocaleContextHolder.getLocale(), "" + maxUploadSize / 1000000);
} else {
customExceptionMessageExplanation = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".explanation", LocaleContextHolder.getLocale());
}
} else {
customExceptionMessageExplanation = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".explanation", LocaleContextHolder.getLocale(), customExceptionMessage.getEntityIdentifier());
}
Throwable rootException = getRootException(exception);
if (rootException instanceof CopyException) {
String copyExplanation = getAdditionalMessageForCopyException((CopyException) rootException, LocaleContextHolder.getLocale());
if (copyExplanation != null) {
customExceptionMessageExplanation = copyExplanation;
}
}
}
return errorController.getAccessDeniedPageView(code, exception, customExceptionMessageHeader, customExceptionMessageExplanation, LocaleContextHolder.getLocale());
}
Aggregations