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()); } }
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 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); } } } }
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; } }