本文整理汇总了Java中org.apache.olingo.server.api.ODataApplicationException类的典型用法代码示例。如果您正苦于以下问题:Java ODataApplicationException类的具体用法?Java ODataApplicationException怎么用?Java ODataApplicationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataApplicationException类属于org.apache.olingo.server.api包,在下文中一共展示了ODataApplicationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeRequest
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
/**
* Execute query request with filter and aggregations.
*
* @param query
* search query
* @return ES search response
* @throws ODataApplicationException
* if any error appeared during executing request
*/
public SearchResponse executeRequest(SearchQuery query) throws ODataApplicationException {
Pagination pagination = query.getPagination();
SearchRequestBuilder requestBuilder = client.prepareSearch(query.getIndex())
.setTypes(query.getTypes()).setQuery(query.getQueryBuilder());
if (pagination != null) {
List<Sort> orderBy = pagination.getOrderBy();
for (Sort sort : orderBy) {
FieldSortBuilder sortQuery = SortBuilders.fieldSort(sort.getProperty())
.order(SortOrder.valueOf(sort.getDirection().toString()));
requestBuilder.addSort(sortQuery);
}
requestBuilder.setSize(pagination.getTop()).setFrom(pagination.getSkip());
}
Set<String> fields = query.getFields();
if (fields != null && !fields.isEmpty()) {
requestBuilder.setFetchSource(fields.toArray(new String[fields.size()]), null);
}
return executeRequest(requestBuilder);
}
示例2: list
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
/**
* Reads multiple instances of an Entity Type.
*
* @param entitySet
* Entity Set to read from
* @param uriInfo
* contains filter, order by and paging arguments
* @return entities
* @throws ODataApplicationException
* if error occurred handling filter option
*/
public EntityCollection list(EdmEntitySet entitySet, UriInfo uriInfo)
throws ODataApplicationException {
SearchRequestBuilder searchRequest = elasticsearchTemplate.getClient()
.prepareSearch(toIndexName(entitySet))
.setTypes(toTypeName(entitySet))
.setQuery(toQueryBuilder(uriInfo.getFilterOption()));
configureSorting(uriInfo, searchRequest);
configurePaging(uriInfo, searchRequest);
SearchResponse response = searchRequest.execute().actionGet();
EntityCollection entityCollection = new EntityCollection();
List<Entity> entities = entityCollection.getEntities();
response.getHits().forEach(hit -> {
Entity entity = toEntity(entitySet, hit.getId(), hit.getSource());
entities.add(entity);
});
return entityCollection;
}
示例3: updateReference
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public void updateReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat) throws ODataApplicationException, ODataLibraryException {
// 1. Retrieve the entity type from the URI
// EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
// EdmEntityType edmEntityType = edmEntitySet.getEntityType();
// 2. create the data in backend
// 2.1. retrieve the payload from the POST request for the entity to create and deserialize it
InputStream requestInputStream = request.getBody();
ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
DeserializerResult result = deserializer.entityReferences(requestInputStream);
List<URI> requestEntityReferences = result.getEntityReferences();
// 2.2 do the creation in backend,
try {
SparqlBaseCommand.updateEntityReference(rdfEdmProvider, uriInfo, requestEntityReferences);
} catch (EdmException | OData2SparqlException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize the response
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例4: deleteReference
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public void deleteReference(ODataRequest request, ODataResponse response, UriInfo uriInfo)
throws ODataApplicationException, ODataLibraryException {
// 1. Retrieve the entity type from the URI
// EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
// EdmEntityType edmEntityType = edmEntitySet.getEntityType();
try {
SparqlBaseCommand.deleteEntityReference(rdfEdmProvider, uriInfo);
} catch (EdmException | OData2SparqlException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize the response
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例5: readReferenceCollection
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
static public EntityCollection readReferenceCollection(RdfEdmProvider rdfEdmProvider, UriInfo uriInfo,
UriType uriType) throws OData2SparqlException, EdmException, ODataApplicationException, ExpressionVisitException {
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
RdfEntityType rdfEntityType = null;
EdmEntitySet edmEntitySet = null;
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
edmEntitySet = uriResourceEntitySet.getEntitySet();
rdfEntityType = rdfEdmProvider.getRdfEntityTypefromEdmEntitySet(edmEntitySet);
SparqlQueryBuilder sparqlBuilder = new SparqlQueryBuilder(rdfEdmProvider.getRdfModel(),
rdfEdmProvider.getEdmMetadata(), uriInfo, uriType);
//prepareQuery
SparqlStatement sparqlStatement = sparqlBuilder.prepareEntityLinksSparql();
SparqlEntityCollection rdfResults = sparqlStatement.executeConstruct(rdfEdmProvider, rdfEntityType, null, null);
if (rdfResults == null) {
throw new ODataApplicationException("No results", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
Locale.ENGLISH);
} else {
return rdfResults;
}
}
示例6: writeEntity
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
public static Entity writeEntity(RdfEdmProvider rdfEdmProvider, UriInfo uriInfo, Entity requestEntity)
throws OData2SparqlException, ODataApplicationException {
SparqlStatement sparqlStatement = null;
EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
RdfEntityType entityType = rdfEdmProvider.getRdfEntityTypefromEdmEntitySet(edmEntitySet);
SparqlCreateUpdateDeleteBuilder sparqlCreateUpdateDeleteBuilder = new SparqlCreateUpdateDeleteBuilder(
rdfEdmProvider);
try {
sparqlStatement = sparqlCreateUpdateDeleteBuilder.generateInsertEntity(entityType, requestEntity);
} catch (Exception e) {
log.error(e.getMessage());
throw new OData2SparqlException(e.getMessage());
}
sparqlStatement.executeInsert(rdfEdmProvider);
return requestEntity;
}
示例7: read
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
/**
* Method is a template to provide behavior for all read processors.
*/
@Override
public void read(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
this.request = request;
ESRequest searchRequest = createRequest(uriInfo);
ElasticEdmEntitySet entitySet = searchRequest.getEntitySet();
SearchResponse searchResponse = searchRequest.execute();
InstanceData<T, V> data = parseResponse(searchResponse, entitySet);
ODataSerializer serializer = odata.createSerializer(responseFormat);
SerializerResult serializerResult = serialize(serializer, data, entitySet, uriInfo);
response.setContent(serializerResult.getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
示例8: visitMethodCall
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public ExpressionMember visitMethodCall(MethodKind methodCall,
List<ExpressionMember> parameters)
throws ExpressionVisitException, ODataApplicationException {
switch (methodCall) {
case CONTAINS:
return parameters.get(0).contains(parameters.get(1));
case STARTSWITH:
return parameters.get(0).startsWith(parameters.get(1));
case ENDSWITH:
return parameters.get(0).endsWith(parameters.get(1));
case DATE:
return parameters.get(0).date();
default:
return throwNotImplemented(
String.format("Method call %s is not implemented", methodCall));
}
}
示例9: getEqQuery
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
/**
* Gets query for equals and not equals operations.
*
* @param expressionMember
* member with value
* @return appropriate query
* @throws ODataApplicationException
* if any error occurred during creating query
*/
protected QueryBuilder getEqQuery(ExpressionMember expressionMember)
throws ODataApplicationException {
Object value = ((LiteralMember) expressionMember).getValue();
if (getField().equals(ID_FIELD_NAME)) {
if (value == null) {
throw new ODataApplicationException("Id value can not be null",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
return idsQuery().addIds(value.toString());
} else {
String fieldName = addKeywordIfNeeded(getField(), getAnnotations());
if (value == null) {
return boolQuery().mustNot(existsQuery(fieldName));
} else {
return termQuery(fieldName, value);
}
}
}
示例10: visitLiteral
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public Object visitLiteral(Literal literal) throws ExpressionVisitException, ODataApplicationException {
String literalAsString = literal.getText();
if(literal.getType() instanceof EdmString) {
String stringLiteral = "";
if (literal.getText().length() > 2) {
stringLiteral = literalAsString.substring(1, literalAsString.length() - 1);
}
return stringLiteral;
}
else {
try {
return Integer.parseInt(literalAsString);
} catch (NumberFormatException e) {
throw new ODataApplicationException("Only Edm.Int32 and Edm.String literals are implemented", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}
}
示例11: readEntity
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public void readEntity(
ODataRequest request,
ODataResponse response,
UriInfo uriInfo,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
// First path segment is Entity Set.
List<UriResource> resourceParts = uriInfo.getUriResourceParts();
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourceParts.get(0);
EdmEntitySet entitySet = uriResourceEntitySet.getEntitySet();
List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
// Retrieve entity from backend.
Entity entity = entityRepository.read(entitySet, keyPredicates);
// Serialize to response format.
ContextURL contextUrl = ContextURL.with()
.entitySet(entitySet)
.suffix(ContextURL.Suffix.ENTITY)
.build();
EntitySerializerOptions options = EntitySerializerOptions.with()
.contextURL(contextUrl)
.build();
ODataSerializer serializer = odata.createSerializer(responseFormat);
SerializerResult serializerResult = serializer.entity(
serviceMetadata, entitySet.getEntityType(), entity, options);
// Set response attributes.
response.setContent(serializerResult.getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
示例12: createEntity
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public void createEntity(
ODataRequest request,
ODataResponse response,
UriInfo uriInfo,
ContentType requestFormat,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
throw new NotImplementedException("createEntity not implemented");
}
示例13: updateEntity
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public void updateEntity(
ODataRequest request,
ODataResponse response,
UriInfo uriInfo,
ContentType requestFormat,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
throw new NotImplementedException("updateEntity not implemented");
}
示例14: deleteEntity
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public void deleteEntity(
ODataRequest request,
ODataResponse response,
UriInfo uriInfo) throws ODataApplicationException, ODataLibraryException {
throw new NotImplementedException("deleteEntity not implemented");
}
示例15: visitBinaryOperator
import org.apache.olingo.server.api.ODataApplicationException; //导入依赖的package包/类
@Override
public Object visitBinaryOperator(
BinaryOperatorKind operator,
Object left,
Object right) throws ExpressionVisitException, ODataApplicationException {
switch (operator) {
case AND:
return and((QueryBuilder) left, (QueryBuilder) right);
case EQ:
return eq((String) left, right);
case GE:
return ge((String) left, right);
case GT:
return gt((String) left, right);
case LE:
return le((String) left, right);
case LT:
return lt((String) left, right);
case NE:
return ne((String) left, right);
case OR:
return or((QueryBuilder) left, (QueryBuilder) right);
default:
throw new NotImplementedException("Binary operator " + operator + " not implemented");
}
}