@Override public EdmURIBuilder appendFunctionImportSegment(EdmFunctionImport functionImport) { try { state = functionImport.getReturnType() != null ? (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY && functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY ? SegmentType.FUNCTIONIMPORT_MANY : SegmentType.FUNCTIONIMPORT) : SegmentType.FUNCTIONIMPORT; segments.add(new Segment(state, functionImport.getName())); } catch (EdmException e) { throw new RuntimeException("Unexpected EDM Exception: ", e);//NOSONAR } return this; }
private List<String> flattenOutProperties(EdmStructuralType type) throws EdmException { List<String> propertyNames = type.getPropertyNames(); List<String> flattenedPropertyNames = new ArrayList<String>(); for(String prop : propertyNames) { EdmTyped edmProp = type.getProperty(prop); if (edmProp.getType() instanceof EdmComplexType) { EdmComplexType complexType = (EdmComplexType) edmProp.getType(); String cpName = edmProp.getName(); for(String s : flattenOutProperties(complexType)) { flattenedPropertyNames.add(cpName + '.' + s); } }else { flattenedPropertyNames.add(prop); } } return flattenedPropertyNames; }
public void castStringToGuidWithCompelxProperty(List<String> coloumnNames, List<Map<String, Object>> resultEntitySet , EdmStructuralType entityType){ for(int i=0; i<resultEntitySet.size(); i++ ){ for(String columnName : coloumnNames){ Object data = resultEntitySet.get(i).get(columnName) ; if(data != null && data instanceof String ){ resultEntitySet.get(i).put(columnName, UUID.fromString((String) data)); }else if(data != null && data instanceof Map ){ try { //Handle Complex type String complexTypeName = entityType.getProperty(columnName).getType().getName(); Map<String, Object> complexData = (Map<String, Object>)data; castStringToGuidWithCompelxProperty( complexPropWithUUID.get(complexTypeName) , Arrays.asList(complexData) , (EdmStructuralType) entityType.getProperty(columnName).getType() ); } catch (EdmException e) { } } } } }
private void validateFunctionImport() throws EntityProviderException, EdmException { for (EdmFunctionImport functionImport : edmFunctionImportList) { EdmTyped returnType = functionImport.getReturnType(); if (returnType != null) { FullQualifiedName fqn = extractFQName(returnType.toString()); String entitySet = ((EdmFunctionImportImpl)functionImport).getEntitySetName(); if (returnType.getMultiplicity() == EdmMultiplicity.MANY && entitySet == null && entityTypesMap.get( fqn) != null) { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("EntitySet = " + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName())); } else if (returnType.getMultiplicity() != EdmMultiplicity.MANY && entitySet != null && entityTypesMap.get( fqn) == null) { throw new EntityProviderException(EntityProviderException.INVALID_ATTRIBUTE.addContent("EntitySet = " + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName())); } } } }
@Override public String getPropertyName() { if (edmProperty == null) { return ""; } try { return edmProperty.getName(); } catch (EdmException e) { return ""; } }
@Override public ElementType getElementType(String elementName) { try { if(entityType.getProperty(elementName).getType().getKind().equals(EdmTypeKind.COMPLEX)) return ElementType.STRUCTURED_TYPE; } catch (EdmException e) { return null; } return ElementType.SIMPLE_TYPE; }
.getMultiplicity().equals(EdmMultiplicity.MANY)) {
@Override public String getPropertyName() { if (edmProperty == null) { return ""; } try { return edmProperty.getName(); } catch (EdmException e) { return ""; } }
@Override public ODataResponse writeFunctionImport(final EdmFunctionImport functionImport, final Object data, final EntityProviderWriteProperties properties) throws EntityProviderException { try { if (functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) data; return writeEntry(functionImport.getEntitySet(), map, properties); } final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport); if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) { return writeCollection(info, (List<?>) data); } else { return writeSingleTypedElement(info, data); } } catch (final EdmException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
private List<String> getNavigationUUIDColumns(EdmEntitySet navigatedEntitySet) throws EdmException{ List<String> coloumnNames = new ArrayList<>(); List<String> propertNames = null; EdmStructuralType entityType = null; if(navigatedEntitySet != null){ entityType = navigatedEntitySet.getEntityType(); propertNames = entityType.getPropertyNames(); } if(entityType != null){ for (String propertyName : propertNames) { EdmTyped property = entityType.getProperty(propertyName) ; if (property.getType() instanceof EdmGuid) { coloumnNames.add(propertyName); } else if(property.getType().getKind().equals(EdmTypeKind.COMPLEX) ){ boolean isUUIDinComplextype = getUUIDColumnsInComplexType(entityType, property); if(isUUIDinComplextype)coloumnNames.add(propertyName); } } } return coloumnNames; }
public boolean getUUIDColumnsInComplexType(EdmStructuralType inputEntityType, EdmTyped property ) throws EdmException{ EdmComplexTypeImplProv complexTypeProv = (EdmComplexTypeImplProv)property.getType(); if(inputEntityType != null){ entityType = (EdmStructuralType)inputEntityType.getProperty(property.getName()).getType() ; entityType = (EdmStructuralType) property.getType() ; EdmTyped edmproperty = entityType.getProperty(propertyName) ; if (edmproperty.getType() instanceof EdmGuid) { coloumnNames.add(propertyName); else if(edmproperty.getType().getKind().equals(EdmTypeKind.COMPLEX) ){ getUUIDColumnsInComplexType(inputEntityType, property);
.getMultiplicity().equals(EdmMultiplicity.MANY)) {
@Override public String getPropertyName() { if (edmProperty == null) { return ""; } try { return edmProperty.getName(); } catch (EdmException e) { return ""; } }
@Override public ODataResponse writeFunctionImport(final EdmFunctionImport functionImport, final Object data, final EntityProviderWriteProperties properties) throws EntityProviderException { try { final EdmType type = functionImport.getReturnType().getType(); final boolean isCollection = functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY; if (type.getKind() == EdmTypeKind.ENTITY) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) data; return writeEntry(functionImport.getEntitySet(), map, properties); } final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport); if (isCollection) { return writeCollection(info, (List<?>) data); } else { return writeSingleTypedElement(info, data); } } catch (EdmException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
private void saveType(String property, EdmEntityType entityType) throws EdmException { if (typeMap.containsKey(property)) return; EdmEntityType targetEntityType = entityType; String targetProperty; /* * The below code finds out the type of the property, in which property can be a direct property * like ProductID or can be a property of a child entity like "Category/CategoryName" * we handle both the conditions with the for loop below. (The for loop does not execute when * it is a direct property, and in the second case, we iterate thru the navigation path, * and find out the target entity type of the child entity which the property belongs to. * Once the target entity type is obtained we get the Edm type in straightforward manner. */ String[] navigationPath = property.split("/"); int pathLengthExcludingProperty = navigationPath.length - 1; targetProperty = navigationPath[pathLengthExcludingProperty]; for (int i = 0;i<pathLengthExcludingProperty;i++) { String navigationProperty = navigationPath[i]; targetEntityType = getTargetEntityTypeFromNavigationProperty(targetEntityType, navigationProperty); } if(targetEntityType.getProperty(targetProperty) != null && targetEntityType.getProperty(targetProperty).getType().getKind().equals(EdmTypeKind.SIMPLE)) typeMap.put(property, targetEntityType.getProperty(targetProperty).getType()); }
public static List<String> extractKeyPredicateFilterExpressions(UriInfo uriInfo, boolean considerActiveEntityKey) throws EdmException { List<KeyPredicate> keypredicates = extractKeyPredicateRefsFromUriInfo(uriInfo, considerActiveEntityKey); EdmEntityType entity = uriInfo.getTargetEntitySet().getEntityType(); List<String> filters=new ArrayList<>(); for (int j = 0; j < keypredicates.size(); j++) { String filter; String kpAlias = keypredicates.get(j).getProperty().getName(); EdmTyped kpRef = entity.getProperty(kpAlias); if(kpRef.getName().equals(DRAFTS_ISACTIVE_ENTITY)) { continue; } String kpNameInFilter = convertToUpperCaseIfRequired(kpRef.getName()); String keyPredType = kpRef.getType().toString(); if (keyPredType != null && (keyPredType.equals("Edm.DateTimeOffset") || keyPredType.equals("Edm.DateTime") || keyPredType.equals("Edm.Date") || keyPredType.equals("Edm.Guid") )) { filter=kpNameInFilter.replace("/", ".") + " = '"+ keypredicates.get(j).getLiteral() + "'"; } else { filter=kpNameInFilter.replace("/", ".") + " = " + keypredicates.get(j).getLiteral(); } filters.add(filter); } return filters; }
final EdmType targetType = uriInfo.getTargetType(); final boolean isCollection = functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY; switch (targetType.getKind()) { case SIMPLE:
private static String getPropertyName(final CommonExpression whereExpression) throws EdmException, ODataJPARuntimeException { EdmTyped edmProperty = ((PropertyExpression) whereExpression).getEdmProperty(); EdmMapping mapping; if (edmProperty instanceof EdmNavigationProperty) { EdmNavigationProperty edmNavigationProperty = (EdmNavigationProperty) edmProperty; mapping = edmNavigationProperty.getMapping(); } else if(edmProperty instanceof EdmProperty) { EdmProperty property = (EdmProperty) edmProperty; mapping = property.getMapping(); } else { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL, null); } return mapping != null ? mapping.getInternalName() : edmProperty.getName(); } }
@Override public Object readFunctionImport(final EdmFunctionImport functionImport, final InputStream content, final EntityProviderReadProperties properties) throws EntityProviderException { try { if (functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY) { return functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY ? new JsonEntityConsumer().readFeed(functionImport.getEntitySet(), content, properties) : new JsonEntityConsumer().readEntry(functionImport.getEntitySet(), content, properties); } else { final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport); return functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY ? new JsonEntityConsumer().readCollection(info, content, properties) : new JsonEntityConsumer().readProperty(info, content, properties).get(info.getName()); } } catch (final EdmException e) { throw new EntityProviderException(e.getMessageReference(), e); } }
if(checkNull(entityType.getProperty(edmName)) && checkNull(entityType.getProperty(edmName).getType())){ Object typeObj = entityType.getProperty(edmName).getType(); if(typeObj instanceof EdmSimpleType){ if(checkNull(typeObj)) if(checkNull(edmCompType.getProperty(edmCompName)) && checkNull(edmCompType.getProperty(edmCompName).getType())){ Object typeCompObj = edmCompType.getProperty(edmCompName).getType(); if( typeCompObj instanceof EdmSimpleType){ edmTypeMap.put(edmName+" - "+edmCompName, ((EdmSimpleType)typeCompObj).getName());