/** * Function import sample model. */ @EdmFunctionImport(function = "UnboundODataDemoFunction", includeInServiceDocument = true, name = "ODataDemoFunctionImport", namespace = "ODataDemo") public class FunctionImportSample { @EdmParameter private String stringFunctionField; @EdmParameter private int intFunctionField; public String getStringFunctionField() { return stringFunctionField; } public void setStringFunctionField(String stringFunctionField) { this.stringFunctionField = stringFunctionField; } public int getIntFunctionField() { return intFunctionField; } public void setIntFunctionField(int intFunctionField) { this.intFunctionField = intFunctionField; } }
if (parameterAnnotation != null) { String parameterName = isNullOrEmpty(parameterAnnotation.name()) ? field.getName() : parameterAnnotation.name(); String parameterType = isNullOrEmpty(parameterAnnotation.type()) ? field.getType().getSimpleName() : parameterAnnotation.type(); parameters.add(new ParameterImpl.Builder() .setMaxLength(parameterAnnotation.maxLength()) .setName(parameterName) .setNullable(parameterAnnotation.nullable()) .setPrecision(parameterAnnotation.precision()) .setScale(parameterAnnotation.scale()) .setSRID(parameterAnnotation.srid()) .setType(parameterType) .setUnicode(parameterAnnotation.unicode()) .setJavaField(field) .build());
public static void setParameter(Object object, Field field, Object bodyParameter) throws ODataUnmarshallingException { Object fieldValue = null; if (bodyParameter != null) { EdmParameter annotation = field.getAnnotation(EdmParameter.class); if (annotation == null) { throw new ODataUnmarshallingException("Field should have EdmParameter annotation"); } PrimitiveType type = resolveType(annotation.type(), field); try { if (field.getType().isAssignableFrom(bodyParameter.getClass())) { fieldValue = bodyParameter; } else if (type != null) { fieldValue = ParserUtil.parsePrimitiveValue(bodyParameter.toString(), type); } } catch (ODataException e) { throw new ODataUnmarshallingException("Can't parse primitive value"); } } field.setAccessible(true); try { field.set(object, fieldValue); } catch (IllegalAccessException e) { throw new ODataUnmarshallingException("Error during setting a parameter to action object field"); } }
EdmParameter parameterAnnotation = field.getAnnotation(EdmParameter.class); if (parameterAnnotation != null) { String parameterName = isNullOrEmpty(parameterAnnotation.name()) ? field.getName() : parameterAnnotation.name(); String parameterType = isNullOrEmpty(parameterAnnotation.type()) ? field.getType().getSimpleName() : parameterAnnotation.type(); parameters.add(new ParameterImpl.Builder() .setMaxLength(parameterAnnotation.maxLength()) .setName(parameterName) .setNullable(parameterAnnotation.nullable()) .setPrecision(parameterAnnotation.precision()) .setScale(parameterAnnotation.scale()) .setSRID(parameterAnnotation.srid()) .setType(parameterType) .setUnicode(parameterAnnotation.unicode()) .setJavaField(field) .build());
public static void setParameter(Object object, Field field, Object bodyParameter) throws ODataUnmarshallingException { Object fieldValue = null; if (bodyParameter != null) { EdmParameter annotation = field.getAnnotation(EdmParameter.class); if (annotation == null) { throw new ODataUnmarshallingException("Field should have EdmParameter annotation"); } PrimitiveType type = resolveType(annotation.type(), field); try { if (field.getType().isAssignableFrom(bodyParameter.getClass())) { fieldValue = bodyParameter; } else if (type != null) { fieldValue = ParserUtil.parsePrimitiveValue(bodyParameter.toString(), type); } } catch (ODataException e) { throw new ODataUnmarshallingException("Can't parse primitive value"); } } field.setAccessible(true); try { field.set(object, fieldValue); } catch (IllegalAccessException e) { throw new ODataUnmarshallingException("Error during setting a parameter to action object field"); } }
if (parameterAnnotation != null) { String parameterName = isNullOrEmpty(parameterAnnotation.name()) ? field.getName() : parameterAnnotation.name(); String parameterType = isNullOrEmpty(parameterAnnotation.type()) ? field.getType().getSimpleName() : parameterAnnotation.type(); parameters.add(new ParameterImpl.Builder() .setMaxLength(parameterAnnotation.maxLength()) .setName(parameterName) .setNullable(parameterAnnotation.nullable()) .setPrecision(parameterAnnotation.precision()) .setScale(parameterAnnotation.scale()) .setSRID(parameterAnnotation.srid()) .setType(parameterType) .setUnicode(parameterAnnotation.unicode()) .setJavaField(field) .build());
/** * Function import sample model. */ @EdmFunctionImport(function = "UnboundODataDemoFunction", includeInServiceDocument = true, name = "ODataDemoFunctionImport", namespace = "ODataDemo") public class FunctionImportSample { @EdmParameter private String stringFunctionField; @EdmParameter private int intFunctionField; public String getStringFunctionField() { return stringFunctionField; } public void setStringFunctionField(String stringFunctionField) { this.stringFunctionField = stringFunctionField; } public int getIntFunctionField() { return intFunctionField; } public void setIntFunctionField(int intFunctionField) { this.intFunctionField = intFunctionField; } }
EdmParameter parameterAnnotation = field.getAnnotation(EdmParameter.class); if (parameterAnnotation != null) { String parameterName = isNullOrEmpty(parameterAnnotation.name()) ? field.getName() : parameterAnnotation.name(); String parameterType = isNullOrEmpty(parameterAnnotation.type()) ? field.getType().getSimpleName() : parameterAnnotation.type(); parameters.add(new ParameterImpl.Builder() .setMaxLength(parameterAnnotation.maxLength()) .setName(parameterName) .setNullable(parameterAnnotation.nullable()) .setPrecision(parameterAnnotation.precision()) .setScale(parameterAnnotation.scale()) .setSRID(parameterAnnotation.srid()) .setType(parameterType) .setUnicode(parameterAnnotation.unicode()) .setJavaField(field) .build());
public class ActionSample implements Operation<Customer> { @EdmParameter(name = "StringParameter") private String stringParameter; @EdmParameter(name = "NumberParameter") private Long number; @EdmParameter private int intNumber; @EdmParameter private Map<String, String> parametersMap; @EdmParameter private List<Map<String, String>> parametersMapList;
public class ActionSample implements Operation<Customer> { @EdmParameter(name = "StringParameter") private String stringParameter; @EdmParameter(name = "NumberParameter") private Long number; @EdmParameter private int intNumber; @EdmParameter private Map<String, String> parametersMap; @EdmParameter private List<Map<String, String>> parametersMapList;
/** * The sample of Unbound Action. */ @EdmAction(namespace = "ODataDemo", name = "ODataDemoUnboundAction", entitySetPath = "ODataDemoEntitySetPath", isBound = false) @EdmReturnType(type = "Customers") public class UnboundActionSample implements Operation<Customer> { @EdmParameter(name = "StringParameter", nullable = false) private String stringParameter; @EdmParameter(name = "NumberParameter", nullable = false) private Long number; public String getStringParameter() { return stringParameter; } public Long getNumber() { return number; } @Override public Customer doOperation(ODataRequestContext requestContext, DataSourceFactory dataSourceFactory) { // Doesn't return anything because there is no possibility to implement it without datasource. return null; } }
/** * The sample of Unbound Action. */ @EdmAction(namespace = "ODataDemo", name = "ODataDemoUnboundAction", entitySetPath = "ODataDemoEntitySetPath", isBound = false) @EdmReturnType(type = "Customers") public class UnboundActionSample implements Operation<Customer> { @EdmParameter(name = "StringParameter", nullable = false) private String stringParameter; @EdmParameter(name = "NumberParameter", nullable = false) private Long number; public String getStringParameter() { return stringParameter; } public Long getNumber() { return number; } @Override public Customer doOperation(ODataRequestContext requestContext, DataSourceFactory dataSourceFactory) { // Doesn't return anything because there is no possibility to implement it without datasource. return null; } }
public class FunctionNotNullableSample implements Operation<String> { @EdmParameter(nullable = false) private String stringFunctionField; @EdmParameter(nullable = false) private int intFunctionField;
public class FunctionSample implements Operation<String> { @EdmParameter private String stringFunctionField; @EdmParameter private int intFunctionField;
public class UnboundFunctionSample implements Operation<String> { @EdmParameter private String stringFunctionField; @EdmParameter private int intFunctionField;
public class FunctionNotNullableSample implements Operation<String> { @EdmParameter(nullable = false) private String stringFunctionField; @EdmParameter(nullable = false) private int intFunctionField;
public class UnboundFunctionSample implements Operation<String> { @EdmParameter private String stringFunctionField; @EdmParameter private int intFunctionField;
public class FunctionSample implements Operation<String> { @EdmParameter private String stringFunctionField; @EdmParameter private int intFunctionField;
/** * Sample of default action. */ @EdmAction @EdmReturnType(type = "BankAccounts") public class DefaultActionSample { @EdmParameter private String someParameter; public void doAction() { // do some action } }
/** * Sample of default action. */ @EdmAction @EdmReturnType(type = "BankAccounts") public class DefaultActionSample { @EdmParameter private String someParameter; public void doAction() { // do some action } }