Return-Path: X-Original-To: apmail-olingo-commits-archive@minotaur.apache.org Delivered-To: apmail-olingo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 60B2D11FE1 for ; Tue, 8 Jul 2014 08:17:23 +0000 (UTC) Received: (qmail 43890 invoked by uid 500); 8 Jul 2014 08:17:23 -0000 Delivered-To: apmail-olingo-commits-archive@olingo.apache.org Received: (qmail 43834 invoked by uid 500); 8 Jul 2014 08:17:23 -0000 Mailing-List: contact commits-help@olingo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@olingo.apache.org Delivered-To: mailing list commits@olingo.apache.org Received: (qmail 43784 invoked by uid 99); 8 Jul 2014 08:17:23 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jul 2014 08:17:23 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F144D945E6B; Tue, 8 Jul 2014 08:17:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sklevenz@apache.org To: commits@olingo.apache.org Date: Tue, 08 Jul 2014 08:17:36 -0000 Message-Id: <4acf0a74ebd741e58b0537a3e18acc7d@git.apache.org> In-Reply-To: <489c5b7331a44e35b391ed51486a0885@git.apache.org> References: <489c5b7331a44e35b391ed51486a0885@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [18/18] git commit: [OLINGO-337] merge origin/master [OLINGO-337] merge origin/master Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/233651a8 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/233651a8 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/233651a8 Branch: refs/heads/olingo337 Commit: 233651a8bf9512592a1904f74c05d4b6071af0ba Parents: 811fff5 f117154 Author: Stephan Klevenz Authored: Tue Jul 8 10:16:48 2014 +0200 Committer: Stephan Klevenz Committed: Tue Jul 8 10:16:48 2014 +0200 ---------------------------------------------------------------------- .../olingo/commons/api/format/AcceptType.java | 3 +++ .../tecsvc/processor/SampleJsonProcessor.java | 28 +++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/233651a8/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/233651a8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java ---------------------------------------------------------------------- diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java index ffb8d7f,b3dc02d..8d43276 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java @@@ -61,9 -58,12 +61,10 @@@ public class SampleJsonProcessor implem } @Override - public void readCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, String format) { + public void readCollection(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, + final ContentType requestedContentType) { long time = System.nanoTime(); - EntitySet entitySet = createEntitySet(); - LOG.info((System.nanoTime() - time) / 1000 + " microseconds"); time = System.nanoTime(); ODataSerializer serializer = odata.createSerializer(ODataFormat.JSON); @@@ -78,50 -79,26 +79,51 @@@ } @Override - public void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, String format) { + public void readEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, + final ContentType requestedContentType) { long time = System.nanoTime(); - Entity entity = createEntity(); LOG.info((System.nanoTime() - time) / 1000 + " microseconds"); time = System.nanoTime(); ODataSerializer serializer = odata.createSerializer(ODataFormat.JSON); - response.setContent(serializer.entity( - edm.getEntityContainer(new FullQualifiedName("com.sap.odata.test1", "Container")) - .getEntitySet("ESAllPrim").getEntityType(), - entity, - ContextURL.getInstance(URI.create("dummyContextURL")))); + EdmEntityType entityType = getEntityType(uriInfo); + Entity entity = createEntity(entityType); + + response.setContent(serializer.entity(entityType, entity, - getContextUrl(request, entityType))); ++ getContextUrl(request, entityType))); LOG.info("Finished in " + (System.nanoTime() - time) / 1000 + " microseconds"); response.setStatusCode(HttpStatusCode.OK.getStatusCode()); response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString()); } - protected Entity createEntity() { + private ContextURL getContextUrl(ODataRequest request, EdmEntityType entityType) { + return ContextURL.getInstance(URI.create(request.getRawBaseUri() + "/" + entityType.getName())); + } + + public EdmEntityType getEntityType(UriInfo uriInfo) { + return getEntitySet(uriInfo).getEntityType(); + } + + public EdmEntitySet getEntitySet(UriInfo uriInfo) { + List resourcePaths = uriInfo.getUriResourceParts(); - if(resourcePaths.isEmpty()) { ++ if (resourcePaths.isEmpty()) { + throw new RuntimeException("Invalid resource path."); + } - String entitySetName = resourcePaths.get(resourcePaths.size()-1).toString(); ++ String entitySetName = resourcePaths.get(resourcePaths.size() - 1).toString(); + return edm.getEntityContainer(new FullQualifiedName("com.sap.odata.test1", "Container")) - .getEntitySet(entitySetName); ++ .getEntitySet(entitySetName); + } + + protected Entity createEntity(EdmEntityType entityType) { + boolean complex = (entityType.getName().contains("Comp")); - if(entityType.getName().contains("Coll")) { ++ if (entityType.getName().contains("Coll")) { + return createEntityWithCollection(complex); + } + return createEntity(complex); + } + + protected Entity createEntity(boolean complex) { Entity entity = new EntityImpl(); Property property = new PropertyImpl(); property.setName("PropertyString"); @@@ -135,95 -112,15 +137,95 @@@ propertyGuid.setName("PropertyGuid"); propertyGuid.setValue(ValueType.PRIMITIVE, UUID.randomUUID()); entity.getProperties().add(propertyGuid); + - if(complex) { ++ if (complex) { + entity.addProperty(createComplexProperty()); + } + return entity; } - protected EntitySet createEntitySet() { + protected Entity createEntityWithCollection(boolean complex) { + Entity entity = new EntityImpl(); + Property propertyInt = new PropertyImpl(); + propertyInt.setName("PropertyInt16"); + propertyInt.setValue(ValueType.PRIMITIVE, 42); + Property property = new PropertyImpl(); + property.setName("CollPropertyString"); + property.setValue(ValueType.COLLECTION_PRIMITIVE, Arrays.asList("dummyValue", "dummyValue_2")); + entity.getProperties().add(property); + entity.getProperties().add(propertyInt); + Property propertyGuid = new PropertyImpl(); + propertyGuid.setName("CollPropertyGuid"); + propertyGuid.setValue(ValueType.COLLECTION_PRIMITIVE, Arrays.asList(UUID.randomUUID(), UUID.randomUUID())); + entity.getProperties().add(propertyGuid); + - if(complex) { ++ if (complex) { + entity.addProperty(createCollectionOfComplexProperty()); + } + + return entity; + } + + protected Property createComplexProperty() { + List properties = new ArrayList(); + Property property = new PropertyImpl(); + property.setName("PropertyString"); + property.setValue(ValueType.PRIMITIVE, "dummyValue"); + properties.add(property); + Property propertyInt = new PropertyImpl(); + propertyInt.setName("PropertyInt16"); + propertyInt.setValue(ValueType.PRIMITIVE, 42); + properties.add(propertyInt); + Property propertyGuid = new PropertyImpl(); + propertyGuid.setName("PropertyGuid"); + propertyGuid.setValue(ValueType.PRIMITIVE, UUID.randomUUID()); + properties.add(propertyGuid); + + return new PropertyImpl("com.sap.odata.test1.ETCompAllPrim", "PropertyComplex", ValueType.COMPLEX, - properties); ++ properties); + } + + protected Property createCollectionOfComplexProperty() { + List properties = new ArrayList(); + Property property = new PropertyImpl(); + property.setName("PropertyString"); + property.setValue(ValueType.PRIMITIVE, "dummyValue"); + properties.add(property); + Property propertyInt = new PropertyImpl(); + propertyInt.setName("PropertyInt16"); + propertyInt.setValue(ValueType.PRIMITIVE, 42); + properties.add(propertyInt); + Property propertyGuid = new PropertyImpl(); + propertyGuid.setName("PropertyGuid"); + propertyGuid.setValue(ValueType.PRIMITIVE, UUID.randomUUID()); + properties.add(propertyGuid); + + List properties2 = new ArrayList(); + Property property2 = new PropertyImpl(); + property2.setName("PropertyString"); + property2.setValue(ValueType.PRIMITIVE, "dummyValue2"); + properties2.add(property2); + Property property2Int = new PropertyImpl(); + property2Int.setName("PropertyInt16"); + property2Int.setValue(ValueType.PRIMITIVE, 44); + properties2.add(property2Int); + Property property2Guid = new PropertyImpl(); + property2Guid.setName("PropertyGuid"); + property2Guid.setValue(ValueType.PRIMITIVE, UUID.randomUUID()); + properties2.add(property2Guid); + + return new PropertyImpl("com.sap.odata.test1.ETCompAllPrim", "PropertyComplex", ValueType.COMPLEX, - Arrays.asList(properties, properties2)); ++ Arrays.asList(properties, properties2)); + } + + protected EntitySet createEntitySet(EdmEntityType edmEntityType, String baseUri) { EntitySet entitySet = new EntitySetImpl(); - entitySet.setCount(4242); - entitySet.setNext(URI.create("nextLinkURI")); - for (int i = 0; i < 1000; i++) { - entitySet.getEntities().add(createEntity()); + int count = (int) ((Math.random() * 50) + 1); + entitySet.setCount(count); + entitySet.setNext(URI.create(baseUri + "nextLink")); + for (int i = 0; i < count; i++) { + entitySet.getEntities().add(createEntity(edmEntityType)); } return entitySet; }