Java Code Examples for org.apache.olingo.commons.api.http.HttpStatusCode#NOT_IMPLEMENTED

The following examples show how to use org.apache.olingo.commons.api.http.HttpStatusCode#NOT_IMPLEMENTED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected static Property primitiveBoundAction(final String name, final Map<String, Parameter> parameters, 
    final Map<String, EntityCollection> data, final EdmEntitySet edmEntitySet, final List<UriParameter> keyList)
    throws DataProviderException {
  List<Object> keyPropertyValues = new ArrayList<Object>();
  List<String> keyPropertyNames = new ArrayList<String>();
  if ("BAETTwoPrimRTString".equals(name)) {
    if (!keyList.isEmpty()) {
      setBindingPropertyKeyNameAndValue(keyList, edmEntitySet, keyPropertyValues, keyPropertyNames);
      EntityCollection entityCollection = data.get(edmEntitySet.getName());
      Entity entity = getSpecificEntity1(entityCollection, keyPropertyValues, keyPropertyNames);
      Property property = entity.getProperty("PropertyString");
      return property;
    }
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 3
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected static Property complexCollectionAction(final String name, final Map<String, Parameter> parameters)
    throws DataProviderException {
  if ("UARTCollCTTwoPrimParam".equals(name)) {
    List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
    final Parameter paramInt16 = parameters.get("ParameterInt16");
    final Short number = paramInt16 == null || paramInt16.isNull() ? 0 : (Short) paramInt16.asPrimitive();
    if (number >= 1) {
      complexCollection.add(createCTTwoPrimComplexProperty("PropertyComp", (short) 16, "Test123").asComplex());
    }
    if (number >= 2) {
      complexCollection.add(createCTTwoPrimComplexProperty("PropertyComp", (short) 17, "Test456").asComplex());
    }
    if (number >= 3) {
      complexCollection.add(createCTTwoPrimComplexProperty("PropertyComp", (short) 18, "Test678").asComplex());
    }
    return new Property("PropertyCollComp", name, ValueType.COLLECTION_COMPLEX, complexCollection);
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 5
Source File: FunctionData.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected static EntityCollection entityCollectionFunction(final String name,
    final Map<String, Parameter> parameters, final Map<String, EntityCollection> data)
    throws DataProviderException {
  if (name.equals("UFCRTCollETTwoKeyNavParam")) {
    final List<Entity> esTwoKeyNav = data.get("ESTwoKeyNav").getEntities();
    EntityCollection result = new EntityCollection();
    final int endIndex = parameters.isEmpty() ? 0 : getParameterInt16(parameters);
    result.getEntities().addAll(
        esTwoKeyNav.subList(0,
            endIndex < 0 ? 0 : endIndex > esTwoKeyNav.size() ? esTwoKeyNav.size() : endIndex));
    return result;
  } else if (name.equals("UFCRTCollETMixPrimCollCompTwoParam")) {
    return data.get("ESMixPrimCollComp");
  } else if (name.equals("UFCRTCollETMedia")) {
    return data.get("ESMedia");
  } else {
    throw new DataProviderException("Function " + name + " is not yet implemented.",
        HttpStatusCode.NOT_IMPLEMENTED);
  }
}
 
Example 6
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static Property complexAction(final String name, final Map<String, Parameter> parameters)
    throws DataProviderException {
  if ("UARTCTTwoPrimParam".equals(name)) {
    Parameter paramInt16 = parameters.get("ParameterInt16");
    final Short number = paramInt16 == null || paramInt16.isNull() ?
        (short) 32767 :
        (Short) paramInt16.asPrimitive();
    return createCTTwoPrimComplexProperty(name, number, "UARTCTTwoPrimParam string value");
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 7
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static Property complexBoundAction(final String name, final Map<String, Parameter> parameters,
    final Map<String, EntityCollection> data, 
    EdmEntitySet edmEntitySet, List<UriParameter> keyList)
    throws DataProviderException {
  if ("BAETTwoKeyNavCTBasePrimCompNavCTTwoBasePrimCompNavRTCTTwoBasePrimCompNav".equals(name)) {
    if (!keyList.isEmpty()) {
      return DataCreator.createComplex(name, 
          ComplexTypeProvider.nameCTTwoBasePrimCompNav.getFullQualifiedNameAsString(), 
          DataCreator.createPrimitive("PropertyInt16", 10),
          createKeyNavAllPrimComplexValue("PropertyComp"));
    }
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 8
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static EntityActionResult entityBoundActionWithNavigation(final String name, 
    final Map<String, Parameter> parameters,
    final Map<String, EntityCollection> data, List<UriParameter> keyList, 
    EdmEntitySet edmEntitySet, EdmNavigationProperty navProperty) 
        throws DataProviderException {
  List<Object> keyPropertyValues = new ArrayList<Object>();
  List<String> keyPropertyNames = new ArrayList<String>();
  if ("BAETTwoKeyNavRTETTwoKeyNavParam".equals(name)) {
    if (!keyList.isEmpty()) {
      setBindingPropertyKeyNameAndValue(keyList, edmEntitySet, keyPropertyValues, keyPropertyNames);
      EntityCollection entityCollection = data.get(edmEntitySet.getName());
      Entity entity = getSpecificEntity(entityCollection, keyPropertyValues, keyPropertyNames);
      
      Link link = entity.getNavigationLink(navProperty.getName());
      Entity inlineEntity = link.getInlineEntity();
      ComplexValue complexValue = inlineEntity.getProperty("PropertyComp").asComplex();
      List<Property> complexProperties = complexValue.getValue();
      Iterator<Property> itr = complexProperties.iterator();
      Parameter actionParam = parameters.get("PropertyComp");
      Property actionProp = actionParam.asComplex().getValue().get(0);
      while (itr.hasNext()) {
        Property property = itr.next();
        if (property.getName().equals(actionProp.getName())) {
          property.setValue(actionProp.getValueType(), actionProp.getValue());
          break;
        }
      }
      return new EntityActionResult().setEntity(inlineEntity);
      }
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 9
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static EntityCollection entityCollectionBoundAction(final String name, 
    final Map<String, Parameter> parameters,
    Map<String, EntityCollection> data, final OData oData, final Edm edm, EdmEntitySet edmEntitySet) 
        throws DataProviderException {
  if ("BAESTwoKeyNavRTESTwoKeyNav".equals(name)) {
    EntityCollection collection = data.get(edmEntitySet.getName());
    collection.getEntities().add(createETTwoKeyNav((short)111, "newValue", oData, edm));
    return collection;
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 10
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static EntityCollection entityCollectionBoundActionWithNav(final String name, 
    final Map<String, Parameter> parameters, Map<String, EntityCollection> data, 
    final OData oData, final Edm edm, EdmEntitySet edmEntitySet, EdmNavigationProperty navProperty) 
        throws DataProviderException {
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 11
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
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);
        }
        Object keyValue = null;
        final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
        if (Calendar.class.isAssignableFrom(value.getClass())) {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), Calendar.class);
        } else {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), 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);
  }
}
 
Example 12
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private Map<String, Object> findFreeComposedKey(final List<Entity> entities, final EdmEntityType entityType)
    throws DataProviderException {
  // Weak key construction
  final HashMap<String, Object> keys = new HashMap<String, Object>();
  List<String> keyPredicateNames = entityType.getKeyPredicateNames();
  for (final String keyName : keyPredicateNames) {
    EdmType type = entityType.getProperty(keyName).getType();
    FullQualifiedName typeName = type.getFullQualifiedName();
    if (type instanceof EdmTypeDefinition) {
      typeName = ((EdmTypeDefinition) type).getUnderlyingType().getFullQualifiedName();
    }
    Object newValue;

    if (EdmPrimitiveTypeKind.Int16.getFullQualifiedName().equals(typeName)) {
      newValue = (short) KEY_INT_16.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = (short) KEY_INT_16.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.Int32.getFullQualifiedName().equals(typeName)) {
      newValue = KEY_INT_32.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = KEY_INT_32.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.Int64.getFullQualifiedName().equals(typeName)) {
      // Integer keys
      newValue = KEY_INT_64.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = KEY_INT_64.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(typeName)) {
      // String keys
      newValue = String.valueOf(KEY_STRING.incrementAndGet());

      while (!isFree(newValue, keyName, entities)) {
        newValue = String.valueOf(KEY_STRING.incrementAndGet());
      }
    } else if (type instanceof EdmEnumType) {
      /* In case of an enum key we only support composite keys. This way we can 0 as a key */
      if (keyPredicateNames.size() <= 1) {
        throw new DataProviderException("Single Enum as key not supported", HttpStatusCode.NOT_IMPLEMENTED);
      }
      newValue = new Short((short) 1);
    } else {
      throw new DataProviderException("Key type not supported", HttpStatusCode.NOT_IMPLEMENTED);
    }

    keys.put(keyName, newValue);
  }

  return keys;
}
 
Example 13
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
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();
        Object keyValue = null;
        if (Calendar.class.isAssignableFrom(value.getClass())) {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), Calendar.class);
        } else {
          keyValue = type.valueOfString(type.fromUriLiteral(text),
              property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
              property.isUnicode(), 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);
  }
}