package com.vci.ubcs.code.util; import com.vci.ubcs.code.bo.AttributeValue; import com.vci.ubcs.starter.exception.VciBaseException; import com.vci.ubcs.starter.revision.model.BaseModel; import lombok.Data; import java.util.ArrayList; import java.util.Locale; @Data public class ClientBusinessObject extends BaseModel { public AttributeValue[] newAttrValList; public AttributeValue[] hisAttrValList; public void setAttributeValue(String attributeName, String attributeValue) throws VciBaseException { this.setAttributeValue(attributeName, attributeValue, false); } public void setAttributeValue(String attributeName, String attributeValue, boolean isCreate) throws VciBaseException { int isValid = (new AttributeChecker()).isAttrValValid(attributeName, attributeValue); if (isValid == 1) { throw getLocalError("P0010SOF-00017", new String[]{attributeName, attributeValue}); } else if (isValid == 2) { throw this.getLocalError("P0010SOF-00018", new String[]{attributeName, attributeValue}); } else if (isValid == 3) { throw this.getLocalError("P0010SOF-00019", new String[]{attributeName, attributeValue}); } else { this.setAttributeValueWithNoCheck(attributeName, attributeValue, isCreate); } } public void setAttributeValueWithNoCheck(String attributeName, String attributeValue) throws VciBaseException { this.setAttributeValueWithNoCheck(attributeName, attributeValue, false); } public void setAttributeValueWithNoCheck(String attributeName, String attributeValue, boolean isCreate) throws VciBaseException { /*if (isCreate) {//&& BusinessConstants.BO_CONSTANTS.containsKey(attributeName.toLowerCase(Locale.ROOT)) this.setConstantsAttrVal(attributeName, attributeValue); } else {*/ AttributeValue[] attrValues = this.newAttrValList; ArrayList attrValList = new ArrayList(); AttributeValue attrVal; int i; if (attrValues != null && attrValues.length > 0) { AttributeValue[] var9 = attrValues; i = attrValues.length; for(int var7 = 0; var7 < i; ++var7) { attrVal = var9[var7]; attrValList.add(attrVal); } } attrVal = null; boolean isExist = false; for(i = 0; i < attrValList.size(); ++i) { attrVal = (AttributeValue)attrValList.get(i); if (attrVal.attrName.toLowerCase(Locale.ROOT).equals(attributeName.toLowerCase(Locale.ROOT))) { attrVal.attrVal = attributeValue; isExist = true; break; } } if (!isExist) { attrVal = new AttributeValue(); attrVal.attrName = attributeName.toLowerCase(Locale.ROOT); attrVal.attrVal = attributeValue; attrValList.add(attrVal); } this.getData().put(attributeName.toLowerCase(Locale.ROOT),attributeValue); this.newAttrValList = (AttributeValue[])attrValList.toArray(new AttributeValue[attrValList.size()]); // } } public String getAttributeValue(String attrName) { String res = ""; boolean existInNewAttr = false; int i; if (this.newAttrValList != null) { for(i = 0; i < this.newAttrValList.length; ++i) { if (this.newAttrValList[i].attrName.toLowerCase(Locale.ROOT).equals(attrName.toLowerCase(Locale.ROOT))) { existInNewAttr = true; res = this.newAttrValList[i].attrVal; } } } if (existInNewAttr) { return res; } else if (this.hisAttrValList == null) { return ""; } else { for(i = 0; i < this.hisAttrValList.length; ++i) { if (this.hisAttrValList[i].attrName.toLowerCase(Locale.ROOT).equals(attrName.toLowerCase(Locale.ROOT))) { res = this.hisAttrValList[i].attrVal; } } return res; } } public VciBaseException getLocalError(String error_code ,String[] error_messages) { return new VciBaseException(error_code, error_messages); } }