Search in sources :

Example 86 with ApplicationExceptions

use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.

the class ValidationRulesEditorAction method do_ValidatorsUrls_Update_Clicked.

/**
 * Invoked if a update button on a row is selected.
 * @param rowId The selected row on the screen.
 * @return The FormKey for the Update screen.
 */
public FormKey do_ValidatorsUrls_Update_Clicked(String rowId) {
    ValidationRulesEditorForm myForm = (ValidationRulesEditorForm) form;
    ValidationRulesEditorComponent myComp = (ValidationRulesEditorComponent) myForm.getComponent();
    FormKey fk = null;
    GridModel model = (GridModel) myForm.getValidatorsUrlsWM();
    GridModelRow selectedRow = model.getRowById(Integer.parseInt(rowId));
    if (selectedRow != null) {
        try {
            String fileName = (String) selectedRow.get("validatorsUrl");
            if (!fileName.equals(myComp.getValidationRulesFile())) {
                myComp.setFileContents(null);
                myComp.setValidationRulesFile(fileName);
                myComp.loadFileContents();
            }
            myComp.determineAndSetNextScreen();
        } catch (ApplicationExceptions e) {
            myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
        } catch (FrameworkException e) {
            log.error(null, e);
            myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
        }
    }
    // Direct User back to current form
    if (fk == null)
        fk = myComp.determineFormKey();
    return fk;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) GridModel(org.jaffa.presentation.portlet.widgets.model.GridModel) FormKey(org.jaffa.presentation.portlet.FormKey) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Example 87 with ApplicationExceptions

use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.

the class ValidationRulesEditorAction method do_Rules_Update_Clicked.

/**
 * Invoked if a update button on a row is selected.
 * @param rowId The selected row on the screen.
 * @return The FormKey for the Update screen.
 */
public FormKey do_Rules_Update_Clicked(String rowId) {
    ValidationRulesEditorForm myForm = (ValidationRulesEditorForm) form;
    ValidationRulesEditorComponent myComp = (ValidationRulesEditorComponent) myForm.getComponent();
    FormKey fk = null;
    GridModel model = (GridModel) myForm.getRulesWM();
    GridModelRow selectedRow = model.getRowById(Integer.parseInt(rowId));
    if (selectedRow != null) {
        try {
            String fileName = (String) selectedRow.get("name");
            if (!fileName.equals(myComp.getValidationRulesFile())) {
                myComp.setFileContents(null);
                myComp.setValidationRulesFile(fileName);
                myComp.loadFileContents();
            }
            myComp.determineAndSetNextScreen();
        } catch (ApplicationExceptions e) {
            myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
        } catch (FrameworkException e) {
            log.error(null, e);
            myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
        }
    }
    // Direct User back to current form
    if (fk == null)
        fk = myComp.determineFormKey();
    return fk;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) GridModel(org.jaffa.presentation.portlet.widgets.model.GridModel) FormKey(org.jaffa.presentation.portlet.FormKey) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Example 88 with ApplicationExceptions

use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.

the class ValidationRulesEditorAction method do_Refresh_Clicked.

/**
 * Clicked event handler for the field Refresh.
 * @return The FormKey.
 */
public FormKey do_Refresh_Clicked() {
    FormKey fk = null;
    ValidationRulesEditorForm myForm = (ValidationRulesEditorForm) form;
    ValidationRulesEditorComponent myComp = (ValidationRulesEditorComponent) myForm.getComponent();
    myComp.setFileContents(null);
    try {
        myComp.loadFileContents();
    } catch (ApplicationExceptions e) {
        myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
    } catch (FrameworkException e) {
        log.error(null, e);
        myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
    }
    if (fk == null)
        fk = myComp.determineFormKey();
    return fk;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) FormKey(org.jaffa.presentation.portlet.FormKey)

Example 89 with ApplicationExceptions

use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.

the class ValidationRulesEditorComponent method performSave.

/**
 * This will save the contents of the current file.
 * @throws ApplicationExceptions if any error occurs while writing the file.
 * @throws FrameworkException if any error occurs.
 */
void performSave() throws FrameworkException, ApplicationExceptions {
    BufferedWriter writer = null;
    try {
        if (m_fileUpdateable) {
            URL url = URLHelper.newExtendedURL(m_validationRulesFile);
            File f = new File(url.getPath());
            writer = new BufferedWriter(new FileWriter(f, false));
            writer.write(getFileContents());
            writer.flush();
            if (log.isDebugEnabled())
                log.debug("Saved contents to the file " + m_validationRulesFile);
            // Clear cache so new rules are loaded.
            RulesMetaDataService.clearCache();
        } else {
            if (log.isDebugEnabled())
                log.debug("File cannot be updated since it cannot be read using File I/O. It is probably part of a JAR: " + m_validationRulesFile);
        }
    } catch (MalformedURLException e) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
        throw appExps;
    } catch (IOException e) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
        throw appExps;
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                String str = "Exception thrown while closing the Writer Stream";
                log.error(str, e);
                ApplicationExceptions appExps = new ApplicationExceptions();
                appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
                throw appExps;
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ConfigException(org.jaffa.applications.jaffa.modules.admin.exceptions.ConfigException) URL(java.net.URL)

Example 90 with ApplicationExceptions

use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.

the class ValidationRulesEditorComponent method loadFileContents.

/**
 * Load a file from a URL, which could be an Extended URL
 * @throws ApplicationExceptions if any error occurs while reading the file.
 * @throws FrameworkException if any error occurs.
 */
void loadFileContents() throws FrameworkException, ApplicationExceptions {
    Reader reader = null;
    try {
        URL url = URLHelper.newExtendedURL(m_validationRulesFile);
        File f = new File(url.getPath());
        m_fileUpdateable = f.exists() && f.isFile();
        reader = new BufferedReader(new InputStreamReader(url.openStream()));
        StringBuffer buf = new StringBuffer();
        int i;
        while ((i = reader.read()) != -1) buf.append((char) i);
        m_fileContents = buf.toString();
        if (log.isDebugEnabled())
            log.debug("Obtained contents from the file " + m_validationRulesFile);
        // remove the EditBoxModel from the WidgetCache
        getUserSession().getWidgetCache(getComponentId()).removeModel("fileContents");
    } catch (MalformedURLException e) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
        throw appExps;
    } catch (IOException e) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
        throw appExps;
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                String str = "Exception thrown while closing the Reader Stream";
                log.error(str, e);
                ApplicationExceptions appExps = new ApplicationExceptions();
                appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
                throw appExps;
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ConfigException(org.jaffa.applications.jaffa.modules.admin.exceptions.ConfigException) URL(java.net.URL)

Aggregations

ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)575 FrameworkException (org.jaffa.exceptions.FrameworkException)307 FormKey (org.jaffa.presentation.portlet.FormKey)205 ApplicationException (org.jaffa.exceptions.ApplicationException)116 GridModel (org.jaffa.presentation.portlet.widgets.model.GridModel)104 GridModelRow (org.jaffa.presentation.portlet.widgets.model.GridModelRow)103 UOW (org.jaffa.persistence.UOW)82 Criteria (org.jaffa.persistence.Criteria)66 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)59 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)23 ValidationException (org.jaffa.datatypes.ValidationException)21 Iterator (java.util.Iterator)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 Method (java.lang.reflect.Method)15 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)15 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)14 OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)11 MalformedURLException (java.net.MalformedURLException)10 UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)10 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)10