private void appendProperty(EdmProperty property, String segmentValue) { try { state = property.getType().getKind() == EdmTypeKind.SIMPLE? SegmentType.SIMPLEPROPERTY : SegmentType.COMPLEXPROPERTY; } catch (EdmException e) { throw new RuntimeException("Unexpected EDM Exception: ", e);//NOSONAR } segments.add(new Segment(state, segmentValue)); }
@Override public String toString() { try { return edmType.getNamespace()+ Edm.DELIMITER + edmType.getName(); } catch (EdmException e) { //NOPMD - suppressed return null; //NOSONAR } } }
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) { } } } } }
public static String getUUIDkeyPropertyName(EdmEntitySet entSet) throws EdmException { String refKeyName = null; EdmEntityType entType = entSet.getEntityType(); for(EdmProperty refs:entType.getKeyProperties()) { if(refs.getType().getName().equalsIgnoreCase("Guid")) { refKeyName = refs.getName(); break; } } return refKeyName; }
if (actType.getKind() != EdmTypeKind.SIMPLE) { return false; // Tested with TestParserExceptions.testAdditionalStuff CASE 8
/** * Returns full qualified name of a type of a given PropertyInfo. * @return Full qualified name */ private String getFqnTypeName(final EntityComplexPropertyInfo propertyInfo) throws EdmException { return propertyInfo.getType().getNamespace() + Edm.DELIMITER + propertyInfo.getType().getName(); }
public static UriInfoDraftHelperV2 getCreateUriInfoForDraftsOneToOneUsingParent(EdmNavigationProperty navPropParent, Map<String, Object> parentDraftsEntry, EdmEntityContainer entityContainer, Map<String, Object> navigatedContent) throws ODataApplicationException { try{ Map<String, Object> childPayload = new HashMap<>(); EdmReferentialConstraint refConstraint = navPropParent.getRelationship().getReferentialConstraint(); if(refConstraint == null){ throw new ODataApplicationException(CREATE_REF_CONSTRAINT_MISSING, Locale.ENGLISH, HttpStatusCodes.INTERNAL_SERVER_ERROR, CREATE_REF_CONSTRAINT_MISSING); } // Map of <ChildKey , ParentKey> Map<String, String> refConstraintsMap = getReferenceMap(refConstraint); for (Map.Entry<String, String> entry : refConstraintsMap.entrySet()) { childPayload.put(entry.getKey(), parentDraftsEntry.get(entry.getValue())); } childPayload.putAll(navigatedContent); ODataEntryImpl content = new ODataEntryImpl(childPayload, null, null, null, false); EdmEntitySet entSet = entityContainer.getEntitySet(navPropParent.getType().getName()); UriInfoImpl uriInfoForCreate = new UriInfoImpl(); uriInfoForCreate.setStartEntitySet(entSet); uriInfoForCreate.setTargetEntitySet(entSet); UriInfoDraftHelperV2 uriT = new UriInfoDraftHelperV2(); uriT.setUriInfo(uriInfoForCreate); uriT.setContent(content); uriT.setUriFunction(UriFunction.CREATE); return uriT; }catch(EdmException ee){ logger.debug(ee.getMessage(), ee); throw new ODataApplicationException(ee.getMessage(), Locale.ENGLISH, HttpStatusCodes.INTERNAL_SERVER_ERROR, ee.getMessage()); } }
if (actType.getKind() != EdmTypeKind.SIMPLE) { return false; // Tested with TestParserExceptions.testAdditionalStuff CASE 8
private static String getType(final CommonExpression expression) { try { final EdmType type = expression.getEdmType(); return type == null ? null : type.getNamespace() + Edm.DELIMITER + type.getName(); } catch (final EdmException e) { return "EdmException occurred: " + e.getMessage(); } } }
private static void constructTreeExpand(EdmEntitySet rootEntitySet, String serviceName, Map<String,List<String>> compositionTree, ArrayList<NavigationPropertySegment> navigationPropertySegments, List<ArrayList<NavigationPropertySegment>> expandOption) throws EdmException { if(rootEntitySet != null && rootEntitySet.getEntityType() != null && rootEntitySet.getEntityType().getNavigationPropertyNames()!=null && !rootEntitySet.getEntityType().getNavigationPropertyNames().isEmpty()) { for(String navName:rootEntitySet.getEntityType().getNavigationPropertyNames()) { EdmNavigationProperty expandNp = (EdmNavigationProperty)rootEntitySet.getEntityType().getProperty(navName); if(compositionTree.get(rootEntitySet.getEntityType().getName()).contains(expandNp.getType().getName())) { String associatedEntityName = EntityDataSourceProvider.getAssociatedEntityName(serviceName, rootEntitySet.getEntityType().getName(), navName); EdmEntitySet edmEntitySet = rootEntitySet.getEntityContainer().getEntitySet(associatedEntityName); NavigationPropertySegmentImpl navSegmentImpl = new NavigationPropertySegmentImpl(); navSegmentImpl.setNavigationProperty(expandNp); navSegmentImpl.setTargetEntitySet(edmEntitySet); navigationPropertySegments.add(navSegmentImpl); //At first level Books/?expand=pages one navigation property entry //At second level Books?$expand=pages, pages/words two navigation property entries //At third level Books?$expand=pages, pages/words, pages/words/letters three navigation property entries and so on... ArrayList<NavigationPropertySegment> innerNavigationSegments = new ArrayList<>(); innerNavigationSegments.addAll(navigationPropertySegments); expandOption.add(innerNavigationSegments); //Recursively set compositions constructTreeExpand(edmEntitySet, serviceName, compositionTree, navigationPropertySegments, expandOption); } } } }
if (actType.getKind() != EdmTypeKind.SIMPLE) { return false; // Tested with TestParserExceptions.testAdditionalStuff CASE 8
/** * Returns full qualified name of a type of a given PropertyInfo. * @return Full qualified name */ private String getFqnTypeName(final EntityComplexPropertyInfo propertyInfo) throws EdmException { return propertyInfo.getType().getNamespace() + Edm.DELIMITER + propertyInfo.getType().getName(); }
private static void constructDraftTreeExpand(EdmEntitySet rootEntitySet, String serviceName, Map<String,List<String>> draftTree, ArrayList<NavigationPropertySegment> navigationPropertySegments, List<ArrayList<NavigationPropertySegment>> expandOption) throws EdmException { if(rootEntitySet != null && rootEntitySet.getEntityType() != null && rootEntitySet.getEntityType().getNavigationPropertyNames()!=null && !rootEntitySet.getEntityType().getNavigationPropertyNames().isEmpty()) { for(String navName:rootEntitySet.getEntityType().getNavigationPropertyNames()) { EdmNavigationProperty expandNp = (EdmNavigationProperty)rootEntitySet.getEntityType().getProperty(navName); if(draftTree.get(rootEntitySet.getEntityType().getName()).contains(expandNp.getType().getName())) { String associatedEntityName = EntityDataSourceProvider.getAssociatedEntityName(serviceName, rootEntitySet.getEntityType().getName(), navName); EdmEntitySet edmEntitySet = rootEntitySet.getEntityContainer().getEntitySet(associatedEntityName); NavigationPropertySegmentImpl navSegmentImpl = new NavigationPropertySegmentImpl(); navSegmentImpl.setNavigationProperty(expandNp); navSegmentImpl.setTargetEntitySet(edmEntitySet); navigationPropertySegments.add(navSegmentImpl); //At first level Books/?expand=pages one navigation property entry //At second level Books?$expand=pages, pages/words two navigation property entries //At third level Books?$expand=pages, pages/words, pages/words/letters three navigation property entries and so on... ArrayList<NavigationPropertySegment> innerNavigationSegments = new ArrayList<>(); innerNavigationSegments.addAll(navigationPropertySegments); expandOption.add(innerNavigationSegments); //Recursively set compositions constructDraftTreeExpand(edmEntitySet, serviceName, draftTree, navigationPropertySegments, expandOption); } } } }
private EntityPropertyInfo createEntityPropertyInfo(final EdmFunctionImport functionImport, final EdmType type) throws EdmException, EntityProviderException { EntityPropertyInfo epi; if (type.getKind() == EdmTypeKind.COMPLEX) { EdmComplexType complex = (EdmComplexType) type; Map<String, EntityPropertyInfo> eia = EntityInfoAggregator.create(complex); List<EntityPropertyInfo> childEntityInfoList = new ArrayList<EntityPropertyInfo>(); for (String propertyName : complex.getPropertyNames()) { childEntityInfoList.add(eia.get(propertyName)); } epi = new EntityComplexPropertyInfo(functionImport.getName(), type, null, null, childEntityInfoList); } else if (type.getKind() == EdmTypeKind.SIMPLE) { epi = new EntityPropertyInfo(functionImport.getName(), type, null, null, null, null); } else { throw new EntityProviderException(EntityProviderException.UNSUPPORTED_PROPERTY_TYPE.addContent(type.getKind())); } return epi; }
private static String getType(final CommonExpression expression) { try { final EdmType type = expression.getEdmType(); return type == null ? null : type.getNamespace() + Edm.DELIMITER + type.getName(); } catch (final EdmException e) { return "EdmException occurred: " + e.getMessage(); } } }
public static EdmEntitySet getEdmEntitySet(final UriInfo uriInfo, Locale locale) throws ODataException { EdmEntitySet entitySet = null; // First must be an entity or a function import. if (uriInfo.getStartEntitySet() != null) { entitySet = uriInfo.getStartEntitySet(); } else if (uriInfo.getFunctionImport() != null) { entitySet = uriInfo.getFunctionImport().getEntitySet(); } else { throw new ODataApplicationException("INVALID_RESOURCE_TYPE", locale, HttpStatusCodes.NOT_IMPLEMENTED, "INVALID_RESOURCE_TYPE_CODE"); } int navigationCount = 0; while (entitySet != null && navigationCount < uriInfo.getNavigationSegments().size()) { final NavigationSegment uriResourceNavigation = uriInfo.getNavigationSegments().get(navigationCount); try { if(entitySet.getRelatedEntitySet(uriResourceNavigation.getNavigationProperty()) == null) { entitySet.getEntityContainer().getEntitySet(uriResourceNavigation.getNavigationProperty().getType().getName()); break; }else { entitySet = entitySet.getRelatedEntitySet(uriResourceNavigation.getNavigationProperty()); } } catch (EdmException e) { throw new ODataApplicationException("NAVIGATION_NOT_SUPPORTED", locale, HttpStatusCodes.NOT_IMPLEMENTED, "NAVIGATION_NOT_SUPPORTED_CODE", e); } navigationCount++; } return entitySet; } }
private EntityPropertyInfo createEntityPropertyInfo(final EdmFunctionImport functionImport, final EdmType type) throws EdmException, EntityProviderException { EntityPropertyInfo epi; if (type.getKind() == EdmTypeKind.COMPLEX) { EdmComplexType complex = (EdmComplexType) type; Map<String, EntityPropertyInfo> eia = EntityInfoAggregator.create(complex); List<EntityPropertyInfo> childEntityInfoList = new ArrayList<EntityPropertyInfo>(); for (String propertyName : complex.getPropertyNames()) { childEntityInfoList.add(eia.get(propertyName)); } epi = new EntityComplexPropertyInfo(functionImport.getName(), type, null, null, childEntityInfoList); } else if (type.getKind() == EdmTypeKind.SIMPLE) { epi = new EntityPropertyInfo(functionImport.getName(), type, null, null, null, null); } else { throw new EntityProviderException(EntityProviderException.UNSUPPORTED_PROPERTY_TYPE.addContent(type.getKind())); } return epi; }
/** * Returns full qualified name of a type of a given PropertyInfo. * @return Full qualified name */ private String getFqnTypeName(final EntityComplexPropertyInfo propertyInfo) throws EdmException { return propertyInfo.getType().getNamespace() + Edm.DELIMITER + propertyInfo.getType().getName(); }
private EntityPropertyInfo createEntityPropertyInfo(final EdmFunctionImport functionImport, final EdmType type) throws EdmException, EntityProviderException { EntityPropertyInfo epi; if (type.getKind() == EdmTypeKind.COMPLEX) { EdmComplexType complex = (EdmComplexType) type; Map<String, EntityPropertyInfo> eia = EntityInfoAggregator.create(complex); List<EntityPropertyInfo> childEntityInfoList = new ArrayList<EntityPropertyInfo>(); for (String propertyName : complex.getPropertyNames()) { childEntityInfoList.add(eia.get(propertyName)); } epi = new EntityComplexPropertyInfo(functionImport.getName(), type, null, null, childEntityInfoList); } else if (type.getKind() == EdmTypeKind.SIMPLE) { epi = new EntityPropertyInfo(functionImport.getName(), type, null, null, null, null); } else { throw new EntityProviderException(EntityProviderException.UNSUPPORTED_PROPERTY_TYPE.addContent(type.getKind())); } return epi; }
private static String getType(final CommonExpression expression) { try { final EdmType type = expression.getEdmType(); return type == null ? null : type.getNamespace() + Edm.DELIMITER + type.getName(); } catch (final EdmException e) { return "EdmException occurred: " + e.getMessage(); } } }