Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 40418 invoked from network); 13 Jan 2010 16:30:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Jan 2010 16:30:42 -0000 Received: (qmail 27982 invoked by uid 500); 13 Jan 2010 16:30:42 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 27938 invoked by uid 500); 13 Jan 2010 16:30:42 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 27928 invoked by uid 99); 13 Jan 2010 16:30:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jan 2010 16:30:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jan 2010 16:30:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 06BCE238897D; Wed, 13 Jan 2010 16:30:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r898825 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/ chemistry-tests/src/main/java/org/apache/chemis... Date: Wed, 13 Jan 2010 16:30:20 -0000 To: chemistry-commits@incubator.apache.org From: fguillaume@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100113163021.06BCE238897D@eris.apache.org> Author: fguillaume Date: Wed Jan 13 16:30:20 2010 New Revision: 898825 URL: http://svn.apache.org/viewvc?rev=898825&view=rev Log: CMIS-95: fix NPE in SimpleConnection#getChildren, throw proper exceptions instead Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=898825&r1=898824&r2=898825&view=diff ============================================================================== --- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java (original) +++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java Wed Jan 13 16:30:20 2010 @@ -214,7 +214,7 @@ public List getDescendants(ObjectId folder, int depth, String orderBy, Inclusion inclusion) { - String href = getObjectEntry(folder).getLink(AtomPub.LINK_DOWN, + String href = getFolderEntry(folder).getLink(AtomPub.LINK_DOWN, AtomPubCMIS.MEDIA_TYPE_CMIS_TREE); Request req = new Request(href); req.setParameter(AtomPubCMIS.PARAM_DEPTH, Integer.toString(depth)); @@ -253,7 +253,7 @@ public ListPage getChildren(ObjectId folder, Inclusion inclusion, String orderBy, Paging paging) { // TODO filter, includeRelationship, includeAllowableActions, orderBy - String href = getObjectEntry(folder).getLink(AtomPub.LINK_DOWN, + String href = getFolderEntry(folder).getLink(AtomPub.LINK_DOWN, AtomPub.MEDIA_TYPE_ATOM_FEED); Request req = new Request(href); if (paging != null) { @@ -273,11 +273,8 @@ public ObjectEntry getFolderParent(ObjectId folder, String filter) { // TODO filter - APPObjectEntry current = getObjectEntry(folder); - if (!current.getBaseType().equals(BaseType.FOLDER)) { - throw new IllegalArgumentException("Not a folder: " + folder); - } - String rootId = current.connection.getRootFolder().getId(); + APPObjectEntry current = getFolderEntry(folder); + String rootId = repository.getInfo().getRootFolderId().getId(); if (current.getId().equals(rootId)) { return null; } @@ -346,6 +343,14 @@ return (APPObjectEntry) resp.getObject(new ReadContext(this)); } + protected APPObjectEntry getFolderEntry(ObjectId objectId) { + APPObjectEntry entry = getObjectEntry(objectId); + if (!entry.getBaseType().equals(BaseType.FOLDER)) { + throw new IllegalArgumentException("Not a folder: " + objectId); + } + return entry; + } + protected String replace(String template, String param, String value) { return template.replace('{' + param + '}', value); } Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=898825&r1=898824&r2=898825&view=diff ============================================================================== --- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java (original) +++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java Wed Jan 13 16:30:20 2010 @@ -180,6 +180,7 @@ public List getFolderTree(ObjectId folder, int depth, Inclusion inclusion) { + checkFolder(folder); List list = new ArrayList(); accumulateFolders(folder, depth, inclusion, list); return list; @@ -206,6 +207,7 @@ public List getDescendants(ObjectId folder, int depth, String orderBy, Inclusion inclusion) { + checkFolder(folder); List list = new ArrayList(); accumulateDescendants(folder, depth, inclusion, orderBy, list); return list; @@ -214,6 +216,7 @@ public ListPage getChildren(ObjectId folder, Inclusion inclusion, String orderBy, Paging paging) { // TODO orderBy + checkFolder(folder); Set ids = repository.children.get(folder.getId()); List all = new ArrayList(ids.size()); for (String id : ids) { @@ -223,6 +226,20 @@ return getListPage(all, paging); } + protected void checkFolder(ObjectId object) throws ObjectNotFoundException, + ConstraintViolationException { + String id = object.getId(); + SimpleData data = repository.datas.get(id); + if (data == null) { + throw new ObjectNotFoundException(id); + } + String baseTypeId = (String) data.get(Property.BASE_TYPE_ID); + if (baseTypeId != BaseType.FOLDER.getId()) { + throw new IllegalArgumentException("Not a folder: " + id); + } + + } + /** * Extracts part of a list according to given paging parameters. * Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=898825&r1=898824&r2=898825&view=diff ============================================================================== --- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java (original) +++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java Wed Jan 13 16:30:20 2010 @@ -318,18 +318,60 @@ assertEquals(2, page.size()); assertTrue(page.getHasMoreItems()); assertEquals(3, page.getNumItems()); + + ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null); + try { + spi.getChildren(doc1, null, null, null); + fail(); + } catch (IllegalArgumentException e) { + // ok + } + try { + spi.getChildren(spi.newObjectId("no-such-id"), null, null, null); + fail(); + } catch (ObjectNotFoundException e) { + // ok + } } public void testGetFolderTree() { Folder root = conn.getRootFolder(); List desc = spi.getFolderTree(root, 4, null); assertEquals(2, desc.size()); + + ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null); + try { + spi.getFolderTree(doc1, -1, null); + fail(); + } catch (IllegalArgumentException e) { + // ok + } + try { + spi.getFolderTree(spi.newObjectId("no-such-id"), -1, null); + fail(); + } catch (ObjectNotFoundException e) { + // ok + } } public void testGetDescendants() { Folder root = conn.getRootFolder(); List desc = spi.getDescendants(root, 4, null, null); assertEquals(6, desc.size()); + + ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null); + try { + spi.getDescendants(doc1, -1, null, null); + fail(); + } catch (IllegalArgumentException e) { + // ok + } + try { + spi.getDescendants(spi.newObjectId("no-such-id"), -1, null, null); + fail(); + } catch (ObjectNotFoundException e) { + // ok + } } public void testGetFolderParent() {