public <V> void setValue(OClass oClass, V value) { setValue(oClass, value, hiearchical); }
@SuppressWarnings("unchecked") public <V> V getValue(OProperty property) { return getValue(property, (V) defaultValue); }
@SuppressWarnings("unchecked") public <V> V getValue(OClass oClass, V defaultValue, boolean hiearchical) { String stringValue = oClass.getCustom(name); if(encode) stringValue = decodeCustomValue(stringValue); V ret; if(OProperty.class.isAssignableFrom(javaClass)) { ret = (V)resolveProperty(oClass, stringValue); } else { ret = (V) OType.convert(stringValue, javaClass); } if(ret==null && hiearchical) { for(OClass superClass : oClass.getSuperClasses()) { if((ret=getValue(superClass, null, true))!=null) break; } } return ret!=null?ret:defaultValue; }
public static CustomAttribute getOrCreate(String name, OType type, Class<?> javaClass, Object defaultValue, boolean encode, boolean hiearchical) { CustomAttribute ret = getIfExists(name); return ret != null ? ret : create(name, type, javaClass, defaultValue, encode, hiearchical); }
public static CustomAttribute create(String name, OType type, Class<?> javaClass, Object defaultValue, boolean encode, boolean hiearchical) { CustomAttribute ret = getIfExists(name); if(ret!=null) throw new IllegalArgumentException("Custom attribute with name '"+name+"' is already exist"); ret = new CustomAttribute(name, type, javaClass, defaultValue, encode, hiearchical); return ret; }
@Override protected Comparable<?> comparableValue(OProperty input, String sortParam) { CustomAttribute custom = CustomAttribute.getIfExists(sortParam); if(custom!=null) { Object value = custom.getValue(input); return value instanceof Comparable?(Comparable<?>)value:null; } else return super.comparableValue(input, sortParam); }
public static void setRestricted(ODatabaseDocument db, OClass oClass) { OClass restricted = db.getMetadata().getSchema().getClass("ORestricted"); if (!oClass.isSubClassOf(restricted)) { oClass.addSuperClass(restricted); Collection<OProperty> properties = restricted.properties(); oClass.properties().stream() .filter(p -> !properties.contains(p)) .filter(p -> !(boolean) CustomAttribute.HIDDEN.getValue(p)) .forEach(p -> CustomAttribute.DISPLAYABLE.setValue(p, true)); } }
else if((CustomAttribute.ON_CREATE_FIELDS.getName().equals(critery)) && (custom = CustomAttribute.getIfExists(critery)) != null) custom.setValue(entity, value!=null?Joiner.on(",").join((List<String>) value):null); else if((custom = CustomAttribute.getIfExists(critery))!=null) custom.setValue(entity, value);
else if((CustomAttribute.ON_CREATE_FIELDS.getName().equals(critery)) && (custom = CustomAttribute.getIfExists(critery)) != null) String onCreateFields = custom.getValue(entity); return (V)(!Strings.isNullOrEmpty(onCreateFields) ? Lists.newArrayList(onCreateFields.split(",")) : new ArrayList<String>()); else if((custom = CustomAttribute.getIfExists(critery))!=null) return custom.getValue(entity);
public <V> void setValue(OClass oClass, V value, boolean hiearchical) { if(hiearchical && Objects.equals(value, getValue(oClass, true))) return; if(OProperty.class.isAssignableFrom(javaClass) && value instanceof OProperty) { OProperty valueProperty = (OProperty)value; boolean fullNameRequired = !Objects.equals(oClass, valueProperty.getOwnerClass()); oClass.setCustom(name, fullNameRequired?valueProperty.getFullName():valueProperty.getName()); } else { if(!hiearchical && defaultValue!=null && defaultValue.equals(value)) value = null; String stringValue = value!=null?value.toString():null; if(stringValue!=null && stringValue.length()==0) stringValue=null; if(encode) stringValue = encodeCustomValue(stringValue); oClass.setCustom(name, stringValue); } }
@Override protected void setValue(OProperty entity, String critery, V value) { ODatabaseDocument db = OrientDbWebSession.get().getDatabase(); db.commit(); try { CustomAttribute custom; if(OPropertyPrototyper.COLLATE.equals(critery)) { entity.setCollate((String)value); } else if((custom = CustomAttribute.getIfExists(critery))!=null) { custom.setValue(entity, value); } else { PropertyResolver.setValue(critery, entity, value, null); } } finally { db.begin(); } }
public OPropertyMetaColumn(CustomAttribute custom, IModel<DisplayMode> modeModel) { this(custom.getName(), modeModel); }
@SuppressWarnings("unchecked") public <V> V getValue(OProperty property, V defaultValue) { String stringValue = property.getCustom(name); if(encode) stringValue = decodeCustomValue(stringValue); V ret; if(OProperty.class.isAssignableFrom(javaClass)) { ret = (V)resolveProperty(property.getOwnerClass(), stringValue); } else { ret = (V) OType.convert(stringValue, javaClass); } return ret!=null?ret:defaultValue; }
public <V> void setValue(OProperty property, V value) { if(OProperty.class.isAssignableFrom(javaClass) && value instanceof OProperty) { OProperty valueProperty = (OProperty)value; boolean fullNameRequired = !Objects.equals(property.getOwnerClass(), valueProperty.getOwnerClass()); property.setCustom(name, fullNameRequired?valueProperty.getFullName():valueProperty.getName()); } else { if(defaultValue!=null && defaultValue.equals(value)) value = null; String stringValue = value!=null?value.toString():null; if(stringValue!=null && stringValue.length()==0) stringValue=null; if(encode) stringValue = encodeCustomValue(stringValue); property.setCustom(name, stringValue); } }
@Test public void testCustomDecode() throws Exception { assertNull(CustomAttribute.decodeCustomValue(null)); assertEquals("", CustomAttribute.decodeCustomValue("")); assertEquals("test", CustomAttribute.decodeCustomValue("test")); assertEquals("test=test", CustomAttribute.decodeCustomValue("test\\etest")); assertEquals("test\rtest", CustomAttribute.decodeCustomValue("test\\rtest")); assertEquals("test\ntest", CustomAttribute.decodeCustomValue("test\\ntest")); assertEquals("test\\test", CustomAttribute.decodeCustomValue("test\\\\test")); assertEquals("test=test\rtest\ntest\\test", CustomAttribute.decodeCustomValue("test\\etest\\rtest\\ntest\\\\test")); }
public static CustomAttribute create(String name, OType type, Object defaultValue, boolean encode, boolean hiearchical) { return create(name, type, null, defaultValue, encode, hiearchical); }
@SuppressWarnings("unchecked") @Override protected V getValue(OProperty entity, String critery) { CustomAttribute custom; if(OPropertyPrototyper.COLLATE.equals(critery)) { OCollate collate = entity.getCollate(); return (V)(collate!=null?collate.getName():null); } else if((custom = CustomAttribute.getIfExists(critery))!=null) { return custom.getValue(entity); } else { return (V) PropertyResolver.getValue(critery, entity); } }
public OClassMetaColumn(CustomAttribute custom, IModel<DisplayMode> modeModel) { this(custom.getName(), modeModel); }
@Test public void testCustomEncode() throws Exception { assertNull(CustomAttribute.encodeCustomValue(null)); assertEquals("", CustomAttribute.encodeCustomValue("")); assertEquals("test", CustomAttribute.encodeCustomValue("test")); assertEquals("test\\etest", CustomAttribute.encodeCustomValue("test=test")); assertEquals("test\\rtest", CustomAttribute.encodeCustomValue("test\rtest")); assertEquals("test\\ntest", CustomAttribute.encodeCustomValue("test\ntest")); assertEquals("test\\\\test", CustomAttribute.encodeCustomValue("test\\test")); assertEquals("test\\etest\\rtest\\ntest\\\\test", CustomAttribute.encodeCustomValue("test=test\rtest\ntest\\test")); }