[OLINGO-665] Data added to the TecSvc

This commit is contained in:
Christian Holzer 2015-05-19 18:38:15 +02:00
parent b5a194731b
commit 24898bda9b
3 changed files with 309 additions and 28 deletions

View File

@ -58,20 +58,13 @@ public class DataCreator {
data.put("ESCompCollComp", createESCompCollComp());
data.put("ESServerSidePaging", createESServerSidePaging());
data.put("ESTwoKeyTwoPrim", createESTwoKeyTwoPrim());
// No data available but to allow an insert operation create empty EntitySets
data.put("ESAllNullable", createESAllNullable());
data.put("ESMixEnumDefCollComp", new EntityCollection());
data.put("ESTwoBase", new EntityCollection());
data.put("ESBaseTwoKeyNav", new EntityCollection());
data.put("ESBaseTwoKeyTwoPrim", new EntityCollection());
data.put("ESCompCollAllPrim", new EntityCollection());
data.put("ESKeyTwoKeyComp", new EntityCollection());
data.put("ESFourKeyAlias", new EntityCollection());
data.put("ESBase", new EntityCollection());
data.put("ESTwoBaseTwoKeyTwoPrim", new EntityCollection());
data.put("ESInvisible", new EntityCollection());
data.put("ESCompMixPrimCollComp", new EntityCollection());
data.put("ESTwoBase", createESTwoBase());
data.put("ESBaseTwoKeyNav", createESBaseTwoKeyNav());
data.put("ESCompCollAllPrim", createESCompCollAllPrim());
data.put("ESFourKeyAlias", createESFourKeyAlias());
data.put("ESBase", createESBase());
data.put("ESCompMixPrimCollComp", createESCompMixPrimCollComp());
linkESTwoPrim(data);
linkESAllPrim(data);
@ -79,6 +72,278 @@ public class DataCreator {
linkESTwoKeyNav(data);
}
@SuppressWarnings("unchecked")
private EntityCollection createESCompMixPrimCollComp() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 1))
.addProperty(createComplex("PropertyMixedPrimCollComp",
createPrimitive("PropertyInt16", 1),
createPrimitiveCollection("CollPropertyString",
"Employee1@company.example",
"Employee2@company.example",
"Employee3@company.example"
),
createComplex("PropertyComp",
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST123")
),
createComplexCollection("CollPropertyComp",
Arrays.asList(new Property[] {
createPrimitive("PropertyInt16", 222),
createPrimitive("PropertyString", "TEST9876")
}),
Arrays.asList(new Property[] {
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST123")
})
)
))
);
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 2))
.addProperty(createComplex("PropertyMixedPrimCollComp",
createPrimitive("PropertyInt16", 1),
createPrimitiveCollection("CollPropertyString",
"Employee1@company.example",
"Employee2@company.example",
"Employee3@company.example"
),
createComplex("PropertyComp",
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST123")
),
createComplexCollection("CollPropertyComp",
Arrays.asList(new Property[] {
createPrimitive("PropertyInt16", 222),
createPrimitive("PropertyString", "TEST9876")
}),
Arrays.asList(new Property[] {
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST123")
})
)
))
);
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 3))
.addProperty(createComplex("PropertyMixedPrimCollComp",
createPrimitive("PropertyInt16", 1),
createPrimitiveCollection("CollPropertyString",
"Employee1@company.example",
"Employee2@company.example",
"Employee3@company.example"
),
createComplex("PropertyComp",
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST123")
),
createComplexCollection("CollPropertyComp",
Arrays.asList(new Property[] {
createPrimitive("PropertyInt16", 222),
createPrimitive("PropertyString", "TEST9876")
}),
Arrays.asList(new Property[] {
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST123")
})
)
))
);
return entityCollection;
}
private EntityCollection createESBase() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 111))
.addProperty(createPrimitive("PropertyString", "TEST A"))
.addProperty(createPrimitive("AdditionalPropertyString_5", "TEST A 0815")));
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 222))
.addProperty(createPrimitive("PropertyString", "TEST B"))
.addProperty(createPrimitive("AdditionalPropertyString_5", "TEST C 0815")));
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 333))
.addProperty(createPrimitive("PropertyString", "TEST C"))
.addProperty(createPrimitive("AdditionalPropertyString_5", "TEST E 0815")));
return entityCollection;
}
private EntityCollection createESFourKeyAlias() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 1))
.addProperty(createComplex("PropertyComp",
createPrimitive("PropertyInt16", 11),
createPrimitive("PropertyString", "Num11")
))
.addProperty(createComplex("PropertyCompComp",
createComplex("PropertyComp",
createPrimitive("PropertyInt16", 111),
createPrimitive("PropertyString", "Num111")
)
))
);
return entityCollection;
}
private EntityCollection createESCompCollAllPrim() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 5678))
.addProperty(createComplex("PropertyComp",
createPrimitiveCollection("CollPropertyString",
"Employee1@company.example",
"Employee2@company.example",
"Employee3@company.example"),
createPrimitiveCollection("CollPropertyBoolean", true, false, true),
createPrimitiveCollection("CollPropertyByte", 50, 200, 249),
createPrimitiveCollection("CollPropertySByte", -120, 120, 126),
createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112),
createPrimitiveCollection("CollPropertyInt32", 23232323, 11223355, 10000001),
createPrimitiveCollection("CollPropertyInt64", 929292929292L, 333333333333L, 444444444444L),
createPrimitiveCollection("CollPropertySingle", 1790, 26600, 3210),
createPrimitiveCollection("CollPropertyDouble", -17900, -27800000, 3210),
createPrimitiveCollection("CollPropertyDecimal", 12, -2, 1234),
createPrimitiveCollection("CollPropertyByte", 50, 200, 249),
createPrimitiveCollection("CollPropertyBinary",
new byte[] { -85, -51, -17 },
new byte[] { 1, 35, 69 },
new byte[] { 84, 103, -119 }
),
createPrimitiveCollection("CollPropertyDate",
getDateTime(1958, 12, 3, 0, 0, 0),
getDateTime(1999, 8, 5, 0, 0, 0),
getDateTime(2013, 6, 25, 0, 0, 0)
),
createPrimitiveCollection("CollPropertyDateTimeOffset",
getDateTime(2015, 8, 12, 3, 8, 34),
getDateTime(1970, 3, 28, 12, 11, 10),
getDateTime(1948, 2, 17, 9, 9, 9)
),
createPrimitiveCollection("CollPropertyDuration",
getDurration(0, 0, 0, 13),
getDurration(0, 5, 28, 20),
getDurration(0, 1, 0, 0)
),
createPrimitiveCollection("CollPropertyGuid",
UUID.fromString("ffffff67-89ab-cdef-0123-456789aaaaaa"),
UUID.fromString("eeeeee67-89ab-cdef-0123-456789bbbbbb"),
UUID.fromString("cccccc67-89ab-cdef-0123-456789cccccc")
),
createPrimitiveCollection("CollPropertyTimeOfDay",
getTime(4, 14, 13),
getTime(23, 59, 59),
getTime(1, 12, 33)
)
))
);
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 12326))
.addProperty(createComplex("PropertyComp",
createPrimitiveCollection("CollPropertyString",
"Employee1@company.example",
"Employee2@company.example",
"Employee3@company.example"),
createPrimitiveCollection("CollPropertyBoolean", true, false, true),
createPrimitiveCollection("CollPropertyByte", 50, 200, 249),
createPrimitiveCollection("CollPropertySByte", -120, 120, 126),
createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112),
createPrimitiveCollection("CollPropertyInt32", 23232323, 11223355, 10000001),
createPrimitiveCollection("CollPropertyInt64", 929292929292L, 333333333333L, 444444444444L),
createPrimitiveCollection("CollPropertySingle", 1790, 26600, 3210),
createPrimitiveCollection("CollPropertyDouble", -17900, -27800000, 3210),
createPrimitiveCollection("CollPropertyDecimal", 12, -2, 1234),
createPrimitiveCollection("CollPropertyByte", 50, 200, 249),
createPrimitiveCollection("CollPropertyBinary",
new byte[] { -85, -51, -17 },
new byte[] { 1, 35, 69 },
new byte[] { 84, 103, -119 }
),
createPrimitiveCollection("CollPropertyDate",
getDateTime(1958, 12, 3, 0, 0, 0),
getDateTime(1999, 8, 5, 0, 0, 0),
getDateTime(2013, 6, 25, 0, 0, 0)
),
createPrimitiveCollection("CollPropertyDateTimeOffset",
getDateTime(2015, 8, 12, 3, 8, 34),
getDateTime(1970, 3, 28, 12, 11, 10),
getDateTime(1948, 2, 17, 9, 9, 9)
),
createPrimitiveCollection("CollPropertyDuration",
getDurration(0, 0, 0, 13),
getDurration(0, 5, 28, 20),
getDurration(0, 1, 0, 0)
),
createPrimitiveCollection("CollPropertyGuid",
UUID.fromString("ffffff67-89ab-cdef-0123-456789aaaaaa"),
UUID.fromString("eeeeee67-89ab-cdef-0123-456789bbbbbb"),
UUID.fromString("cccccc67-89ab-cdef-0123-456789cccccc")
),
createPrimitiveCollection("CollPropertyTimeOfDay",
getTime(4, 14, 13),
getTime(23, 59, 59),
getTime(1, 12, 33)
)
))
);
return entityCollection;
}
private EntityCollection createESBaseTwoKeyNav() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(createESTwoKeyNavEntity(1, "1")
.addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
entityCollection.getEntities().add(createESTwoKeyNavEntity(1, "2")
.addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
entityCollection.getEntities().add(createESTwoKeyNavEntity(2, "1")
.addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
entityCollection.getEntities().add(createESTwoKeyNavEntity(3, "1")
.addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
return entityCollection;
}
private EntityCollection createESTwoBase() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 111))
.addProperty(createPrimitive("PropertyString", "TEST A"))
.addProperty(createPrimitive("AdditionalPropertyString_5", "TEST A 0815"))
.addProperty(createPrimitive("AdditionalPropertyString_6", "TEST B 0815")));
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 222))
.addProperty(createPrimitive("PropertyString", "TEST B"))
.addProperty(createPrimitive("AdditionalPropertyString_5", "TEST C 0815"))
.addProperty(createPrimitive("AdditionalPropertyString_6", "TEST D 0815")));
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", 333))
.addProperty(createPrimitive("PropertyString", "TEST C"))
.addProperty(createPrimitive("AdditionalPropertyString_5", "TEST E 0815"))
.addProperty(createPrimitive("AdditionalPropertyString_6", "TEST F 0815")));
return entityCollection;
}
private EntityCollection createESAllNullable() {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(
@ -680,6 +945,13 @@ public class DataCreator {
return dateTime;
}
protected static int getDurration(final int days, int hours, int minutes, int seconds) {
return days * 24 * 60 * 60
+ hours * 60 * 60
+ minutes * 60
+ seconds;
}
protected static Calendar getTime(final int hour, final int minute, final int second) {
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
time.clear();

View File

@ -73,7 +73,9 @@ public class DataProvider {
}
public EntityCollection readAll(final EdmEntitySet edmEntitySet) throws DataProviderException {
return data.get(edmEntitySet.getName());
final EntityCollection entityCollection = data.get(edmEntitySet.getName());
return (entityCollection == null) ? createEntityCollection(edmEntitySet) : entityCollection;
}
public Entity read(final EdmEntitySet edmEntitySet, final List<UriParameter> keys) throws DataProviderException {
@ -135,10 +137,10 @@ public class DataProvider {
}
}
}
public Entity create(final EdmEntitySet edmEntitySet) throws DataProviderException {
final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
final EntityCollection entitySet = readAll(edmEntitySet);
EntityCollection entitySet = readAll(edmEntitySet);
final List<Entity> entities = entitySet.getEntities();
final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
Entity newEntity = new Entity();
@ -152,7 +154,15 @@ public class DataProvider {
return newEntity;
}
private EntityCollection createEntityCollection(final EdmEntitySet edmEntitySet) {
if(data.get(edmEntitySet.getName()) == null ) {
data.put(edmEntitySet.getName(), new EntityCollection());
}
return data.get(edmEntitySet.getName());
}
private Map<String, Object> findFreeComposedKey(final List<Entity> entities, final EdmEntityType entityType)
throws DataProviderException {
// Weak key construction

View File

@ -132,17 +132,14 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
validateOptions(uriInfo.asUriInfoResource());
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo); // including checks
final EntityCollection entitySetInitial = readEntityCollection(uriInfo);
if (entitySetInitial == null) {
throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ROOT);
} else {
EntityCollection entitySet = new EntityCollection();
entitySet.getEntities().addAll(entitySetInitial.getEntities());
FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, edmEntitySet);
response.setContent(odata.createFixedFormatSerializer().count(
entitySet.getEntities().size()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, HttpContentType.TEXT_PLAIN);
}
EntityCollection entitySet = new EntityCollection();
entitySet.getEntities().addAll(entitySetInitial.getEntities());
FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, edmEntitySet);
response.setContent(odata.createFixedFormatSerializer().count(
entitySet.getEntities().size()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, HttpContentType.TEXT_PLAIN);
}
@Override
@ -158,6 +155,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final ContentType responseFormat) throws ODataApplicationException, SerializerException {
getEdmEntitySet(uriInfo); // including checks
final Entity entity = readEntity(uriInfo);
response.setContent(odata.createFixedFormatSerializer().binary(dataProvider.readMedia(entity)));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, entity.getMediaContentType());
@ -443,6 +441,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
edmEntitySet.getEntityType();
EntityCollection entitySetInitial = readEntityCollection(uriInfo);
if(entitySetInitial == null) {
entitySetInitial = new EntityCollection();
}