Search in sources :

Example 1 with ISOVException

use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.

the class GenericValidatingPackager method validate.

public ISOComponent validate(ISOComponent m) throws ISOException {
    LogEvent evt = new LogEvent(this, "validate");
    try {
        ISOComponent c;
        Map<Object, ISOComponent> fields = m.getChildren();
        /**
         * Field  validations *
         */
        for (ISOValidator val : fvlds) {
            if ((c = fields.get(((ISOFieldValidator) val).getFieldId())) != null) {
                try {
                    m.set(val.validate(c));
                } catch (ISOVException e) {
                    if (!e.treated()) {
                        m.set(e.getErrComponent());
                        e.setTreated(true);
                    }
                    evt.addMessage("Component Validation Error.");
                    throw e;
                }
            }
        }
        /**
         * msg validations *
         */
        try {
            for (ISOBaseValidator mval : mvlds) m = mval.validate(m);
        } catch (ISOVException ex) {
            evt.addMessage("Component Validation Error.");
            throw ex;
        }
        return m;
    } finally {
        Logger.log(evt);
    }
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) LogEvent(org.jpos.util.LogEvent) ISOVException(org.jpos.iso.validator.ISOVException) ISOValidator(org.jpos.iso.ISOValidator) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator)

Example 2 with ISOVException

use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.

the class ISOBaseValidatingPackager method validate.

public ISOComponent validate(ISOComponent m) throws ISOException {
    LogEvent evt = new LogEvent(this, "validate");
    try {
        ISOComponent c;
        Map fields = m.getChildren();
        /**
         * Field  validations *
         */
        for (ISOValidator aFldVld : fldVld) {
            if (aFldVld != null && (c = (ISOComponent) fields.get(Integer.valueOf(((ISOFieldValidator) aFldVld).getFieldId()))) != null) {
                try {
                    m.set(aFldVld.validate(c));
                } catch (ISOVException e) {
                    if (!e.treated()) {
                        m.set(e.getErrComponent());
                        e.setTreated(true);
                    }
                    evt.addMessage("Component Validation Error.");
                    throw e;
                }
            }
        }
        /**
         * msg validations *
         */
        try {
            if (msgVld != null) {
                for (ISOBaseValidator aMsgVld : this.msgVld) {
                    if (aMsgVld != null)
                        m = aMsgVld.validate(m);
                }
            }
        } catch (ISOVException ex) {
            evt.addMessage("Component Validation Error.");
            throw ex;
        }
        return m;
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ISOVException(org.jpos.iso.validator.ISOVException) Map(java.util.Map)

Example 3 with ISOVException

use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.

the class IVA_NUM method validate.

/**
 * Validate numeric condition. @see ISOFieldValidator class.
 * @param f ISOField to validate
 * @return see validate method in ISOFieldValidator class.
 * @throws ISOException if any validation error.
 */
public ISOComponent validate(ISOComponent f) throws ISOException {
    ISOField c = (ISOField) f;
    c = (ISOField) super.validate(c);
    if (!ISOUtil.isNumeric((String) c.getValue(), this.radix)) {
        ISOVError e = new ISOVError("Invalid Value Error. " + c.getValue() + " is not a numeric value in radix " + this.radix, getRejCode(ISOVError.ERR_INVALID_VALUE));
        if (c instanceof ISOVField)
            ((ISOVField) c).addISOVError(e);
        else
            c = new ISOVField(c, e);
        if (breakOnError)
            throw new ISOVException("Error on field " + c.getKey(), c);
    }
    return c;
}
Also used : ISOVException(org.jpos.iso.validator.ISOVException)

Example 4 with ISOVException

use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.

the class GenericValidatingPackagerTest method testValidateThrowsISOVException.

@Test
public void testValidateThrowsISOVException() throws Throwable {
    GenericValidatingPackager genericValidatingPackager = new GenericValidatingPackager();
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[0] = new MSGTEST(false);
    msgVlds[1] = new MSGTEST(true);
    genericValidatingPackager.setMsgValidator(msgVlds);
    ISOFieldValidator[] fvlds = new ISOFieldValidator[1];
    fvlds[0] = new IVA_ALPHANUM("testGenericValidatingPackagerDescription");
    genericValidatingPackager.setFieldValidator(fvlds);
    try {
        genericValidatingPackager.validate(new ISOMsg(100));
        fail("Expected ISOVException to be thrown");
    } catch (ISOVException ex) {
        assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
        assertFalse("ex.treated()", ex.treated());
        assertNotNull("ex.getErrComponent()", ex.getErrComponent());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : MSGTEST(org.jpos.iso.validator.MSGTEST) ISOMsg(org.jpos.iso.ISOMsg) IVA_ALPHANUM(org.jpos.iso.IVA_ALPHANUM) ISOVException(org.jpos.iso.validator.ISOVException) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Example 5 with ISOVException

use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.

the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException6.

@Test
public void testValidateThrowsISOException6() throws Throwable {
    ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[0] = new MSGTEST(true);
    ISOFieldValidator[] fvlds = new ISOFieldValidator[3];
    fvlds[0] = iVA_ALPHANUMNOBLANK;
    ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
    iSOBaseValidatingPackager.setFieldValidator(fvlds);
    iSOBaseValidatingPackager.setMsgValidator(msgVlds);
    try {
        iSOBaseValidatingPackager.validate(new ISOMsg());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
        assertFalse("ex.treated()", ((ISOVException) ex).treated());
        assertNotNull("ex.getErrComponent()", ((ISOVException) ex).getErrComponent());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : IVA_ALPHANUMNOBLANK(org.jpos.iso.IVA_ALPHANUMNOBLANK) MSGTEST(org.jpos.iso.validator.MSGTEST) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOVException(org.jpos.iso.validator.ISOVException) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Aggregations

ISOVException (org.jpos.iso.validator.ISOVException)6 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)3 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)3 ISOMsg (org.jpos.iso.ISOMsg)2 MSGTEST (org.jpos.iso.validator.MSGTEST)2 LogEvent (org.jpos.util.LogEvent)2 Test (org.junit.Test)2 Map (java.util.Map)1 ISOComponent (org.jpos.iso.ISOComponent)1 ISOException (org.jpos.iso.ISOException)1 ISOValidator (org.jpos.iso.ISOValidator)1 IVA_ALPHANUM (org.jpos.iso.IVA_ALPHANUM)1 IVA_ALPHANUMNOBLANK (org.jpos.iso.IVA_ALPHANUMNOBLANK)1