[OLINGO-557] more function imports for technical service
Change-Id: If789d9f289ebc71a4bc98df6998d319a355593ae Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
be7f0fd1db
commit
9a666bd957
|
@ -22,14 +22,21 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.olingo.client.api.ODataClient;
|
import org.apache.olingo.client.api.ODataClient;
|
||||||
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
|
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
|
||||||
|
import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
|
||||||
|
import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
|
||||||
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
|
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
|
||||||
|
import org.apache.olingo.client.api.communication.response.ODataRawResponse;
|
||||||
|
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.client.core.ODataClientFactory;
|
import org.apache.olingo.client.core.ODataClientFactory;
|
||||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
||||||
|
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
|
@ -82,6 +89,61 @@ public class FunctionImportITCase extends AbstractBaseTestITCase {
|
||||||
assertEquals("2", property.getPrimitiveValue().toValue());
|
assertEquals("2", property.getPrimitiveValue().toValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void countEntityCollection() throws Exception {
|
||||||
|
final ODataRawRequest request = getClient().getRetrieveRequestFactory()
|
||||||
|
.getRawRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI)
|
||||||
|
.appendOperationCallSegment("FICRTCollESMedia").count().build());
|
||||||
|
final ODataRawResponse response = request.execute();
|
||||||
|
assertEquals("4", IOUtils.toString(response.getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void complexWithPath() throws Exception {
|
||||||
|
final ODataInvokeRequest<ODataProperty> request = getClient().getInvokeRequestFactory()
|
||||||
|
.getFunctionInvokeRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI)
|
||||||
|
.appendOperationCallSegment("FICRTCTTwoPrim").appendPropertySegment("PropertyInt16").build(),
|
||||||
|
ODataProperty.class);
|
||||||
|
assertNotNull(request);
|
||||||
|
|
||||||
|
final ODataInvokeResponse<ODataProperty> response = request.execute();
|
||||||
|
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
||||||
|
|
||||||
|
final ODataProperty property = response.getBody();
|
||||||
|
assertNotNull(property);
|
||||||
|
assertEquals(16, property.getPrimitiveValue().toValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primitiveCollection() throws Exception {
|
||||||
|
final ODataInvokeRequest<ODataProperty> request = getClient().getInvokeRequestFactory()
|
||||||
|
.getFunctionInvokeRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI)
|
||||||
|
.appendOperationCallSegment("FICRTCollString").build(), ODataProperty.class);
|
||||||
|
assertNotNull(request);
|
||||||
|
|
||||||
|
final ODataInvokeResponse<ODataProperty> response = request.execute();
|
||||||
|
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
||||||
|
|
||||||
|
final ODataProperty property = response.getBody();
|
||||||
|
assertNotNull(property);
|
||||||
|
assertNotNull(property.getCollectionValue());
|
||||||
|
assertEquals(3, property.getCollectionValue().size());
|
||||||
|
Iterator<ODataValue> iterator = property.getCollectionValue().iterator();
|
||||||
|
assertEquals("Employee1@company.example", iterator.next().asPrimitive().toValue());
|
||||||
|
assertEquals("Employee2@company.example", iterator.next().asPrimitive().toValue());
|
||||||
|
assertEquals("Employee3@company.example", iterator.next().asPrimitive().toValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primitiveValue() throws Exception {
|
||||||
|
final ODataValueRequest request = getClient().getRetrieveRequestFactory()
|
||||||
|
.getPropertyValueRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI)
|
||||||
|
.appendOperationCallSegment("FICRTString").appendValueSegment().build());
|
||||||
|
final ODataRetrieveResponse<ODataPrimitiveValue> response = request.execute();
|
||||||
|
assertEquals("UFCRTString string value", response.getBody().toValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ODataClient getClient() {
|
protected ODataClient getClient() {
|
||||||
ODataClient odata = ODataClientFactory.getClient();
|
ODataClient odata = ODataClientFactory.getClient();
|
||||||
|
|
|
@ -408,6 +408,11 @@ public class DataProvider {
|
||||||
return FunctionData.entityFunction(function.getName(), parameters, data);
|
return FunctionData.entityFunction(function.getName(), parameters, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Property readFunctionPrimitiveComplex(final EdmFunction function, final List<UriParameter> parameters)
|
||||||
|
throws DataProviderException {
|
||||||
|
return FunctionData.primitiveComplexFunction(function.getName(), parameters, data);
|
||||||
|
}
|
||||||
|
|
||||||
public void setEdm(final Edm edm) {
|
public void setEdm(final Edm edm) {
|
||||||
this.edm = edm;
|
this.edm = edm;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.server.tecsvc.data;
|
package org.apache.olingo.server.tecsvc.data;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.EntitySet;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||||
|
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||||
import org.apache.olingo.server.api.uri.UriParameter;
|
import org.apache.olingo.server.api.uri.UriParameter;
|
||||||
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
|
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
|
||||||
|
|
||||||
|
@ -64,4 +69,54 @@ public class FunctionData {
|
||||||
throw new DataProviderException("Function " + name + " is not yet implemented.");
|
throw new DataProviderException("Function " + name + " is not yet implemented.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected static Property primitiveComplexFunction(final String name, final List<UriParameter> parameters,
|
||||||
|
final Map<String, EntitySet> data) throws DataProviderException {
|
||||||
|
if (name.equals("UFNRTInt16")) {
|
||||||
|
return DataCreator.createPrimitive(name, 12345);
|
||||||
|
} else if (name.equals("UFCRTString")) {
|
||||||
|
return DataCreator.createPrimitive(name, "UFCRTString string value");
|
||||||
|
} else if (name.equals("UFCRTCollString")) {
|
||||||
|
return data.get("ESCollAllPrim").getEntities().get(0).getProperty("CollPropertyString");
|
||||||
|
} else if (name.equals("UFCRTCTTwoPrim")) {
|
||||||
|
return DataCreator.createComplex(name,
|
||||||
|
DataCreator.createPrimitive("PropertyInt16", 16),
|
||||||
|
DataCreator.createPrimitive("PropertyString", "UFCRTCTTwoPrim string value"));
|
||||||
|
} else if (name.equals("UFCRTCTTwoPrimParam")) {
|
||||||
|
try {
|
||||||
|
return DataCreator.createComplex(name,
|
||||||
|
DataCreator.createPrimitive("PropertyInt16",
|
||||||
|
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).valueOfString(
|
||||||
|
getParameterText("ParameterInt16", parameters),
|
||||||
|
null, null, null, null, null, Short.class)),
|
||||||
|
DataCreator.createPrimitive("PropertyString",
|
||||||
|
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).valueOfString(
|
||||||
|
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).fromUriLiteral(
|
||||||
|
getParameterText("ParameterString", parameters)),
|
||||||
|
null, null, null, null, null, String.class)));
|
||||||
|
} catch (final EdmPrimitiveTypeException e) {
|
||||||
|
throw new DataProviderException("Error in function " + name + ".", e);
|
||||||
|
}
|
||||||
|
} else if (name.equals("UFCRTCollCTTwoPrim")) {
|
||||||
|
return DataCreator.createComplexCollection(name,
|
||||||
|
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 16),
|
||||||
|
DataCreator.createPrimitive("PropertyString", "Test123")),
|
||||||
|
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 17),
|
||||||
|
DataCreator.createPrimitive("PropertyString", "Test456")),
|
||||||
|
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 18),
|
||||||
|
DataCreator.createPrimitive("PropertyString", "Test678")));
|
||||||
|
} else {
|
||||||
|
throw new DataProviderException("Function " + name + " is not yet implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getParameterText(final String name, final List<UriParameter> parameters) {
|
||||||
|
for (final UriParameter parameter : parameters) {
|
||||||
|
if (parameter.getName().equals(name)) {
|
||||||
|
return parameter.getText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.ContextURL;
|
import org.apache.olingo.commons.api.data.ContextURL;
|
||||||
|
import org.apache.olingo.commons.api.data.ContextURL.Builder;
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||||
|
@ -31,7 +32,10 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmReturnType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmType;
|
||||||
|
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
|
@ -61,6 +65,7 @@ import org.apache.olingo.server.api.uri.UriHelper;
|
||||||
import org.apache.olingo.server.api.uri.UriInfo;
|
import org.apache.olingo.server.api.uri.UriInfo;
|
||||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||||
import org.apache.olingo.server.api.uri.UriResource;
|
import org.apache.olingo.server.api.uri.UriResource;
|
||||||
|
import org.apache.olingo.server.api.uri.UriResourceFunction;
|
||||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||||
import org.apache.olingo.server.api.uri.UriResourceProperty;
|
import org.apache.olingo.server.api.uri.UriResourceProperty;
|
||||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||||
|
@ -203,7 +208,12 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
||||||
final List<String> path = getPropertyPath(resourceParts, 0);
|
final List<String> path = getPropertyPath(resourceParts, 0);
|
||||||
|
|
||||||
final Entity entity = readEntity(uriInfo);
|
final Entity entity = readEntity(uriInfo);
|
||||||
final Property property = getPropertyData(entity, path);
|
final Property property =
|
||||||
|
entity == null ?
|
||||||
|
getPropertyData(dataProvider.readFunctionPrimitiveComplex(((UriResourceFunction) resourceParts.get(0))
|
||||||
|
.getFunction(),
|
||||||
|
((UriResourceFunction) resourceParts.get(0)).getParameters()), path) :
|
||||||
|
getPropertyData(entity, path);
|
||||||
|
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ROOT);
|
throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ROOT);
|
||||||
|
@ -211,38 +221,49 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
||||||
if (property.getValue() == null) {
|
if (property.getValue() == null) {
|
||||||
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
||||||
} else {
|
} else {
|
||||||
final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(resourceParts.size() - 1))
|
final EdmProperty edmProperty = path.isEmpty() ? null :
|
||||||
.getProperty();
|
((UriResourceProperty) resourceParts.get(resourceParts.size() - 1)).getProperty();
|
||||||
|
final EdmType type = edmProperty == null ?
|
||||||
|
((UriResourceFunction) resourceParts.get(0)).getType() :
|
||||||
|
edmProperty.getType();
|
||||||
|
final EdmReturnType returnType = resourceParts.get(0) instanceof UriResourceFunction ?
|
||||||
|
((UriResourceFunction) resourceParts.get(0)).getFunction().getReturnType() : null;
|
||||||
|
|
||||||
final ODataFormat format = ODataFormat.fromContentType(contentType);
|
final ODataFormat format = ODataFormat.fromContentType(contentType);
|
||||||
ODataSerializer serializer = odata.createSerializer(format);
|
ODataSerializer serializer = odata.createSerializer(format);
|
||||||
final ExpandOption expand = uriInfo.getExpandOption();
|
final ExpandOption expand = uriInfo.getExpandOption();
|
||||||
final SelectOption select = uriInfo.getSelectOption();
|
final SelectOption select = uriInfo.getSelectOption();
|
||||||
final UriHelper helper = odata.createUriHelper();
|
|
||||||
final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null :
|
final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null :
|
||||||
ContextURL.with().entitySet(edmEntitySet)
|
getContextUrl(edmEntitySet, entity, path, type, representationType, expand, select);
|
||||||
.keyPath(helper.buildKeyPredicate(edmEntitySet.getEntityType(), entity))
|
|
||||||
.navOrPropertyPath(buildPropertyPath(path))
|
|
||||||
.selectList(edmProperty.isPrimitive() ? null :
|
|
||||||
helper.buildContextURLSelectList((EdmStructuredType) edmProperty.getType(), expand, select))
|
|
||||||
.build();
|
|
||||||
switch (representationType) {
|
switch (representationType) {
|
||||||
case PRIMITIVE:
|
case PRIMITIVE:
|
||||||
response.setContent(serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
|
response.setContent(serializer.primitive((EdmPrimitiveType) type, property,
|
||||||
PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
|
PrimitiveSerializerOptions.with().contextURL(contextURL)
|
||||||
|
.nullable(edmProperty == null ? returnType.isNullable() : edmProperty.isNullable())
|
||||||
|
.maxLength(edmProperty == null ? returnType.getMaxLength() : edmProperty.getMaxLength())
|
||||||
|
.precision(edmProperty == null ? returnType.getPrecision() : edmProperty.getPrecision())
|
||||||
|
.scale(edmProperty == null ? returnType.getScale() : edmProperty.getScale())
|
||||||
|
.unicode(edmProperty == null ? null : edmProperty.isUnicode())
|
||||||
|
.build()));
|
||||||
break;
|
break;
|
||||||
case COMPLEX:
|
case COMPLEX:
|
||||||
response.setContent(serializer.complex((EdmComplexType) edmProperty.getType(), property,
|
response.setContent(serializer.complex((EdmComplexType) type, property,
|
||||||
ComplexSerializerOptions.with().contextURL(contextURL)
|
ComplexSerializerOptions.with().contextURL(contextURL)
|
||||||
.expand(expand).select(select)
|
.expand(expand).select(select)
|
||||||
.build()));
|
.build()));
|
||||||
break;
|
break;
|
||||||
case COLLECTION_PRIMITIVE:
|
case COLLECTION_PRIMITIVE:
|
||||||
response.setContent(serializer.primitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
|
response.setContent(serializer.primitiveCollection((EdmPrimitiveType) type, property,
|
||||||
PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
|
PrimitiveSerializerOptions.with().contextURL(contextURL)
|
||||||
|
.nullable(edmProperty == null ? returnType.isNullable() : edmProperty.isNullable())
|
||||||
|
.maxLength(edmProperty == null ? returnType.getMaxLength() : edmProperty.getMaxLength())
|
||||||
|
.precision(edmProperty == null ? returnType.getPrecision() : edmProperty.getPrecision())
|
||||||
|
.scale(edmProperty == null ? returnType.getScale() : edmProperty.getScale())
|
||||||
|
.unicode(edmProperty == null ? null : edmProperty.isUnicode())
|
||||||
|
.build()));
|
||||||
break;
|
break;
|
||||||
case COLLECTION_COMPLEX:
|
case COLLECTION_COMPLEX:
|
||||||
response.setContent(serializer.complexCollection((EdmComplexType) edmProperty.getType(), property,
|
response.setContent(serializer.complexCollection((EdmComplexType) type, property,
|
||||||
ComplexSerializerOptions.with().contextURL(contextURL)
|
ComplexSerializerOptions.with().contextURL(contextURL)
|
||||||
.expand(expand).select(select)
|
.expand(expand).select(select)
|
||||||
.build()));
|
.build()));
|
||||||
|
@ -277,22 +298,25 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Property getPropertyData(final Entity entity, final List<String> path)
|
private Property getPropertyData(final Entity entity, final List<String> path) {
|
||||||
throws ODataApplicationException {
|
return getPropertyData(entity.getProperty(path.get(0)), path.subList(1, path.size()));
|
||||||
Property property = entity.getProperty(path.get(0));
|
}
|
||||||
for (final String name : path.subList(1, path.size())) {
|
|
||||||
if (property != null && (property.isComplex() || property.isComplex())) {
|
private Property getPropertyData(final Property property, final List<String> path) {
|
||||||
final List<Property> complex = property.asComplex().getValue();
|
Property result = property;
|
||||||
property = null;
|
for (final String name : path) {
|
||||||
|
if (result != null && property.isComplex()) {
|
||||||
|
final List<Property> complex = result.asComplex().getValue();
|
||||||
|
result = null;
|
||||||
for (final Property innerProperty : complex) {
|
for (final Property innerProperty : complex) {
|
||||||
if (innerProperty.getName().equals(name)) {
|
if (innerProperty.getName().equals(name)) {
|
||||||
property = innerProperty;
|
result = innerProperty;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return property;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getPropertyPath(final List<UriResource> path, final int trailing) {
|
private List<String> getPropertyPath(final List<UriResource> path, final int trailing) {
|
||||||
|
@ -313,6 +337,24 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ContextURL getContextUrl(final EdmEntitySet entitySet, final Entity entity, final List<String> path,
|
||||||
|
final EdmType type, final RepresentationType representationType,
|
||||||
|
final ExpandOption expand, final SelectOption select) throws SerializerException {
|
||||||
|
final UriHelper helper = odata.createUriHelper();
|
||||||
|
Builder builder = ContextURL.with();
|
||||||
|
builder = entitySet == null ?
|
||||||
|
representationType == RepresentationType.PRIMITIVE || representationType == RepresentationType.COMPLEX ?
|
||||||
|
builder.type(type) :
|
||||||
|
builder.type(type).asCollection() :
|
||||||
|
builder.entitySet(entitySet).keyPath(helper.buildKeyPredicate(entitySet.getEntityType(), entity));
|
||||||
|
if (entitySet != null && !path.isEmpty()) {
|
||||||
|
builder = builder.navOrPropertyPath(buildPropertyPath(path));
|
||||||
|
}
|
||||||
|
builder = builder.selectList(type.getKind() == EdmTypeKind.PRIMITIVE ? null :
|
||||||
|
helper.buildContextURLSelectList((EdmStructuredType) type, expand, select));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readPrimitiveValue(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
|
public void readPrimitiveValue(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
|
||||||
final ContentType contentType) throws ODataApplicationException, SerializerException {
|
final ContentType contentType) throws ODataApplicationException, SerializerException {
|
||||||
|
@ -324,19 +366,33 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
||||||
final List<UriResource> resourceParts = resource.getUriResourceParts();
|
final List<UriResource> resourceParts = resource.getUriResourceParts();
|
||||||
final List<String> path = getPropertyPath(resourceParts, 1);
|
final List<String> path = getPropertyPath(resourceParts, 1);
|
||||||
|
|
||||||
final Property property = getPropertyData(readEntity(uriInfo), path);
|
final Entity entity = readEntity(uriInfo);
|
||||||
|
final Property property = entity == null ?
|
||||||
|
dataProvider.readFunctionPrimitiveComplex(((UriResourceFunction) resourceParts.get(0)).getFunction(),
|
||||||
|
((UriResourceFunction) resourceParts.get(0)).getParameters()) :
|
||||||
|
getPropertyData(entity, path);
|
||||||
|
|
||||||
if (property == null || property.getValue() == null) {
|
if (property == null || property.getValue() == null) {
|
||||||
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
||||||
} else {
|
} else {
|
||||||
final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(resourceParts.size() - 2))
|
final EdmProperty edmProperty = path.isEmpty() ? null :
|
||||||
.getProperty();
|
((UriResourceProperty) resourceParts.get(resourceParts.size() - 2)).getProperty();
|
||||||
final EdmPrimitiveType type = (EdmPrimitiveType) edmProperty.getType();
|
final EdmPrimitiveType type = (EdmPrimitiveType) (edmProperty == null ?
|
||||||
|
((UriResourceFunction) resourceParts.get(0)).getType() :
|
||||||
|
edmProperty.getType());
|
||||||
|
final EdmReturnType returnType = resourceParts.get(0) instanceof UriResourceFunction ?
|
||||||
|
((UriResourceFunction) resourceParts.get(0)).getFunction().getReturnType() : null;
|
||||||
final FixedFormatSerializer serializer = odata.createFixedFormatSerializer();
|
final FixedFormatSerializer serializer = odata.createFixedFormatSerializer();
|
||||||
response.setContent(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
|
response.setContent(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
|
||||||
serializer.binary((byte[]) property.getValue()) :
|
serializer.binary((byte[]) property.getValue()) :
|
||||||
serializer.primitiveValue(type, property.getValue(),
|
serializer.primitiveValue(type, property.getValue(),
|
||||||
PrimitiveValueSerializerOptions.with().facetsFrom(edmProperty).build()));
|
PrimitiveValueSerializerOptions.with()
|
||||||
|
.nullable(edmProperty == null ? returnType.isNullable() : edmProperty.isNullable())
|
||||||
|
.maxLength(edmProperty == null ? returnType.getMaxLength() : edmProperty.getMaxLength())
|
||||||
|
.precision(edmProperty == null ? returnType.getPrecision() : edmProperty.getPrecision())
|
||||||
|
.scale(edmProperty == null ? returnType.getScale() : edmProperty.getScale())
|
||||||
|
.unicode(edmProperty == null ? null : edmProperty.isUnicode())
|
||||||
|
.build()));
|
||||||
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
|
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
|
||||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ public class FunctionProvider {
|
||||||
} else if (functionName.equals(nameUFCRTCollETTwoKeyNavParam)) {
|
} else if (functionName.equals(nameUFCRTCollETTwoKeyNavParam)) {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new Function()
|
new Function()
|
||||||
.setName("UFCRTESTwoKeyNavParam")
|
.setName(functionName.getName())
|
||||||
.setParameters(Collections.singletonList(
|
.setParameters(Collections.singletonList(
|
||||||
new Parameter()
|
new Parameter()
|
||||||
.setName("ParameterInt16")
|
.setName("ParameterInt16")
|
||||||
|
@ -375,7 +375,7 @@ public class FunctionProvider {
|
||||||
} else if (functionName.equals(nameUFCRTCollETMixPrimCollCompTwoParam)) {
|
} else if (functionName.equals(nameUFCRTCollETMixPrimCollCompTwoParam)) {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new Function()
|
new Function()
|
||||||
.setName("UFNRTESMixPrimCollCompTwoParam")
|
.setName(functionName.getName())
|
||||||
.setParameters(Arrays.asList(
|
.setParameters(Arrays.asList(
|
||||||
new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(false),
|
new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(false),
|
||||||
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16).setNullable(false)))
|
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16).setNullable(false)))
|
||||||
|
@ -400,7 +400,7 @@ public class FunctionProvider {
|
||||||
} else if (functionName.equals(nameUFCRTESMixPrimCollCompTwoParam)) {
|
} else if (functionName.equals(nameUFCRTESMixPrimCollCompTwoParam)) {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new Function()
|
new Function()
|
||||||
.setName("UFCRTESMixPrimCollCompTwoParam")
|
.setName(functionName.getName())
|
||||||
.setParameters(Arrays.asList(
|
.setParameters(Arrays.asList(
|
||||||
new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(false),
|
new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(false),
|
||||||
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16).setNullable(false)
|
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16).setNullable(false)
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class SchemaProvider {
|
||||||
|
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTInt16));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTInt16));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETKeyNav));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETKeyNav));
|
||||||
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNav));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParam));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParam));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParamCTTwoPrim));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParamCTTwoPrim));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTStringTwoParam));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTStringTwoParam));
|
||||||
|
@ -140,6 +141,7 @@ public class SchemaProvider {
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCTTwoPrim));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCTTwoPrim));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollCTTwoPrim));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollCTTwoPrim));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETMedia));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETMedia));
|
||||||
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMedia));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMixPrimCollCompTwoParam));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMixPrimCollCompTwoParam));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETAllPrimTwoParam));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETAllPrimTwoParam));
|
||||||
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTESMixPrimCollCompTwoParam));
|
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTESMixPrimCollCompTwoParam));
|
||||||
|
|
Loading…
Reference in New Issue