@Override public InputParameter property(String key, Object value) { super.property(key, value); return this; } @Override
@Override public InputParameter propertyOpt(String key, Object value) { super.propertyOpt(key, value); return this; } }
private void checkValueCollection(String key, Collection value) { for (Object element: (Collection)value) { checkValue(key, element); } }
/** throws RuntimeException if a property is set with an invalid key. * All the known fieldnames are invalid values because the properties are * serialized inside the containing object json. * @param value * @see Extensible */ private void checkProperty(String key, Object value) { Set<String> invalidPropertyKeys = getInvalidPropertyKeys(getClass()); if (key==null || invalidPropertyKeys.contains(key)) { throw new RuntimeException("Invalid property '"+key+"'"); } // TODO checkValue(key, value); // checkValue still fails on the bpmn tests }
/** @see Extensible */ public Extensible propertyOpt(String key,Object value) { if (value!=null) { setProperty(key, value); } return this; } /** @see Extensible */
private void checkValue(String key, Object value) { if ( value==null || (value instanceof String) || (value instanceof Number) || (value instanceof Boolean) ) { return; } if (value instanceof Map) { checkValueMap(key, (Map)value); return; } if (value instanceof Collection) { checkValueCollection(key, (Collection)value); return; } throw new RuntimeException("Invalid value in property '"+key+"': "+value+" ("+value.getClass()+") Allowed types: String,Number,Boolean,Collection,Map"); }
public static Set<String> getInvalidPropertyKeys(Class<?> clazz) { Set<String> invalidPropertyKeys = invalidPropertyKeysByClass.get(clazz); if (invalidPropertyKeys!=null) { return invalidPropertyKeys; } invalidPropertyKeys = new HashSet<>(); collectInvalidPropertyKeys(clazz, invalidPropertyKeys); invalidPropertyKeysByClass.put(clazz, invalidPropertyKeys); return invalidPropertyKeys; }
/** @see Extensible */ public void setProperty(String key,Object value) { checkProperty(key, value); if (properties==null) { properties = new HashMap<>(); } this.properties.put(key, value); } /** only sets the property if the value is not null
/** throws RuntimeException if a property is set with an invalid key. * All the known fieldnames are invalid values because the properties are * serialized inside the containing object json. * @param value * @see Extensible */ private void checkProperty(String key, Object value) { Set<String> invalidPropertyKeys = getInvalidPropertyKeys(getClass()); if (key==null || invalidPropertyKeys.contains(key)) { throw new RuntimeException("Invalid property '"+key+"'"); } // TODO checkValue(key, value); // checkValue still fails on the bpmn tests }
/** @see Extensible */ public Extensible property(String key,Object value) { setProperty(key, value); return this; } /** @see Extensible */
private void checkValue(String key, Object value) { if ( value==null || (value instanceof String) || (value instanceof Number) || (value instanceof Boolean) ) { return; } if (value instanceof Map) { checkValueMap(key, (Map)value); return; } if (value instanceof Collection) { checkValueCollection(key, (Collection)value); return; } throw new RuntimeException("Invalid value in property '"+key+"': "+value+" ("+value.getClass()+") Allowed types: String,Number,Boolean,Collection,Map"); }
public static Set<String> getInvalidPropertyKeys(Class<?> clazz) { Set<String> invalidPropertyKeys = invalidPropertyKeysByClass.get(clazz); if (invalidPropertyKeys!=null) { return invalidPropertyKeys; } invalidPropertyKeys = new HashSet<>(); collectInvalidPropertyKeys(clazz, invalidPropertyKeys); invalidPropertyKeysByClass.put(clazz, invalidPropertyKeys); return invalidPropertyKeys; }
/** @see Extensible */ public void setProperty(String key,Object value) { checkProperty(key, value); if (properties==null) { properties = new HashMap<>(); } this.properties.put(key, value); } /** only sets the property if the value is not null
/** * Reads database fields (that do not have Java fields) and copies them to workflow instance properties. * This makes it possible to write non-standard fields to the database and read them from properties. */ private void copyProperties(BasicDBObject dbWorkflowInstance, WorkflowInstanceImpl workflowInstance) { if (dbWorkflowInstance == null || workflowInstance == null) { return; } Set<String> invalidPropertyKeys = Extensible.getInvalidPropertyKeys(WorkflowInstance.class); // Map<String,?> mappedBeanFields = mongoMapper.write(workflowInstance.toWorkflowInstance()); for (String fieldName : dbWorkflowInstance.keySet()) { boolean property = !invalidPropertyKeys.contains(fieldName); if (property) { workflowInstance.setProperty(fieldName, dbWorkflowInstance.get(fieldName)); } } }
@Override public InputParameter property(String key, Object value) { super.property(key, value); return this; } @Override
@Override public InputParameter propertyOpt(String key, Object value) { super.propertyOpt(key, value); return this; } }
/** @see Extensible */ public Extensible propertyOpt(String key,Object value) { if (value!=null) { setProperty(key, value); } return this; } /** @see Extensible */
private void checkValueCollection(String key, Collection value) { for (Object element: (Collection)value) { checkValue(key, element); } }
private static void collectInvalidPropertyKeys(Class<?> clazz, Set<String> invalidPropertyKeys) { Field[] fields = clazz.getDeclaredFields(); if (fields!=null) { for (Field field: fields) { invalidPropertyKeys.add(field.getName()); } } Class<?> superclass = clazz.getSuperclass(); if (superclass!=Object.class) { collectInvalidPropertyKeys(superclass, invalidPropertyKeys); } } }
/** * Reads database fields (that do not have Java fields) and copies them to workflow instance properties. * This makes it possible to write non-standard fields to the database and read them from properties. */ private void copyProperties(BasicDBObject dbWorkflowInstance, WorkflowInstanceImpl workflowInstance) { if (dbWorkflowInstance == null || workflowInstance == null) { return; } Set<String> invalidPropertyKeys = Extensible.getInvalidPropertyKeys(WorkflowInstance.class); // Map<String,?> mappedBeanFields = mongoMapper.write(workflowInstance.toWorkflowInstance()); for (String fieldName : dbWorkflowInstance.keySet()) { boolean property = !invalidPropertyKeys.contains(fieldName); if (property) { workflowInstance.setProperty(fieldName, dbWorkflowInstance.get(fieldName)); } } }