当前位置: 首页>>代码示例>>Java>>正文


Java EntityProvider.writeEntry方法代码示例

本文整理汇总了Java中org.apache.olingo.odata2.api.ep.EntityProvider.writeEntry方法的典型用法代码示例。如果您正苦于以下问题:Java EntityProvider.writeEntry方法的具体用法?Java EntityProvider.writeEntry怎么用?Java EntityProvider.writeEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.olingo.odata2.api.ep.EntityProvider的用法示例。


在下文中一共展示了EntityProvider.writeEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeEntry

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
    final T data, final String contentType) throws ODataException, EntityProviderException {
  final EdmEntityType entityType = entitySet.getEntityType();
  final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);

  ODataContext context = getContext();
  EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .expandSelectTree(expandSelectTree)
      .callbacks(getCallbacks(data, entityType))
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");

  final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return response;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ListsProcessor.java

示例2: selectOnlyProperties

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void selectOnlyProperties() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> selectedProperties = new ArrayList<String>(roomData.keySet());

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).selectedProperties(selectedProperties).build();

  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).expandSelectTree(expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties", xml);
  assertXpathNotExists("/a:entry/a:link[@type]", xml);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:17,代码来源:ExpandSelectProducerWithBuilderTest.java

示例3: selectOnlyLinks

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void selectOnlyLinks() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> selectedNavigationProperties = new ArrayList<String>();
  selectedNavigationProperties.add("nr_Building");
  selectedNavigationProperties.add("nr_Employees");

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).selectedLinks(selectedNavigationProperties).build();

  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).expandSelectTree(expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathNotExists("/a:entry/a:content/m:properties", xml);
  assertXpathExists("/a:entry/a:link[@type]", xml);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:19,代码来源:ExpandSelectProducerWithBuilderTest.java

示例4: selectIdAndBuildingLink

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void selectIdAndBuildingLink() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> selectedNavigationProperties = new ArrayList<String>();
  selectedNavigationProperties.add("nr_Building");

  List<String> selectedProperties = new ArrayList<String>();
  selectedProperties.add("Id");

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).selectedProperties(selectedProperties).selectedLinks(
          selectedNavigationProperties).build();

  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).expandSelectTree(expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties", xml);
  assertXpathExists("/a:entry/a:link[@type]", xml);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:22,代码来源:ExpandSelectProducerWithBuilderTest.java

示例5: expandBuilding

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void expandBuilding() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> expandedNavigationProperties = new ArrayList<String>();
  expandedNavigationProperties.add("nr_Building");

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).expandedLinks(expandedNavigationProperties).build();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new LocalCallback());
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).callbacks(callbacks).expandSelectTree(
          expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties", xml);
  assertXpathExists("/a:entry/a:link[@type]/m:inline", xml);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ExpandSelectProducerWithBuilderTest.java

示例6: expandBuildingAndSelectIdFromRoom

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void expandBuildingAndSelectIdFromRoom() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> expandedNavigationProperties = new ArrayList<String>();
  expandedNavigationProperties.add("nr_Building");

  List<String> selectedProperties = new ArrayList<String>();
  selectedProperties.add("Id");

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).selectedProperties(selectedProperties).expandedLinks(
          expandedNavigationProperties).build();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new LocalCallback());
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).callbacks(callbacks).expandSelectTree(
          expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties/d:Id", xml);
  assertXpathNotExists("/a:entry/a:content/m:properties/d:Name", xml);
  assertXpathExists("/a:entry/a:link[@type]/m:inline", xml);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:26,代码来源:ExpandSelectProducerWithBuilderTest.java

示例7: readEntity

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build();

  // query
  final String mappedKeyName =
      (String) uriInfo.getTargetEntitySet().getEntityType().getKeyProperties().get(0).getMapping().getObject();
  final String keyValue = uriInfo.getKeyPredicates().get(0).getLiteral();
  final int index = indexOf(mappedKeyName, keyValue);
  if ((index < 0) || (index > records.size())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY.addContent(keyValue));
  }
  final HashMap<String, String> record = records.get(index);

  final HashMap<String, Object> data = new HashMap<String, Object>();
  for (final String pName : uriInfo.getTargetEntitySet().getEntityType().getPropertyNames()) {
    final EdmProperty property = (EdmProperty) uriInfo.getTargetEntitySet().getEntityType().getProperty(pName);
    final String mappedPropertyName = (String) property.getMapping().getObject();
    data.put(pName, record.get(mappedPropertyName));
  }

  final ODataResponse response =
      EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), data, properties);
  return response;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:27,代码来源:MapProcessor.java

示例8: readEntity

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Override
public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
  HashMap<String, Object> data = new HashMap<String, Object>();

  if ("Employees".equals(uriInfo.getTargetEntitySet().getName())) {
    if ("2".equals(uriInfo.getKeyPredicates().get(0).getLiteral())) {
      data.put("EmployeeId", "1");
      data.put("TeamId", "420");
    }

    ODataContext context = getContext();
    EntityProviderWriteProperties writeProperties =
        EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).build();

    return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), data, writeProperties);
  } else {
    throw new ODataApplicationException("Wrong testcall", Locale.getDefault(), HttpStatusCodes.NOT_IMPLEMENTED);
  }
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:InvalidDataInScenarioTest.java

示例9: readEntity

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Override
public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
  String filterID = uriInfo.getKeyPredicates().get(0).getLiteral();
  SearchRequest filter = filterManager.getSearchRequestById(Long.parseLong(filterID));

  switch (uriInfo.getNavigationSegments().size()) {
    case 0:
      ODataFilter oDataFilter = new ODataFilter(filter, serviceRoot);
      return EntityProvider.writeEntry(contentType, uriInfo.getStartEntitySet(), oDataFilter.getOData(), propertiesBuilder.build());
  }

  throw new ODataNotImplementedException();
}
 
开发者ID:SAP,项目名称:SAPJamWorkPatternJIRAIntegration,代码行数:14,代码来源:FilterProcessor.java

示例10: readEntity

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Override
public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException
{
	String issueKey = uriInfo.getKeyPredicates().get(0).getLiteral();
	Issue issue = issueManager.getIssueObject(issueKey);

	switch (uriInfo.getNavigationSegments().size()) {
	case 0:
		ODataIssue odataIssue = new ODataIssue(issue, serviceRoot);
		return EntityProvider.writeEntry(contentType, uriInfo.getStartEntitySet(), odataIssue.getOData(), propertiesBuilder.build());
	}
	throw new ODataNotImplementedException();
}
 
开发者ID:SAP,项目名称:SAPJamWorkPatternJIRAIntegration,代码行数:14,代码来源:IssueProcessor.java

示例11: customExpandBuildingAndSelectIdFromCustomNode

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void customExpandBuildingAndSelectIdFromCustomNode() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");

  List<String> selectedPropertiesAtCustomProperties = new ArrayList<String>();
  selectedPropertiesAtCustomProperties.add("Id");
  EdmEntitySet buildingsSet =
      roomsSet.getRelatedEntitySet((EdmNavigationProperty) roomsSet.getEntityType().getProperty("nr_Building"));
  ExpandSelectTreeNode customNode =
      ExpandSelectTreeNode.entitySet(buildingsSet).selectedProperties(selectedPropertiesAtCustomProperties).build();

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).customExpandedLink("nr_Building", customNode).build();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new LocalCallback());
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).callbacks(callbacks).expandSelectTree(
          expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties", xml);
  assertXpathExists("/a:entry/a:link[@type]/m:inline", xml);
  assertXpathExists("/a:entry/a:link[@type]/m:inline/a:entry/a:content/m:properties/d:Id", xml);
  assertXpathNotExists("/a:entry/a:link[@type]/m:inline/a:entry/a:content/m:properties/d:Name", xml);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:28,代码来源:ExpandSelectProducerWithBuilderTest.java

示例12: execute

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
private Map<String, Object> execute(final Map<String, Object> localRoomData, final EdmEntitySet roomSet,
    final String contentType)
    throws EntityProviderException {
  ODataResponse response = EntityProvider.writeEntry(contentType, roomSet, localRoomData, DEFAULT_WRITE_PROPERTIES);
  InputStream content = (InputStream) response.getEntity();

  ODataEntry entry = EntityProvider.readEntry(contentType, roomSet, content, DEFAULT_READ_PROPERTIES);
  Map<String, Object> properties = entry.getProperties();
  return properties;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:11,代码来源:ProducerConsumerIntegrationTest.java

示例13: readEntity

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Override
public ODataResponse readEntity(GetEntityUriInfo uri_info, String content_type)
      throws ODataException
{
   EdmEntitySet targetES = uri_info.getTargetEntitySet();
   AbstractEntitySet<?> target = Model.getEntitySet(targetES.getName());

   // Validity and security checks.
   if (!target.isAuthorized(Security.getCurrentUser()))
   {
      throw new NotAllowedException();
   }

   // Contained target workaround (non OData2: non standard!)
   int last_id = getContext().getPathInfo().getODataSegments().size() - 1;
   String navlinkname = getContext().getPathInfo().getODataSegments().get(last_id).getPath();
   // remove the key
   last_id = navlinkname.indexOf('(');
   if (last_id != -1)
   {
      navlinkname = navlinkname.substring(0, last_id);
   }
   if (!navlinkname.equals(targetES.getName()))
   {
      targetES = new ContainedEntitySetDecorator(navlinkname, targetES);
   }

   // Navigate to target Entity
   KeyPredicate startKP = uri_info.getKeyPredicates().get(0);
   AbstractEntity entity = Navigator.<AbstractEntity>navigate(
         uri_info.getStartEntitySet(), startKP, uri_info.getNavigationSegments(), null);

   // handle custom formats (metalink, csv)
   if(uri_info.getFormat() != null)
   {
      if (uri_info.getFormat().equals(CsvFormatter.CONTENT_TYPE))
      {
         return CsvFormatter.writeFeed(targetES, Collections.singleton(entity), uri_info.getSelect());
      }
      if (uri_info.getFormat().equals(MetalinkBuilder.CONTENT_TYPE))
      {
         return MetalinkFormatter.writeFeed(targetES, Collections.singleton(entity), makeLink().toString());
      }
   }

   Map<String, Object> data = entity.toEntityResponse(makeLink().toString());

   // $expand & $select
   ExpandSelectTreeNode expand_select_tree =
         UriParser.createExpandSelectTree(uri_info.getSelect(), uri_info.getExpand());

   EntityProviderWriteProperties prop = EntityProviderWriteProperties
         .serviceRoot(makeLink())
         .expandSelectTree(expand_select_tree)
         .callbacks(makeCallbacks(
               entity.getExpandableNavLinkNames(),
               new Expander(makeLink(false), entity)))
         .build();

   return EntityProvider.writeEntry(content_type, targetES, data, prop);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:62,代码来源:Processor.java

示例14: writeContent

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
private ODataResponse writeContent(Edm edm, UriInfoWithType uriInfo, Object content)
    throws ODataApplicationException, EdmException, EntityProviderException, URISyntaxException, IOException {

    String responseContentType = getContentType();
    ODataResponse response;

    switch (uriInfo.getUriType()) {
    case URI4:
    case URI5:
        // simple property
        final List<EdmProperty> simplePropertyPath = uriInfo.getPropertyPath();
        final EdmProperty simpleProperty = simplePropertyPath.get(simplePropertyPath.size() - 1);
        responseContentType = simpleProperty.getMimeType();
        if (uriInfo.isValue()) {
            response = EntityProvider.writePropertyValue(simpleProperty, content);
            responseContentType = TEXT_PLAIN_WITH_CS_UTF_8.toString();
        } else {
            response = EntityProvider.writeProperty(getContentType(), simpleProperty, content);
        }
        break;

    case URI3:
        // complex property
        final List<EdmProperty> complexPropertyPath = uriInfo.getPropertyPath();
        final EdmProperty complexProperty = complexPropertyPath.get(complexPropertyPath.size() - 1);
        response = EntityProvider.writeProperty(responseContentType, complexProperty, content);
        break;

    case URI7A:
        // $links with 0..1 cardinality property
        final EdmEntitySet targetLinkEntitySet = uriInfo.getTargetEntitySet();
        EntityProviderWriteProperties linkProperties =
            EntityProviderWriteProperties.serviceRoot(new URI(serviceUri + SEPARATOR)).build();
        @SuppressWarnings("unchecked")
        final Map<String, Object> linkMap = (Map<String, Object>) content;
        response = EntityProvider.writeLink(responseContentType, targetLinkEntitySet, linkMap, linkProperties);
        break;

    case URI7B:
        // $links with * cardinality property
        final EdmEntitySet targetLinksEntitySet = uriInfo.getTargetEntitySet();
        EntityProviderWriteProperties linksProperties =
            EntityProviderWriteProperties.serviceRoot(new URI(serviceUri + SEPARATOR)).build();
        @SuppressWarnings("unchecked")
        final List<Map<String, Object>> linksMap = (List<Map<String, Object>>) content;
        response = EntityProvider.writeLinks(responseContentType, targetLinksEntitySet, linksMap, linksProperties);
        break;

    case URI1:
    case URI2:
    case URI6A:
    case URI6B:
        // Entity
        final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
        EntityProviderWriteProperties properties =
            EntityProviderWriteProperties.serviceRoot(new URI(serviceUri + SEPARATOR)).build();
        @SuppressWarnings("unchecked")
        final Map<String, Object> objectMap = (Map<String, Object>) content;
        response = EntityProvider.writeEntry(responseContentType, targetEntitySet, objectMap, properties);
        break;

    case URI9:
        // $batch
        @SuppressWarnings("unchecked")
        final List<Olingo2BatchRequest> batchParts = (List<Olingo2BatchRequest>) content;
        response = parseBatchRequest(edm, batchParts);
        break;

    default:
        // notify exception and return!!!
        throw new ODataApplicationException("Unsupported resource type " + uriInfo.getTargetType(),
            Locale.ENGLISH);
    }

    return response.getContentHeader() != null ? response
        : ODataResponse.fromResponse(response).contentHeader(responseContentType).build();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:78,代码来源:Olingo2AppImpl.java

示例15: readEntity

import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Override
public ODataResponse readEntity(GetEntityUriInfo uri_info, String content_type)
      throws ODataException
{
   EdmEntitySet targetES = uri_info.getTargetEntitySet();
   AbstractEntitySet target = Model.getEntitySet(targetES.getName());

   // Validity and security checks.
   if (!target.isAuthorized(Security.getCurrentUser()))
   {
      throw new NotAllowedException();
   }

   // Contained target workaround (non OData2: non standard!)
   int last_id = getContext().getPathInfo().getODataSegments().size() - 1;
   String navlinkname = getContext().getPathInfo().getODataSegments().get(last_id).getPath();
   // remove the key
   last_id = navlinkname.indexOf('(');
   if (last_id != -1)
   {
      navlinkname = navlinkname.substring(0, last_id);
   }
   if (!navlinkname.equals(targetES.getName()))
   {
      targetES = new ContainedEntitySetDecorator(navlinkname, targetES);
   }

   // Navigate to target Entity
   KeyPredicate startKP = uri_info.getKeyPredicates().get(0);
   AbstractEntity entity = Navigator.<AbstractEntity>navigate(
         uri_info.getStartEntitySet(), startKP, uri_info.getNavigationSegments(), null);
   Map<String, Object> data = entity.toEntityResponse(makeLink().toString());

   // $expand & $select
   ExpandSelectTreeNode expand_select_tree =
         UriParser.createExpandSelectTree(uri_info.getSelect(), uri_info.getExpand());

   EntityProviderWriteProperties prop = EntityProviderWriteProperties
         .serviceRoot(makeLink())
         .expandSelectTree(expand_select_tree)
         .callbacks(makeCallbacks(
               entity.getExpandableNavLinkNames(),
               new Expander(makeLink(false), entity)))
         .build();

   return EntityProvider.writeEntry(content_type, targetES, data, prop);
}
 
开发者ID:SentinelDataHub,项目名称:DataHubSystem,代码行数:48,代码来源:Processor.java


注:本文中的org.apache.olingo.odata2.api.ep.EntityProvider.writeEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。