/** * This methods write @odata.type of complex type. * If complex type has root-level, @odata.type won't be written. * * @param structuredType structuredType */ private void writeODataType(StructuredType structuredType) throws IOException { if (entitySet != null) { String typeName = entitySet.getTypeName(); String type = typeName.substring(typeName.lastIndexOf(".") + 1, typeName.length()); if (!type.equals(structuredType.getName())) { jsonGenerator.writeStringField(TYPE, String.format("#%s.%s", structuredType.getNamespace(), structuredType.getName())); } else { LOG.trace("{} has root level. {} won't be written here", entitySet.getName(), TYPE); } } }
/** * Gets the properties of a structural type, including the properties of its base types (recursively). * * @param structuredType structuredType * @param entityDataModel The entity data model * @return listOfProperties * @throws ODataException If unable to get all properties from edm */ public static List<StructuralProperty> getAllProperties(StructuredType structuredType, EntityDataModel entityDataModel) throws ODataException { List<StructuralProperty> properties = new ArrayList<>(); String baseTypeName = structuredType.getBaseTypeName(); if (!isNullOrEmpty(baseTypeName)) { StructuredType baseType = (StructuredType) entityDataModel.getType(baseTypeName); if (baseType == null) { throw new ODataUnmarshallingException("OData type not found: " + baseTypeName); } // Get the properties of the base type properties.addAll(getAllProperties(baseType, entityDataModel)); } properties.addAll(structuredType.getStructuralProperties()); LOG.info("Total number of properties returning are {} for given structured type {}", properties.size(), structuredType.getName()); return properties; }
/** * This methods write @odata.type of complex type. * If complex type has root-level, @odata.type won't be written. * * @param structuredType structuredType */ private void writeODataType(StructuredType structuredType) throws IOException { if (entitySet != null) { String typeName = entitySet.getTypeName(); String type = typeName.substring(typeName.lastIndexOf(".") + 1, typeName.length()); if (!type.equals(structuredType.getName())) { jsonGenerator.writeStringField(TYPE, String.format("#%s.%s", structuredType.getNamespace(), structuredType.getName())); } else { LOG.trace("{} has root level. {} won't be written here", entitySet.getName(), TYPE); } } }
/** * Gets the properties of a structural type, including the properties of its base types (recursively). * * @param structuredType structuredType * @param entityDataModel The entity data model * @return listOfProperties * @throws ODataException If unable to get all properties from edm */ public static List<StructuralProperty> getAllProperties(StructuredType structuredType, EntityDataModel entityDataModel) throws ODataException { List<StructuralProperty> properties = new ArrayList<>(); String baseTypeName = structuredType.getBaseTypeName(); if (!isNullOrEmpty(baseTypeName)) { StructuredType baseType = (StructuredType) entityDataModel.getType(baseTypeName); if (baseType == null) { throw new ODataUnmarshallingException("OData type not found: " + baseTypeName); } // Get the properties of the base type properties.addAll(getAllProperties(baseType, entityDataModel)); } properties.addAll(structuredType.getStructuralProperties()); LOG.info("Total number of properties returning are {} for given structured type {}", properties.size(), structuredType.getName()); return properties; }