Example usage for org.springframework.dao DataRetrievalFailureException getCause

List of usage examples for org.springframework.dao DataRetrievalFailureException getCause

Introduction

In this page you can find the example usage for org.springframework.dao DataRetrievalFailureException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.kuali.student.myplan.audit.controller.DegreeAuditController.java

/**
 * Method to run a regular degree audit/*from  w w w. j  a  v a 2  s  . c  o  m*/
 *
 * @param auditForm
 * @param result
 * @param request
 * @param response
 * @return
 */
@RequestMapping(params = "methodToCall=runAudit")
public ModelAndView runAudit(@ModelAttribute("KualiForm") AuditForm auditForm, BindingResult result,
        HttpServletRequest request, HttpServletResponse response) {
    DegreeAuditForm form = auditForm.getDegreeAudit();
    try {
        String regid = getUserSessionHelper().getStudentId();
        if (StringUtils.hasText(regid)) {
            String programId = getDegreeAuditHelper().getFormProgramID(form);
            if (!programId.equalsIgnoreCase(DegreeAuditConstants.DEFAULT_KEY)) {
                DegreeAuditService degreeAuditService = getDegreeAuditService();
                ContextInfo context = DegreeAuditConstants.CONTEXT_INFO;
                String auditType = form.getAuditType();
                AuditReportInfo info = degreeAuditService.runAudit(regid, programId, auditType, context);
                String auditID = info.getAuditId();
                // TODO: For now we are getting the auditType from the end user. This needs to be remvoed before
                // going live and hard coded to audit type key html
                AuditReportInfo report = degreeAuditService.getAuditReport(auditID, auditType, context);
                copyReportToForm(report, form);
            } else {
                String[] params = {};
                GlobalVariables.getMessageMap().putError(DEGREE_AUDIT_PROGRAM_PARAM_SEATTLE,
                        DegreeAuditConstants.AUDIT_RUN_FAILED, params);
                form.setAuditHtml(String.format(DegreeAuditConstants.AUDIT_FAILED_HTML,
                        DegreeAuditConstants.AUDIT_STATUS_ERROR_MSG, DegreeAuditConstants.AUDIT_TYPE_DEGREE));
            }
        }

    } catch (DataRetrievalFailureException e) {
        String[] params = {};
        GlobalVariables.getMessageMap().putError(DEGREE_AUDIT_PROGRAM_PARAM_SEATTLE,
                DegreeAuditConstants.NO_SYSTEM_KEY, params);

    } catch (Exception e) {
        logger.error("Could not complete audit run");
        String[] params = {};
        GlobalVariables.getMessageMap().putError(DEGREE_AUDIT_PROGRAM_PARAM_SEATTLE,
                DegreeAuditConstants.AUDIT_RUN_FAILED, params);
        Throwable cause = e.getCause();
        if (cause != null) {
            String message = cause.getMessage();
            if (message != null) {
                String errorMessage = getErrorMessageFromXml(message);
                String html = String.format(DegreeAuditConstants.AUDIT_FAILED_HTML, errorMessage,
                        DegreeAuditConstants.AUDIT_TYPE_DEGREE);
                form.setAuditHtml(html);
            }
        }
    }
    return getUIFModelAndView(auditForm);
}

From source file:org.kuali.student.myplan.audit.controller.DegreeAuditController.java

/**
 * Method to run a plan audit/*from   w ww .j  ava2  s  .  c om*/
 *
 * @param auditForm
 * @param result
 * @param request
 * @param response
 * @return
 */
@RequestMapping(params = "methodToCall=runPlanAudit")
public ModelAndView runPlanAudit(@ModelAttribute("KualiForm") AuditForm auditForm, BindingResult result,
        HttpServletRequest request, HttpServletResponse response) {
    PlanAuditForm form = auditForm.getPlanAudit();
    // Plan Audit Report Process
    try {
        String regid = getUserSessionHelper().getStudentId();
        if (StringUtils.hasText(regid)) {
            String programId = getDegreeAuditHelper().getFormProgramID(form);
            if (!programId.equals(DegreeAuditConstants.DEFAULT_KEY)) {
                ContextInfo context = new ContextInfo();
                context.setPrincipalId(regid);
                DegreeAuditService degreeAuditService = getDegreeAuditService();
                List<LearningPlanInfo> learningPlanList = getAcademicPlanService()
                        .getLearningPlansForStudentByType(regid, LEARNING_PLAN_TYPE_PLAN, CONTEXT_INFO);
                for (LearningPlanInfo learningPlan : learningPlanList) {
                    LearningPlanInfo learningPlanInfo = getAcademicPlanService().copyLearningPlan(
                            learningPlan.getId(), AcademicPlanServiceConstants.LEARNING_PLAN_TYPE_PLAN_AUDIT,
                            context);
                    String learningPlanInfoId = learningPlanInfo.getId();

                    savePlanItemSnapshots(form, learningPlanInfoId);
                    String auditId = degreeAuditService.runWhatIfAuditAsync(regid, programId,
                            form.getAuditType(), learningPlanInfoId, context);
                    AuditReportInfo report = degreeAuditService.getAuditReport(auditId, form.getAuditType(),
                            context);

                    copyReportToForm(report, form);
                    break;
                }

            } else {
                String[] params = {};
                GlobalVariables.getMessageMap().putError(PLAN_AUDIT_PROGRAM_PARAM_SEATTLE,
                        DegreeAuditConstants.AUDIT_RUN_FAILED, params);
                form.setAuditHtml(String.format(DegreeAuditConstants.AUDIT_FAILED_HTML,
                        DegreeAuditConstants.AUDIT_STATUS_ERROR_MSG, DegreeAuditConstants.AUDIT_TYPE_PLAN));
            }
        }

    } catch (DataRetrievalFailureException e) {
        String[] params = {};
        form.setCampusParam("306");
        GlobalVariables.getMessageMap().putError(PLAN_AUDIT_PROGRAM_PARAM_SEATTLE,
                DegreeAuditConstants.NO_SYSTEM_KEY, params);

    } catch (Exception e) {
        logger.error("Could not complete audit run", e);
        String[] params = {};
        GlobalVariables.getMessageMap().putError(PLAN_AUDIT_PROGRAM_PARAM_SEATTLE,
                DegreeAuditConstants.AUDIT_RUN_FAILED, params);
        Throwable cause = e.getCause();
        if (cause != null) {
            String message = cause.getMessage();
            if (message != null) {
                String errorMessage = getErrorMessageFromXml(message);
                String html = String.format(DegreeAuditConstants.AUDIT_FAILED_HTML, errorMessage,
                        DegreeAuditConstants.AUDIT_TYPE_PLAN);
                form.setAuditHtml(html);
            }
        }
    }
    return getUIFModelAndView(auditForm);
}

From source file:de.tudarmstadt.ukp.clarin.webanno.monitoring.page.MonitoringPage.java

/**
 * Get the finished CASes used to compute agreement.
 *//*  ww  w .  j  a v  a2 s . c o  m*/
private Map<SourceDocument, Map<User, JCas>> getJCases(List<User> users, List<SourceDocument> sourceDocuments) {
    Map<SourceDocument, Map<User, JCas>> documentJCases = new HashMap<SourceDocument, Map<User, JCas>>();
    for (SourceDocument document : sourceDocuments) {
        Map<User, JCas> jCases = new HashMap<User, JCas>();
        for (User user : users) {
            if (repository.existsAnnotationDocument(document, user)) {
                AnnotationDocument annotationDocument = repository.getAnnotationDocument(document, user);
                if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
                    try {
                        JCas jCas = repository.readAnnotationCas(annotationDocument);
                        repository.upgradeCas(jCas.getCas(), annotationDocument);
                        // REC: I think there is no need to write the CASes here. We would not
                        // want to interfere with currently active annotator users
                        jCases.put(user, jCas);
                    } catch (DataRetrievalFailureException e) {
                        error(e.getCause().getMessage());
                    } catch (UIMAException e) {
                        error(ExceptionUtils.getRootCause(e));
                    } catch (IOException e) {
                        error(ExceptionUtils.getRootCause(e));
                    }
                }
            }
        }
        documentJCases.put(document, jCases);
    }
    return documentJCases;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotationDocumentVisualizer.java

@Override
protected String getDocumentData() {
    if (!dirty) {
        return docData;
    }//w  w  w. ja va  2s . com

    dirty = false;

    // Clear the rendered document
    docData = EMPTY_DOC;

    // Check if a document is set
    if (getModelObject() == null) {
        return docData;
    }

    // Get CAS from the repository
    JCas jCas = null;
    try {
        jCas = repository.readAnnotationCas(getModelObject());
    } catch (DataRetrievalFailureException e) {
        error(e.getCause().getMessage());
    } catch (IOException e) {
        error("Unable to read annotation document " + ExceptionUtils.getRootCauseMessage(e));
    }
    // Generate BRAT object model from CAS
    GetDocumentResponse response = new GetDocumentResponse();
    response.setText(jCas.getDocumentText());

    BratAnnotatorModel bratAnnotatorModel = new BratAnnotatorModel();
    SpanAdapter.renderTokenAndSentence(jCas, response, bratAnnotatorModel);

    int i = 0;
    for (AnnotationLayer layer : bratAnnotatorModel.getAnnotationLayers()) {
        if (layer.getName().equals(Token.class.getName())) {
            continue;
        }
        List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
        List<AnnotationFeature> invisibleFeatures = new ArrayList<AnnotationFeature>();
        for (AnnotationFeature feature : features) {
            if (!feature.isVisible()) {
                invisibleFeatures.add(feature);
            }
        }
        features.removeAll(invisibleFeatures);

        ColoringStrategy coloringStrategy = ColoringStrategy.getBestStrategy(layer,
                bratAnnotatorModel.getPreferences(), i);

        getAdapter(annotationService, layer).render(jCas, features, response, bratAnnotatorModel,
                coloringStrategy);
        i++;
    }

    // Serialize BRAT object model to JSON
    try {
        StringWriter out = new StringWriter();
        JsonGenerator jsonGenerator = JSONUtil.getJsonConverter().getObjectMapper().getJsonFactory()
                .createJsonGenerator(out);
        jsonGenerator.writeObject(response);
        docData = out.toString();
    } catch (IOException e) {
        error(ExceptionUtils.getRootCauseMessage(e));
    }

    return docData;
}