static NavigationPropertyInfo create(final EdmNavigationProperty property) throws EdmException { NavigationPropertyInfo info = new NavigationPropertyInfo(); info.name = property.getName(); info.multiplicity = property.getMultiplicity(); return info; }
@Override public EdmAssociationSet getAssociationSet(final EdmEntitySet sourceEntitySet, final EdmNavigationProperty navigationProperty) throws EdmException { EdmAssociation edmAssociation = navigationProperty.getRelationship(); String association = edmAssociation.getNamespace() + "." + edmAssociation.getName(); String entitySetName = sourceEntitySet.getName(); String entitySetFromRole = navigationProperty.getFromRole(); String key = entitySetName + ">>" + association + ">>" + entitySetFromRole; for (Entry<String, EdmAssociationSet> edmAssociationSet : edmAssociationSetMap.entrySet()) { if (edmAssociationSet.getKey().equalsIgnoreCase(key)) { return edmAssociationSet.getValue(); } } return null; }
@Override public EdmEntitySet getRelatedEntitySet(final EdmNavigationProperty navigationProperty) throws EdmException { EdmAssociationSet associationSet = edmEntityContainer.getAssociationSet(edmEntityContainer.getEntitySet(name), navigationProperty); if(associationSet == null){ return null; } EdmAssociationSetEnd toEnd = associationSet.getEnd(navigationProperty.getToRole()); if (toEnd == null) { throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND,navigationProperty.getName()); } EdmEntitySet targetEntitySet = toEnd.getEntitySet(); if (targetEntitySet == null) { throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND,navigationProperty.getName()); } return targetEntitySet; }
private String getRelationShipName(final EdmNavigationProperty navigationProperty) throws EdmException { EdmMapping mapping = navigationProperty.getMapping(); String relationShipName = null; if (mapping != null) { relationShipName = mapping.getInternalName(); } else { relationShipName = navigationProperty.getName(); } return relationShipName; }
private EdmEntityType getTargetEntityType(Edm edm, EdmEntitySet srcEtySet ,EdmNavigationProperty navigationProp) throws EdmException { if(navigationProp == null) return null ; else { //Look for Target Entity Type based on Navigation Property String toRole = navigationProp.getToRole() ; return navigationProp.getRelationship().getEnd(toRole).getEntityType(); } } private EdmEntitySet getTargetEntitySet(Edm edm, EdmEntitySet srcEtySet, EdmNavigationProperty navigationProp) throws EdmException, ODataException{
@Override protected EdmTyped getPropertyInternal(final String name) throws EdmException { EdmTyped edmProperty = super.getPropertyInternal(name); if (edmProperty != null) { return edmProperty; } for (EdmNavigationProperty navigations : navigationProperties) { if (navigations.getName().equals(name)) { return navigations; } } return edmProperty; }
Map<String, Object> targetEntityValues = null; if (navigationProperty.getMultiplicity().equals(EdmMultiplicity.MANY)) { providerResponse = readEntitySet(gwUriInfo, context); targetEntitySetValues = providerResponse.getResultEntities();
JPAEdmMapping navPropMapping = (JPAEdmMapping) navigationProperty.getMapping(); name = getAccessModifierName(navigationProperty.getName(), (EdmMapping) navPropMapping, accessModifier); EdmAssociationEnd end = navigationProperty.getRelationship().getEnd(navigationProperty.getToRole()); switch (end.getMultiplicity()) { case MANY:
EdmEntityType targetType = navigationProperty.getRelationship().getEnd(navigationProperty.getToRole()) .getEntityType(); if (navigationProperty.getMultiplicity().equals(EdmMultiplicity.MANY)) { List<Map<String, Object>> childEntities = null; if (properties.get(propertyName) instanceof List)
private boolean testNavPropertySegment( final EdmNavigationProperty navProperty, final EdmEntityType sourceEntityType, final EdmNavigationProperty navigationProperty) throws EdmException { if(navigationProperty.getFromRole().toLowerCase(Locale.ENGLISH).startsWith( sourceEntityType.getName().toLowerCase(Locale.ENGLISH))) { final String roleNum = navigationProperty.getFromRole().substring(sourceEntityType.getName().length()); if(roleNum.length() > 0) { try { Integer.parseInt(roleNum); } catch (NumberFormatException e) { return false; } } } return navProperty.getName().equals(navigationProperty.getName()); }
NavigationProperty navigationProperty = ((EdmEntityTypeImplProv) createView.getStartEntitySet().getEntityType()).getNavigationProperties().get(createView.getNavigationSegments().get(0).getNavigationProperty().getName()); property = createView.getNavigationSegments().get(0).getNavigationProperty().getRelationship().getReferentialConstraint().getDependent().getPropertyRefNames().get(0);
private Map<String,String> getReferenceMap(PostUriInfo uriInfo) throws EdmException, ODataApplicationException{ // Is navigation segment always of size one? // // add try catch // Map<String,String> referenceMap = new HashMap<>(); EdmReferentialConstraint refConstraint = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getRelationship().getReferentialConstraint(); if(refConstraint == null) throw new ODataApplicationException (NO_REF_CONSTRAINT, LocaleUtil.getLocaleforException()); List<String> principalPropertyList = refConstraint.getPrincipal().getPropertyRefNames(); List<String> dependentPropertList = refConstraint.getDependent().getPropertyRefNames(); for (int i = 0; i < principalPropertyList.size(); i++) { referenceMap.put(principalPropertyList.get(i), dependentPropertList.get(i)); } return referenceMap; }
if (navigationProperty.getMapping() instanceof JPAEdmMappingImpl) { jpaEdmMappingImpl = (JPAEdmMappingImpl) navigationProperty.getMapping(); targetJPAEntities.iterator().next()); } else { switch (navigationProperty.getMultiplicity()) { case MANY: Method getMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
private void validateRelationship() throws EntityProviderException, EdmException { for (EdmNavigationProperty navProperty : navProperties) { EdmNavigationPropertyImpl navigationImpl = (EdmNavigationPropertyImpl) navProperty; if (associationsMap.containsKey(navigationImpl.getRelationshipName())) { EdmAssociationImpl assoc = (EdmAssociationImpl) associationsMap.get(navigationImpl.getRelationshipName()); if (!(assoc.getEnd1().getRole().equals(navProperty.getFromRole()) ^ assoc.getEnd1().getRole().equals(navProperty.getToRole()) && (assoc.getEnd2().getRole().equals(navProperty.getFromRole()) ^ assoc.getEnd2().getRole().equals( navProperty.getToRole())))) { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT .addContent("Invalid end of association")); } if (!entityTypesMap.containsKey(extractFQNameFromEntityType(assoc.getEnd1().getEntityType()))) { EdmEntityType entityType = assoc.getEnd1().getEntityType(); validateEntityTypeWithAlias(extractFQNameFromEntityType(entityType)); } if (!entityTypesMap.containsKey(extractFQNameFromEntityType(assoc.getEnd2().getEntityType()))) { EdmEntityType entityType = assoc.getEnd2().getEntityType(); validateEntityTypeWithAlias(extractFQNameFromEntityType(entityType)); } } else { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent("Invalid Relationship")); } } }
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()); } }
@Override public EdmEntitySet getRelatedEntitySet(final EdmNavigationProperty navigationProperty) throws EdmException { EdmAssociationSet associationSet = edmEntityContainer.getAssociationSet(edmEntityContainer.getEntitySet(entitySet.getName()), navigationProperty); EdmAssociationSetEnd toEnd = associationSet.getEnd(navigationProperty.getToRole()); if (toEnd == null) { throw new EdmException(EdmException.COMMON); } EdmEntitySet targetEntitySet = toEnd.getEntitySet(); if (targetEntitySet == null) { throw new EdmException(EdmException.COMMON); } return targetEntitySet; }
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 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(); } }
private EdmEntitySet getTargetEntitySetFromNavigation(UriInfoImpl uriInfoForRead, String navigationName) throws EdmException { EdmEntitySet entitySet = null; for(ArrayList<NavigationPropertySegment> expand : uriInfoForRead.getExpand()) { Iterator<NavigationPropertySegment> navigationIterator = expand.iterator(); while(navigationIterator.hasNext()) { NavigationPropertySegment navName = navigationIterator.next(); if(navigationName.equals(navName.getNavigationProperty().getName())) { entitySet = navName.getTargetEntitySet(); break; } } } return entitySet; }
final NavigationSegment lastSegment = segments.get(segments.size() - 1); many = lastSegment.getKeyPredicates().isEmpty() && lastSegment.getNavigationProperty().getMultiplicity() == EdmMultiplicity.MANY;