本文整理汇总了Java中org.apache.olingo.odata2.api.ep.EntityProvider类的典型用法代码示例。如果您正苦于以下问题:Java EntityProvider类的具体用法?Java EntityProvider怎么用?Java EntityProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityProvider类属于org.apache.olingo.odata2.api.ep包,在下文中一共展示了EntityProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeFunctionImport
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
@Override
public ODataResponse executeFunctionImport(GetFunctionImportUriInfo uri_info, String content_type)
throws ODataException
{
EdmFunctionImport function_import = uri_info.getFunctionImport();
Map<String, EdmLiteral> params = uri_info.getFunctionImportParameters();
EntityProviderWriteProperties entry_props =
EntityProviderWriteProperties.serviceRoot(makeLink()).build();
AbstractOperation op = Model.getServiceOperation(function_import.getName());
fr.gael.dhus.database.object.User current_user =
ApplicationContextProvider.getBean(SecurityService.class).getCurrentUser();
if (!op.canExecute(current_user))
{
throw new NotAllowedException();
}
Object res = op.execute(params);
return EntityProvider.writeFunctionImport(content_type, function_import, res, entry_props);
}
示例2: readFeed
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
/**
* Reads a feed (the content of an EntitySet).
*
* @param resource_path the resource path to the parent of the requested
* EntitySet, as defined in {@link #getResourcePath(URI)}.
* @param query_parameters Query parameters, as defined in {@link URI}.
*
* @return an ODataFeed containing the ODataEntries for the given
* {@code resource_path}.
*
* @throws HttpException if the server emits an HTTP error code.
* @throws IOException if the connection with the remote service fails.
* @throws EdmException if the EDM does not contain the given entitySetName.
* @throws EntityProviderException if reading of data (de-serialization)
* fails.
* @throws UriSyntaxException violation of the OData URI construction rules.
* @throws UriNotMatchingException URI parsing exception.
* @throws ODataException encapsulate the OData exceptions described above.
* @throws InterruptedException if running thread has been interrupted.
*/
public ODataFeed readFeed(String resource_path,
Map<String, String> query_parameters) throws IOException, ODataException, InterruptedException
{
if (resource_path == null || resource_path.isEmpty ())
throw new IllegalArgumentException (
"resource_path must not be null or empty.");
ContentType contentType = ContentType.APPLICATION_ATOM_XML;
String absolutUri = serviceRoot.toString () + '/' + resource_path;
// Builds the query parameters string part of the URL.
absolutUri = appendQueryParam (absolutUri, query_parameters);
InputStream content = execute (absolutUri, contentType, "GET");
return EntityProvider.readFeed (contentType.type (),
getEntitySet (resource_path), content,
EntityProviderReadProperties.init ().build ());
}
示例3: readEntry
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
/**
* Reads an entry (an Entity, a property, a complexType, ...).
*
* @param resource_path the resource path to the parent of the requested
* EntitySet, as defined in {@link #getResourcePath(URI)}.
* @param query_parameters Query parameters, as defined in {@link URI}.
*
* @return an ODataEntry for the given {@code resource_path}.
*
* @throws HttpException if the server emits an HTTP error code.
* @throws IOException if the connection with the remote service fails.
* @throws EdmException if the EDM does not contain the given entitySetName.
* @throws EntityProviderException if reading of data (de-serialization)
* fails.
* @throws UriSyntaxException violation of the OData URI construction rules.
* @throws UriNotMatchingException URI parsing exception.
* @throws ODataException encapsulate the OData exceptions described above.
* @throws InterruptedException if running thread has been interrupted.
*/
public ODataEntry readEntry(String resource_path,
Map<String, String> query_parameters) throws IOException, ODataException, InterruptedException
{
if (resource_path == null || resource_path.isEmpty ())
throw new IllegalArgumentException (
"resource_path must not be null or empty.");
ContentType contentType = ContentType.APPLICATION_ATOM_XML;
String absolutUri = serviceRoot.toString () + '/' + resource_path;
// Builds the query parameters string part of the URL.
absolutUri = appendQueryParam (absolutUri, query_parameters);
InputStream content = execute (absolutUri, contentType, "GET");
return EntityProvider.readEntry(contentType.type (),
getEntitySet (resource_path), content,
EntityProviderReadProperties.init ().build ());
}
示例4: readEdm
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
private Edm readEdm() throws EntityProviderException,
IllegalStateException, IOException {
// This is used for both setting the Edm and CSRF Token :)
if (m_edm != null) {
return m_edm;
}
String serviceUrl = new StringBuilder(getODataServiceUrl())
.append(SEPARATOR).append(METADATA).toString();
logger.info("Metadata url => " + serviceUrl);
final HttpGet get = new HttpGet(serviceUrl);
get.setHeader(AUTHORIZATION_HEADER, getAuthorizationHeader());
get.setHeader(CSRF_TOKEN_HEADER, CSRF_TOKEN_FETCH);
HttpResponse response = getHttpClient().execute(get);
m_csrfToken = response.getFirstHeader(CSRF_TOKEN_HEADER).getValue();
logger.info("CSRF token => " + m_csrfToken);
m_edm = EntityProvider.readMetadata(response.getEntity().getContent(),
false);
return m_edm;
}
示例5: readEntry
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
public ODataEntry readEntry(String serviceUri, String contentType,
String entitySetName, String keyValue, SystemQueryOptions options)
throws IllegalStateException, IOException, EdmException,
EntityProviderException {
EdmEntityContainer entityContainer = readEdm()
.getDefaultEntityContainer();
logger.info("Entity container is => " + entityContainer.getName());
String absolutUri = createUri(serviceUri, entitySetName, keyValue,
options);
InputStream content = executeGet(absolutUri, contentType);
return EntityProvider.readEntry(contentType,
entityContainer.getEntitySet(entitySetName), content,
EntityProviderReadProperties.init().build());
}
示例6: readEntityMedia
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
@Override
public ODataResponse readEntityMedia(final GetMediaResourceUriInfo uriInfo, final String contentType)
throws ODataException {
final Object data = retrieveData(
uriInfo.getStartEntitySet(),
uriInfo.getKeyPredicates(),
uriInfo.getFunctionImport(),
mapFunctionParameters(uriInfo.getFunctionImportParameters()),
uriInfo.getNavigationSegments());
if (!appliesFilter(data, uriInfo.getFilter())) {
throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
}
final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
final BinaryData binaryData = dataSource.readBinaryData(entitySet, data);
if (binaryData == null) {
throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
}
final String mimeType = binaryData.getMimeType() == null ?
HttpContentType.APPLICATION_OCTET_STREAM : binaryData.getMimeType();
return ODataResponse.fromResponse(EntityProvider.writeBinary(mimeType, binaryData.getData())).eTag(
constructETag(entitySet, data)).build();
}
示例7: updateEntityMedia
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
@Override
public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
final String requestContentType, final String contentType) throws ODataException {
final Object data = retrieveData(
uriInfo.getStartEntitySet(),
uriInfo.getKeyPredicates(),
uriInfo.getFunctionImport(),
mapFunctionParameters(uriInfo.getFunctionImportParameters()),
uriInfo.getNavigationSegments());
if (!appliesFilter(data, uriInfo.getFilter())) {
throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
}
ODataContext context = getContext();
final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");
final byte[] value = EntityProvider.readBinary(content);
context.stopRuntimeMeasurement(timingHandle);
final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));
return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
示例8: simpleBatchWithAbsoluteUri
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
@Test
public void simpleBatchWithAbsoluteUri() throws Exception {
final String batchRequestBody = StringHelper.inputStreamToStringCRLFLineBreaks(
EntityProvider.writeBatchRequest(
Collections.<BatchPart> singletonList(
BatchQueryPart
.method(ODataHttpMethod.GET.name())
.uri(getEndpoint().getPath() + "Employees('2')/EmployeeName/$value")
.build()),
BOUNDARY));
final HttpResponse batchResponse = execute(batchRequestBody);
final List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(
batchResponse.getEntity().getContent(),
batchResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
assertEquals(1, responses.size());
final BatchSingleResponse response = responses.get(0);
assertEquals(Integer.toString(HttpStatusCodes.OK.getStatusCode()), response.getStatusCode());
assertEquals(HttpStatusCodes.OK.getInfo(), response.getStatusInfo());
assertEquals(EMPLOYEE_2_NAME, response.getBody());
assertEquals(HttpContentType.TEXT_PLAIN_UTF8, response.getHeader(HttpHeaders.CONTENT_TYPE));
assertNotNull(response.getHeader(HttpHeaders.CONTENT_LENGTH));
}
示例9: parseEntry
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
ODataContext context = getContext();
final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");
ODataEntry entryValues;
try {
entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
} catch (final EntityProviderException e) {
throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
}
context.stopRuntimeMeasurement(timingHandle);
return entryValues;
}
示例10: parseLink
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
public final UriInfo parseLink(final EdmEntitySet entitySet, final InputStream content, final String contentType)
throws ODataJPARuntimeException {
String uriString = null;
UriInfo uri = null;
try {
uriString = EntityProvider.readLink(contentType, entitySet, content);
ODataContext odataContext = context.getODataContext();
final String svcRoot = odataContext.getPathInfo().getServiceRoot().toString();
final String path =
uriString.startsWith(svcRoot.toString()) ? uriString.substring(svcRoot.length()) : uriString;
final List<PathSegment> pathSegment = getPathSegment(path);
edm = getEdm();
uri = UriParser.parse(edm, pathSegment, Collections.<String, String> emptyMap());
} catch (ODataException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
}
return uri;
}
示例11: executeBatch
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入依赖的package包/类
@Override
public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
throws ODataException {
try {
oDataJPAContext.setODataContext(getContext());
ODataResponse batchResponse;
List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
PathInfo pathInfo = getContext().getPathInfo();
EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
for (BatchRequestPart batchPart : batchParts) {
batchResponseParts.add(handler.handleBatchPart(batchPart));
}
batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
return batchResponse;
} finally {
close(true);
}
}
示例12: 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);
}
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}