@Override public DefinitionId getId(final T pojo) { final String fieldId = getIdField(pojo); final String definitionId = getDefinitionId(pojo.getClass()); if (null != fieldId) { final String id = BindableAdapterUtils.getDynamicDefinitionId(definitionId, getStringFieldValue(pojo, fieldId)); return DefinitionId.build(id, definitionId.length()); } return DefinitionId.build(definitionId); }
@Override public Class<? extends ElementFactory> getGraphFactoryType(final T pojo) { return getGraphFactory(pojo.getClass()); }
@Override @SuppressWarnings("unchecked") protected String getStringFieldValue(T pojo, String fieldName) { return delegate.getStringFieldValue(pojo, fieldName); }
@Override @SuppressWarnings("unchecked") protected Set<?> getBindProperties(T pojo) { return delegate.getBindProperties(pojo); }
@Override @SuppressWarnings("unchecked") public String getBaseType(final Class<?> type) { final Class<?> baseType = baseTypes.get(type); if (null != baseType) { return getDefinitionId(baseType); } return null; }
@Override @SuppressWarnings("unchecked") public String getCategory(T pojo) { return delegate.getCategory(pojo); }
@Override public Object getMetaProperty(final PropertyMetaTypes metaPropertyType, final T pojo) { final Class pClass = metaPropertyTypeClasses.get(metaPropertyType); if (null != pClass) { final Set<?> properties = getProperties(pojo); if (null != properties) { return properties.stream() .filter(property -> pClass.equals(property.getClass())) .findFirst() .orElse(null); } } return null; }
@Override @SuppressWarnings("unchecked") public Set<String> getLabels(T pojo) { return delegate.getLabels(pojo); }
@Override @SuppressWarnings("unchecked") public String getDescription(T pojo) { return delegate.getDescription(pojo); }
@Override @SuppressWarnings("unchecked") public Optional<String> getNameField(T pojo) { return delegate.getNameField(pojo); } }
@Test @SuppressWarnings("unchecked") public void testGetIdWhenDynamic() { String idFieldName = "theIdField"; String idFieldValue = "theIdFieldValue"; propertyIdFieldNames.put(SomePojo.class, idFieldName); when(delegate.getStringFieldValue(eq(pojo), eq(idFieldName))).thenReturn(idFieldValue); DefinitionId id = testeed.getId(pojo); assertEquals(getDynamicDefinitionId(SomePojo.class, idFieldValue), id.value()); assertEquals(getDefinitionId(SomePojo.class), id.type()); assertTrue(id.isDynamic()); }
public Set<?> getProperties(final T pojo) { final Set<Object> result = new HashSet<>(); // Obtain all properties from property sets. final Set<?> propertySetProperties = definitionUtils.getPropertiesFromPropertySets(pojo); if (null != propertySetProperties) { result.addAll(propertySetProperties); } final Set<?> bindProperties = getBindProperties(pojo); if (null != bindProperties && !bindProperties.isEmpty()) { result.addAll(bindProperties); } return result; }
@Override public String[] getTypes(final String baseType) { List<String> result = new LinkedList<>(); for (Map.Entry<Class, Class> entry : baseTypes.entrySet()) { final Class type = entry.getKey(); final Class _baseType = entry.getValue(); final String _id = getDefinitionId(_baseType); if (baseType.equals(_id)) { result.add(getDefinitionId(type)); } } if (!result.isEmpty()) { return result.toArray(new String[result.size()]); } return null; }