http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java index 4fae878..51f51c8 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java @@ -40,6 +40,7 @@ import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException; +import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider; public class ActionData { @@ -118,6 +119,7 @@ public class ActionData { private static Property createCTTwoPrimComplexProperty(final String name, final Short number, final String text) { return DataCreator.createComplex(name, + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyInt16", number), DataCreator.createPrimitive("PropertyString", text)); } @@ -244,18 +246,23 @@ public class ActionData { Entity entity = new Entity() .addProperty(DataCreator.createPrimitive("PropertyInt16", number)) .addProperty(DataCreator.createPrimitive("PropertyString", "UARTCollETKeyNavParam int16 value: " + number)) - .addProperty(DataCreator.createComplex("PropertyCompNav", + .addProperty(DataCreator.createComplex("PropertyCompNav", + ComplexTypeProvider.nameCTNavFiveProp.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyInt16", (short) 0))) .addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim")) .addProperty(DataCreator.createComplex("PropertyCompTwoPrim", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyInt16", (short) 0), DataCreator.createPrimitive("PropertyString", ""))).addProperty( DataCreator.createPrimitiveCollection("CollPropertyString")) .addProperty(DataCreator.createPrimitiveCollection("CollPropertyInt16")) - .addProperty(DataCreator.createComplexCollection("CollPropertyComp")) - .addProperty(DataCreator.createComplex("PropertyCompCompNav", + .addProperty(DataCreator.createComplexCollection("CollPropertyComp", + ComplexTypeProvider.nameCTPrimComp.getFullQualifiedNameAsString())) + .addProperty(DataCreator.createComplex("PropertyCompCompNav", + ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyString", ""), DataCreator.createComplex("PropertyCompNav", + ComplexTypeProvider.nameCTNavFiveProp.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyInt16", (short) 0)))); setEntityId(entity, "ESKeyNav", oData, edm); return entity; @@ -273,6 +280,7 @@ public class ActionData { protected static Property createKeyNavAllPrimComplexValue(final String name) { return DataCreator.createComplex(name, + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyString", ""), DataCreator.createPrimitive("PropertyBinary", new byte[] {}), DataCreator.createPrimitive("PropertyBoolean", false),
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java index 1241bc5..aac9a34 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java @@ -36,16 +36,25 @@ import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Link; +import org.apache.olingo.commons.api.data.Operation; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.provider.CsdlAction; +import org.apache.olingo.commons.api.edm.provider.CsdlFunction; +import org.apache.olingo.commons.api.edm.provider.CsdlParameter; +import org.apache.olingo.commons.api.ex.ODataException; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.uri.UriHelper; +import org.apache.olingo.server.tecsvc.provider.ActionProvider; import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider; import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; +import org.apache.olingo.server.tecsvc.provider.FunctionProvider; +import org.apache.olingo.server.tecsvc.provider.SchemaProvider; public class DataCreator { @@ -77,6 +86,7 @@ public class DataCreator { data.put("ESCompMixPrimCollComp", createESCompMixPrimCollComp(edm, odata)); data.put("ESMixEnumDefCollComp", createESMixEnumDefCollComp(edm, odata)); data.put("ESStream", createESStream(edm, odata)); + data.put("ESWithStream", createESWithStream(edm, odata)); linkESTwoPrim(data); linkESAllPrim(data); @@ -93,7 +103,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMixEnumDefCollComp)); createEntityId(edm, odata, "ESMixEnumDefCollComp", entityCollection); - + createOperations("ESMixEnumDefCollComp", entityCollection, EntityTypeProvider.nameETMixEnumDefCollComp); return entityCollection; } @@ -114,7 +124,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCompMixPrimCollComp)); createEntityId(edm, odata, "ESCompMixPrimCollComp", entityCollection); - + createOperations("ESCompMixPrimCollComp", entityCollection, EntityTypeProvider.nameETCompMixPrimCollComp); return entityCollection; } @@ -123,6 +133,7 @@ public class DataCreator { return new Entity() .addProperty(createPrimitive("PropertyInt16", propertyInt16)) .addProperty(createComplex("PropertyMixedPrimCollComp", + ComplexTypeProvider.nameCTMixPrimCollComp.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 1), createPrimitiveCollection("CollPropertyString", "[email protected]", @@ -130,10 +141,12 @@ public class DataCreator { "[email protected]" ), createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 333), createPrimitive("PropertyString", "TEST123") ), createComplexCollection("CollPropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), Arrays.asList(new Property[] { createPrimitive("PropertyInt16", (short) 222), createPrimitive("PropertyString", "TEST9876") @@ -166,7 +179,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETBase)); createEntityId(edm, odata, "ESBase", entityCollection); - + createOperations("ESBase", entityCollection, EntityTypeProvider.nameETBase); return entityCollection; } @@ -176,11 +189,14 @@ public class DataCreator { entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 1)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 11), createPrimitive("PropertyString", "Num11") )) .addProperty(createComplex("PropertyCompComp", + ComplexTypeProvider.nameCTCompComp.getFullQualifiedNameAsString(), createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 111), createPrimitive("PropertyString", "Num111") ) @@ -189,7 +205,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETFourKeyAlias)); createEntityId(edm, odata, "ESFourKeyAlias", entityCollection); - + createOperations("ESFourKeyAlias", entityCollection, EntityTypeProvider.nameETFourKeyAlias); return entityCollection; } @@ -201,6 +217,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCompCollAllPrim)); createEntityId(edm, odata, "ESCompCollAllPrim", entityCollection); + createOperations("ESCompCollAllPrim", entityCollection, EntityTypeProvider.nameETCompCollAllPrim); return entityCollection; } @@ -208,6 +225,7 @@ public class DataCreator { return new Entity() .addProperty(createPrimitive("PropertyInt16", propertyInt16)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTCollAllPrim.getFullQualifiedNameAsString(), createPrimitiveCollection("CollPropertyString", "[email protected]", "[email protected]", @@ -305,7 +323,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav)); createEntityId(edm, odata, "ESBaseTwoKeyNav", entityCollection); - + createOperations("ESBaseTwoKeyNav", entityCollection, EntityTypeProvider.nameETBaseTwoKeyNav); return entityCollection; } @@ -331,7 +349,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoBase)); createEntityId(edm, odata, "ESTwoBase", entityCollection); - + createOperations("ESTwoBase", entityCollection, EntityTypeProvider.nameETTwoBase); return entityCollection; } @@ -423,6 +441,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETAllNullable)); createEntityId(edm, odata, "ESAllNullable", entityCollection); + createOperations("ESAllNullable", entityCollection, EntityTypeProvider.nameETAllNullable); return entityCollection; } @@ -438,7 +457,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoKeyTwoPrim)); createEntityId(edm, odata, "ESTwoKeyTwoPrim", entityCollection); - + createOperations("ESTwoKeyTwoPrim", entityCollection, EntityTypeProvider.nameETTwoKeyTwoPrim); return entityCollection; } @@ -459,7 +478,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETServerSidePaging)); createEntityId(edm, odata, "ESServerSidePaging", entityCollection); - + createOperations("ESServerSidePaging", entityCollection, EntityTypeProvider.nameETServerSidePaging); return entityCollection; } @@ -472,7 +491,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETKeyNav)); createEntityId(edm, odata, "ESKeyNav", entityCollection); - + createOperations("ESKeyNav", entityCollection, EntityTypeProvider.nameETKeyNav); return entityCollection; } @@ -482,9 +501,11 @@ public class DataCreator { .addProperty(createPrimitive("PropertyInt16", propertyInt16)) .addProperty(createPrimitive("PropertyString", propertyString)) .addProperty(createComplex("PropertyCompNav", + ComplexTypeProvider.nameCTNavFiveProp.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", 1))) .addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim")) .addProperty(createComplex("PropertyCompTwoPrim", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 16), createPrimitive("PropertyString", "Test123"))) .addProperty(createPrimitiveCollection("CollPropertyString", @@ -496,6 +517,7 @@ public class DataCreator { (short) 2000, (short) 30112)) .addProperty(createComplexCollection("CollPropertyComp", + ComplexTypeProvider.nameCTPrimComp.getFullQualifiedNameAsString(), Arrays.asList( createPrimitive("PropertyInt16", (short) 1), createKeyNavAllPrimComplexValue("PropertyComp")), @@ -506,8 +528,10 @@ public class DataCreator { createPrimitive("PropertyInt16", (short) 3), createKeyNavAllPrimComplexValue("PropertyComp")))) .addProperty(createComplex("PropertyCompCompNav", + ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(), createPrimitive("PropertyString", "1"), createComplex("PropertyCompNav", + ComplexTypeProvider.nameCTNavFiveProp.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 1)))); } @@ -521,7 +545,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav)); createEntityId(edm, odata, "ESTwoKeyNav", entityCollection); - + createOperations("ESTwoKeyNav", entityCollection, EntityTypeProvider.nameETTwoKeyNav); return entityCollection; } @@ -531,8 +555,10 @@ public class DataCreator { .addProperty(createPrimitive("PropertyInt16", propertyInt16)) .addProperty(createPrimitive("PropertyString", propertyString)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTPrimComp.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", 11), createComplex("PropertyComp", + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyString", "StringValue"), createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }), createPrimitive("PropertyBoolean", true), @@ -549,22 +575,26 @@ public class DataCreator { createPrimitive("PropertySByte", Byte.MAX_VALUE), createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59))))) .addProperty(createComplex("PropertyCompNav", + ComplexTypeProvider.nameCTBasePrimCompNav.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 1), createKeyNavAllPrimComplexValue("PropertyComp"))) - .addProperty(createComplexCollection("CollPropertyComp")) + .addProperty(createComplexCollection("CollPropertyComp", null)) .addProperty(createComplexCollection("CollPropertyCompNav", + ComplexTypeProvider.nameCTNavFiveProp.getFullQualifiedNameAsString(), Arrays.asList( createPrimitive("PropertyInt16", (short) 1)))) .addProperty(createPrimitiveCollection("CollPropertyString", "1", "2")) .addProperty(createComplex("PropertyCompTwoPrim", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 11), createPrimitive("PropertyString", "11"))); } protected Property createKeyNavAllPrimComplexValue(final String name) { return createComplex(name, + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyString", "First Resource - positive values"), createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }), createPrimitive("PropertyBoolean", true), @@ -588,7 +618,9 @@ public class DataCreator { entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTCompCollComp.getFullQualifiedNameAsString(), createComplexCollection("CollPropertyComp", + ComplexTypeProvider.nameCTCompCollComp.getFullQualifiedNameAsString(), Arrays.asList( createPrimitive("PropertyInt16", (short) 555), createPrimitive("PropertyString", "1 Test Complex in Complex Property")), @@ -602,7 +634,9 @@ public class DataCreator { entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", 12345)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTCompCollComp.getFullQualifiedNameAsString(), createComplexCollection("CollPropertyComp", + ComplexTypeProvider.nameCTCompCollComp.getFullQualifiedNameAsString(), Arrays.asList( createPrimitive("PropertyInt16", (short) 888), createPrimitive("PropertyString", "11 Test Complex in Complex Property")), @@ -615,7 +649,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCompCollComp)); createEntityId(edm, odata, "ESCompCollComp", entityCollection); - + createOperations("ESCompCollComp", entityCollection, EntityTypeProvider.nameETCompCollComp); return entityCollection; } @@ -640,6 +674,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoPrim)); createEntityId(edm, odata, "ESTwoPrim", entityCollection); + createOperations("ESTwoPrim", entityCollection, EntityTypeProvider.nameETTwoPrim); return entityCollection; } @@ -710,16 +745,92 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETAllPrim)); createEntityId(edm, odata, "ESAllPrim", entityCollection); - + createOperations("ESAllPrim", entityCollection, EntityTypeProvider.nameETAllPrim); return entityCollection; } + private void createOperations(String entitySetName, + EntityCollection entityCollection, FullQualifiedName entityTypeName) { + try { + List<CsdlAction> actions = ActionProvider.getBoundActionsForEntityType(entityTypeName); + for (CsdlAction action : actions) { + if (action.getParameters().get(0).isCollection()) { + Operation operation = buildOperation(action, entitySetName); + entityCollection.getOperations().add(operation); + } else { + for (Entity entity:entityCollection.getEntities()) { + Operation operation = buildOperation(action, entity.getId().toASCIIString()); + entity.getOperations().add(operation); + } + } + } + + List<CsdlFunction> functions = FunctionProvider.getBoundFunctionsForType(entityTypeName); + for (CsdlFunction func : functions) { + if (func.getParameters().get(0).isCollection()) { + Operation operation = buildOperation(func, entitySetName); + entityCollection.getOperations().add(operation); + } else { + for (Entity entity:entityCollection.getEntities()) { + Operation operation = buildOperation(func, entity.getId().toASCIIString()); + entity.getOperations().add(operation); + } + } + } + } catch (ODataException e) { + e.printStackTrace(); + } + } + + private static Operation buildOperation(CsdlFunction function, String id) { + String fqn = SchemaProvider.NAMESPACE+"."+function.getName(); + Operation operation = new Operation(); + operation.setType(Operation.Type.FUNCTION); + operation.setTitle(fqn); + StringBuilder params = new StringBuilder(); + StringBuilder nameFQN = new StringBuilder(); + params.append(fqn); + nameFQN.append(fqn); + if (!function.getParameters().isEmpty() && function.getParameters().size() > 1) { + params.append("("); + nameFQN.append("("); + boolean first = true; + for (int i = 1; i < function.getParameters().size(); i++) { + CsdlParameter p = function.getParameters().get(i); + if (first) { + first = false; + } else { + params.append(","); + nameFQN.append(","); + } + params.append(p.getName()).append("=").append("@").append(p.getName()); + nameFQN.append(p.getName()); + } + params.append(")"); + nameFQN.append(")"); + } + operation.setMetadataAnchor("#"+nameFQN); + operation.setTarget(URI.create(id+"/"+params.toString())); + return operation; + } + + private Operation buildOperation(CsdlAction action, String id) { + String fqn = SchemaProvider.NAMESPACE+"."+action.getName(); + Operation operation = new Operation(); + operation.setMetadataAnchor("#"+fqn); + operation.setType(Operation.Type.ACTION); + operation.setTitle(fqn); + operation.setTarget(URI.create(id+"/"+fqn)); + return operation; + } + private EntityCollection createESCompAllPrim(final Edm edm, final OData odata) { EntityCollection entityCollection = new EntityCollection(); Entity entity = new Entity() .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyString", "First Resource - first"), createPrimitive("PropertyBinary", new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }), @@ -743,6 +854,7 @@ public class DataCreator { entity = new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 7)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyString", "Second Resource - second"), createPrimitive("PropertyBinary", new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }), @@ -766,6 +878,7 @@ public class DataCreator { entity = new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 0)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyString", "Third Resource - third"), createPrimitive("PropertyBinary", new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }), @@ -789,6 +902,7 @@ public class DataCreator { entity = new Entity() .addProperty(createPrimitive("PropertyInt16", (short) -32768)) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyString", null), createPrimitive("PropertyBinary", null), createPrimitive("PropertyBoolean", null), @@ -810,7 +924,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCompAllPrim)); createEntityId(edm, odata, "ESCompAllPrim", entityCollection); - + createOperations("ESCompAllPrim", entityCollection, EntityTypeProvider.nameETCompAllPrim); return entityCollection; } @@ -823,7 +937,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCollAllPrim)); createEntityId(edm, odata, "ESCollAllPrim", entityCollection); - + createOperations("ESCollAllPrim", entityCollection, EntityTypeProvider.nameETCollAllPrim); return entityCollection; } @@ -906,6 +1020,7 @@ public class DataCreator { "[email protected]", "[email protected]")) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 111), createPrimitive("PropertyString", "TEST A"))) .addProperty(createCollPropertyComp())); @@ -917,6 +1032,7 @@ public class DataCreator { "[email protected]", "[email protected]")) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 222), createPrimitive("PropertyString", "TEST B"))) .addProperty(createCollPropertyComp())); @@ -928,13 +1044,14 @@ public class DataCreator { "[email protected]", "[email protected]")) .addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 333), createPrimitive("PropertyString", "TEST C"))) .addProperty(createCollPropertyComp())); setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMixPrimCollComp)); createEntityId(edm, odata, "ESMixPrimCollComp", entityCollection); - + createOperations("ESMixPrimCollComp", entityCollection, EntityTypeProvider.nameETMixPrimCollComp); return entityCollection; } @@ -948,6 +1065,7 @@ public class DataCreator { "[email protected]", "[email protected]")) .addProperty(createComplex("PropertyComp", + null, createPrimitive("PropertyInt16", (short) 111), createPrimitive("PropertyString", "TEST A"))) .addProperty(createCollPropertyComp())); @@ -959,6 +1077,7 @@ public class DataCreator { "[email protected]", "[email protected]")) .addProperty(createComplex("PropertyComp", + null, createPrimitive("PropertyInt16", (short) 222), createPrimitive("PropertyString", "TEST B"))) .addProperty(createCollPropertyComp())); @@ -970,19 +1089,48 @@ public class DataCreator { "[email protected]", "[email protected]")) .addProperty(createComplex("PropertyComp", + null, createPrimitive("PropertyInt16", (short) 333), createPrimitive("PropertyString", "TEST C"))) .addProperty(createCollPropertyComp())); setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMixPrimCollComp)); createEntityId(edm, odata, "ESStream", entityCollection); - + createOperations("ESStream", entityCollection, EntityTypeProvider.nameETMixPrimCollComp); return entityCollection; } + private EntityCollection createESWithStream(final Edm edm, final OData odata) { + EntityCollection entityCollection = new EntityCollection(); + + Link readLink = new Link(); + readLink.setRel(Constants.NS_MEDIA_READ_LINK_REL); + readLink.setHref("readLink"); + + entityCollection.getEntities().add(new Entity() + .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE)) + .addProperty(new Property(null, "PropertyStream", ValueType.PRIMITIVE, readLink))); + + Link editLink = new Link(); + editLink.setRel(Constants.NS_MEDIA_EDIT_LINK_REL); + editLink.setHref("http://mediaserver:1234/editLink"); + editLink.setMediaETag("eTag"); + editLink.setType("image/jpeg"); + + entityCollection.getEntities().add(new Entity() + .addProperty(createPrimitive("PropertyInt16", (short) 7)) + .addProperty(new Property(null, "PropertyStream", ValueType.PRIMITIVE, editLink))); + + setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETStream)); + createEntityId(edm, odata, "ESWithStream", entityCollection); + createOperations("ESWithStream", entityCollection, EntityTypeProvider.nameETStream); + return entityCollection; + } + @SuppressWarnings("unchecked") private Property createCollPropertyComp() { return createComplexCollection("CollPropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), Arrays.asList( createPrimitive("PropertyInt16", (short) 123), createPrimitive("PropertyString", "TEST 1")), @@ -1029,7 +1177,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETAllKey)); createEntityId(edm, odata, "ESAllKey", entityCollection); - + createOperations( "ESAllKey", entityCollection, EntityTypeProvider.nameETAllKey); return entityCollection; } @@ -1039,7 +1187,9 @@ public class DataCreator { Entity entity = new Entity(); entity.addProperty(createPrimitive("PropertyInt16", (short) 1)); entity.addProperty(createComplex("PropertyComp", + ComplexTypeProvider.nameCTCompComp.getFullQualifiedNameAsString(), createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 123), createPrimitive("PropertyString", "String 1")))); entityCollection.getEntities().add(entity); @@ -1048,7 +1198,8 @@ public class DataCreator { entity.addProperty(createPrimitive("PropertyInt16", (short) 2)); entity.addProperty(createComplex("PropertyComp", ComplexTypeProvider.nameCTCompCompExtended.getFullQualifiedNameAsString(), - createComplex("PropertyComp", + createComplex("PropertyComp", + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 987), createPrimitive("PropertyString", "String 2")), createPrimitive("PropertyDate", getDate(2012, 12, 3)))); @@ -1056,7 +1207,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCompComp)); createEntityId(edm, odata, "ESCompComp", entityCollection); - + createOperations("ESCompComp", entityCollection, EntityTypeProvider.nameETCompComp); return entityCollection; } @@ -1097,7 +1248,7 @@ public class DataCreator { setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMedia)); createEntityId(edm, odata, "ESMedia", entityCollection); - + createOperations("ESMedia", entityCollection, EntityTypeProvider.nameETMedia); return entityCollection; } @@ -1211,31 +1362,48 @@ public class DataCreator { } return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, propertyValues); } - - protected static Property createComplex(final String name, final Property... properties) { - ComplexValue complexValue = new ComplexValue(); - for (final Property property : properties) { - complexValue.getValue().add(property); - } - return new Property(null, name, ValueType.COMPLEX, complexValue); - } protected static Property createComplex(final String name, final String type, final Property... properties) { ComplexValue complexValue = new ComplexValue(); for (final Property property : properties) { complexValue.getValue().add(property); } - return new Property(type, name, ValueType.COMPLEX, complexValue); + Property property = new Property(type, name, ValueType.COMPLEX, complexValue); + createOperations(name, type, property); + return property; + } + + private static void createOperations(final String name, final String type, + Property property) { + if (type != null) { + try { + List<CsdlFunction> functions = FunctionProvider.getBoundFunctionsForType(new FullQualifiedName(type)); + for (CsdlFunction func : functions) { + if (func.getParameters().get(0).isCollection() && property.isCollection()) { + Operation operation = buildOperation(func, name); + property.getOperations().add(operation); + } else { + Operation operation = buildOperation(func, name); + property.getOperations().add(operation); + } + } + } catch (ODataException e) { + // ignore + } + } } - protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) { + protected static Property createComplexCollection(final String name, + String type, final List<Property>... propertiesList) { List<ComplexValue> complexCollection = new ArrayList<ComplexValue>(); for (final List<Property> properties : propertiesList) { ComplexValue complexValue = new ComplexValue(); complexValue.getValue().addAll(properties); complexCollection.add(complexValue); } - return new Property(null, name, ValueType.COLLECTION_COMPLEX, complexCollection); + Property property = new Property(type, name, ValueType.COLLECTION_COMPLEX, complexCollection); + createOperations(name, type, property); + return property; } private static Calendar getDateTime(final int year, final int month, final int day, http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java index 9dad2b9..da5da65 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java @@ -267,10 +267,12 @@ public class DataProvider { } else { if (edmProperty.isCollection()) { @SuppressWarnings("unchecked") - Property newProperty2 = DataCreator.createComplexCollection(propertyName); + Property newProperty2 = DataCreator.createComplexCollection(propertyName, + edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString()); newProperty = newProperty2; } else { - newProperty = DataCreator.createComplex(propertyName); + newProperty = DataCreator.createComplex(propertyName, + edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString()); createProperties((EdmComplexType) type, newProperty.asComplex().getValue()); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java index e31ff80..ef1fa70 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java @@ -31,6 +31,7 @@ import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException; +import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider; public class FunctionData { @@ -100,14 +101,17 @@ public class FunctionData { return data.get("ESCollAllPrim").getEntities().get(0).getProperty("CollPropertyString"); } else if (name.equals("UFCRTCTTwoPrim")) { return DataCreator.createComplex(name, + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyInt16", (short) 16), DataCreator.createPrimitive("PropertyString", "UFCRTCTTwoPrim string value")); } else if (name.equals("UFCRTCTTwoPrimParam")) { return DataCreator.createComplex(name, + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), DataCreator.createPrimitive("PropertyInt16", getParameterInt16(parameters)), DataCreator.createPrimitive("PropertyString", getParameterString(parameters))); } else if (name.equals("UFCRTCollCTTwoPrim")) { return DataCreator.createComplexCollection(name, + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), Arrays.asList(DataCreator.createPrimitive("PropertyInt16", (short) 16), DataCreator.createPrimitive("PropertyString", "Test123")), Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 17), @@ -138,6 +142,7 @@ public class FunctionData { final String parameterString = getParameterString(parameters); if (parameterString == null) { return DataCreator.createComplexCollection(name, + ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 1), DataCreator.createPrimitive("PropertyString", name + " int16 value: " + parameterInt16)), Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 2), http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index c59f3ef..c547992 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@ -30,6 +30,7 @@ import org.apache.olingo.commons.api.data.ContextURL.Suffix; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.EntityIterator; +import org.apache.olingo.commons.api.data.Operation; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmEntitySet; @@ -488,6 +489,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor // copy of the entity set (new EntitySet, but exactly the same data). EntityCollection entitySet = new EntityCollection(); entitySet.getEntities().addAll(entitySetInitial.getEntities()); + entitySet.getOperations().addAll(entitySetInitial.getOperations()); // Apply system query options. SearchHandler.applySearchSystemQueryOption(uriInfo.getSearchOption(), entitySet); @@ -599,6 +601,11 @@ public class TechnicalEntityProcessor extends TechnicalProcessor Iterator<Entity> entityIterator = entityCollection.iterator(); @Override + public List<Operation> getOperations() { + return entityCollection.getOperations(); + } + + @Override public boolean hasNext() { return entityIterator.hasNext(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java index f3d707a..7ddad53 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java @@ -196,7 +196,7 @@ public class ExpandSystemQueryOptionHandler { newEntitySet.setNext(entitySet.getNext()); newEntitySet.setId(entitySet.getId()); newEntitySet.setBaseURI(entitySet.getBaseURI()); - + newEntitySet.getOperations().addAll(entitySet.getOperations()); return newEntitySet; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java index c62b5d7..39244b3 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.server.tecsvc.provider; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -79,8 +80,27 @@ public class ActionProvider { new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTTwoParam"); public static final FullQualifiedName nameUARTByteNineParam = new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTByteNineParam"); + + public static List<CsdlAction> getBoundActionsForEntityType(FullQualifiedName entityType) throws ODataException { + FullQualifiedName[] actionNames = {nameBAESAllPrimRTETAllPrim, + nameBAESTwoKeyNavRTESTwoKeyNav, nameBAESTwoKeyNavRTESKeyNav, nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav, + nameBAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav,nameBAETTwoKeyNavRTETTwoKeyNav, + nameBAESAllPrimRT,nameBAETAllPrimRT}; + + List<CsdlAction> actions = new ArrayList<CsdlAction>(); + for (FullQualifiedName fqn:actionNames) { + List<CsdlAction> entityActions = getActions(fqn); + for (CsdlAction action:entityActions) { + CsdlParameter parameter = action.getParameters().get(0); + if (parameter.getTypeFQN().equals(entityType)) { + actions.add(action); + } + } + } + return actions; + } - public List<CsdlAction> getActions(final FullQualifiedName actionName) throws ODataException { + public static List<CsdlAction> getActions(final FullQualifiedName actionName) throws ODataException { if (actionName.equals(nameUARTString)) { return Collections.singletonList( new CsdlAction().setName(nameUARTString.getName()) http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java index 9f06b89..8dd07a8 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java @@ -102,6 +102,7 @@ public class ContainerProvider { entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESTwoBaseTwoKeyNav")); entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESKeyNavCont")); entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESTwoKeyNavCont")); + entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESWithStream")); entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, ES_STREAM)); // Singletons @@ -647,6 +648,10 @@ public class ContainerProvider { "type primitive, collection of primitive, complex and collection of complex")), new CsdlAnnotation().setTerm(TermProvider.TERM_DATA.getFullQualifiedNameAsString()).setExpression( new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.Bool, "true")))); + } else if (name.equals("ESWithStream")) { + return new CsdlEntitySet() + .setName("ESWithStream") + .setType(EntityTypeProvider.nameETStream); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java index c2397c4..10f3971 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java @@ -84,6 +84,9 @@ public class EntityTypeProvider { public static final FullQualifiedName nameETMixEnumDefCollComp = new FullQualifiedName(SchemaProvider.NAMESPACE, "ETMixEnumDefCollComp"); + public static final FullQualifiedName nameETStream = new FullQualifiedName(SchemaProvider.NAMESPACE, + "ETWithStream"); + public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException { if (entityTypeName.equals(nameETAllPrim)) { @@ -469,8 +472,16 @@ public class EntityTypeProvider { PropertyProvider.collPropertyTypeDefinition_TDString, PropertyProvider.propertyComp_CTMixEnumTypeDefColl, PropertyProvider.propertyCompColl_CTMixEnumTypeDefColl)); + } else if (entityTypeName.equals(nameETStream)) { + return new CsdlEntityType() + .setName(nameETStream.getName()) + .setKey(Arrays.asList( + new CsdlPropertyRef() + .setName("PropertyInt16"))) + .setProperties(Arrays.asList( + PropertyProvider.propertyInt16_NotNullable, + PropertyProvider.propertyStream)); } - return null; } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java index b60b954..69d179d 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.server.tecsvc.provider; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -31,6 +32,11 @@ import org.apache.olingo.commons.api.ex.ODataException; public class FunctionProvider { // Bound Functions + + + public static final FullQualifiedName nameBFCColCTAllPrimRTESAllPrim = + new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCColCTAllPrimRTESAllPrim"); + public static final FullQualifiedName nameBFCCollCTPrimCompRTESAllPrim = new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCCollCTPrimCompRTESAllPrim"); @@ -181,7 +187,56 @@ public class FunctionProvider { public static final FullQualifiedName nameUFNRTByteNineParam = new FullQualifiedName(SchemaProvider.NAMESPACE, "UFNRTByteNineParam"); - public List<CsdlFunction> getFunctions(final FullQualifiedName functionName) throws ODataException { + + public static List<CsdlFunction> getBoundFunctionsForType(FullQualifiedName entityType) throws ODataException { + FullQualifiedName[] funcNames = { + nameBFCColCTAllPrimRTESAllPrim, + nameBFCCollCTPrimCompRTESAllPrim, + nameBFCCollStringRTESTwoKeyNav, + nameBFCCTPrimCompRTESBaseTwoKeyNav, + nameBFCCTPrimCompRTESTwoKeyNav, + nameBFCCTPrimCompRTESTwoKeyNavParam, + nameBFCCTPrimCompRTETTwoKeyNavParam, + nameBFNESAllPrimRTCTAllPrim, + nameBFCESBaseTwoKeyNavRTESBaseTwoKey, + nameBFCESKeyNavRTETKeyNav, + nameBFCESKeyNavRTETKeyNavParam, + nameBFCESTwoKeyNavRTCollCTTwoPrim, + nameBFCESTwoKeyNavRTCollString, + nameBFCESTwoKeyNavRTCTTwoPrim, + nameBFCESTwoKeyNavRTESTwoKeyNav, + nameBFCESTwoKeyNavRTString, + nameBFCESTwoKeyNavRTStringParam, + nameBFCESTwoKeyNavRTTwoKeyNav, + nameBFCETBaseTwoKeyNavRTESBaseTwoKey, + nameBFCETBaseTwoKeyNavRTESTwoKeyNav, + nameBFCETBaseTwoKeyNavRTETTwoKeyNav, + nameBFCETKeyNavRTETKeyNav, + nameBFCETTwoKeyNavRTCTTwoPrim, + nameBFCETTwoKeyNavRTESTwoKeyNav, + nameBFCETTwoKeyNavRTETTwoKeyNav, + nameBFCSINavRTESTwoKeyNav, + nameBFCStringRTESTwoKeyNav, + nameBFESTwoKeyNavRTESTwoKeyNav, + nameBFCESTwoKeyNavRTCTNavFiveProp, + nameBFCESTwoKeyNavRTCollCTNavFiveProp, + nameBFCESKeyNavRTESTwoKeyNav + }; + + List<CsdlFunction> functions = new ArrayList<CsdlFunction>(); + for (FullQualifiedName fqn:funcNames) { + List<CsdlFunction> entityFuncs = getFunctions(fqn); + for (CsdlFunction func:entityFuncs) { + CsdlParameter parameter = func.getParameters().get(0); + if (parameter.getTypeFQN().equals(entityType)) { + functions.add(func); + } + } + } + return functions; + } + + public static List<CsdlFunction> getFunctions(final FullQualifiedName functionName) throws ODataException { if (functionName.equals(nameUFNRTInt16)) { return Collections.singletonList( @@ -564,7 +619,7 @@ public class FunctionProvider { .setNullable(false))); } else if (functionName.equals(nameBFNESAllPrimRTCTAllPrim)) { - return Collections.singletonList( + return Arrays.asList( new CsdlFunction() .setName("BFNESAllPrimRTCTAllPrim") .setBound(true) @@ -573,7 +628,19 @@ public class FunctionProvider { .setCollection(true).setNullable(false))) .setComposable(false) .setReturnType( - new CsdlReturnType().setType(ComplexTypeProvider.nameCTAllPrim).setNullable(false))); + new CsdlReturnType().setType(ComplexTypeProvider.nameCTAllPrim).setNullable(false)), + new CsdlFunction() + .setName("BFNESAllPrimRTCTAllPrim") + .setBound(true) + .setParameters(Arrays.asList( + new CsdlParameter().setName("BindingParam").setType(EntityTypeProvider.nameETAllPrim) + .setCollection(true).setNullable(false), + new CsdlParameter().setName("Param2").setType(PropertyProvider.nameInt16) + .setCollection(true).setNullable(false))) + .setComposable(false) + .setReturnType( + new CsdlReturnType().setType(ComplexTypeProvider.nameCTAllPrim).setNullable(false)) + ); } else if (functionName.equals(nameBFCESTwoKeyNavRTCTTwoPrim)) { return Collections.singletonList( @@ -716,6 +783,19 @@ public class FunctionProvider { new CsdlReturnType().setType(EntityTypeProvider.nameETBaseTwoKeyNav).setCollection(true) .setNullable(false))); + } else if (functionName.equals(nameBFCColCTAllPrimRTESAllPrim)) { + return Collections.singletonList( + new CsdlFunction() + .setName("BFCColCTAllPrimRTESAllPrim") + .setBound(true) + .setParameters(Collections.singletonList( + new CsdlParameter().setName("BindingParam").setType(ComplexTypeProvider.nameCTAllPrim) + .setNullable(false))) + .setComposable(true) + .setReturnType( + new CsdlReturnType().setType(EntityTypeProvider.nameETAllPrim).setCollection(true) + .setNullable(false))); + } else if (functionName.equals(nameBFCCollCTPrimCompRTESAllPrim)) { return Collections.singletonList( new CsdlFunction() http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java index c163d59..42e253d 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java @@ -48,6 +48,7 @@ public class PropertyProvider { public static final FullQualifiedName nameString = EdmPrimitiveTypeKind.String.getFullQualifiedName(); public static final FullQualifiedName nameTimeOfDay = EdmPrimitiveTypeKind.TimeOfDay.getFullQualifiedName(); + public static final FullQualifiedName nameStream = EdmPrimitiveTypeKind.Stream.getFullQualifiedName(); // Primitive Properties -------------------------------------------------------------------------------------------- public static final CsdlProperty collPropertyBinary = new CsdlProperty() @@ -563,6 +564,11 @@ public class PropertyProvider { .setType(nameTimeOfDay) .setNullable(true); + public static final CsdlProperty propertyStream = new CsdlProperty() + .setName("PropertyStream") + .setType(nameStream) + .setNullable(true); + // Complex Properties ---------------------------------------------------------------------------------------------- public static final CsdlProperty collPropertyComp_CTPrimComp = new CsdlProperty() .setName("CollPropertyComp") http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eaceb01d/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java index e4f62c2..9540dda 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java @@ -26,6 +26,7 @@ import java.nio.channels.WritableByteChannel; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; +import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; @@ -35,6 +36,7 @@ import org.apache.olingo.commons.api.data.ContextURL.Suffix; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.EntityIterator; +import org.apache.olingo.commons.api.data.Operation; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmComplexType; @@ -83,6 +85,7 @@ public class ODataJsonSerializerTest { private final DataProvider data = new DataProvider(odata, metadata.getEdm()); private final ODataSerializer serializer = new ODataJsonSerializer(ContentType.JSON); private final ODataSerializer serializerNoMetadata = new ODataJsonSerializer(ContentType.JSON_NO_METADATA); + private final ODataSerializer serializerFullMetadata = new ODataJsonSerializer(ContentType.JSON_FULL_METADATA); private final ODataSerializer serializerIEEECompatible = new ODataJsonSerializer(ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true")); private final UriHelper helper = odata.createUriHelper(); @@ -118,7 +121,130 @@ public class ODataJsonSerializerTest { + "}"; Assert.assertEquals(expectedResult, resultString); } + + @Test + public void entitySimpleMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); + final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); + InputStream result = serializerFullMetadata.entity(metadata, edmEntitySet.getEntityType(), entity, + EntitySerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expected = "{\"@odata.context\":\"$metadata#ESAllPrim/$entity\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"@odata.type\":\"#olingo.odata.test1.ETAllPrim\"," + + "\"@odata.id\":\"ESAllPrim(32767)\"," + + "\"[email protected]\":\"#Int16\"," + + "\"PropertyInt16\":32767," + + "\"PropertyString\":\"First Resource - positive values\"," + + "\"PropertyBoolean\":true," + + "\"[email protected]\":\"#Byte\"," + + "\"PropertyByte\":255," + + "\"[email protected]\":\"#SByte\"," + + "\"PropertySByte\":127," + + "\"[email protected]\":\"#Int32\"," + + "\"PropertyInt32\":2147483647," + + "\"[email protected]\":\"#Int64\"," + + "\"PropertyInt64\":9223372036854775807," + + "\"[email protected]\":\"#Single\"," + + "\"PropertySingle\":1.79E20," + + "\"PropertyDouble\":-1.79E19," + + "\"[email protected]\":\"#Decimal\"," + + "\"PropertyDecimal\":34," + + "\"[email protected]\":\"#Binary\"," + + "\"PropertyBinary\":\"ASNFZ4mrze8=\"," + + "\"[email protected]\":\"#Date\"," + + "\"PropertyDate\":\"2012-12-03\"," + + "\"[email protected]\":\"#DateTimeOffset\"," + + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," + + "\"[email protected]\":\"#Duration\"," + + "\"PropertyDuration\":\"PT6S\"," + + "\"[email protected]\":\"#Guid\"," + + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," + + "\"[email protected]\":\"#TimeOfDay\"," + + "\"PropertyTimeOfDay\":\"03:26:05\"," + + "\"[email protected]\":\"ESTwoPrim(32767)\"," + + "\"[email protected]\":\"ESAllPrim(32767)/NavPropertyETTwoPrimMany\"," + + "\"#olingo.odata.test1.BAETAllPrimRT\":{" + + "\"title\":\"olingo.odata.test1.BAETAllPrimRT\"," + + "\"target\":\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\"" + + "}}"; + Assert.assertEquals(expected, resultString); + } + + @Test + public void entitySetMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); + final EntityCollection entityCol = data.readAll(edmEntitySet); + InputStream result = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), entityCol, + EntityCollectionSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expected = "{" + + "\"@odata.context\":\"$metadata#ESAllPrim\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"#olingo.odata.test1.BAESAllPrimRTETAllPrim\":{" + + "\"title\":\"olingo.odata.test1.BAESAllPrimRTETAllPrim\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BAESAllPrimRTETAllPrim\"" + + "}," + + "\"#olingo.odata.test1.BAESAllPrimRT\":{" + + "\"title\":\"olingo.odata.test1.BAESAllPrimRT\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BAESAllPrimRT\"" + + "}," + + "\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim\":{" + + "\"title\":\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"" + + "}," + + "\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim(Param2)\":{" + + "\"title\":\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"," + + "\"target\":\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim(Param2=@Param2)\"" + + "}," + + "\"value\":[" + + "{" + + "\"@odata.type\":\"#olingo.odata.test1.ETAllPrim\"," + + "\"@odata.id\":\"ESAllPrim(32767)\"," + + "\"[email protected]\":\"#Int16\"," + + "\"PropertyInt16\":32767," + + "\"PropertyString\":\"First Resource - positive values\"," + + "\"PropertyBoolean\":true," + + "\"[email protected]\":\"#Byte\"," + + "\"PropertyByte\":255," + + "\"[email protected]\":\"#SByte\"," + + "\"PropertySByte\":127," + + "\"[email protected]\":\"#Int32\"," + + "\"PropertyInt32\":2147483647," + + "\"[email protected]\":\"#Int64\"," + + "\"PropertyInt64\":9223372036854775807," + + "\"[email protected]\":\"#Single\"," + + "\"PropertySingle\":1.79E20," + + "\"PropertyDouble\":-1.79E19," + + "\"[email protected]\":\"#Decimal\"," + + "\"PropertyDecimal\":34," + + "\"[email protected]\":\"#Binary\"," + + "\"PropertyBinary\":\"ASNFZ4mrze8=\"," + + "\"[email protected]\":\"#Date\"," + + "\"PropertyDate\":\"2012-12-03\"," + + "\"[email protected]\":\"#DateTimeOffset\"," + + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," + + "\"[email protected]\":\"#Duration\"," + + "\"PropertyDuration\":\"PT6S\"," + + "\"[email protected]\":\"#Guid\"," + + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," + + "\"[email protected]\":\"#TimeOfDay\"," + + "\"PropertyTimeOfDay\":\"03:26:05\"," + + "\"[email protected]\":\"ESTwoPrim(32767)\"," + + "\"[email protected]\":\"ESAllPrim(32767)/NavPropertyETTwoPrimMany\"," + + "\"#olingo.odata.test1.BAETAllPrimRT\":{" + + "\"title\":\"olingo.odata.test1.BAETAllPrimRT\"," + + "\"target\":\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\"" + + "}},"; + + Assert.assertTrue(resultString.startsWith(expected)); + } + @Test public void entityAllPrimAllNull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); @@ -207,7 +333,14 @@ public class ODataJsonSerializerTest { public void entityCollectionStreamed() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EntityIterator entityIterator = new EntityIterator() { - Iterator<Entity> innerIterator = data.readAll(edmEntitySet).iterator(); + EntityCollection entityCollection = data.readAll(edmEntitySet); + Iterator<Entity> innerIterator = entityCollection.iterator(); + + @Override + public List<Operation> getOperations() { + return entityCollection.getOperations(); + } + @Override public boolean hasNext() { return innerIterator.hasNext(); @@ -248,7 +381,14 @@ public class ODataJsonSerializerTest { public void entityCollectionStreamedWithError() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EntityIterator entityIterator = new EntityIterator() { - Iterator<Entity> innerIterator = data.readAll(edmEntitySet).iterator(); + EntityCollection entityCollection = data.readAll(edmEntitySet); + Iterator<Entity> innerIterator = entityCollection.iterator(); + + @Override + public List<Operation> getOperations() { + return entityCollection.getOperations(); + } + @Override public boolean hasNext() { return innerIterator.hasNext(); @@ -502,6 +642,114 @@ public class ODataJsonSerializerTest { } @Test + public void entityTwoPrimWithMetadataMinimal() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); + final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); + InputStream result = serializer + .entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test + public void entitySetTwoPrimWithMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); + final EntityCollection entitySet = data.readAll(edmEntitySet); + InputStream result = serializerFullMetadata + .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet, + EntityCollectionSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) + .build()) + .getContent(); + final String resultString = IOUtils.toString(result); + final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"value\":[{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(32766)\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":32766," + + "\"PropertyString\":\"Test String1\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(-365)\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":-365," + + "\"PropertyString\":\"Test String2\"," + + "\"[email protected]\":\"ESTwoPrim(-365)/NavPropertyETAllPrimMany\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(-32766)\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":-32766," + + "\"PropertyString\":null}," + + "{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(32767)\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":32767," + + "\"PropertyString\":\"Test String4\"," + + "\"[email protected]\":\"ESAllPrim(32767)\"}]}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test + public void entityWithStreamMetadataMinimal() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream"); + final EntityCollection collection = data.readAll(edmEntitySet); + InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), collection, + EntityCollectionSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expectedResult = "{\"@odata.context\":\"$metadata#ESWithStream\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"value\":[{\"PropertyInt16\":32767}," + + "{\"PropertyInt16\":7,\"[email protected]\":\"eTag\"," + + "\"[email protected]\":\"image/jpeg\"}]}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test + public void entityWithStreamMetadataNone() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream"); + final EntityCollection collection = data.readAll(edmEntitySet); + InputStream result = serializerNoMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), collection, + EntityCollectionSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expectedResult = "{" + + "\"value\":[{\"PropertyInt16\":32767}," + + "{\"PropertyInt16\":7}]}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test + public void entityWithStreamMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream"); + final EntityCollection collection = data.readAll(edmEntitySet); + InputStream result = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), collection, + EntityCollectionSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) + .build()).getContent(); + final String resultString = IOUtils.toString(result); + final String expectedResult = "{\"@odata.context\":\"$metadata#ESWithStream\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"value\":[{" + + "\"@odata.type\":\"#olingo.odata.test1.ETWithStream\"," + + "\"@odata.id\":\"ESWithStream(32767)\"," + + "\"[email protected]\":\"#Int16\"," + + "\"PropertyInt16\":32767," + + "\"[email protected]\":\"#Stream\"," + + "\"[email protected]\":\"readLink\"}," + + "{" + + "\"@odata.type\":\"#olingo.odata.test1.ETWithStream\"," + + "\"@odata.id\":\"ESWithStream(7)\"," + + "\"[email protected]\":\"#Int16\"," + + "\"PropertyInt16\":7," + + "\"[email protected]\":\"#Stream\"," + + "\"[email protected]\":\"eTag\"," + + "\"[email protected]\":\"image/jpeg\"," + + "\"[email protected]\":\"http://mediaserver:1234/editLink\"" + + "}]}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test public void entitySetTwoPrimNoMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final EntityCollection entitySet = data.readAll(edmEntitySet); @@ -559,6 +807,26 @@ public class ODataJsonSerializerTest { } @Test + public void entityMediaWithMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia"); + final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); + entity.setMediaETag("W/\\\"08D25949E3BFB7AB\\\""); + InputStream result = serializerFullMetadata + .entity(metadata, edmEntitySet.getEntityType(), entity, + EntitySerializerOptions.with().contextURL(ContextURL.with() + .entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()).build()) + .getContent(); + final String resultString = IOUtils.toString(result); + final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"@odata.mediaEtag\":\"W/\\\\\\\"08D25949E3BFB7AB\\\\\\\"\",\"@odata.mediaContentType\":\"image/svg+xml\"," + + "\"@odata.mediaEditLink\":\"ESMedia(1)/$value\"," + + "\"@odata.type\":\"#olingo.odata.test1.ETMedia\",\"@odata.id\":\"ESMedia(1)\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":1}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test public void primitiveValuesAllNull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllNullable"); final EntityCollection entitySet = data.readAll(edmEntitySet); @@ -932,6 +1200,29 @@ public class ODataJsonSerializerTest { .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, null).getContent()); Assert.assertEquals("{\"value\":\"First Resource - positive values\"}", resultString); } + + @Test + public void primitivePropertyWithMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); + final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType() + .getProperty("PropertyString"); + final Property property = data.readAll(edmEntitySet).getEntities().get(0) + .getProperty(edmProperty.getName()); + final String resultString = IOUtils + .toString(serializerFullMetadata + .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, + PrimitiveSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet) + .keyPath("32767") + .navOrPropertyPath(edmProperty.getName()).build()) + .build()) + .getContent()); + Assert.assertEquals( + "{\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyString\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"value\":\"First Resource - positive values\"}", + resultString); + } @Test(expected = SerializerException.class) public void primitivePropertyNull() throws Exception { @@ -979,6 +1270,25 @@ public class ODataJsonSerializerTest { } @Test + public void primitiveCollectionPropertyWithMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); + final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyString"); + final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); + + final String resultString = IOUtils.toString(serializerFullMetadata + .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property, + PrimitiveSerializerOptions.with() + .contextURL(ContextURL.with() + .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) + .build()) + .build()).getContent()); + Assert.assertEquals("{\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"@odata.type\":\"#Collection(String)\",\"value\":[\"[email protected]\"," + + "\"[email protected]\",\"[email protected]\"]}", resultString); + } + + @Test public void complexProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); @@ -1009,6 +1319,24 @@ public class ODataJsonSerializerTest { } @Test + public void complexPropertyWithMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); + final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); + final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp"); + final String resultString = IOUtils.toString(serializerFullMetadata + .complex(metadata, (EdmComplexType) edmProperty.getType(), property, + ComplexSerializerOptions.with() + .contextURL(ContextURL.with() + .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) + .build()).build()).getContent()); + Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":111," + + "\"PropertyString\":\"TEST A\"}",resultString); + } + + @Test public void complexCollectionProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp"); @@ -1044,6 +1372,34 @@ public class ODataJsonSerializerTest { } @Test + public void complexCollectionPropertyWithMetadataFull() throws Exception { + final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); + final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp"); + final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); + final String resultString = IOUtils.toString(serializerFullMetadata + .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), + property, ComplexSerializerOptions.with() + .contextURL(ContextURL.with().entitySet(edmEntitySet) + .keyPath("32767") + .navOrPropertyPath(edmProperty.getName()).build()) + .build()) + .getContent()); + final String expectedResult = "{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + + "\"@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\"," + + "\"value\":[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":123," + + "\"PropertyString\":\"TEST 1\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":456," + + "\"PropertyString\":\"TEST 2\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":789," + + "\"PropertyString\":\"TEST 3\"}]}"; + Assert.assertEquals(expectedResult, resultString); + } + + @Test public void entityReference() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
