/** * Check if the attribute value contains value. In case of list, it uses method contains. In case of array it searches in both keys and values. * * @param value value * @return true if the attribute value contains value. */ @SuppressWarnings("unchecked") public boolean valueContains(String value) { if (this.getType().equals(String.class.getName()) || this.getType().equals(BeansUtils.largeStringClassName)) { return value == null ? this.getValue() == null : value.equals(this.getValue()); } else if (this.getType().equals(ArrayList.class.getName()) || this.getType().equals(BeansUtils.largeArrayListClassName)) { return this.getValue() == null ? value == null : ((ArrayList<String>) this.getValue()).contains(value); } else if (this.getType().equals(LinkedHashMap.class.getName())) { return this.getValue() == null ? value == null : (((LinkedHashMap<String, String>) this.getValue()).containsKey(value) || ((LinkedHashMap<String, String>) this.getValue()).containsValue(value)); } else return false; }
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); String stringValue; if(getValue() == null) stringValue = null; else try { stringValue = BeansUtils.attributeValueToString(this); } catch (InternalErrorException ex) { //WARNING: This error is not catched. There is very low chance to occur. //When this happens, error is logged and there is need to look on attributeValueToString script above. log.error("Attribute value can't be serialize! {}",ex); stringValue = null; } return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", friendlyName=<").append(getFriendlyName() == null ? "\\0" : BeansUtils.createEscaping(getFriendlyName())).append(">").append( ", namespace=<").append(getNamespace() == null ? "\\0" : BeansUtils.createEscaping(getNamespace())).append(">").append( ", type=<").append(getType() == null ? "\\0" : BeansUtils.createEscaping(getType())).append(">").append( ", unique=<").append(isUnique()).append(">").append( ", value=<").append(BeansUtils.createEscaping(stringValue)).append(">").append( ']').toString(); }
@Override public String toString() { return this.getClass().getSimpleName() + ":[" + "id='" + getId() + '\'' + ", friendlyName='" + getFriendlyName() + '\'' + ", namespace='" + getNamespace() + '\'' + ", type='" + getType() + '\'' + ", unique='" + isUnique() + '\'' + ", value='" + getValue() + '\'' + ']'; } }
private static Attribute createAttribute(Map<String, String> beanAttr) throws InternalErrorException { if(beanAttr==null) return null; Attribute attribute = new Attribute(); attribute.setId(Integer.valueOf(beanAttr.get("id"))); attribute.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName"))); attribute.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace"))); attribute.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); attribute.setValue(BeansUtils.stringToAttributeValue(BeansUtils.eraseEscaping(beanAttr.get("value")), attribute.getType())); attribute.setUnique(Boolean.valueOf(beanAttr.get("unique"))); return attribute; }
public AttributeHolders(Attribute attribute, Holder primaryHolder, Holder secondaryHolder, SavedBy savedBy) throws InternalErrorException { super(attribute, true); if (primaryHolder != null && secondaryHolder != null) { if (secondaryHolder.getType().equals(Holder.HolderType.GROUP) && (!primaryHolder.getType().equals(Holder.HolderType.MEMBER)) || (secondaryHolder.getType().equals(Holder.HolderType.MEMBER)) || (secondaryHolder.getType().equals(Holder.HolderType.USER))) { this.primaryHolder = secondaryHolder; this.secondaryHolder = primaryHolder; } else { this.primaryHolder = primaryHolder; this.secondaryHolder = secondaryHolder; } } else { this.primaryHolder = primaryHolder; this.secondaryHolder = secondaryHolder; } this.nameForSearch = attribute.getNamespace() + ":" + attribute.getFriendlyName(); this.namespaceForSearch = attribute.getNamespace(); this.friendlyNameForSearch = attribute.getFriendlyName(); this.typeForSearch = attribute.getType(); this.idForSearch = attribute.getId(); this.valueForSearch = BeansUtils.attributeValueToString(attribute); this.savedBy = savedBy; }