Search in sources :

Example 11 with MandatoryFieldException

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

the class UserRequestMaintenanceForm method passwordFieldCheck.

// .//GEN-END:_doValidateMain_2_be
// All the custom code goes here //GEN-FIRST:_custom
/**
 * Perform password checks
 */
private boolean passwordFieldCheck(HttpServletRequest request) {
    boolean valid = true;
    String pass1 = getPassword1WM().getValue();
    if (pass1 != null && pass1.length() == 0)
        pass1 = null;
    pass1 = Parser.parseString(pass1);
    String pass2 = getPassword2WM().getValue();
    if (pass2 != null && pass2.length() == 0)
        pass2 = null;
    pass2 = Parser.parseString(pass2);
    if (pass1 == null && ((UserRequestMaintenanceComponent) getComponent()).isCreateMode()) {
        raiseError(request, UserMeta.META_PASSWORD.getLabelToken(), new MandatoryFieldException(UserMeta.META_PASSWORD.getLabelToken()));
        valid = false;
    }
    if (pass2 == null && ((UserRequestMaintenanceComponent) getComponent()).isCreateMode()) {
        raiseError(request, "[label.Jaffa.User.User.VerifyPassword]", new MandatoryFieldException("[label.Jaffa.User.User.VerifyPassword]"));
        valid = false;
    }
    if ((pass1 != null && !pass1.equals(pass2)) || (pass2 != null && !pass2.equals(pass1))) {
        raiseError(request, UserMeta.META_PASSWORD.getLabelToken(), new ActionMessage("error.Jaffa.User.UserMaintenance.InvalidPassword.Different"));
        valid = false;
    }
    return valid;
}
Also used : MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException) ActionMessage(org.apache.struts.action.ActionMessage)

Example 12 with MandatoryFieldException

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

the class UserRequestViewerComponent method display.

// .//GEN-END:_UserRequestViewerOutDto_1_be
// .//GEN-BEGIN:_display_1_be
/**
 * This retrieves the details for the UserRequest.
 * @throws ApplicationExceptions This will be thrown in case any invalid data has been set, or if no data has been set.
 * @throws FrameworkException Indicates some system error.
 * @return The FormKey for the View screen.
 */
public FormKey display() throws ApplicationExceptions, FrameworkException {
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_display_2_be
    if (getRequestId() == null) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(new MandatoryFieldException(UserRequestMeta.META_REQUEST_ID.getLabelToken()));
    }
    if (appExps != null && appExps.size() > 0)
        throw appExps;
    doInquiry();
    return getViewerFormKey();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException)

Example 13 with MandatoryFieldException

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

the class FormTemplateMaintenanceForm method doValidate0.

// .//GEN-END:_doValidate_2_be
// .//GEN-BEGIN:_doValidateMain_1_be
/**
 * This method should be invoked to ensure a valid state of the FormBean. It will validate the data in the models and set the corresponding properties.
 * Errors will be raised in the FormBean, if any validation fails.
 * @param request The request stream
 * @return A true indicates validations went through successfully.
 */
public boolean doValidate0(HttpServletRequest request) {
    boolean valid = true;
    try {
        String htmlString = getFormIdWM().getValue();
        if (htmlString != null && htmlString.length() == 0)
            htmlString = null;
        java.lang.Long value = (java.lang.Long) FieldValidator.validateData(htmlString, (IntegerFieldMetaData) FormTemplateMeta.META_FORM_ID, true);
        if (value == null)
            throw new MandatoryFieldException(((IntegerFieldMetaData) FormTemplateMeta.META_FORM_ID).getLabelToken());
        setFormId(value);
    } catch (ValidationException e) {
        valid = false;
        raiseError(request, ((IntegerFieldMetaData) FormTemplateMeta.META_FORM_ID).getLabelToken(), e);
    }
    try {
        String htmlString = getTemplateDataWM().getValue();
        if (htmlString != null && htmlString.length() == 0)
            htmlString = null;
        byte[] value = (byte[]) FieldValidator.validateData(htmlString, (RawFieldMetaData) FormTemplateMeta.META_TEMPLATE_DATA, true);
        setTemplateData(value);
    } catch (ValidationException e) {
        valid = false;
        raiseError(request, ((RawFieldMetaData) FormTemplateMeta.META_TEMPLATE_DATA).getLabelToken(), e);
    }
    try {
        String htmlString = getLayoutDataWM().getValue();
        if (htmlString != null && htmlString.length() == 0)
            htmlString = null;
        byte[] value = (byte[]) FieldValidator.validateData(htmlString, (RawFieldMetaData) FormTemplateMeta.META_LAYOUT_DATA, true);
        setLayoutData(value);
    } catch (ValidationException e) {
        valid = false;
        raiseError(request, ((RawFieldMetaData) FormTemplateMeta.META_LAYOUT_DATA).getLabelToken(), e);
    }
    // .//GEN-BEGIN:_doValidateMain_2_be
    return valid;
}
Also used : MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException)

Example 14 with MandatoryFieldException

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

the class OutputCommandViewerComponent method display.

// .//GEN-END:_OutputCommandViewerOutDto_1_be
// .//GEN-BEGIN:_display_1_be
/**
 * This retrieves the details for the OutputCommand.
 * @throws ApplicationExceptions This will be thrown in case any invalid data has been set, or if no data has been set.
 * @throws FrameworkException Indicates some system error.
 * @return The FormKey for the View screen.
 */
public FormKey display() throws ApplicationExceptions, FrameworkException {
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_display_2_be
    if (getOutputCommandId() == null) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(new MandatoryFieldException(OutputCommandMeta.META_OUTPUT_COMMAND_ID.getLabelToken()));
    }
    if (appExps != null && appExps.size() > 0)
        throw appExps;
    doInquiry();
    return getViewerFormKey();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException)

Example 15 with MandatoryFieldException

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

the class BatchValidatorTest method testValidationException.

/**
 * Test that a validation exception is returned to the caller of the validation method
 *
 * @throws org.jaffa.exceptions.FrameworkException
 *
 * @throws org.jaffa.exceptions.ApplicationException
 */
@Test(expected = ApplicationException.class)
public void testValidationException() throws FrameworkException, ApplicationException {
    // validator that will throw exception on validation
    Validator mockValidator = mock(Validator.class);
    doThrow(new MandatoryFieldException()).when(mockValidator).validate(anyObject());
    // create bulk validator with a sub-validators that will throw an exception
    BatchValidator validator = new BatchValidator();
    validator.getValidatorSet().add(mockValidator);
    // call validate
    validator.validate(new Object());
}
Also used : MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException) Matchers.anyObject(org.mockito.Matchers.anyObject) Validator(org.jaffa.rules.fieldvalidators.Validator) Test(org.junit.Test)

Aggregations

MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)31 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)22 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ActionMessage (org.apache.struts.action.ActionMessage)2 FormSelectionException (org.jaffa.modules.printing.components.formselectionmaintenance.FormSelectionException)2 Iterator (java.util.Iterator)1 IAttachmentData (org.jaffa.components.attachment.apis.IAttachmentData)1 IVoucherGenerator (org.jaffa.components.voucher.IVoucherGenerator)1 org.jaffa.datatypes (org.jaffa.datatypes)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 FieldMetaData (org.jaffa.metadata.FieldMetaData)1 FormSelectionMaintenanceInDto (org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceInDto)1 FormSelectionMaintenanceOutDto (org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutDto)1 FormSelectionMaintenanceOutRowDto (org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto)1 DomainObjectValidationException (org.jaffa.persistence.exceptions.DomainObjectValidationException)1 CheckBoxModel (org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)1 EditBoxModel (org.jaffa.presentation.portlet.widgets.model.EditBoxModel)1 GridModel (org.jaffa.presentation.portlet.widgets.model.GridModel)1 GridModelRow (org.jaffa.presentation.portlet.widgets.model.GridModelRow)1