protected IAttributeValidationRules getValidationRuleNewIntance() { return new BaseAttributeValidationRules(); }
@Override public void setConfig(Element attributeElement) { Element validationElement = attributeElement.getChild(VALIDATIONS_ELEMENT_NAME); if (null != validationElement) { this.extractValidationRules(validationElement); } }
protected void extractValidationRules(Element validationElement) { String required = this.extractValue(validationElement, "required"); this.setRequired(null != required && required.equalsIgnoreCase("true")); Element expressionElement = validationElement.getChild("expression"); if (null != expressionElement) { OgnlValidationRule validationRule = new OgnlValidationRule(expressionElement); this.setOgnlValidationRule(validationRule); } }
@Override public boolean isEmpty() { return (!this.isRequired() && null == this.getOgnlValidationRule()); }
@Override public Element getJDOMConfigElement() { Element configElement = null; try { if (this.isEmpty()) { return null; } configElement = new Element(VALIDATIONS_ELEMENT_NAME); this.fillJDOMConfigElement(configElement); } catch (Throwable t) { _logger.error("Error detected while creating jdom element", t); throw new RuntimeException("Error detected while creating jdom element", t); } return configElement; }
@Override public IAttributeValidationRules clone() { BaseAttributeValidationRules clone = null; try { Class validationConditionClass = Class.forName(this.getClass().getName()); clone = (BaseAttributeValidationRules) validationConditionClass.newInstance(); clone.setRequired(this.isRequired()); if (null != this.getOgnlValidationRule()) { clone.setOgnlValidationRule(this.getOgnlValidationRule().clone()); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { _logger.error("Error detected while cloning the ValidationRules", e); throw new RuntimeException("Error detected while cloning the ValidationRules class '" + this.getClass().getName() + "' "); } return clone; }
@Override public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) { List<AttributeFieldError> errors = new ArrayList<>(); if (this.isEmpty()) { return errors; } try { if (this.isRequired() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) { AttributeTracer tracerClone = tracer.clone(); tracerClone.setLang(langManager.getDefaultLang()); errors.add(new AttributeFieldError(attribute, FieldError.MANDATORY, tracerClone)); } OgnlValidationRule ognlValidationRule = this.getOgnlValidationRule(); if (null != ognlValidationRule) { AttributeFieldError error = ognlValidationRule.validate(attribute, tracer, langManager); if (null != error) { errors.add(error); } } } catch (Throwable t) { _logger.error("Error validating Attribute '{}'", attribute.getName(), t); throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t); } return errors; }
@Override public boolean isEmpty() { return (super.isEmpty() && (null == this.getRangeStart()) && (null == this.getRangeEnd()) && (null == this.getValue()) && (null == this.getRangeStartAttribute() || this.getRangeStartAttribute().trim().length() == 0) && (null == this.getRangeEndAttribute() || this.getRangeEndAttribute().trim().length() == 0) && (null == this.getValueAttribute() || this.getValueAttribute().trim().length() == 0) ); }
@Override public IAttributeValidationRules clone() { AbstractAttributeValidationRules clone = (AbstractAttributeValidationRules) super.clone(); clone.setRangeEnd(this.getRangeEnd()); clone.setRangeEndAttribute(this.getRangeEndAttribute()); clone.setRangeStart(this.getRangeStart()); clone.setRangeStartAttribute(this.getRangeStartAttribute()); clone.setValue(this.getValue()); clone.setValueAttribute(this.getValueAttribute()); return clone; }
@Override public IAttributeValidationRules clone() { BaseAttributeValidationRules clone = null; try { Class validationConditionClass = Class.forName(this.getClass().getName()); clone = (BaseAttributeValidationRules) validationConditionClass.newInstance(); clone.setRequired(this.isRequired()); if (null != this.getOgnlValidationRule()) { clone.setOgnlValidationRule(this.getOgnlValidationRule().clone()); } } catch (Exception e) { ApsSystemUtils.logThrowable(e, this, "clone"); throw new RuntimeException("Error detected while cloning the ValidationRules class '" + this.getClass().getName() + "' "); } return clone; }
@Override public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) { List<AttributeFieldError> errors = new ArrayList<AttributeFieldError>(); if (this.isEmpty()) { return errors; } try { if (this.isRequired() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) { AttributeTracer tracerClone = tracer.clone(); tracerClone.setLang(langManager.getDefaultLang()); errors.add(new AttributeFieldError(attribute, FieldError.MANDATORY, tracerClone)); } OgnlValidationRule ognlValidationRule = this.getOgnlValidationRule(); if (null != ognlValidationRule) { AttributeFieldError error = ognlValidationRule.validate(attribute, tracer, langManager); if (null != error) { errors.add(error); } } } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "validate", "Error validating Attribute '" + attribute.getName() + "'"); throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t); } return errors; }
@Override public boolean isEmpty() { return (!this.isRequired() && null == this.getOgnlValidationRule()); }
@Override public Element getJDOMConfigElement() { Element configElement = null; try { if (this.isEmpty()) { return null; } configElement = new Element(VALIDATIONS_ELEMENT_NAME); this.fillJDOMConfigElement(configElement); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "getJDOMConfigElement"); throw new RuntimeException("Error detected while creating jdom element", t); } return configElement; }
@Override public boolean isEmpty() { return (super.isEmpty() && (null == this.getRangeStart()) && (null == this.getRangeEnd()) && (null == this.getValue()) && (null == this.getRangeStartAttribute() || this.getRangeStartAttribute().trim().length() == 0) && (null == this.getRangeEndAttribute() || this.getRangeEndAttribute().trim().length() == 0) && (null == this.getValueAttribute() || this.getValueAttribute().trim().length() == 0) ); }
@Override public IAttributeValidationRules clone() { AbstractAttributeValidationRules clone = (AbstractAttributeValidationRules) super.clone(); clone.setRangeEnd(this.getRangeEnd()); clone.setRangeEndAttribute(this.getRangeEndAttribute()); clone.setRangeStart(this.getRangeStart()); clone.setRangeStartAttribute(this.getRangeStartAttribute()); clone.setValue(this.getValue()); clone.setValueAttribute(this.getValueAttribute()); return clone; }
protected void extractValidationRules(Element validationElement) { String required = this.extractValue(validationElement, "required"); this.setRequired(null != required && required.equalsIgnoreCase("true")); Element expressionElement = validationElement.getChild("expression"); if (null != expressionElement) { OgnlValidationRule validationRule = new OgnlValidationRule(expressionElement); this.setOgnlValidationRule(validationRule); } }
protected void fillJDOMConfigElement(Element configElement) { if (this.isRequired()) { Element element = new Element("required"); element.setText("true"); configElement.addContent(element); } if (null != this.getOgnlValidationRule()) { Element exprElement = this.getOgnlValidationRule().getConfigElement(); if (null != exprElement) { configElement.addContent(exprElement); } } }
@Override public void setConfig(Element attributeElement) { Element validationElement = attributeElement.getChild(VALIDATIONS_ELEMENT_NAME); if (null != validationElement) { this.extractValidationRules(validationElement); } }
protected IAttributeValidationRules getValidationRuleNewIntance() { return new BaseAttributeValidationRules(); }
protected void fillJDOMConfigElement(Element configElement) { if (this.isRequired()) { Element element = new Element("required"); element.setText("true"); configElement.addContent(element); } if (null != this.getOgnlValidationRule()) { Element exprElement = this.getOgnlValidationRule().getConfigElement(); if (null != exprElement) { configElement.addContent(exprElement); } } }