Search in sources :

Example 1 with CopyException

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) CopyException(com.qcadoo.model.api.CopyException) ArrayList(java.util.ArrayList) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with CopyException

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());
}
Also used : CopyException(com.qcadoo.model.api.CopyException) ExceptionInfoResolver(com.qcadoo.view.api.exception.ExceptionInfoResolver) ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionInfo(com.qcadoo.view.api.exception.ExceptionInfo)

Aggregations

CopyException (com.qcadoo.model.api.CopyException)2 Entity (com.qcadoo.model.api.Entity)1 Monitorable (com.qcadoo.model.api.aop.Monitorable)1 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)1 ExceptionInfo (com.qcadoo.view.api.exception.ExceptionInfo)1 ExceptionInfoResolver (com.qcadoo.view.api.exception.ExceptionInfoResolver)1 ArrayList (java.util.ArrayList)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1