private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType) throws EdmException { final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames(); if (navigationPropertyNames.isEmpty()) { return null; } else { final WriteCallback callback = new WriteCallback(data); Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>(); for (final String name : navigationPropertyNames) { callbacks.put(name, callback); } return callbacks; } }
private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType) throws EdmException { final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames(); if (navigationPropertyNames.isEmpty()) { return null; } else { final WriteCallback callback = new WriteCallback(data); Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>(); for (final String name : navigationPropertyNames) { callbacks.put(name, callback); } return callbacks; } }
private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType) throws EdmException { final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames(); if (navigationPropertyNames.isEmpty()) { return null; } else { final WriteCallback callback = new WriteCallback(data); Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>(); for (final String name : navigationPropertyNames) { callbacks.put(name, callback); } return callbacks; } }
@Override public List<String> getNavigationPropertyNames() throws EdmException { if (edmNavigationPropertyNames == null) { edmNavigationPropertyNames = new ArrayList<String>(); if (edmBaseType != null) { edmNavigationPropertyNames.addAll(((EdmEntityType) edmBaseType).getNavigationPropertyNames()); } if (entityType.getNavigationProperties() != null) { for (final NavigationProperty navigationProperty : entityType.getNavigationProperties()) { edmNavigationPropertyNames.add(navigationProperty.getName()); } } } return edmNavigationPropertyNames; }
@Override public List<String> getNavigationPropertyNames() throws EdmException { if (edmNavigationPropertyNames == null) { edmNavigationPropertyNames = new ArrayList<String>(); if (edmBaseType != null) { edmNavigationPropertyNames.addAll(((EdmEntityType) edmBaseType).getNavigationPropertyNames()); } if (entityType.getNavigationProperties() != null) { for (final NavigationProperty navigationProperty : entityType.getNavigationProperties()) { edmNavigationPropertyNames.add(navigationProperty.getName()); } } } return edmNavigationPropertyNames; }
@Override public List<String> getNavigationPropertyNames() throws EdmException { if (edmNavigationPropertyNames == null) { edmNavigationPropertyNames = new ArrayList<String>(); if (edmBaseType != null) { edmNavigationPropertyNames.addAll(((EdmEntityType) edmBaseType).getNavigationPropertyNames()); } if (entityType.getNavigationProperties() != null) { for (final NavigationProperty navigationProperty : entityType.getNavigationProperties()) { edmNavigationPropertyNames.add(navigationProperty.getName()); } } } return edmNavigationPropertyNames; }
private static void fillInTranformCreate(EdmEntitySet draftEdmEntitySet, Map<String, Object> draftEnt, Map<UUID,UriInfoDraftHelperV2> uriTransformerMap, EdmEntityContainer entityContainer, DraftFlow flow) throws ODataException{ if(draftEdmEntitySet.getEntityType().getNavigationPropertyNames() != null) { for(String draftLinkName:draftEdmEntitySet.getEntityType().getNavigationPropertyNames()) { //one to one case Object draftLink = draftEnt.get(draftLinkName); String draftNavigateEntityName = EntityDataSourceProvider.getAssociatedEntityName(entityContainer.getNamespace(), draftEdmEntitySet.getName(), draftLinkName); EdmEntitySet draftNavigatedEdmEntitySet = entityContainer.getEntitySet(draftNavigateEntityName); if(draftLink instanceof Map) { uriTransformerMap.putAll(compareMainandDraft(new ArrayList<Map<String, Object>>(), null, Arrays.asList((Map<String, Object>)draftLink), draftNavigatedEdmEntitySet, entityContainer, flow)); }else if(draftLink instanceof List) /*collection flow*/ { uriTransformerMap.putAll(compareMainandDraft(new ArrayList<Map<String, Object>>(), null, (List<Map<String, Object>>)draftLink, draftNavigatedEdmEntitySet, entityContainer, flow)); } } } }
private static void fillInTransformDelete(Map<String, Object> activeEnt, EdmEntitySet activeEdmEntitySet, Map<UUID,UriInfoDraftHelperV2> uriTransformerMap, EdmEntityContainer entityContainer, DraftFlow flow) throws ODataException{ if(activeEdmEntitySet.getEntityType().getNavigationPropertyNames() != null) { for(String activeLinkName:activeEdmEntitySet.getEntityType().getNavigationPropertyNames()) { //one to one case String activeNavigateEntityName = EntityDataSourceProvider.getAssociatedEntityName(entityContainer.getNamespace(), activeEdmEntitySet.getName(), activeLinkName); EdmEntitySet activeNavigatedEdmEntitySet = entityContainer.getEntitySet(activeNavigateEntityName); Object activeLink = activeEnt.get(activeLinkName); if(activeLink instanceof Map) { uriTransformerMap.putAll(compareMainandDraft(Arrays.asList((Map<String, Object>)activeLink), activeNavigatedEdmEntitySet, new ArrayList<Map<String, Object>>(), null, entityContainer, flow)); }else if(activeLink instanceof List)/*collection flow*/ { uriTransformerMap.putAll(compareMainandDraft((List<Map<String,Object>>)activeLink, activeNavigatedEdmEntitySet, new ArrayList<Map<String, Object>>(), null, entityContainer, flow)); } } } }
private void normalizeInlineEntries(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException { List<ODataEntry> entries = null; try { for (String navigationPropertyName : oDataEntityType.getNavigationPropertyNames()) { Object inline = oDataEntryProperties.get(navigationPropertyName); if (inline instanceof ODataFeed) { entries = ((ODataFeed) inline).getEntries(); } else if (inline instanceof ODataEntry) { entries = new ArrayList<ODataEntry>(); entries.add((ODataEntry) inline); } if (entries != null) { oDataEntryProperties.put(navigationPropertyName, entries); entries = null; } } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } }
private void normalizeInlineEntries(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException { List<ODataEntry> entries = null; try { for (String navigationPropertyName : oDataEntityType.getNavigationPropertyNames()) { Object inline = oDataEntryProperties.get(navigationPropertyName); if (inline instanceof ODataFeed) { entries = ((ODataFeed) inline).getEntries(); } else if (inline instanceof ODataEntry) { entries = new ArrayList<ODataEntry>(); entries.add((ODataEntry) inline); } if (entries != null) { oDataEntryProperties.put(navigationPropertyName, entries); entries = null; } } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } }
private void writeNavigationProperties(final Writer writer, final EntityInfoAggregator entityInfo, final Map<String, Object> data, final EdmEntityType type) throws EdmException, EntityProviderException, IOException { for (final String navigationPropertyName : type.getNavigationPropertyNames()) { if (data.containsKey(navigationPropertyName)) { if (data.get(navigationPropertyName) == null) { throw new EntityProviderException(EntityProviderException.NULL_VALUE); } if (data.get(navigationPropertyName) instanceof Entity || data.get(navigationPropertyName) instanceof EntityCollection) { jsonStreamWriter.separator(); jsonStreamWriter.name(navigationPropertyName); writeExpandedNavigationProperty(writer, entityInfo, data, type, navigationPropertyName); } else if (data.get(navigationPropertyName) instanceof Map<?,?>){ writeNavigationLinks(entityInfo, data); } else { throw new EntityProviderException(EntityProviderException.INCORRECT_NAVIGATION_TYPE); } } } }
public Map<String, List<String>> getAllNavigationUUIDColumns(UriInfo uriInfo) throws EdmException{ Map<String, List<String>> navigationsUUIDs = new HashMap<>(); if(uriInfo.getEntityContainer() == null){ return navigationsUUIDs; } List<EdmEntitySet> entitySets = uriInfo.getEntityContainer().getEntitySets(); for(int i=0; i<entitySets.size(); i++){ EdmEntitySet entitySet = entitySets.get(i); EdmEntityType entityType = entitySet.getEntityType(); List<String> navigationProperties = entityType.getNavigationPropertyNames(); for(int j=0; j<navigationProperties.size(); j++){ EdmNavigationProperty navigationProperty = (EdmNavigationProperty) entityType.getProperty(navigationProperties.get(j)); EdmEntitySet navigatedEntitySet = entitySet.getRelatedEntitySet(navigationProperty); navigationsUUIDs.put(navigationProperty.getName(), this.getNavigationUUIDColumns(navigatedEntitySet)); } } return navigationsUUIDs; }
private static void fillInTransformUpdate(EdmEntitySet activeEdmEntitySet, EdmEntitySet draftEdmEntitySet, Map<String, Object> draftEnt, Map<String, Object> activeEnt, Map<UUID,UriInfoDraftHelperV2> uriTransformerMap, EdmEntityContainer entityContainer, DraftFlow flow) throws ODataException { if(draftEdmEntitySet.getEntityType().getNavigationPropertyNames() != null && activeEdmEntitySet.getEntityType().getNavigationPropertyNames() != null) { for(String draftLinkName:draftEdmEntitySet.getEntityType().getNavigationPropertyNames()) { //Active entity navigated details String activeNavigateEntityName = EntityDataSourceProvider.getAssociatedEntityName(entityContainer.getNamespace(), activeEdmEntitySet.getName(), draftLinkName); EdmEntitySet activetNavigatedEdmEntitySet = entityContainer.getEntitySet(activeNavigateEntityName); //Draft entity navigated details String draftNavigateEntityName = EntityDataSourceProvider.getAssociatedEntityName(entityContainer.getNamespace(), draftEdmEntitySet.getName(), draftLinkName); EdmEntitySet draftNavigatedEdmEntitySet = entityContainer.getEntitySet(draftNavigateEntityName); Object draftLink = draftEnt.get(draftLinkName); Object activeLink = activeEnt.get(draftLinkName); if(draftLink instanceof Map || activeLink instanceof Map) { uriTransformerMap.putAll(compareMainandDraft(Arrays.asList((Map<String, Object>)activeLink), activetNavigatedEdmEntitySet, Arrays.asList((Map<String, Object>)draftLink), draftNavigatedEdmEntitySet, entityContainer, flow)); }else if(draftLink instanceof List){ uriTransformerMap.putAll(compareMainandDraft((List<Map<String,Object>>)activeLink, activetNavigatedEdmEntitySet, (List<Map<String, Object>>)draftLink, draftNavigatedEdmEntitySet, entityContainer, flow)); } } } }
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); } } } }
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 void writeNavigationProperties(final Writer writer, final EntityInfoAggregator entityInfo, final Map<String, Object> data, final EdmEntityType type) throws EdmException, EntityProviderException, IOException { for (final String navigationPropertyName : type.getNavigationPropertyNames()) { if (entityInfo.getSelectedNavigationPropertyNames().contains(navigationPropertyName)) { jsonStreamWriter.separator(); jsonStreamWriter.name(navigationPropertyName); if (entityInfo.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) { if (properties.getCallbacks() != null && properties.getCallbacks().containsKey(navigationPropertyName)) { writeExpandedNavigationProperty(writer, entityInfo, data, type, navigationPropertyName); } else { writeDeferredUri(entityInfo, navigationPropertyName); } } else { writeDeferredUri(entityInfo, navigationPropertyName); } } } }
private void writeNavigationProperties(final Writer writer, final EntityInfoAggregator entityInfo, final Map<String, Object> data, final EdmEntityType type) throws EdmException, EntityProviderException, IOException { for (final String navigationPropertyName : type.getNavigationPropertyNames()) { if (entityInfo.getSelectedNavigationPropertyNames().contains(navigationPropertyName)) { jsonStreamWriter.separator(); jsonStreamWriter.name(navigationPropertyName); if (entityInfo.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) { if (properties.getCallbacks() != null && properties.getCallbacks().containsKey(navigationPropertyName)) { writeExpandedNavigationProperty(writer, entityInfo, data, type, navigationPropertyName); } else { writeDeferredUri(navigationPropertyName); } } else { writeDeferredUri(navigationPropertyName); } } } }
private void writeNavigationProperties(final Writer writer, final EntityInfoAggregator entityInfo, final Map<String, Object> data, final EdmEntityType type) throws EdmException, EntityProviderException, IOException { for (final String navigationPropertyName : type.getNavigationPropertyNames()) { if (entityInfo.getSelectedNavigationPropertyNames().contains(navigationPropertyName)) { jsonStreamWriter.separator(); jsonStreamWriter.name(navigationPropertyName); if (entityInfo.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) { if (properties.getCallbacks() != null && properties.getCallbacks().containsKey(navigationPropertyName)) { writeExpandedNavigationProperty(writer, entityInfo, data, type, navigationPropertyName); } else { writeDeferredUri(entityInfo, navigationPropertyName); } } else { writeDeferredUri(entityInfo, navigationPropertyName); } } } }
public void update(final ODataEntry oDataEntry) throws ODataJPARuntimeException { if (oDataEntry == null) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL, null); } Map<String, Object> oDataEntryProperties = oDataEntry.getProperties(); if (oDataEntry.containsInlineEntry()) { normalizeInlineEntries(oDataEntryProperties); } write(oDataEntryProperties, false); JPALink link = new JPALink(oDataJPAContext); link.setSourceJPAEntity(jpaEntity); try { link.create(oDataEntitySet, oDataEntry, oDataEntityType.getNavigationPropertyNames()); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (ODataJPAModelException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } }
public void update(final ODataEntry oDataEntry) throws ODataJPARuntimeException { if (oDataEntry == null) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL, null); } Map<String, Object> oDataEntryProperties = oDataEntry.getProperties(); if (oDataEntry.containsInlineEntry()) { normalizeInlineEntries(oDataEntryProperties); } write(oDataEntryProperties, false); JPALink link = new JPALink(oDataJPAContext); link.setSourceJPAEntity(jpaEntity); try { link.create(oDataEntitySet, oDataEntry, oDataEntityType.getNavigationPropertyNames()); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (ODataJPAModelException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } }