private static String getKeyValueFromPropertyRef(EntityDataModel entityDataModel, Object entity, PropertyRef propertyRef) throws IllegalAccessException, ODataEdmException { EntityType entityType = getAndCheckEntityType(entityDataModel, entity.getClass()); Field field = entityType.getStructuralProperty(propertyRef.getPath()).getJavaField(); field.setAccessible(true); Object value = field.get(entity); if (value instanceof String) { return String.format("'%s'", ((String) value).replaceAll("'", "''")); } else if (value instanceof Period) { return String.format("duration'%s'", value.toString()); } else { return value != null ? value.toString() : null; } }
private static String getKeyValueFromPropertyRef(EntityDataModel entityDataModel, Object entity, PropertyRef propertyRef) throws IllegalAccessException, ODataEdmException { EntityType entityType = getAndCheckEntityType(entityDataModel, entity.getClass()); Field field = entityType.getStructuralProperty(propertyRef.getPath()).getJavaField(); field.setAccessible(true); Object value = field.get(entity); if (value instanceof String) { return String.format("'%s'", ((String) value).replaceAll("'", "''")); } else if (value instanceof Period) { return String.format("duration'%s'", value.toString()); } else { return value != null ? value.toString() : null; } }
private String processNavigationLink(Object entity, EntityType entityType, Element linkElement) throws ODataException { String propertyName = linkElement.getAttribute(REL).substring(getODataNavLinkRelationNSPrefix().length()); LOG.debug("Found link element for navigation property: {}", propertyName); StructuralProperty property = entityType.getStructuralProperty(propertyName); if (!(property instanceof NavigationProperty)) { throw new ODataUnmarshallingException("The request contains a navigation link '" + propertyName + "' but the entity type '" + entityType + "' does not contain a navigation property " + "with this name."); } processReferencedEntity(entity, entityType, linkElement); return propertyName; }
private String processNavigationLink(Object entity, EntityType entityType, Element linkElement) throws ODataException { String propertyName = linkElement.getAttribute(REL).substring(getODataNavLinkRelationNSPrefix().length()); LOG.debug("Found link element for navigation property: {}", propertyName); StructuralProperty property = entityType.getStructuralProperty(propertyName); if (!(property instanceof NavigationProperty)) { throw new ODataUnmarshallingException("The request contains a navigation link '" + propertyName + "' but the entity type '" + entityType + "' does not contain a navigation property " + "with this name."); } processReferencedEntity(entity, entityType, linkElement); return propertyName; }
private Map<String, Object> getKeyValues(Object entity, EntityType entityType) throws ODataProcessorException { Map<String, Object> keyValues = new HashMap<>(); for (PropertyRef propertyRef : entityType.getKey().getPropertyRefs()) { try { String keyFieldName = entityType.getStructuralProperty(propertyRef.getPath()).getJavaField().getName(); Field keyField = entity.getClass().getDeclaredField(keyFieldName); keyField.setAccessible(true); keyValues.put(keyFieldName, keyField.get(entity)); } catch (NoSuchFieldException | IllegalAccessException e) { throw new ODataProcessorException(PROCESSOR_ERROR, "Not possible to extract the key/values from the entity", e); } } return keyValues; }
private Map<String, Object> getKeyValues(Object entity, EntityType entityType) throws ODataProcessorException { Map<String, Object> keyValues = new HashMap<>(); for (PropertyRef propertyRef : entityType.getKey().getPropertyRefs()) { try { String keyFieldName = entityType.getStructuralProperty(propertyRef.getPath()).getJavaField().getName(); Field keyField = entity.getClass().getDeclaredField(keyFieldName); keyField.setAccessible(true); keyValues.put(keyFieldName, keyField.get(entity)); } catch (NoSuchFieldException | IllegalAccessException e) { throw new ODataProcessorException(PROCESSOR_ERROR, "Not possible to extract the key/values from the entity", e); } } return keyValues; }
/** * Gets the values of the properties that part of the key of an entity type. * * @param entityType The entity type. * @param entity The entity. * @return A {@code Map} containing the values of the key properties of the entity, mapped by property name. */ public static Map<String, Object> getKeyPropertyValues(EntityType entityType, Object entity) { Map<String, Object> keyPropertyValues = new HashMap<>(); for (PropertyRef propertyRef : entityType.getKey().getPropertyRefs()) { String propertyName = propertyRef.getPath(); Object propertyValue = getPropertyValue(entityType.getStructuralProperty(propertyName), entity); keyPropertyValues.put(propertyName, propertyValue); } return keyPropertyValues; }
/** * Gets the values of the properties that part of the key of an entity type. * * @param entityType The entity type. * @param entity The entity. * @return A {@code Map} containing the values of the key properties of the entity, mapped by property name. */ public static Map<String, Object> getKeyPropertyValues(EntityType entityType, Object entity) { Map<String, Object> keyPropertyValues = new HashMap<>(); for (PropertyRef propertyRef : entityType.getKey().getPropertyRefs()) { String propertyName = propertyRef.getPath(); Object propertyValue = getPropertyValue(entityType.getStructuralProperty(propertyName), entity); keyPropertyValues.put(propertyName, propertyValue); } return keyPropertyValues; }
StructuralProperty property = entityType.getStructuralProperty(propertyName);
StructuralProperty property = entityType.getStructuralProperty(propertyName);