本文整理汇总了Java中org.apache.olingo.commons.api.http.HttpStatusCode.BAD_REQUEST属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCode.BAD_REQUEST属性的具体用法?Java HttpStatusCode.BAD_REQUEST怎么用?Java HttpStatusCode.BAD_REQUEST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.olingo.commons.api.http.HttpStatusCode
的用法示例。
在下文中一共展示了HttpStatusCode.BAD_REQUEST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntityByReference
protected Entity getEntityByReference(final String entityId, final String rawServiceRoot)
throws DataProviderException {
try {
final UriResourceEntitySet uriResource =
odata.createUriHelper().parseEntityId(edm, entityId, rawServiceRoot);
final Entity targetEntity = read(uriResource.getEntitySet(), uriResource.getKeyPredicates());
if (targetEntity != null) {
return targetEntity;
} else {
throw new DataProviderException("Entity not found", HttpStatusCode.NOT_FOUND);
}
} catch (DeserializerException e) {
throw new DataProviderException("Invalid entity-id", HttpStatusCode.BAD_REQUEST);
}
}
示例2: validateProperties
private void validateProperties(final List<Property> properties, final EdmBindingTarget edmBindingTarget,
final EdmStructuredType edmType, final List<String> keyPredicateNames, final List<String> path)
throws DataProviderException {
for (final String propertyName : edmType.getPropertyNames()) {
final EdmProperty edmProperty = (EdmProperty) edmType.getProperty(propertyName);
// Ignore key properties, they are set automatically
if (!keyPredicateNames.contains(propertyName)) {
final Property property = getProperty(properties, propertyName);
// Check if all "not nullable" properties are set
if (!edmProperty.isNullable()) {
if ((property != null && property.isNull()) // Update,insert; Property is explicit set to null
|| (isInsert && property == null) // Insert; Property not provided
|| (!isInsert && !isPatch && property == null)) { // Insert(Put); Property not provided
throw new DataProviderException("Property " + propertyName + " must not be null",
HttpStatusCode.BAD_REQUEST);
}
}
// Validate property value
validatePropertyValue(property, edmProperty, edmBindingTarget, path);
}
}
}
示例3: getFunctionParameters
private Map<String, Parameter> getFunctionParameters(final EdmFunction function,
final List<UriParameter> parameters, final UriInfoResource uriInfo) throws DataProviderException {
Map<String, Parameter> values = new HashMap<String, Parameter>();
for (final UriParameter parameter : parameters) {
if (parameter.getExpression() != null && !(parameter.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in function-parameter value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final EdmParameter edmParameter = function.getParameter(parameter.getName());
final String text = parameter.getAlias() == null ?
parameter.getText() :
uriInfo.getValueForAlias(parameter.getAlias());
if (text != null) {
try {
values.put(parameter.getName(),
odata.createFixedFormatDeserializer().parameter(text, edmParameter));
} catch (final DeserializerException e) {
throw new DataProviderException("Invalid function parameter.", HttpStatusCode.BAD_REQUEST, e);
}
}
}
return values;
}
示例4: primitiveCollectionBoundAction
protected static Property primitiveCollectionBoundAction(final String name, final Map<String, Parameter> parameters,
final Map<String, EntityCollection> data,
EdmEntitySet edmEntitySet, List<UriParameter> keyList, final OData oData) throws DataProviderException {
List<Object> collectionValues = new ArrayList<Object>();
if ("BAETTwoPrimRTCollString".equals(name)) {
EdmPrimitiveType strType = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String);
try {
String strValue1 = strType.valueToString("ABC", false, 100, null, null, false);
collectionValues.add(strValue1);
String strValue2 = strType.valueToString("XYZ", false, 100, null, null, false);
collectionValues.add(strValue2);
} catch (EdmPrimitiveTypeException e) {
throw new DataProviderException("EdmPrimitiveTypeException", HttpStatusCode.BAD_REQUEST, e);
}
return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, collectionValues);
}
throw new DataProviderException("Action " + name + " is not yet implemented.",
HttpStatusCode.NOT_IMPLEMENTED);
}
示例5: validateNavigationProperties
private void validateNavigationProperties(final Linked entity,
final EdmBindingTarget edmBindingTarget, final EdmStructuredType edmType,
final List<String> path) throws DataProviderException {
for (final String navPropertyName : edmType.getNavigationPropertyNames()) {
final EdmNavigationProperty edmProperty = edmType.getNavigationProperty(navPropertyName);
if (entity == null && !edmProperty.isNullable()) {
throw new DataProviderException(
"Navigation property " + navPropertyName + " must not be null",
HttpStatusCode.BAD_REQUEST);
} else if (entity != null) {
final Link navigationBinding = entity.getNavigationBinding(navPropertyName);
final Link navigationLink = entity.getNavigationLink(navPropertyName);
final List<String> newPath = new ArrayList<String>(path);
newPath.add(edmProperty.getName());
final EdmBindingTarget target =
edmBindingTarget.getRelatedBindingTarget(buildPath(newPath));
final ValidationResult bindingResult = validateBinding(navigationBinding, edmProperty);
final ValidationResult linkResult =
validateNavigationLink(navigationLink, edmProperty, target);
if ((isInsert && !edmProperty.isNullable()
&& (bindingResult != ValidationResult.FOUND && linkResult != ValidationResult.FOUND))
|| (!(isInsert && isPatch) && !edmProperty.isNullable()
&& linkResult == ValidationResult.EMPTY)) {
throw new DataProviderException(
"Navigation property " + navPropertyName + " must not be null",
HttpStatusCode.BAD_REQUEST);
}
}
}
}
示例6: validateNavigationLink
private ValidationResult validateNavigationLink(final Link navigationLink,
final EdmNavigationProperty edmProperty, final EdmBindingTarget edmBindingTarget)
throws DataProviderException {
if (navigationLink == null) {
return ValidationResult.NOT_FOUND;
}
if (edmProperty.isCollection()) {
final EntityCollection inlineEntitySet = navigationLink.getInlineEntitySet();
if (inlineEntitySet != null) {
if (!isInsert && inlineEntitySet.getEntities().size() > 0) {
throw new DataProvider.DataProviderException("Deep update is not allowed",
HttpStatusCode.BAD_REQUEST);
} else {
for (final Entity entity : navigationLink.getInlineEntitySet().getEntities()) {
validate(edmBindingTarget, entity);
}
}
}
} else {
final Entity inlineEntity = navigationLink.getInlineEntity();
if (!isInsert && inlineEntity != null) {
throw new DataProvider.DataProviderException("Deep update is not allowed",
HttpStatusCode.BAD_REQUEST);
} else if (inlineEntity != null) {
validate(edmBindingTarget, navigationLink.getInlineEntity());
}
}
return ValidationResult.FOUND;
}
示例7: validateProperties
private void validateProperties(final List<Property> properties,
final EdmBindingTarget edmBindingTarget, final EdmStructuredType edmType,
final List<String> keyPredicateNames, final List<String> path) throws DataProviderException {
for (final String propertyName : edmType.getPropertyNames()) {
final EdmProperty edmProperty = (EdmProperty) edmType.getProperty(propertyName);
// Ignore key properties, they are set automatically
if (!keyPredicateNames.contains(propertyName)) {
final Property property = getProperty(properties, propertyName);
// Check if all "not nullable" properties are set
if (!edmProperty.isNullable()) {
if ((property != null && property.isNull()) // Update,insert; Property is explicit set to
// null
|| (isInsert && property == null) // Insert; Property not provided
|| (!isInsert && !isPatch && property == null)) { // Insert(Put); Property not
// provided
throw new DataProviderException("Property " + propertyName + " must not be null",
HttpStatusCode.BAD_REQUEST);
}
}
// Validate property value
validatePropertyValue(property, edmProperty, edmBindingTarget, path);
}
}
}
示例8: validateNavigationProperties
private void validateNavigationProperties(final Linked entity, final EdmBindingTarget edmBindingTarget,
final EdmStructuredType edmType, final List<String> path) throws DataProviderException {
for (final String navPropertyName : edmType.getNavigationPropertyNames()) {
final EdmNavigationProperty edmProperty = edmType.getNavigationProperty(navPropertyName);
if (entity == null && !edmProperty.isNullable()) {
throw new DataProviderException("Navigation property " + navPropertyName + " must not be null",
HttpStatusCode.BAD_REQUEST);
} else if (entity != null) {
final Link navigationBinding = entity.getNavigationBinding(navPropertyName);
final Link navigationLink = entity.getNavigationLink(navPropertyName);
final List<String> newPath = new ArrayList<String>(path);
newPath.add(edmProperty.getName());
final EdmBindingTarget target = edmBindingTarget.getRelatedBindingTarget(buildPath(newPath));
final ValidationResult bindingResult = validateBinding(navigationBinding, edmProperty);
final ValidationResult linkResult = validateNavigationLink(navigationLink,
edmProperty,
target);
if ((isInsert && !edmProperty.isNullable()
&& (bindingResult != ValidationResult.FOUND
&& linkResult != ValidationResult.FOUND))
|| (!(isInsert && isPatch) && !edmProperty.isNullable() && linkResult == ValidationResult.EMPTY)) {
throw new DataProviderException("Navigation property " + navPropertyName + " must not be null",
HttpStatusCode.BAD_REQUEST);
}
}
}
}
示例9: validateNavigationLink
private ValidationResult validateNavigationLink(final Link navigationLink, final EdmNavigationProperty edmProperty,
final EdmBindingTarget edmBindingTarget) throws DataProviderException {
if (navigationLink == null) {
return ValidationResult.NOT_FOUND;
}
if (edmProperty.isCollection()) {
final EntityCollection inlineEntitySet = navigationLink.getInlineEntitySet();
if (inlineEntitySet != null) {
if (!isInsert && inlineEntitySet.getEntities().size() > 0) {
throw new DataProvider.DataProviderException("Deep update is not allowed", HttpStatusCode.BAD_REQUEST);
} else {
for (final Entity entity : navigationLink.getInlineEntitySet().getEntities()) {
validate(edmBindingTarget, entity);
}
}
}
} else {
final Entity inlineEntity = navigationLink.getInlineEntity();
if (!isInsert && inlineEntity != null) {
throw new DataProvider.DataProviderException("Deep update is not allowed", HttpStatusCode.BAD_REQUEST);
} else if (inlineEntity != null) {
validate(edmBindingTarget, navigationLink.getInlineEntity());
}
}
return ValidationResult.FOUND;
}
示例10: read
public Entity read(final EdmEntityType edmEntityType, final EntityCollection entitySet,
final List<UriParameter> keys) throws DataProviderException {
try {
for (final Entity entity : entitySet.getEntities()) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例11: updateProperty
@SuppressWarnings("unchecked")
public void updateProperty(final EdmProperty edmProperty, Property property, final Property newProperty,
final boolean patch) throws DataProviderException {
if(property == null){
throw new DataProviderException("Cannot update type of the entity",
HttpStatusCode.BAD_REQUEST);
}
final EdmType type = edmProperty.getType();
if (edmProperty.isCollection()) {
// Updating collection properties means replacing all entries with the given ones.
property.asCollection().clear();
if (newProperty != null) {
if (type.getKind() == EdmTypeKind.COMPLEX) {
// Create each complex value.
for (final ComplexValue complexValue : (List<ComplexValue>) newProperty.asCollection()) {
((List<ComplexValue>) property.asCollection()).add(createComplexValue(edmProperty, complexValue, patch));
}
} else {
// Primitive type
((List<Object>) property.asCollection()).addAll(newProperty.asCollection());
}
}
} else if (type.getKind() == EdmTypeKind.COMPLEX) {
for (final String propertyName : ((EdmComplexType) type).getPropertyNames()) {
final List<Property> newProperties = newProperty == null || newProperty.asComplex() == null ? null :
newProperty.asComplex().getValue();
updateProperty(((EdmComplexType) type).getStructuralProperty(propertyName),
findProperty(propertyName, property.asComplex().getValue()),
newProperties == null ? null : findProperty(propertyName, newProperties),
patch);
}
} else {
if (newProperty != null || !patch) {
final Object value = newProperty == null ? null : newProperty.getValue();
updatePropertyValue(property, value);
}
}
}
示例12: deleteReference
public void deleteReference(final Entity entity, final EdmNavigationProperty navigationProperty,
final String entityId, final String rawServiceRoot) throws DataProviderException {
if (navigationProperty.isCollection()) {
final Entity targetEntity = getEntityByReference(entityId, rawServiceRoot);
final Link navigationLink = entity.getNavigationLink(navigationProperty.getName());
if (navigationLink != null && navigationLink.getInlineEntitySet() != null
&& navigationLink.getInlineEntitySet().getEntities().contains(targetEntity)) {
// Remove partner single-valued navigation property
if (navigationProperty.getPartner() != null) {
final EdmNavigationProperty edmPartnerNavigationProperty = navigationProperty.getPartner();
if (!edmPartnerNavigationProperty.isCollection() && !edmPartnerNavigationProperty.isNullable()) {
throw new DataProviderException("Navigation property must not be null", HttpStatusCode.BAD_REQUEST);
} else if (!edmPartnerNavigationProperty.isCollection()) {
removeLink(edmPartnerNavigationProperty, targetEntity);
} else if (edmPartnerNavigationProperty.isCollection()
&& edmPartnerNavigationProperty.getPartner() != null) {
// Bidirectional referential constraint
final Link partnerNavigationLink = targetEntity.getNavigationLink(edmPartnerNavigationProperty.getName());
if (partnerNavigationLink != null && partnerNavigationLink.getInlineEntitySet() != null) {
partnerNavigationLink.getInlineEntitySet().getEntities().remove(entity);
}
}
}
// Remove target entity from collection-valued navigation property
navigationLink.getInlineEntitySet().getEntities().remove(targetEntity);
} else {
throw new DataProviderException("Entity not found", HttpStatusCode.NOT_FOUND);
}
} else {
if (navigationProperty.isNullable()) {
removeLink(navigationProperty, entity);
} else {
throw new DataProviderException("Navigation property must not be null", HttpStatusCode.BAD_REQUEST);
}
}
}
示例13: getEntityByReference
protected Entity getEntityByReference(final String entityId, final String rawServiceRoot)
throws DataProviderException {
try {
final UriResourceEntitySet uriResource = odata.createUriHelper().parseEntityId(edm, entityId, rawServiceRoot);
final Entity targetEntity = read(uriResource.getEntitySet(), uriResource.getKeyPredicates());
if (targetEntity != null) {
return targetEntity;
} else {
throw new DataProviderException("Entity not found", HttpStatusCode.NOT_FOUND);
}
} catch (DeserializerException e) {
throw new DataProviderException("Invalid entity-id", HttpStatusCode.BAD_REQUEST, e);
}
}
示例14: readDataFromEntity
public Entity readDataFromEntity(final EdmEntityType edmEntityType,
final List<UriParameter> keys) throws DataProviderException {
EntityCollection coll = data.get(edmEntityType.getName());
List<Entity> entities = coll.getEntities();
try {
for (final Entity entity : entities) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例15: setBindingPropertyKeyNameAndValue
/**
* @param keyList
* @param edmEntitySet
* @param values
* @param propertyNames
* @throws DataProviderException
*/
private static void setBindingPropertyKeyNameAndValue(List<UriParameter> keyList, EdmEntitySet edmEntitySet,
List<Object> values, List<String> propertyNames) throws DataProviderException {
for (final UriParameter key : keyList) {
EdmKeyPropertyRef refType = edmEntitySet.getEntityType().getKeyPropertyRef(key.getName());
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
try {
values.add(type.fromUriLiteral(key.getText()));
} catch (EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
propertyNames.add(key.getName());
}
}