From 4aa5513c75f9e826e406941482d8dabc1b032376 Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Mon, 15 May 2017 15:38:41 +0000 Subject: [PATCH] Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1) 136749 jkaabimofrad: Minor re-formatting (replace tabs with spaces) noted via APPSREPO-147. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@136756 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/Favourites.java | 54 +- .../api/people/PersonFavouritesRelation.java | 48 +- .../rest/api/tests/TestFavourites.java | 3120 +++++++-------- .../api/tests/client/PublicApiClient.java | 3428 ++++++++--------- .../tests/client/data/FavouriteDocument.java | 210 +- .../tests/client/data/FavouriteFolder.java | 126 +- .../api/tests/client/data/FavouriteNode.java | 322 +- 7 files changed, 3654 insertions(+), 3654 deletions(-) diff --git a/source/java/org/alfresco/rest/api/Favourites.java b/source/java/org/alfresco/rest/api/Favourites.java index 24694236e4..6084e0fae5 100644 --- a/source/java/org/alfresco/rest/api/Favourites.java +++ b/source/java/org/alfresco/rest/api/Favourites.java @@ -39,13 +39,13 @@ public interface Favourites { String PARAM_INCLUDE_PATH = Nodes.PARAM_INCLUDE_PATH; - /** - * Add a favourite for user personId - * - * @param personId the personId for which the favourite is to be added - * @param favourite the favourite to add - */ - Favourite addFavourite(String personId, Favourite favourite); + /** + * Add a favourite for user personId + * + * @param personId the personId for which the favourite is to be added + * @param favourite the favourite to add + */ + Favourite addFavourite(String personId, Favourite favourite); /** * Add a favourite for user personId taking parameters into account @@ -56,30 +56,30 @@ public interface Favourites */ Favourite addFavourite(String personId, Favourite favourite, Parameters parameters); - /** - * Add a favourite for user personId - * - * @param personId the personId for which the favourite is to be removed - * @param id the id of the favourite to remove (id is a uuid) - */ + /** + * Add a favourite for user personId + * + * @param personId the personId for which the favourite is to be removed + * @param id the id of the favourite to remove (id is a uuid) + */ void removeFavourite(String personId, String id); - /** - * Get a paged list of favourites for user personId - * - * @param personId the personId for which the favourite is to be removed - * @param parameters Parameters - * @return paged favourites - */ + /** + * Get a paged list of favourites for user personId + * + * @param personId the personId for which the favourite is to be removed + * @param parameters Parameters + * @return paged favourites + */ CollectionWithPagingInfo getFavourites(String personId, final Parameters parameters); - /** - * Get a specific favourite for user personId - * - * @param personId the personId for which the favourite is to be removed - * @param favouriteId the favourite id - * @return the favourite - */ + /** + * Get a specific favourite for user personId + * + * @param personId the personId for which the favourite is to be removed + * @param favouriteId the favourite id + * @return the favourite + */ Favourite getFavourite(String personId, String favouriteId); /** diff --git a/source/java/org/alfresco/rest/api/people/PersonFavouritesRelation.java b/source/java/org/alfresco/rest/api/people/PersonFavouritesRelation.java index ac47aafa5b..5124a765a2 100644 --- a/source/java/org/alfresco/rest/api/people/PersonFavouritesRelation.java +++ b/source/java/org/alfresco/rest/api/people/PersonFavouritesRelation.java @@ -49,12 +49,12 @@ RelationshipResourceAction.Create, RelationshipResourceAction.Delete private Favourites favourites; - public void setFavourites(Favourites favourites) - { - this.favourites = favourites; - } + public void setFavourites(Favourites favourites) + { + this.favourites = favourites; + } - @Override + @Override public void afterPropertiesSet() { ParameterCheck.mandatory("favourites", this.favourites); @@ -72,34 +72,34 @@ RelationshipResourceAction.Create, RelationshipResourceAction.Delete return favourites.getFavourites(personId, parameters); } - /** + /** * Adds the given site as a favourite site for the user. * * @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.Create#create(String, java.util.List, org.alfresco.rest.framework.resource.parameters.Parameters) - */ - @Override + */ + @Override @WebApiDescription(title = "Add Person Favorite", description = "Favorite something") - public List create(String personId, List entity, Parameters parameters) - { - List ret = new ArrayList(entity.size()); + public List create(String personId, List entity, Parameters parameters) + { + List ret = new ArrayList(entity.size()); for(Favourite favourite : entity) { - ret.add(favourites.addFavourite(personId, favourite, parameters)); + ret.add(favourites.addFavourite(personId, favourite, parameters)); } return ret; - } + } - @Override + @Override @WebApiDescription(title = "Remove Person Favorite", description = "Un-favorite something") - public void delete(String personId, String id, Parameters parameters) - { - favourites.removeFavourite(personId, id); - } + public void delete(String personId, String id, Parameters parameters) + { + favourites.removeFavourite(personId, id); + } - @Override - public Favourite readById(String personId, String favouriteId, Parameters parameters) - throws RelationshipResourceNotFoundException - { - return favourites.getFavourite(personId, favouriteId, parameters); - } + @Override + public Favourite readById(String personId, String favouriteId, Parameters parameters) + throws RelationshipResourceNotFoundException + { + return favourites.getFavourite(personId, favouriteId, parameters); + } } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestFavourites.java b/source/test-java/org/alfresco/rest/api/tests/TestFavourites.java index 664415cdaa..43ce03f273 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestFavourites.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestFavourites.java @@ -97,1625 +97,1625 @@ import com.google.common.collect.Lists; */ public class TestFavourites extends AbstractBaseApiTest { - private static enum TARGET_TYPE - { - file, folder, site; - }; - - private TestNetwork network1; - private TestPerson person10; - private String person10Id; - private TestPerson person11; - private String person11Id; - private TestPerson person12; - private String person12Id; - private TestPerson person14; - private String person14Id; + private static enum TARGET_TYPE + { + file, folder, site; + }; - private TestNetwork network2; - private TestPerson person21; - private String person21Id; + private TestNetwork network1; + private TestPerson person10; + private String person10Id; + private TestPerson person11; + private String person11Id; + private TestPerson person12; + private String person12Id; + private TestPerson person14; + private String person14Id; - private List personSites = new ArrayList(); - private List person1PublicSites = new ArrayList(); - private List person1PrivateSites = new ArrayList(); + private TestNetwork network2; + private TestPerson person21; + private String person21Id; - private List personDocs = new ArrayList(); - private List personFolders = new ArrayList(); - private List person1PublicDocs = new ArrayList(); - private List person1PublicFolders = new ArrayList(); - private List person1PrivateDocs = new ArrayList(); - private List person1PrivateFolders = new ArrayList(); - - private Favourites favouritesProxy; - private SiteMembershipRequests siteMembershipRequestsProxy; + private List personSites = new ArrayList(); + private List person1PublicSites = new ArrayList(); + private List person1PrivateSites = new ArrayList(); - @Override - @Before - public void setup() throws Exception - { - // init networks - super.setup(); + private List personDocs = new ArrayList(); + private List personFolders = new ArrayList(); + private List person1PublicDocs = new ArrayList(); + private List person1PublicFolders = new ArrayList(); + private List person1PrivateDocs = new ArrayList(); + private List person1PrivateFolders = new ArrayList(); - final Iterator networksIt = getTestFixture().networksIterator(); + private Favourites favouritesProxy; + private SiteMembershipRequests siteMembershipRequestsProxy; - // Workaround for domain name mismatch in lucene indexing that occurs when this test runs. - repoService.disableInTxnIndexing(); + @Override + @Before + public void setup() throws Exception + { + // init networks + super.setup(); - transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() - { - @SuppressWarnings("synthetic-access") - public Void execute() throws Throwable - { - try - { - AuthenticationUtil.pushAuthentication(); - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + final Iterator networksIt = getTestFixture().networksIterator(); - // create some users - TestFavourites.this.network1 = networksIt.next(); + // Workaround for domain name mismatch in lucene indexing that occurs when this test runs. + repoService.disableInTxnIndexing(); - String name = GUID.generate(); - PersonInfo personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); - TestFavourites.this.person10 = network1.createUser(personInfo); - assertNotNull(TestFavourites.this.person10); - TestFavourites.this.person10Id = TestFavourites.this.person10.getId(); - name = GUID.generate(); - personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); - TestFavourites.this.person11 = network1.createUser(personInfo); - assertNotNull(TestFavourites.this.person11); - TestFavourites.this.person11Id = TestFavourites.this.person11.getId(); - name = GUID.generate(); - personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); - TestFavourites.this.person12 = network1.createUser(personInfo); - assertNotNull(TestFavourites.this.person12); - TestFavourites.this.person12Id = TestFavourites.this.person12.getId(); - name = GUID.generate(); - personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); - TestFavourites.this.person14 = network1.createUser(personInfo); - assertNotNull(TestFavourites.this.person14); - TestFavourites.this.person14Id = TestFavourites.this.person14.getId(); + transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() + { + @SuppressWarnings("synthetic-access") + public Void execute() throws Throwable + { + try + { + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - TestFavourites.this.network2 = networksIt.next(); - name = GUID.generate(); - personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); - TestFavourites.this.person21 = network2.createUser(personInfo); - assertNotNull(TestFavourites.this.person21); - TestFavourites.this.person21Id = TestFavourites.this.person21.getId(); + // create some users + TestFavourites.this.network1 = networksIt.next(); - return null; - } - finally - { - AuthenticationUtil.popAuthentication(); - } - } - }, false, true); + String name = GUID.generate(); + PersonInfo personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); + TestFavourites.this.person10 = network1.createUser(personInfo); + assertNotNull(TestFavourites.this.person10); + TestFavourites.this.person10Id = TestFavourites.this.person10.getId(); + name = GUID.generate(); + personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); + TestFavourites.this.person11 = network1.createUser(personInfo); + assertNotNull(TestFavourites.this.person11); + TestFavourites.this.person11Id = TestFavourites.this.person11.getId(); + name = GUID.generate(); + personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); + TestFavourites.this.person12 = network1.createUser(personInfo); + assertNotNull(TestFavourites.this.person12); + TestFavourites.this.person12Id = TestFavourites.this.person12.getId(); + name = GUID.generate(); + personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); + TestFavourites.this.person14 = network1.createUser(personInfo); + assertNotNull(TestFavourites.this.person14); + TestFavourites.this.person14Id = TestFavourites.this.person14.getId(); - // Create some favourite targets, sites, files and folders - TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public Void doWork() throws Exception - { - String siteName = "site" + GUID.generate(); - SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); - TestSite site = network1.createSite(siteInfo); - person1PublicSites.add(site); + TestFavourites.this.network2 = networksIt.next(); + name = GUID.generate(); + personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null); + TestFavourites.this.person21 = network2.createUser(personInfo); + assertNotNull(TestFavourites.this.person21); + TestFavourites.this.person21Id = TestFavourites.this.person21.getId(); - NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content"); - person1PublicDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description"); - person1PublicFolders.add(nodeRef); - nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content"); - person1PublicDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description"); - person1PublicFolders.add(nodeRef); - nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content"); - person1PublicDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description"); - person1PublicFolders.add(nodeRef); + return null; + } + finally + { + AuthenticationUtil.popAuthentication(); + } + } + }, false, true); - siteName = "site" + GUID.generate(); - siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); - site = network1.createSite(siteInfo); - person1PublicSites.add(site); + // Create some favourite targets, sites, files and folders + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public Void doWork() throws Exception + { + String siteName = "site" + GUID.generate(); + SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); + TestSite site = network1.createSite(siteInfo); + person1PublicSites.add(site); - siteName = "site" + GUID.generate(); - siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE); - site = network1.createSite(siteInfo); - person1PrivateSites.add(site); + NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content"); + person1PublicDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description"); + person1PublicFolders.add(nodeRef); + nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content"); + person1PublicDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description"); + person1PublicFolders.add(nodeRef); + nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content"); + person1PublicDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description"); + person1PublicFolders.add(nodeRef); - nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content"); - person1PrivateDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description"); - person1PrivateFolders.add(nodeRef); - nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content"); - person1PrivateDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description"); - person1PrivateFolders.add(nodeRef); - nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content"); - person1PrivateDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description"); - person1PrivateFolders.add(nodeRef); + siteName = "site" + GUID.generate(); + siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); + site = network1.createSite(siteInfo); + person1PublicSites.add(site); - return null; - } - }, person11Id, network1.getId()); + siteName = "site" + GUID.generate(); + siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE); + site = network1.createSite(siteInfo); + person1PrivateSites.add(site); - TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public Void doWork() throws Exception - { - String siteName = "site" + System.currentTimeMillis(); - SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); - TestSite site = network1.createSite(siteInfo); - person1PublicSites.add(site); + nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content"); + person1PrivateDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description"); + person1PrivateFolders.add(nodeRef); + nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content"); + person1PrivateDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description"); + person1PrivateFolders.add(nodeRef); + nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content"); + person1PrivateDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description"); + person1PrivateFolders.add(nodeRef); - NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content"); - personDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1"); - personFolders.add(nodeRef); - nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content"); - personDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2"); - personFolders.add(nodeRef); - nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content"); - personDocs.add(nodeRef); - nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3"); - personFolders.add(nodeRef); + return null; + } + }, person11Id, network1.getId()); - return null; - } - }, person10Id, network1.getId()); + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public Void doWork() throws Exception + { + String siteName = "site" + System.currentTimeMillis(); + SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); + TestSite site = network1.createSite(siteInfo); + person1PublicSites.add(site); - TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public Void doWork() throws Exception - { - String siteName = "site" + GUID.generate(); - SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); - TestSite site = network1.createSite(siteInfo); - personSites.add(site); + NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content"); + personDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1"); + personFolders.add(nodeRef); + nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content"); + personDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2"); + personFolders.add(nodeRef); + nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content"); + personDocs.add(nodeRef); + nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3"); + personFolders.add(nodeRef); - site.inviteToSite(person11Id, SiteRole.SiteCollaborator); + return null; + } + }, person10Id, network1.getId()); - siteName = "site" + GUID.generate(); - siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); - site = network1.createSite(siteInfo); - personSites.add(site); + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public Void doWork() throws Exception + { + String siteName = "site" + GUID.generate(); + SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); + TestSite site = network1.createSite(siteInfo); + personSites.add(site); - return null; - } - }, person10Id, network1.getId()); + site.inviteToSite(person11Id, SiteRole.SiteCollaborator); - this.favouritesProxy = publicApiClient.favourites(); - this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests(); - } + siteName = "site" + GUID.generate(); + siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); + site = network1.createSite(siteInfo); + personSites.add(site); + + return null; + } + }, person10Id, network1.getId()); + + this.favouritesProxy = publicApiClient.favourites(); + this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests(); + } private void sort(List favourites, final List> sortProps) - { - Comparator comparator = new Comparator() - { - @Override - public int compare(Favourite o1, Favourite o2) - { - int ret = 0; - for(Pair sort : sortProps) - { - FavouritesService.SortFields field = sort.getFirst(); - Boolean ascending = sort.getSecond(); - if(field.equals(FavouritesService.SortFields.username)) - { - if(ascending) - { - if(o1.getUsername() != null && o2.getUsername() != null) - { - ret = collator.compare(o1.getUsername(), o2.getUsername()); - } - } - else - { - if(o1.getUsername() != null && o2.getUsername() != null) - { - ret = o2.getUsername().compareTo(o1.getUsername()); - } - } - - if(ret != 0) - { - break; - } - } - else if(field.equals(FavouritesService.SortFields.type)) - { - if(ascending) - { - ret = o1.getType().compareTo(o2.getType()); - } - else - { - ret = o2.getType().compareTo(o1.getType()); - } - - if(ret != 0) - { - break; - } - } - else if(field.equals(FavouritesService.SortFields.createdAt)) - { - if(ascending) - { - ret = o1.getCreatedAt().compareTo(o2.getCreatedAt()); - } - else - { - ret = o2.getCreatedAt().compareTo(o1.getCreatedAt()); - } - - if(ret != 0) - { - break; - } - } - } - - return ret; - } - }; - Collections.sort(favourites, comparator); - } - - /** - * Returns a new list. - * - * @param favourites List - * @param types Set - * @return ArrayList - */ - private ArrayList filter(List favourites, final Set types) - { - Predicate predicate = new Predicate() - { - @Override - public boolean apply(Favourite other) - { - Type type = null; - if(other.getTarget() instanceof FileFavouriteTarget) - { - type = Type.FILE; - } - else if(other.getTarget() instanceof FolderFavouriteTarget) - { - type = Type.FOLDER; - } - else if(other.getTarget() instanceof SiteFavouriteTarget) - { - type = Type.SITE; - } - - boolean ret = (type != null && types.contains(type)); - return ret; - } - }; - ArrayList ret = Lists.newArrayList(Collections2.filter(favourites, predicate)); - return ret; - } - - private void updateFavourite(String networkId, String runAsUserId, String personId, TARGET_TYPE type) throws Exception - { - { - int size = 0; - - try - { - // get a favourite id - ListResponse resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); - List favourites = resp.getList(); - size = favourites.size(); - assertTrue(size > 0); - Favourite favourite = favourites.get(0); - - favouritesProxy.update("people", personId, "favorites", favourite.getTargetGuid(), favourite.toJSON().toString(), "Unable to update favourite"); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); - } - - // check nothing has changed - ListResponse resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); - List favourites = resp.getList(); - assertEquals(size, favourites.size()); - } - } - - private Favourite deleteFavourite(String networkId, String runAsUserId, String personId, TARGET_TYPE type) throws Exception - { - Exception e = null; - - publicApiClient.setRequestContext(new RequestContext(networkId, runAsUserId)); - - // get a favourite id - ListResponse resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); - List favourites = resp.getList(); - int size = favourites.size(); - assertTrue(size > 0); - Favourite favourite = favourites.get(0); - - try - { - // catch 404's - favouritesProxy.removeFavourite(personId, favourite.getTargetGuid()); - } - catch(PublicApiException exc) - { - e = exc; - } - - // check favourite has been removed - resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); - favourites = resp.getList(); - boolean stillExists = false; - for(Favourite f : favourites) - { - if(f.getTargetGuid().equals(favourite.getTargetGuid())) - { - stillExists = true; - break; - } - } - assertFalse(stillExists); - - if(e != null) - { - throw e; - } - - return favourite; - } - - private ListResponse getFavourites(String networkId, String runAsUserId, String personId, int skipCount, int maxItems, Integer total, - Integer expectedTotal, TARGET_TYPE type) throws PublicApiException, ParseException - { - publicApiClient.setRequestContext(new RequestContext(networkId, runAsUserId)); - - Paging paging = null; - if(total == null && expectedTotal == null) - { - paging = getPaging(skipCount, maxItems); - } - else - { - paging = getPaging(skipCount, maxItems, total, expectedTotal); - } - Map params = null; - if(type != null) - { - params = Collections.singletonMap("where", "(EXISTS(target/" + type + "))"); - } - ListResponse resp = favouritesProxy.getFavourites(personId, createParams(paging, params)); - return resp; - } - - private Favourite makeFolderFavourite(String targetGuid) throws ParseException - { - FavouriteFolder folder = new FavouriteFolder(targetGuid); - FolderFavouriteTarget target = new FolderFavouriteTarget(folder); - Date creationData = new Date(); - Favourite favourite = new Favourite(creationData, null, target); - return favourite; - } - - private Favourite makeFileFavourite(String targetGuid) throws ParseException - { - FavouriteDocument document = new FavouriteDocument(targetGuid); - FileFavouriteTarget target = new FileFavouriteTarget(document); - Date creationData = new Date(); - Favourite favourite = new Favourite(creationData, null, target); - return favourite; - } - - private Favourite makeSiteFavourite(Site site) throws ParseException - { - SiteFavouriteTarget target = new SiteFavouriteTarget(site); - Date creationDate = new Date(); - Favourite favourite = new Favourite(creationDate, null, target); - return favourite; - } - - @Test - public void testInvalidRequests() throws Exception - { - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite favourite = makeSiteFavourite(person1PublicSites.get(0)); - Favourite ret = favouritesProxy.createFavourite(person11Id, favourite); - favourite.expected(ret); - fail(); - } - catch(PublicApiException e) - { - // Note: un-authorized comes back as 404 - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // cloud-2468 - // invalid type - // NOTE: The test below has swapped to attempt to favorite a comment rather than a - // a wiki page as the WikiService has moved to the Share Services AMP in 5.1 - - try - { - log("cloud-2468"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - final NodeRef document = personDocs.get(0); - final NodeRef comment = TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public NodeRef doWork() throws Exception - { - NodeRef comment = repoService.createComment(document, new Comment("Title", "Content")); - return comment; - } - }, person10Id, network1.getId()); - - final String guid = comment.getId(); - JSONAble commentJSON = new JSONAble() - { - @SuppressWarnings("unchecked") - @Override - public JSONObject toJSON() - { - JSONObject json = new JSONObject(); - json.put("guid", guid); - return json; - } - }; - - FavouritesTarget target = new InvalidFavouriteTarget("comment", commentJSON, guid); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); - } - - try - { - log("cloud-2468"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Site site = person1PublicSites.get(0); - FavouritesTarget target = new InvalidFavouriteTarget(GUID.generate(), site, site.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); - } - - // type = file, target is a site - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - String siteGuid = person1PublicSites.get(0).getGuid(); - FavouriteDocument document = new FavouriteDocument(siteGuid); - Favourite favourite = makeFileFavourite(document.getGuid()); - Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); - favourite.expected(ret); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // type = folder, target is a site - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - String siteGuid = person1PublicSites.get(0).getGuid(); - FavouriteFolder folder = new FavouriteFolder(siteGuid); - Favourite favourite = makeFolderFavourite(folder.getGuid()); - Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); - favourite.expected(ret); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // type = folder, target is a file - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouriteFolder folder = new FavouriteFolder(person1PublicDocs.get(0).getId()); - Favourite favourite = makeFolderFavourite(folder.getGuid()); - Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); - favourite.expected(ret); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // type = file, target is a folder - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouriteDocument document = new FavouriteDocument(person1PublicFolders.get(0).getId()); - Favourite favourite = makeFileFavourite(document.getGuid()); - Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); - favourite.expected(ret); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // make sure that a user can't favourite on behalf of another user - // 2471 - { - log("cloud-2471"); - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); - Favourite favourite = makeFileFavourite(document.getGuid()); - favouritesProxy.createFavourite(person11Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - // Note: un-authorized comes back as 404 - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // person1 should have no favourites - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); - ListResponse response = favouritesProxy.getFavourites(person11Id, createParams(null, null)); - assertEquals(0, response.getList().size()); - } - - // invalid/non-existent user - // 2469 - try - { - log("cloud-2469"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite favourite = makeSiteFavourite(personSites.get(0)); - Favourite ret = favouritesProxy.createFavourite(GUID.generate(), favourite); - favourite.expected(ret); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // make sure that a user can't see other user's favourites. - // 2465 - try - { - log("cloud-2465"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - favouritesProxy.getFavourites(person11Id, null); - fail(); - } - catch(PublicApiException e) - { - // Note: un-authorized comes back as 404 - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // 2464, unknown user - try - { - log("cloud-2464"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - favouritesProxy.getFavourites(GUID.generate(), null); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // non-existent entity for a given type - // 2480 - { - log("cloud-2480"); - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - SiteImpl site = new SiteImpl(); - site.setGuid(GUID.generate()); - Favourite favourite = makeSiteFavourite((Site)site); - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); - assertEquals(0, response.getList().size()); - } - - { - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouriteDocument document = new FavouriteDocument(GUID.generate()); - Favourite favourite = makeFileFavourite(document.getGuid()); - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); - assertEquals(0, response.getList().size()); - } - - { - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouriteFolder folder = new FavouriteFolder(GUID.generate()); - Favourite favourite = makeFolderFavourite(folder.getGuid()); - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); - assertEquals(0, response.getList().size()); - } - - // 2470 - // incorrect type for a given favourite target - { - log("cloud-2470"); - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Site site = person1PublicSites.get(0); - FavouritesTarget target = new InvalidFavouriteTarget("folder", site, site.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); - } - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Site site = person1PublicSites.get(0); - FavouritesTarget target = new InvalidFavouriteTarget("file", site, site.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); - } - - FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouritesTarget target = new InvalidFavouriteTarget("site", document, document.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouritesTarget target = new InvalidFavouriteTarget("folder", document, document.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - FavouriteFolder folder = new FavouriteFolder(person1PublicFolders.get(0).getId()); - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouritesTarget target = new InvalidFavouriteTarget("site", folder, folder.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - FavouritesTarget target = new InvalidFavouriteTarget("file", folder, folder.getGuid()); - Favourite favourite = new Favourite(target); - - favouritesProxy.createFavourite(person10Id, favourite); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - // none of these POSTs should have resulted in favourites being created... - ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); - assertEquals(0, response.getList().size()); - } - - // invalid methods - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - try - { - Favourite favourite = new Favourite(null); - favouritesProxy.update("people", "-me-", "favorites", null, favourite.toJSON().toString(), "Unable to PUT favourites"); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); - } - } - } - - @Test - public void testValidRequests() throws Exception - { - List expectedFavourites = new ArrayList(); - - { - // add some favourites - // 2467 - - log("cloud-2467"); - - Favourite siteFavourite1 = makeSiteFavourite(person1PublicSites.get(0)); - - FavouriteDocument document = repoService.getDocument(network1.getId(), person1PublicDocs.get(0)); - Favourite fileFavourite1 = makeFileFavourite(document.getGuid()); - - FavouriteFolder folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(0)); - Favourite folderFavourite1 = makeFolderFavourite(folder.getGuid()); - - Favourite siteFavourite2 = makeSiteFavourite(person1PublicSites.get(1)); - - document = repoService.getDocument(network1.getId(), person1PublicDocs.get(1)); - Favourite fileFavourite2 = makeFileFavourite(document.getGuid()); - - folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(1)); - Favourite folderFavourite2 = makeFolderFavourite(folder.getGuid()); - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1); - expectedFavourites.add(ret); - siteFavourite1.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1); - expectedFavourites.add(ret); - fileFavourite1.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1); - expectedFavourites.add(ret); - folderFavourite1.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite2); - expectedFavourites.add(ret); - siteFavourite2.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite2); - expectedFavourites.add(ret); - fileFavourite2.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite2); - expectedFavourites.add(ret); - folderFavourite2.expected(ret); - } - - // already a favourite - 201 - { - log("cloud-2472"); - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1); - siteFavourite1.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1); - folderFavourite1.expected(ret); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1); - fileFavourite1.expected(ret); - } - } - - { - // cloud-2498 - // cloud-2499 - // create and list favourites across networks - - List person21ExpectedFavourites = new ArrayList(); - - log("cloud-2498"); - log("cloud-2499"); - - { - // favourite a site in another network - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); - - Favourite favourite = makeSiteFavourite(person1PrivateSites.get(0)); - try - { - favouritesProxy.createFavourite("-me-", favourite); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); - } - - int skipCount = 0; - int maxItems = 10; - Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size()); - try - { - favouritesProxy.getFavourites("-me-", createParams(paging, null)); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); - } - } - - // favourite a document in another network - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); - - FavouriteDocument document1 = new FavouriteDocument(person1PrivateDocs.get(0).getId()); - Favourite favourite = makeFileFavourite(document1.getGuid()); - try - { - favouritesProxy.createFavourite("-me-", favourite); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); - } - - sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = 10; - Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size()); - try - { - favouritesProxy.getFavourites("-me-", createParams(paging, null)); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); - } - } - - // favourite a folder in another network - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); - - FavouriteFolder folder1 = new FavouriteFolder(person1PrivateFolders.get(0).getId()); - Favourite favourite = makeFolderFavourite(folder1.getGuid()); - try - { - favouritesProxy.createFavourite("-me-", favourite); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); - } - - sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = 10; - Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size()); - try - { - favouritesProxy.getFavourites("-me-", createParams(paging, null)); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); - } - } - } - } - - // GET favourites - // test paging and sorting - { - // cloud-2458 - // cloud-2462 - // cloud-2461 - { - log("cloud-2458"); - log("cloud-2461"); - log("cloud-2462"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - List expected = new ArrayList(expectedFavourites); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = 2; - Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - List expected = new ArrayList(expectedFavourites); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 2; - int maxItems = 4; - Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // 2466 - // GET favourites for "-me-" - { - log("cloud-2466"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - List expected = new ArrayList(expectedFavourites); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); - ListResponse resp = favouritesProxy.getFavourites("-me-", createParams(paging, null)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - } - - // 2459 - { - log("cloud-2459"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, 0, 0); - ListResponse resp = favouritesProxy.getFavourites(person11Id, createParams(paging, null)); - List empty = Collections.emptyList(); - checkList(empty, paging.getExpectedPaging(), resp); - } - - // cloud-2460: filtering by target type - { - log("cloud-2460"); - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.FILE)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/file))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.FOLDER)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/folder))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // target/file - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.FILE)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/file))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // target/folder - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.FOLDER)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/folder))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // target/site - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.SITE)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/site))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // target/folder OR target/file. - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.FOLDER, Type.FILE)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/folder))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // target/site OR target/file. - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.SITE, Type.FILE)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/site))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // target/site OR target/folder. - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Set types = new HashSet(Arrays.asList(Type.SITE, Type.FOLDER)); - List expected = filter(expectedFavourites, types); - sort(expected, FavouritesService.DEFAULT_SORT_PROPS); - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); - Map params = Collections.singletonMap("where", "(EXISTS(target/site) OR EXISTS(target/folder))"); - ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); - checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - } - - // GET a favourite - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - favouritesProxy.getFavourite(person10Id, GUID.generate()); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite favourite = expectedFavourites.get(0); - - favouritesProxy.getFavourite(GUID.generate(), favourite.getTargetGuid()); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - Favourite favourite = expectedFavourites.get(0); - - Favourite resp = favouritesProxy.getFavourite(person10Id, favourite.getTargetGuid()); - favourite.expected(resp); - } - - // cloud-2479, PUT case - { - log("cloud-2479.1"); - updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site); - - log("cloud-2479.2"); - updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file); - - log("cloud-2479.3"); - updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder); - } - - try - { - // cloud-2474 - // non-existent personId - log("cloud-2474"); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - favouritesProxy.removeFavourite(GUID.generate(), GUID.generate()); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // cloud-2475 - // try delete a non-existent favourite for a node that exists - { - log("cloud-2475"); - - NodeRef doc = TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public NodeRef doWork() throws Exception - { - NodeRef containerNodeRef = person1PublicSites.get(0).getContainerNodeRef("documentLibrary"); - NodeRef doc = repoService.createDocument(containerNodeRef, GUID.generate(), ""); - return doc; - } - }, person11Id, network1.getId()); - - String favouriteId = doc.getId(); - - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - - ListResponse before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); - List beforeList = before.getList(); - assertTrue(beforeList.size() > 0); - - try - { - favouritesProxy.removeFavourite(person10Id, favouriteId); - fail("Should be a 404"); - } - catch(PublicApiException e) - { - // expected - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - // check no favourites have been removed - ListResponse after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); - assertEquals(beforeList.size(), after.getList().size()); - } - - // cloud-2473, DELETE case - { - log("cloud-2473.1"); - deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site); - - log("cloud-2473.2"); - deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file); - - log("cloud-2473.3"); - Favourite favourite = deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder); - - // try to delete non-existent favourite - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); - favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid()); - - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - } - - // cloud-2476 - // try delete another user's favourite - { - log("cloud-2476"); - - // make sure there are favourites to delete + { + Comparator comparator = new Comparator() + { + @Override + public int compare(Favourite o1, Favourite o2) + { + int ret = 0; + for(Pair sort : sortProps) + { + FavouritesService.SortFields field = sort.getFirst(); + Boolean ascending = sort.getSecond(); + if(field.equals(FavouritesService.SortFields.username)) + { + if(ascending) + { + if(o1.getUsername() != null && o2.getUsername() != null) + { + ret = collator.compare(o1.getUsername(), o2.getUsername()); + } + } + else + { + if(o1.getUsername() != null && o2.getUsername() != null) + { + ret = o2.getUsername().compareTo(o1.getUsername()); + } + } + + if(ret != 0) + { + break; + } + } + else if(field.equals(FavouritesService.SortFields.type)) + { + if(ascending) + { + ret = o1.getType().compareTo(o2.getType()); + } + else + { + ret = o2.getType().compareTo(o1.getType()); + } + + if(ret != 0) + { + break; + } + } + else if(field.equals(FavouritesService.SortFields.createdAt)) + { + if(ascending) + { + ret = o1.getCreatedAt().compareTo(o2.getCreatedAt()); + } + else + { + ret = o2.getCreatedAt().compareTo(o1.getCreatedAt()); + } + + if(ret != 0) + { + break; + } + } + } + + return ret; + } + }; + Collections.sort(favourites, comparator); + } + + /** + * Returns a new list. + * + * @param favourites List + * @param types Set + * @return ArrayList + */ + private ArrayList filter(List favourites, final Set types) + { + Predicate predicate = new Predicate() + { + @Override + public boolean apply(Favourite other) + { + Type type = null; + if(other.getTarget() instanceof FileFavouriteTarget) + { + type = Type.FILE; + } + else if(other.getTarget() instanceof FolderFavouriteTarget) + { + type = Type.FOLDER; + } + else if(other.getTarget() instanceof SiteFavouriteTarget) + { + type = Type.SITE; + } + + boolean ret = (type != null && types.contains(type)); + return ret; + } + }; + ArrayList ret = Lists.newArrayList(Collections2.filter(favourites, predicate)); + return ret; + } + + private void updateFavourite(String networkId, String runAsUserId, String personId, TARGET_TYPE type) throws Exception + { + { + int size = 0; + + try + { + // get a favourite id + ListResponse resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); + List favourites = resp.getList(); + size = favourites.size(); + assertTrue(size > 0); + Favourite favourite = favourites.get(0); + + favouritesProxy.update("people", personId, "favorites", favourite.getTargetGuid(), favourite.toJSON().toString(), "Unable to update favourite"); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); + } + + // check nothing has changed + ListResponse resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); + List favourites = resp.getList(); + assertEquals(size, favourites.size()); + } + } + + private Favourite deleteFavourite(String networkId, String runAsUserId, String personId, TARGET_TYPE type) throws Exception + { + Exception e = null; + + publicApiClient.setRequestContext(new RequestContext(networkId, runAsUserId)); + + // get a favourite id + ListResponse resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); + List favourites = resp.getList(); + int size = favourites.size(); + assertTrue(size > 0); + Favourite favourite = favourites.get(0); + + try + { + // catch 404's + favouritesProxy.removeFavourite(personId, favourite.getTargetGuid()); + } + catch(PublicApiException exc) + { + e = exc; + } + + // check favourite has been removed + resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); + favourites = resp.getList(); + boolean stillExists = false; + for(Favourite f : favourites) + { + if(f.getTargetGuid().equals(favourite.getTargetGuid())) + { + stillExists = true; + break; + } + } + assertFalse(stillExists); + + if(e != null) + { + throw e; + } + + return favourite; + } + + private ListResponse getFavourites(String networkId, String runAsUserId, String personId, int skipCount, int maxItems, Integer total, + Integer expectedTotal, TARGET_TYPE type) throws PublicApiException, ParseException + { + publicApiClient.setRequestContext(new RequestContext(networkId, runAsUserId)); + + Paging paging = null; + if(total == null && expectedTotal == null) + { + paging = getPaging(skipCount, maxItems); + } + else + { + paging = getPaging(skipCount, maxItems, total, expectedTotal); + } + Map params = null; + if(type != null) + { + params = Collections.singletonMap("where", "(EXISTS(target/" + type + "))"); + } + ListResponse resp = favouritesProxy.getFavourites(personId, createParams(paging, params)); + return resp; + } + + private Favourite makeFolderFavourite(String targetGuid) throws ParseException + { + FavouriteFolder folder = new FavouriteFolder(targetGuid); + FolderFavouriteTarget target = new FolderFavouriteTarget(folder); + Date creationData = new Date(); + Favourite favourite = new Favourite(creationData, null, target); + return favourite; + } + + private Favourite makeFileFavourite(String targetGuid) throws ParseException + { + FavouriteDocument document = new FavouriteDocument(targetGuid); + FileFavouriteTarget target = new FileFavouriteTarget(document); + Date creationData = new Date(); + Favourite favourite = new Favourite(creationData, null, target); + return favourite; + } + + private Favourite makeSiteFavourite(Site site) throws ParseException + { + SiteFavouriteTarget target = new SiteFavouriteTarget(site); + Date creationDate = new Date(); + Favourite favourite = new Favourite(creationDate, null, target); + return favourite; + } + + @Test + public void testInvalidRequests() throws Exception + { + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite favourite = makeSiteFavourite(person1PublicSites.get(0)); + Favourite ret = favouritesProxy.createFavourite(person11Id, favourite); + favourite.expected(ret); + fail(); + } + catch(PublicApiException e) + { + // Note: un-authorized comes back as 404 + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // cloud-2468 + // invalid type + // NOTE: The test below has swapped to attempt to favorite a comment rather than a + // a wiki page as the WikiService has moved to the Share Services AMP in 5.1 + + try + { + log("cloud-2468"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + final NodeRef document = personDocs.get(0); + final NodeRef comment = TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public NodeRef doWork() throws Exception + { + NodeRef comment = repoService.createComment(document, new Comment("Title", "Content")); + return comment; + } + }, person10Id, network1.getId()); + + final String guid = comment.getId(); + JSONAble commentJSON = new JSONAble() + { + @SuppressWarnings("unchecked") + @Override + public JSONObject toJSON() + { + JSONObject json = new JSONObject(); + json.put("guid", guid); + return json; + } + }; + + FavouritesTarget target = new InvalidFavouriteTarget("comment", commentJSON, guid); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); + } + + try + { + log("cloud-2468"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Site site = person1PublicSites.get(0); + FavouritesTarget target = new InvalidFavouriteTarget(GUID.generate(), site, site.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); + } + + // type = file, target is a site + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + String siteGuid = person1PublicSites.get(0).getGuid(); + FavouriteDocument document = new FavouriteDocument(siteGuid); + Favourite favourite = makeFileFavourite(document.getGuid()); + Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); + favourite.expected(ret); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // type = folder, target is a site + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + String siteGuid = person1PublicSites.get(0).getGuid(); + FavouriteFolder folder = new FavouriteFolder(siteGuid); + Favourite favourite = makeFolderFavourite(folder.getGuid()); + Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); + favourite.expected(ret); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // type = folder, target is a file + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouriteFolder folder = new FavouriteFolder(person1PublicDocs.get(0).getId()); + Favourite favourite = makeFolderFavourite(folder.getGuid()); + Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); + favourite.expected(ret); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // type = file, target is a folder + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouriteDocument document = new FavouriteDocument(person1PublicFolders.get(0).getId()); + Favourite favourite = makeFileFavourite(document.getGuid()); + Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); + favourite.expected(ret); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // make sure that a user can't favourite on behalf of another user + // 2471 + { + log("cloud-2471"); + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); + Favourite favourite = makeFileFavourite(document.getGuid()); + favouritesProxy.createFavourite(person11Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + // Note: un-authorized comes back as 404 + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // person1 should have no favourites + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); + ListResponse response = favouritesProxy.getFavourites(person11Id, createParams(null, null)); + assertEquals(0, response.getList().size()); + } + + // invalid/non-existent user + // 2469 + try + { + log("cloud-2469"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite favourite = makeSiteFavourite(personSites.get(0)); + Favourite ret = favouritesProxy.createFavourite(GUID.generate(), favourite); + favourite.expected(ret); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // make sure that a user can't see other user's favourites. + // 2465 + try + { + log("cloud-2465"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + favouritesProxy.getFavourites(person11Id, null); + fail(); + } + catch(PublicApiException e) + { + // Note: un-authorized comes back as 404 + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // 2464, unknown user + try + { + log("cloud-2464"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + favouritesProxy.getFavourites(GUID.generate(), null); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // non-existent entity for a given type + // 2480 + { + log("cloud-2480"); + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + SiteImpl site = new SiteImpl(); + site.setGuid(GUID.generate()); + Favourite favourite = makeSiteFavourite((Site)site); + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); + assertEquals(0, response.getList().size()); + } + + { + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouriteDocument document = new FavouriteDocument(GUID.generate()); + Favourite favourite = makeFileFavourite(document.getGuid()); + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); + assertEquals(0, response.getList().size()); + } + + { + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouriteFolder folder = new FavouriteFolder(GUID.generate()); + Favourite favourite = makeFolderFavourite(folder.getGuid()); + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); + assertEquals(0, response.getList().size()); + } + + // 2470 + // incorrect type for a given favourite target + { + log("cloud-2470"); + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Site site = person1PublicSites.get(0); + FavouritesTarget target = new InvalidFavouriteTarget("folder", site, site.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); + } + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Site site = person1PublicSites.get(0); + FavouritesTarget target = new InvalidFavouriteTarget("file", site, site.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); + } + + FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouritesTarget target = new InvalidFavouriteTarget("site", document, document.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouritesTarget target = new InvalidFavouriteTarget("folder", document, document.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + FavouriteFolder folder = new FavouriteFolder(person1PublicFolders.get(0).getId()); + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouritesTarget target = new InvalidFavouriteTarget("site", folder, folder.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + FavouritesTarget target = new InvalidFavouriteTarget("file", folder, folder.getGuid()); + Favourite favourite = new Favourite(target); + + favouritesProxy.createFavourite(person10Id, favourite); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + // none of these POSTs should have resulted in favourites being created... + ListResponse response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); + assertEquals(0, response.getList().size()); + } + + // invalid methods + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + try + { + Favourite favourite = new Favourite(null); + favouritesProxy.update("people", "-me-", "favorites", null, favourite.toJSON().toString(), "Unable to PUT favourites"); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); + } + } + } + + @Test + public void testValidRequests() throws Exception + { + List expectedFavourites = new ArrayList(); + + { + // add some favourites + // 2467 + + log("cloud-2467"); + + Favourite siteFavourite1 = makeSiteFavourite(person1PublicSites.get(0)); + + FavouriteDocument document = repoService.getDocument(network1.getId(), person1PublicDocs.get(0)); + Favourite fileFavourite1 = makeFileFavourite(document.getGuid()); + + FavouriteFolder folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(0)); + Favourite folderFavourite1 = makeFolderFavourite(folder.getGuid()); + + Favourite siteFavourite2 = makeSiteFavourite(person1PublicSites.get(1)); + + document = repoService.getDocument(network1.getId(), person1PublicDocs.get(1)); + Favourite fileFavourite2 = makeFileFavourite(document.getGuid()); + + folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(1)); + Favourite folderFavourite2 = makeFolderFavourite(folder.getGuid()); + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1); + expectedFavourites.add(ret); + siteFavourite1.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1); + expectedFavourites.add(ret); + fileFavourite1.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1); + expectedFavourites.add(ret); + folderFavourite1.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite2); + expectedFavourites.add(ret); + siteFavourite2.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite2); + expectedFavourites.add(ret); + fileFavourite2.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite2); + expectedFavourites.add(ret); + folderFavourite2.expected(ret); + } + + // already a favourite - 201 + { + log("cloud-2472"); + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1); + siteFavourite1.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1); + folderFavourite1.expected(ret); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1); + fileFavourite1.expected(ret); + } + } + + { + // cloud-2498 + // cloud-2499 + // create and list favourites across networks + + List person21ExpectedFavourites = new ArrayList(); + + log("cloud-2498"); + log("cloud-2499"); + + { + // favourite a site in another network + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); + + Favourite favourite = makeSiteFavourite(person1PrivateSites.get(0)); + try + { + favouritesProxy.createFavourite("-me-", favourite); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); + } + + int skipCount = 0; + int maxItems = 10; + Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size()); + try + { + favouritesProxy.getFavourites("-me-", createParams(paging, null)); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); + } + } + + // favourite a document in another network + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); + + FavouriteDocument document1 = new FavouriteDocument(person1PrivateDocs.get(0).getId()); + Favourite favourite = makeFileFavourite(document1.getGuid()); + try + { + favouritesProxy.createFavourite("-me-", favourite); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); + } + + sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = 10; + Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size()); + try + { + favouritesProxy.getFavourites("-me-", createParams(paging, null)); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); + } + } + + // favourite a folder in another network + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); + + FavouriteFolder folder1 = new FavouriteFolder(person1PrivateFolders.get(0).getId()); + Favourite favourite = makeFolderFavourite(folder1.getGuid()); + try + { + favouritesProxy.createFavourite("-me-", favourite); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); + } + + sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = 10; + Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size()); + try + { + favouritesProxy.getFavourites("-me-", createParams(paging, null)); + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); + } + } + } + } + + // GET favourites + // test paging and sorting + { + // cloud-2458 + // cloud-2462 + // cloud-2461 + { + log("cloud-2458"); + log("cloud-2461"); + log("cloud-2462"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + List expected = new ArrayList(expectedFavourites); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = 2; + Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + List expected = new ArrayList(expectedFavourites); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 2; + int maxItems = 4; + Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // 2466 + // GET favourites for "-me-" + { + log("cloud-2466"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + List expected = new ArrayList(expectedFavourites); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); + ListResponse resp = favouritesProxy.getFavourites("-me-", createParams(paging, null)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + } + + // 2459 + { + log("cloud-2459"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, 0, 0); + ListResponse resp = favouritesProxy.getFavourites(person11Id, createParams(paging, null)); + List empty = Collections.emptyList(); + checkList(empty, paging.getExpectedPaging(), resp); + } + + // cloud-2460: filtering by target type + { + log("cloud-2460"); + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.FILE)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/file))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.FOLDER)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/folder))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // target/file + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.FILE)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/file))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // target/folder + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.FOLDER)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/folder))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // target/site + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.SITE)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/site))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // target/folder OR target/file. + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.FOLDER, Type.FILE)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/folder))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // target/site OR target/file. + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.SITE, Type.FILE)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/site))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + + // target/site OR target/folder. + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Set types = new HashSet(Arrays.asList(Type.SITE, Type.FOLDER)); + List expected = filter(expectedFavourites, types); + sort(expected, FavouritesService.DEFAULT_SORT_PROPS); + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size()); + Map params = Collections.singletonMap("where", "(EXISTS(target/site) OR EXISTS(target/folder))"); + ListResponse resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params)); + checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + } + + // GET a favourite + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + favouritesProxy.getFavourite(person10Id, GUID.generate()); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite favourite = expectedFavourites.get(0); + + favouritesProxy.getFavourite(GUID.generate(), favourite.getTargetGuid()); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + Favourite favourite = expectedFavourites.get(0); + + Favourite resp = favouritesProxy.getFavourite(person10Id, favourite.getTargetGuid()); + favourite.expected(resp); + } + + // cloud-2479, PUT case + { + log("cloud-2479.1"); + updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site); + + log("cloud-2479.2"); + updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file); + + log("cloud-2479.3"); + updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder); + } + + try + { + // cloud-2474 + // non-existent personId + log("cloud-2474"); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + favouritesProxy.removeFavourite(GUID.generate(), GUID.generate()); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // cloud-2475 + // try delete a non-existent favourite for a node that exists + { + log("cloud-2475"); + + NodeRef doc = TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public NodeRef doWork() throws Exception + { + NodeRef containerNodeRef = person1PublicSites.get(0).getContainerNodeRef("documentLibrary"); + NodeRef doc = repoService.createDocument(containerNodeRef, GUID.generate(), ""); + return doc; + } + }, person11Id, network1.getId()); + + String favouriteId = doc.getId(); + + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + + ListResponse before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); + List beforeList = before.getList(); + assertTrue(beforeList.size() > 0); + + try + { + favouritesProxy.removeFavourite(person10Id, favouriteId); + fail("Should be a 404"); + } + catch(PublicApiException e) + { + // expected + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + // check no favourites have been removed + ListResponse after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); + assertEquals(beforeList.size(), after.getList().size()); + } + + // cloud-2473, DELETE case + { + log("cloud-2473.1"); + deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site); + + log("cloud-2473.2"); + deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file); + + log("cloud-2473.3"); + Favourite favourite = deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder); + + // try to delete non-existent favourite + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); + favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid()); + + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + } + + // cloud-2476 + // try delete another user's favourite + { + log("cloud-2476"); + + // make sure there are favourites to delete // publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId)); // SiteFavouriteTarget target = new SiteFavouriteTarget(person1Sites.get(0)); // Favourite favourite = new Favourite(target); // favouritesProxy.createFavourite(personId, favourite); - ListResponse before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); - assertTrue(before.getList().size() > 0); - Favourite favourite = before.getList().get(0); + ListResponse before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); + assertTrue(before.getList().size() > 0); + Favourite favourite = before.getList().get(0); - try - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); - favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid()); + try + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); + favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid()); - fail(); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } + fail(); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } - ListResponse after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); - assertEquals(before.getList().size(), after.getList().size()); - } - } + ListResponse after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null); + assertEquals(before.getList().size(), after.getList().size()); + } + } - @Test - public void testPUBLICAPI141() throws Exception - { - final TestSite publicSite = person1PublicSites.get(0); // person1's public site - final TestSite publicSite1 = person1PublicSites.get(1); // person1's public site - final TestSite privateSite = person1PrivateSites.get(0); // person1's private site - final NodeRef folderNodeRef = person1PublicFolders.get(0); // person1's folder - final NodeRef nodeRef = person1PublicDocs.get(1); // a file in the folder - final List expectedFavourites = new ArrayList(); + @Test + public void testPUBLICAPI141() throws Exception + { + final TestSite publicSite = person1PublicSites.get(0); // person1's public site + final TestSite publicSite1 = person1PublicSites.get(1); // person1's public site + final TestSite privateSite = person1PrivateSites.get(0); // person1's private site + final NodeRef folderNodeRef = person1PublicFolders.get(0); // person1's folder + final NodeRef nodeRef = person1PublicDocs.get(1); // a file in the folder + final List expectedFavourites = new ArrayList(); - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id)); + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id)); - // invite to another user's public site - SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest(); - siteMembershipRequest.setId(publicSite.getSiteId()); - siteMembershipRequest.setMessage("Please can I join your site?"); - siteMembershipRequestsProxy.createSiteMembershipRequest(person12Id, siteMembershipRequest); + // invite to another user's public site + SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest(); + siteMembershipRequest.setId(publicSite.getSiteId()); + siteMembershipRequest.setMessage("Please can I join your site?"); + siteMembershipRequestsProxy.createSiteMembershipRequest(person12Id, siteMembershipRequest); - // favourite other users site, folder and file - Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId()); - favouritesProxy.createFavourite(person12Id, folderFavourite); + // favourite other users site, folder and file + Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId()); + favouritesProxy.createFavourite(person12Id, folderFavourite); - Favourite fileFavourite = makeFileFavourite(nodeRef.getId()); - favouritesProxy.createFavourite(person12Id, fileFavourite); - - final Favourite siteFavourite = makeSiteFavourite(publicSite); - favouritesProxy.createFavourite(person12Id, siteFavourite); - expectedFavourites.add(siteFavourite); + Favourite fileFavourite = makeFileFavourite(nodeRef.getId()); + favouritesProxy.createFavourite(person12Id, fileFavourite); - final Favourite siteFavourite1 = makeSiteFavourite(publicSite1); - favouritesProxy.createFavourite(person12Id, siteFavourite1); - expectedFavourites.add(siteFavourite1); + final Favourite siteFavourite = makeSiteFavourite(publicSite); + favouritesProxy.createFavourite(person12Id, siteFavourite); + expectedFavourites.add(siteFavourite); - sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + final Favourite siteFavourite1 = makeSiteFavourite(publicSite1); + favouritesProxy.createFavourite(person12Id, siteFavourite1); + expectedFavourites.add(siteFavourite1); - // move the folder and file to person1's private site - TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public Void doWork() throws Exception - { - NodeRef documentLibraryNodeRef = privateSite.getContainerNodeRef("documentLibrary"); - repoService.moveNode(folderNodeRef, documentLibraryNodeRef); + sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); - return null; - } - }, person11Id, network1.getId()); - - try - { - favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid()); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } + // move the folder and file to person1's private site + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public Void doWork() throws Exception + { + NodeRef documentLibraryNodeRef = privateSite.getContainerNodeRef("documentLibrary"); + repoService.moveNode(folderNodeRef, documentLibraryNodeRef); - try - { - favouritesProxy.getFavourite(person12Id, fileFavourite.getTargetGuid()); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - { - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); - ListResponse resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null)); - checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - - // make the public sites private - TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public Void doWork() throws Exception - { - publicSite.setSiteVisibility(SiteVisibility.PRIVATE); - publicSite1.setSiteVisibility(SiteVisibility.PRIVATE); - - return null; - } - }, person11Id, network1.getId()); - expectedFavourites.remove(siteFavourite1); + return null; + } + }, person11Id, network1.getId()); - // Given that person2Id is still a member of 'publicSite', they should still have access and therefore - // it should show up in their favourites. But person2Id is not a member of 'publicSite1', they should - // not have access and therefore it should not show up in their favourites. - { - Favourite actual = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid()); - siteFavourite.expected(actual); + try + { + favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid()); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } - try - { - favouritesProxy.getFavourite(person12Id, siteFavourite1.getTargetGuid()); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } + try + { + favouritesProxy.getFavourite(person12Id, fileFavourite.getTargetGuid()); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); - ListResponse resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null)); - checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - } - } - - @Test - public void testPUBLICAPI156() throws Exception - { - final TestSite publicSite = person1PublicSites.get(0); // person1's public site - final TestSite publicSite1 = person1PublicSites.get(1); // person1's public site - final NodeRef folderNodeRef = person1PublicFolders.get(0); // person1's folder - final NodeRef nodeRef = person1PublicDocs.get(1); // a file in the folder - final List expectedFavourites = new ArrayList(); + { + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); + ListResponse resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null)); + checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } - { - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id)); + // make the public sites private + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public Void doWork() throws Exception + { + publicSite.setSiteVisibility(SiteVisibility.PRIVATE); + publicSite1.setSiteVisibility(SiteVisibility.PRIVATE); - // invite to another user's public site - SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest(); - siteMembershipRequest.setId(publicSite.getSiteId()); - siteMembershipRequest.setMessage("Please can I join your site?"); - siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest); + return null; + } + }, person11Id, network1.getId()); + expectedFavourites.remove(siteFavourite1); - // favourite other users site, folder and file - Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId()); - favouritesProxy.createFavourite(person14Id, folderFavourite); - expectedFavourites.add(folderFavourite); + // Given that person2Id is still a member of 'publicSite', they should still have access and therefore + // it should show up in their favourites. But person2Id is not a member of 'publicSite1', they should + // not have access and therefore it should not show up in their favourites. + { + Favourite actual = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid()); + siteFavourite.expected(actual); - Favourite fileFavourite = makeFileFavourite(nodeRef.getId()); - favouritesProxy.createFavourite(person14Id, fileFavourite); - expectedFavourites.add(fileFavourite); - - final Favourite siteFavourite = makeSiteFavourite(publicSite); - favouritesProxy.createFavourite(person14Id, siteFavourite); - expectedFavourites.add(siteFavourite); + try + { + favouritesProxy.getFavourite(person12Id, siteFavourite1.getTargetGuid()); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } - final Favourite siteFavourite1 = makeSiteFavourite(publicSite1); - favouritesProxy.createFavourite(person14Id, siteFavourite1); - expectedFavourites.add(siteFavourite1); + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); + ListResponse resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null)); + checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + } + } - sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + @Test + public void testPUBLICAPI156() throws Exception + { + final TestSite publicSite = person1PublicSites.get(0); // person1's public site + final TestSite publicSite1 = person1PublicSites.get(1); // person1's public site + final NodeRef folderNodeRef = person1PublicFolders.get(0); // person1's folder + final NodeRef nodeRef = person1PublicDocs.get(1); // a file in the folder + final List expectedFavourites = new ArrayList(); - // remove the folder and file - TenantUtil.runAsUserTenant(new TenantRunAsWork() - { - @Override - public Void doWork() throws Exception - { - repoService.deleteNode(nodeRef); - repoService.deleteNode(folderNodeRef); + { + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id)); - return null; - } - }, person11Id, network1.getId()); + // invite to another user's public site + SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest(); + siteMembershipRequest.setId(publicSite.getSiteId()); + siteMembershipRequest.setMessage("Please can I join your site?"); + siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest); - expectedFavourites.remove(folderFavourite); - expectedFavourites.remove(fileFavourite); - sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + // favourite other users site, folder and file + Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId()); + favouritesProxy.createFavourite(person14Id, folderFavourite); + expectedFavourites.add(folderFavourite); - // GETs should not return the favourites nor error - { - try - { - favouritesProxy.getFavourite(person14Id, folderFavourite.getTargetGuid()); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } - - try - { - favouritesProxy.getFavourite(person14Id, fileFavourite.getTargetGuid()); - } - catch(PublicApiException e) - { - assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); - } + Favourite fileFavourite = makeFileFavourite(nodeRef.getId()); + favouritesProxy.createFavourite(person14Id, fileFavourite); + expectedFavourites.add(fileFavourite); - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); - ListResponse resp = favouritesProxy.getFavourites(person14Id, createParams(paging, null)); - checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); - } - } - } + final Favourite siteFavourite = makeSiteFavourite(publicSite); + favouritesProxy.createFavourite(person14Id, siteFavourite); + expectedFavourites.add(siteFavourite); + + final Favourite siteFavourite1 = makeSiteFavourite(publicSite1); + favouritesProxy.createFavourite(person14Id, siteFavourite1); + expectedFavourites.add(siteFavourite1); + + sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + + // remove the folder and file + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public Void doWork() throws Exception + { + repoService.deleteNode(nodeRef); + repoService.deleteNode(folderNodeRef); + + return null; + } + }, person11Id, network1.getId()); + + expectedFavourites.remove(folderFavourite); + expectedFavourites.remove(fileFavourite); + sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS); + + // GETs should not return the favourites nor error + { + try + { + favouritesProxy.getFavourite(person14Id, folderFavourite.getTargetGuid()); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + try + { + favouritesProxy.getFavourite(person14Id, fileFavourite.getTargetGuid()); + } + catch(PublicApiException e) + { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); + } + + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size()); + ListResponse resp = favouritesProxy.getFavourites(person14Id, createParams(paging, null)); + checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); + } + } + } /** * Tests get favourites with 'include' parameter. diff --git a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java index 8ad9af89d8..ac85bc5bb4 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java @@ -108,381 +108,381 @@ public class PublicApiClient { private static final Log logger = LogFactory.getLog(PublicApiClient.class); - private UserDataService userDataService; - private PublicApiHttpClient client; + private UserDataService userDataService; + private PublicApiHttpClient client; - private Sites sites; - private Tags tags; - private Comments comments; - private Nodes nodes; - private People people; - private Favourites favourites; - private SiteMembershipRequests siteMembershipRequests; + private Sites sites; + private Tags tags; + private Comments comments; + private Nodes nodes; + private People people; + private Favourites favourites; + private SiteMembershipRequests siteMembershipRequests; private Groups groups; - private RawProxy rawProxy; - - private ThreadLocal rc = new ThreadLocal(); - - public PublicApiClient(PublicApiHttpClient client, UserDataService userDataService) - { - this.client = client; - this.userDataService = userDataService; + private RawProxy rawProxy; - init(); - } + private ThreadLocal rc = new ThreadLocal(); - public void init() - { - sites = new Sites(); - tags = new Tags(); - comments = new Comments(); - nodes = new Nodes(); - people = new People(); - favourites = new Favourites(); - siteMembershipRequests = new SiteMembershipRequests(); + public PublicApiClient(PublicApiHttpClient client, UserDataService userDataService) + { + this.client = client; + this.userDataService = userDataService; + + init(); + } + + public void init() + { + sites = new Sites(); + tags = new Tags(); + comments = new Comments(); + nodes = new Nodes(); + people = new People(); + favourites = new Favourites(); + siteMembershipRequests = new SiteMembershipRequests(); groups = new Groups(); - rawProxy = new RawProxy(); - } + rawProxy = new RawProxy(); + } - public void setRequestContext(RequestContext rc) - { - this.rc.set(rc); - } + public void setRequestContext(RequestContext rc) + { + this.rc.set(rc); + } - public RequestContext getRequestContext() - { - RequestContext context = rc.get(); - if(context == null) - { - throw new RuntimeException("Must set a request context"); - } - return context; - } + public RequestContext getRequestContext() + { + RequestContext context = rc.get(); + if(context == null) + { + throw new RuntimeException("Must set a request context"); + } + return context; + } - protected UserData findUser(String userName) - { - return userDataService.findUserByUserName(userName); - } - - public RawProxy rawProxy() - { - return rawProxy; - } + protected UserData findUser(String userName) + { + return userDataService.findUserByUserName(userName); + } - public People people() - { - return people; - } + public RawProxy rawProxy() + { + return rawProxy; + } - public Nodes nodes() - { - return nodes; - } + public People people() + { + return people; + } - public Sites sites() - { - return sites; - } - - public Favourites favourites() - { - return favourites; - } - - public SiteMembershipRequests siteMembershipRequests() - { - return siteMembershipRequests; - } - - public Tags tags() - { - return tags; - } - - public Comments comments() - { - return comments; - } + public Nodes nodes() + { + return nodes; + } + + public Sites sites() + { + return sites; + } + + public Favourites favourites() + { + return favourites; + } + + public SiteMembershipRequests siteMembershipRequests() + { + return siteMembershipRequests; + } + + public Tags tags() + { + return tags; + } + + public Comments comments() + { + return comments; + } public Groups groups() { return groups; } - public CmisSession createPublicApiCMISSession(Binding binding, String version) + public CmisSession createPublicApiCMISSession(Binding binding, String version) { return createPublicApiCMISSession(binding, version, null); } - public CmisSession createPublicApiCMISSession(Binding binding, String version, String objectFactoryName) - { - CmisSession cmisSession = null; + public CmisSession createPublicApiCMISSession(Binding binding, String version, String objectFactoryName) + { + CmisSession cmisSession = null; - RequestContext rc = getRequestContext(); - if(rc == null) - { - throw new RuntimeException("Must set a request context"); - } - - String networkId = rc.getNetworkId(); - String username = rc.getRunAsUser(); - UserData userData = findUser(rc.getRunAsUser()); - if(userData != null) - { - String password = userData.getPassword(); - - // default factory implementation - SessionFactory factory = SessionFactoryImpl.newInstance(); - Map parameters = new HashMap(); - - // user credentials - parameters.put(SessionParameter.USER, username); - parameters.put(SessionParameter.PASSWORD, password); - - // connection settings - if(binding == Binding.atom) - { - parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(networkId, binding, version, null)); - parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value()); - } - else if(binding == Binding.browser) - { - parameters.put(SessionParameter.BROWSER_URL, client.getPublicApiCmisUrl(networkId, binding, version, null)); - parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value()); - } - if(networkId != null) - { - parameters.put(SessionParameter.REPOSITORY_ID, networkId); - } - if(objectFactoryName != null) - { - parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, objectFactoryName); - } + RequestContext rc = getRequestContext(); + if(rc == null) + { + throw new RuntimeException("Must set a request context"); + } - // create session - Session session = factory.createSession(parameters); + String networkId = rc.getNetworkId(); + String username = rc.getRunAsUser(); + UserData userData = findUser(rc.getRunAsUser()); + if(userData != null) + { + String password = userData.getPassword(); - cmisSession = new CmisSession(session); - } + // default factory implementation + SessionFactory factory = SessionFactoryImpl.newInstance(); + Map parameters = new HashMap(); - return cmisSession; - } + // user credentials + parameters.put(SessionParameter.USER, username); + parameters.put(SessionParameter.PASSWORD, password); - public CmisSession createCMISSession(String repositoryId, RequestContext rc) - { - CmisSession session = null; + // connection settings + if(binding == Binding.atom) + { + parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(networkId, binding, version, null)); + parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value()); + } + else if(binding == Binding.browser) + { + parameters.put(SessionParameter.BROWSER_URL, client.getPublicApiCmisUrl(networkId, binding, version, null)); + parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value()); + } + if(networkId != null) + { + parameters.put(SessionParameter.REPOSITORY_ID, networkId); + } + if(objectFactoryName != null) + { + parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, objectFactoryName); + } - UserData userData = findUser(rc.getRunAsUser()); - if(userData != null) - { - session = createCMISSession(repositoryId, rc.getRunAsUser(), userData.getPassword()); - } + // create session + Session session = factory.createSession(parameters); - return session; - } - - /** - * Get CMIS repositories (Enterprise AtomPub CMIS binding) - * - * @return List - */ - public List getCMISRepositories() - { - List repositories = null; + cmisSession = new CmisSession(session); + } - RequestContext rc = getRequestContext(); - if(rc == null) - { - throw new RuntimeException("Must set a request context"); - } + return cmisSession; + } - UserData userData = findUser(rc.getRunAsUser()); - if(userData != null) - { - // default factory implementation - SessionFactory factory = SessionFactoryImpl.newInstance(); - Map parameters = new HashMap(); + public CmisSession createCMISSession(String repositoryId, RequestContext rc) + { + CmisSession session = null; - // user credentials - parameters.put(SessionParameter.USER, rc.getRunAsUser()); - parameters.put(SessionParameter.PASSWORD, userData.getPassword()); + UserData userData = findUser(rc.getRunAsUser()); + if(userData != null) + { + session = createCMISSession(repositoryId, rc.getRunAsUser(), userData.getPassword()); + } - // connection settings - parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(null, null)); - parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); + return session; + } - repositories = factory.getRepositories(parameters); - } + /** + * Get CMIS repositories (Enterprise AtomPub CMIS binding) + * + * @return List + */ + public List getCMISRepositories() + { + List repositories = null; - return repositories; - } + RequestContext rc = getRequestContext(); + if(rc == null) + { + throw new RuntimeException("Must set a request context"); + } - /** - * Create a CMIS session using Enterprise AtomPub binding. - * - * @param repositoryId String - * @param username String - * @param password String - * @return CmisSession - */ - public CmisSession createCMISSession(String repositoryId, String username, String password) - { - // default factory implementation - SessionFactory factory = SessionFactoryImpl.newInstance(); - Map parameters = new HashMap(); - - // user credentials - parameters.put(SessionParameter.USER, username); - parameters.put(SessionParameter.PASSWORD, password); + UserData userData = findUser(rc.getRunAsUser()); + if(userData != null) + { + // default factory implementation + SessionFactory factory = SessionFactoryImpl.newInstance(); + Map parameters = new HashMap(); - // connection settings - parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(repositoryId, null)); - parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); - if(repositoryId != null) - { - parameters.put(SessionParameter.REPOSITORY_ID, repositoryId); - } - parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, AlfrescoObjectFactoryImpl.class.getName()); + // user credentials + parameters.put(SessionParameter.USER, rc.getRunAsUser()); + parameters.put(SessionParameter.PASSWORD, userData.getPassword()); - // create session - Session session = factory.createSession(parameters); + // connection settings + parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(null, null)); + parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); - CmisSession cmisSession = new CmisSession(session); - return cmisSession; - } - - public CmisSession getCMISSession(Repository respository) - { - RequestContext rc = getRequestContext(); - if(rc == null) - { - throw new RuntimeException("Must set a request context"); - } + repositories = factory.getRepositories(parameters); + } - CmisSession session = createCMISSession(respository.getId(), rc); - return session; - } + return repositories; + } - public HttpResponse post(Binding cmisBinding, String version, String cmisOperation, String body) throws PublicApiException - { - try - { - HttpResponse response = client.post(getRequestContext(), cmisBinding, version, cmisOperation, body); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } - - public HttpResponse put(Binding cmisBinding, String version, String cmisOperation, String body) throws PublicApiException - { - try - { - HttpResponse response = client.put(getRequestContext(), cmisBinding, version, cmisOperation, body); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } - - public HttpResponse get(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException - { - try - { - HttpResponse response = client.get(getRequestContext(), cmisBinding, version, cmisOperation, parameters); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } - - public HttpResponse patch(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException - { - try - { - HttpResponse response = client.patch(getRequestContext(), cmisBinding, version, cmisOperation); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } - - public HttpResponse trace(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException - { - try - { - HttpResponse response = client.trace(getRequestContext(), cmisBinding, version, cmisOperation); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } + /** + * Create a CMIS session using Enterprise AtomPub binding. + * + * @param repositoryId String + * @param username String + * @param password String + * @return CmisSession + */ + public CmisSession createCMISSession(String repositoryId, String username, String password) + { + // default factory implementation + SessionFactory factory = SessionFactoryImpl.newInstance(); + Map parameters = new HashMap(); - public HttpResponse options(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException - { - try - { - HttpResponse response = client.options(getRequestContext(), cmisBinding, version, cmisOperation); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } - - public HttpResponse head(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException - { - try - { - HttpResponse response = client.head(getRequestContext(), cmisBinding, version, cmisOperation); - - logger.debug(response.toString()); - - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } + // user credentials + parameters.put(SessionParameter.USER, username); + parameters.put(SessionParameter.PASSWORD, password); - public HttpResponse post(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, String body) throws IOException - { - HttpResponse response = client.post(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId != null ? relationshipEntityId.toString() : null, body); + // connection settings + parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(repositoryId, null)); + parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); + if(repositoryId != null) + { + parameters.put(SessionParameter.REPOSITORY_ID, repositoryId); + } + parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, AlfrescoObjectFactoryImpl.class.getName()); - logger.debug(response.toString()); + // create session + Session session = factory.createSession(parameters); - return response; - } + CmisSession cmisSession = new CmisSession(session); + return cmisSession; + } + + public CmisSession getCMISSession(Repository respository) + { + RequestContext rc = getRequestContext(); + if(rc == null) + { + throw new RuntimeException("Must set a request context"); + } + + CmisSession session = createCMISSession(respository.getId(), rc); + return session; + } + + public HttpResponse post(Binding cmisBinding, String version, String cmisOperation, String body) throws PublicApiException + { + try + { + HttpResponse response = client.post(getRequestContext(), cmisBinding, version, cmisOperation, body); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse put(Binding cmisBinding, String version, String cmisOperation, String body) throws PublicApiException + { + try + { + HttpResponse response = client.put(getRequestContext(), cmisBinding, version, cmisOperation, body); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse get(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException + { + try + { + HttpResponse response = client.get(getRequestContext(), cmisBinding, version, cmisOperation, parameters); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse patch(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException + { + try + { + HttpResponse response = client.patch(getRequestContext(), cmisBinding, version, cmisOperation); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse trace(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException + { + try + { + HttpResponse response = client.trace(getRequestContext(), cmisBinding, version, cmisOperation); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse options(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException + { + try + { + HttpResponse response = client.options(getRequestContext(), cmisBinding, version, cmisOperation); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse head(Binding cmisBinding, String version, String cmisOperation, Map parameters) throws PublicApiException + { + try + { + HttpResponse response = client.head(getRequestContext(), cmisBinding, version, cmisOperation); + + logger.debug(response.toString()); + + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } + + public HttpResponse post(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, String body) throws IOException + { + HttpResponse response = client.post(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId != null ? relationshipEntityId.toString() : null, body); + + logger.debug(response.toString()); + + return response; + } public HttpResponse post(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, String body, final Map params) throws IOException @@ -507,89 +507,89 @@ public class PublicApiClient } - public HttpResponse post(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, - byte[] body, String contentType) throws IOException - { - HttpResponse response = client.post(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, - relationshipEntityId != null ? relationshipEntityId.toString() : null, body, contentType); + public HttpResponse post(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, + byte[] body, String contentType) throws IOException + { + HttpResponse response = client.post(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, + relationshipEntityId != null ? relationshipEntityId.toString() : null, body, contentType); - logger.debug(response.toString()); + logger.debug(response.toString()); - return response; - } + return response; + } - public HttpResponse post(String urlSuffix, String body) throws IOException - { - HttpResponse response = client.post(getRequestContext(), urlSuffix, body); - - logger.debug(response.toString()); + public HttpResponse post(String urlSuffix, String body) throws IOException + { + HttpResponse response = client.post(getRequestContext(), urlSuffix, body); - return response; - } + logger.debug(response.toString()); - public HttpResponse post(final Class c, Object entityId, Object relationshipEntityId, String body) throws IOException - { - HttpResponse response = client.post(c, getRequestContext(), entityId, relationshipEntityId, body); - - logger.debug(response.toString()); + return response; + } - return response; - } - - public HttpResponse get(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, Map params) throws IOException - { - HttpResponse response = client.get(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); - - logger.debug(response.toString()); + public HttpResponse post(final Class c, Object entityId, Object relationshipEntityId, String body) throws IOException + { + HttpResponse response = client.post(c, getRequestContext(), entityId, relationshipEntityId, body); - return response; - } - - public HttpResponse getWithPassword(String scope, String password, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, Map params) throws IOException - { - HttpResponse response = client.get(getRequestContext(), scope, password, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); - - logger.debug(response.toString()); + logger.debug(response.toString()); - return response; - } + return response; + } - public HttpResponse get(String url, Map params) throws IOException - { - RequestContext rc = getRequestContext(); - HttpResponse response = client.get(url, rc, params); - - logger.debug(response.toString()); + public HttpResponse get(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, Map params) throws IOException + { + HttpResponse response = client.get(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); - return response; - } - - public HttpResponse get(final Class c, final Object entityId, final Object relationshipEntityId, Map params) throws IOException - { - HttpResponse response = client.get(c, getRequestContext(), entityId, relationshipEntityId, params); - - logger.debug(response.toString()); + logger.debug(response.toString()); - return response; - } + return response; + } - public HttpResponse put(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, String body, Map params) throws IOException - { - HttpResponse response = client.put(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, body, params); - - logger.debug(response.toString()); + public HttpResponse getWithPassword(String scope, String password, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, Map params) throws IOException + { + HttpResponse response = client.get(getRequestContext(), scope, password, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); - return response; - } - - public HttpResponse put(final Class c, Object entityId, Object relationshipEntityId, String body) throws IOException - { - HttpResponse response = client.put(c, getRequestContext(), entityId, relationshipEntityId, body); - - logger.debug(response.toString()); + logger.debug(response.toString()); - return response; - } + return response; + } + + public HttpResponse get(String url, Map params) throws IOException + { + RequestContext rc = getRequestContext(); + HttpResponse response = client.get(url, rc, params); + + logger.debug(response.toString()); + + return response; + } + + public HttpResponse get(final Class c, final Object entityId, final Object relationshipEntityId, Map params) throws IOException + { + HttpResponse response = client.get(c, getRequestContext(), entityId, relationshipEntityId, params); + + logger.debug(response.toString()); + + return response; + } + + public HttpResponse put(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, String body, Map params) throws IOException + { + HttpResponse response = client.put(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, body, params); + + logger.debug(response.toString()); + + return response; + } + + public HttpResponse put(final Class c, Object entityId, Object relationshipEntityId, String body) throws IOException + { + HttpResponse response = client.put(c, getRequestContext(), entityId, relationshipEntityId, body); + + logger.debug(response.toString()); + + return response; + } public HttpResponse putBinary(String scope, int version, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, BinaryPayload payload, Map params) throws IOException @@ -602,28 +602,28 @@ public class PublicApiClient return response; } - public HttpResponse delete(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId) throws IOException - { - return delete(scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, null); - } + public HttpResponse delete(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId) throws IOException + { + return delete(scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, null); + } - public HttpResponse delete(String scope, int version, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, Map params) throws IOException - { - HttpResponse response = client.delete(getRequestContext(), scope, version, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); - - logger.debug(response.toString()); + public HttpResponse delete(String scope, int version, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId, Map params) throws IOException + { + HttpResponse response = client.delete(getRequestContext(), scope, version, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); - return response; - } - - public HttpResponse put(final Class c, Object entityId, Object relationshipEntityId) throws IOException - { - HttpResponse response = client.delete(c, getRequestContext(), entityId, relationshipEntityId); - - logger.debug(response.toString()); + logger.debug(response.toString()); - return response; - } + return response; + } + + public HttpResponse put(final Class c, Object entityId, Object relationshipEntityId) throws IOException + { + HttpResponse response = client.delete(c, getRequestContext(), entityId, relationshipEntityId); + + logger.debug(response.toString()); + + return response; + } public HttpResponse execute(RequestBuilder requestBuilder) throws IOException { @@ -638,46 +638,46 @@ public class PublicApiClient return response; } - public HttpResponse index(Map params) throws IOException - { - HttpResponse response = get("", params); - return response; - } + public HttpResponse index(Map params) throws IOException + { + HttpResponse response = get("", params); + return response; + } - public List getNetworkIds(String version) - { - RequestContext rc = getRequestContext(); - - UserData userData = findUser(rc.getRunAsUser()); - if(userData == null) - { - throw new RuntimeException("Must provide a valid username"); - } + public List getNetworkIds(String version) + { + RequestContext rc = getRequestContext(); - SessionFactory factory = SessionFactoryImpl.newInstance(); + UserData userData = findUser(rc.getRunAsUser()); + if(userData == null) + { + throw new RuntimeException("Must provide a valid username"); + } - Map parameters = new HashMap(); + SessionFactory factory = SessionFactoryImpl.newInstance(); - // connection settings - parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(null, Binding.atom, version, null)); - parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); + Map parameters = new HashMap(); - // user credentials - parameters.put(SessionParameter.USER, rc.getRunAsUser()); - parameters.put(SessionParameter.PASSWORD, userData.getPassword()); - List repositories = factory.getRepositories(parameters); + // connection settings + parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(null, Binding.atom, version, null)); + parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); - List repositoryIds = new ArrayList(repositories.size()); - for(Repository repository : repositories) - { - repositoryIds.add(repository.getId()); - } + // user credentials + parameters.put(SessionParameter.USER, rc.getRunAsUser()); + parameters.put(SessionParameter.PASSWORD, userData.getPassword()); + List repositories = factory.getRepositories(parameters); - return repositoryIds; - } + List repositoryIds = new ArrayList(repositories.size()); + for(Repository repository : repositories) + { + repositoryIds.add(repository.getId()); + } - public class AbstractProxy - { + return repositoryIds; + } + + public class AbstractProxy + { public HttpResponse getAll(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage) throws PublicApiException { @@ -705,18 +705,18 @@ public class PublicApiClient } public HttpResponse getSingle(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage, int expectedStatus) throws PublicApiException - { - try - { - HttpResponse response = get("public", entityCollectionName, entityId, relationCollectionName, relationId, null); + { + try + { + HttpResponse response = get("public", entityCollectionName, entityId, relationCollectionName, relationId, null); checkStatus(errorMessage, expectedStatus, response); return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } public HttpResponse getSingle(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage, int expectedStatus) throws PublicApiException @@ -733,24 +733,24 @@ public class PublicApiClient } } - public HttpResponse update(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage) throws PublicApiException - { - return update(entityCollectionName, entityId, relationCollectionName, relationId, body, null, errorMessage, 200); - } - - public HttpResponse update(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, Map params, String errorMessage, int expectedStatus) throws PublicApiException - { - try - { - HttpResponse response = put("public", entityCollectionName, entityId, relationCollectionName, relationId, body, params); - checkStatus(errorMessage, expectedStatus, response); - return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } + public HttpResponse update(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage) throws PublicApiException + { + return update(entityCollectionName, entityId, relationCollectionName, relationId, body, null, errorMessage, 200); + } + + public HttpResponse update(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, Map params, String errorMessage, int expectedStatus) throws PublicApiException + { + try + { + HttpResponse response = put("public", entityCollectionName, entityId, relationCollectionName, relationId, body, params); + checkStatus(errorMessage, expectedStatus, response); + return response; + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } public HttpResponse create(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage) throws PublicApiException { @@ -782,82 +782,82 @@ public class PublicApiClient { return remove(entityCollectionName, entityId, relationCollectionName, relationId, null, errorMessage, HttpServletResponse.SC_NO_CONTENT); } - - public HttpResponse remove(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage, int expectedStatus) throws PublicApiException - { - try - { - HttpResponse response = delete("public", 1, entityCollectionName, entityId, relationCollectionName, relationId, params); + + public HttpResponse remove(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage, int expectedStatus) throws PublicApiException + { + try + { + HttpResponse response = delete("public", 1, entityCollectionName, entityId, relationCollectionName, relationId, params); checkStatus(errorMessage, expectedStatus, response); return response; - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } + } + catch(IOException e) + { + throw new PublicApiException(e); + } + } - public JSONObject parseListSource(JSONObject jsonResponse) - { - JSONObject jsonList = (JSONObject)jsonResponse.get("list"); - assertNotNull(jsonList); + public JSONObject parseListSource(JSONObject jsonResponse) + { + JSONObject jsonList = (JSONObject)jsonResponse.get("list"); + assertNotNull(jsonList); - JSONObject source = (JSONObject)jsonList.get("source"); - assertNotNull(source); - return source; - } + JSONObject source = (JSONObject)jsonList.get("source"); + assertNotNull(source); + return source; + } - public void checkStatus(String errorMessage, int expectedStatus, HttpResponse response) throws PublicApiException - { + public void checkStatus(String errorMessage, int expectedStatus, HttpResponse response) throws PublicApiException + { int actualStatus = response.getStatusCode(); - if ((expectedStatus > 0) && (expectedStatus != actualStatus)) - { + if ((expectedStatus > 0) && (expectedStatus != actualStatus)) + { String msg = "Status code " + actualStatus + " returned, but expected " + expectedStatus + ": \n"+ errorMessage + ": \n" + " Response: " + response; - throw new PublicApiException(msg, response); - } - } - } + throw new PublicApiException(msg, response); + } + } + } - public static class ListResponse - { - private ExpectedPaging paging; - private List list; + public static class ListResponse + { + private ExpectedPaging paging; + private List list; - public ListResponse(ExpectedPaging paging, List list) - { - super(); - this.paging = paging; - this.list = list; - } + public ListResponse(ExpectedPaging paging, List list) + { + super(); + this.paging = paging; + this.list = list; + } - public ExpectedPaging getPaging() - { - return paging; - } + public ExpectedPaging getPaging() + { + return paging; + } - public List getList() - { - return list; - } - } - - public class Sites extends AbstractProxy - { - public ListResponse getSites(Map params) throws PublicApiException - { - HttpResponse response = getAll("sites", null, null, null, params, "Failed to get sites"); - return SiteImpl.parseSites(response.getJsonResponse()); - } + public List getList() + { + return list; + } + } + + public class Sites extends AbstractProxy + { + public ListResponse getSites(Map params) throws PublicApiException + { + HttpResponse response = getAll("sites", null, null, null, params, "Failed to get sites"); + return SiteImpl.parseSites(response.getJsonResponse()); + } public Site getSite(String siteId) throws PublicApiException { return getSite(siteId, 200); } - - public Site getSite(String siteId, int expectedStatus) throws PublicApiException - { - HttpResponse response = getSingle("sites", siteId, null, null, "Failed to get site " + siteId, expectedStatus); + + public Site getSite(String siteId, int expectedStatus) throws PublicApiException + { + HttpResponse response = getSingle("sites", siteId, null, null, "Failed to get site " + siteId, expectedStatus); if ((response != null) && (response.getJsonResponse() != null)) { return SiteImpl.parseSite((JSONObject)response.getJsonResponse().get("entry")); @@ -866,18 +866,18 @@ public class PublicApiClient { return null; } - } + } public Site createSite(Site site) throws PublicApiException { return createSite(site, 201); } - public Site createSite(Site site, int expectedStatus) throws PublicApiException - { - HttpResponse response = create("sites", null, null, null, site.toJSON().toString(), "Failed to create site "+site.getTitle(), expectedStatus); + public Site createSite(Site site, int expectedStatus) throws PublicApiException + { + HttpResponse response = create("sites", null, null, null, site.toJSON().toString(), "Failed to create site "+site.getTitle(), expectedStatus); return SiteImpl.parseSite((JSONObject)response.getJsonResponse().get("entry")); - } + } public void removeSite(String siteId) throws PublicApiException { @@ -886,205 +886,205 @@ public class PublicApiClient public void removeSite(String siteId, boolean permanent, int expectedStatus) throws PublicApiException { - Map params = null; - if (permanent) - { - params = Collections.singletonMap("permanent", "true"); - } + Map params = null; + if (permanent) + { + params = Collections.singletonMap("permanent", "true"); + } remove("sites", siteId, null, null, params, "Failed to remove site", expectedStatus); } - public Site updateSite(String siteId, SiteUpdate update, int expectedStatus) throws PublicApiException - { - JSONAble jsonizer = new TestSites.SiteUpdateJSONSerializer(update); - HttpResponse response = update("sites", siteId, null, null, jsonizer.toJSON().toString(), null, "Failed to update site " + update.getTitle(), expectedStatus); - if (response.getJsonResponse() != null) - { - return SiteImpl.parseSite((JSONObject) response.getJsonResponse().get("entry")); - } - // No JSON response to parse. - return null; - } + public Site updateSite(String siteId, SiteUpdate update, int expectedStatus) throws PublicApiException + { + JSONAble jsonizer = new TestSites.SiteUpdateJSONSerializer(update); + HttpResponse response = update("sites", siteId, null, null, jsonizer.toJSON().toString(), null, "Failed to update site " + update.getTitle(), expectedStatus); + if (response.getJsonResponse() != null) + { + return SiteImpl.parseSite((JSONObject) response.getJsonResponse().get("entry")); + } + // No JSON response to parse. + return null; + } - public ListResponse getSiteContainers(String siteId, Map params) throws PublicApiException - { - HttpResponse response = getAll("sites", siteId, "containers", null, params, "Failed to get site containers"); - return SiteContainer.parseSiteContainers(response.getJsonResponse()); - } - - public SiteContainer getSingleSiteContainer(String siteId, String containerId) throws PublicApiException - { - HttpResponse response = getSingle("sites", siteId, "containers", containerId, "Failed to get site container"); - SiteContainer siteContainer = SiteContainer.parseSiteContainer(siteId, (JSONObject)response.getJsonResponse().get("entry")); - return siteContainer; - } - - public SiteContainer updateSiteContainer(SiteContainer siteContainer) throws PublicApiException - { - HttpResponse response = update("sites", siteContainer.getSiteId(), "containers", siteContainer.getId(), siteContainer.toJSON().toString(), "Failed to update site container"); - SiteContainer retSiteContainer = SiteContainer.parseSiteContainer(siteContainer.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); - return retSiteContainer; - } + public ListResponse getSiteContainers(String siteId, Map params) throws PublicApiException + { + HttpResponse response = getAll("sites", siteId, "containers", null, params, "Failed to get site containers"); + return SiteContainer.parseSiteContainers(response.getJsonResponse()); + } - public SiteContainer createSiteContainer(SiteContainer siteContainer) throws PublicApiException - { - HttpResponse response = create("sites", siteContainer.getSiteId(), "containers", null, siteContainer.toJSON().toString(), "Failed to create site container"); - SiteContainer retSiteContainer = SiteContainer.parseSiteContainer(siteContainer.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); - return retSiteContainer; - } + public SiteContainer getSingleSiteContainer(String siteId, String containerId) throws PublicApiException + { + HttpResponse response = getSingle("sites", siteId, "containers", containerId, "Failed to get site container"); + SiteContainer siteContainer = SiteContainer.parseSiteContainer(siteId, (JSONObject)response.getJsonResponse().get("entry")); + return siteContainer; + } - public void removeSiteContainer(SiteContainer siteContainer) throws PublicApiException - { - remove("sites", siteContainer.getSiteId(), "containers", siteContainer.getId(), "Failed to remove site container"); - } - - public ListResponse getSiteMembers(String siteId, Map params) throws PublicApiException - { - HttpResponse response = getAll("sites", siteId, "members", null, params, "Failed to get all site members"); - return SiteMember.parseSiteMembers(siteId, response.getJsonResponse()); - } - - public SiteMember getSingleSiteMember(String siteId, String personId) throws PublicApiException - { - HttpResponse response = getSingle("sites", siteId, "members", personId, "Failed to get site member"); - SiteMember retSiteMember = SiteMember.parseSiteMember(siteId, (JSONObject)response.getJsonResponse().get("entry")); - return retSiteMember; - } - - public SiteMember updateSiteMember(String siteId, SiteMember siteMember) throws PublicApiException - { - HttpResponse response = update("sites", siteId, "members", siteMember.getMemberId(), siteMember.toJSON().toString(), "Failed to update site member"); - SiteMember retSiteMember = SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); - return retSiteMember; - } + public SiteContainer updateSiteContainer(SiteContainer siteContainer) throws PublicApiException + { + HttpResponse response = update("sites", siteContainer.getSiteId(), "containers", siteContainer.getId(), siteContainer.toJSON().toString(), "Failed to update site container"); + SiteContainer retSiteContainer = SiteContainer.parseSiteContainer(siteContainer.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); + return retSiteContainer; + } - public SiteMember createSiteMember(String siteId, SiteMember siteMember) throws PublicApiException - { - HttpResponse response = create("sites", siteId, "members", null, siteMember.toJSON().toString(), "Failed to create site member"); - SiteMember retSiteMember = SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); - return retSiteMember; - } + public SiteContainer createSiteContainer(SiteContainer siteContainer) throws PublicApiException + { + HttpResponse response = create("sites", siteContainer.getSiteId(), "containers", null, siteContainer.toJSON().toString(), "Failed to create site container"); + SiteContainer retSiteContainer = SiteContainer.parseSiteContainer(siteContainer.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); + return retSiteContainer; + } - public void removeSiteMember(String siteId, SiteMember siteMember) throws PublicApiException - { - remove("sites", siteId, "members", siteMember.getMemberId(), "Failed to remove site member"); - } - - public ListResponse getPersonSites(String personId, Map params) throws PublicApiException - { - HttpResponse response = getAll("people", personId, "sites", null, params, "Failed to get person sites"); - return MemberOfSite.parseMemberOfSites(response.getJsonResponse()); - } - - public MemberOfSite getPersonSite(String personId, String siteId) throws PublicApiException - { - HttpResponse response = getSingle("people", personId, "sites", siteId, "Failed to get person site" + siteId); - return MemberOfSite.parseMemberOfSite((JSONObject)response.getJsonResponse().get("entry")); - } - - public MemberOfSite updatePersonSite(String personId, SiteMember siteMember) throws PublicApiException - { - HttpResponse response = update("people", personId, "sites", siteMember.getSiteId(), siteMember.toJSON().toString(), "Failed to update person site"); - MemberOfSite retSiteMember = MemberOfSite.parseMemberOfSite((JSONObject)response.getJsonResponse().get("entry")); - return retSiteMember; - } + public void removeSiteContainer(SiteContainer siteContainer) throws PublicApiException + { + remove("sites", siteContainer.getSiteId(), "containers", siteContainer.getId(), "Failed to remove site container"); + } - public MemberOfSite createPersonSite(String personId, SiteMember siteMember) throws PublicApiException - { - HttpResponse response = create("people", personId, "sites", null, siteMember.toJSON().toString(), "Failed to create person site"); - MemberOfSite retSiteMember = MemberOfSite.parseMemberOfSite((JSONObject)response.getJsonResponse().get("entry")); - return retSiteMember; - } + public ListResponse getSiteMembers(String siteId, Map params) throws PublicApiException + { + HttpResponse response = getAll("sites", siteId, "members", null, params, "Failed to get all site members"); + return SiteMember.parseSiteMembers(siteId, response.getJsonResponse()); + } - public void removePersonSite(String personId, SiteMember siteMember) throws PublicApiException - { - remove("people", personId, "sites", siteMember.getSiteId(), "Failed to remove person site"); - } - - public ListResponse getFavouriteSites(String personId, Map params) throws PublicApiException - { - HttpResponse response = getAll("people", personId, "favorite-sites", null, params, "Failed to get favourite sites"); - return FavouriteSite.parseFavouriteSites(response.getJsonResponse()); - } - - public FavouriteSite getSingleFavouriteSite(String personId, String siteId) throws PublicApiException - { - HttpResponse response = getSingle("people", personId, "favorite-sites", siteId, "Failed to get favourite site"); - FavouriteSite favouriteSite = FavouriteSite.parseFavouriteSite((JSONObject)response.getJsonResponse().get("entry")); - return favouriteSite; - } - - public FavouriteSite updateFavouriteSite(String personId, FavouriteSite site) throws PublicApiException - { - HttpResponse response = update("people", personId, "favorite-sites", site.getSiteId(), site.toJSON().toString(), "Failed to update favourite site"); - FavouriteSite favouriteSite = FavouriteSite.parseFavouriteSite((JSONObject)response.getJsonResponse().get("entry")); - return favouriteSite; - } + public SiteMember getSingleSiteMember(String siteId, String personId) throws PublicApiException + { + HttpResponse response = getSingle("sites", siteId, "members", personId, "Failed to get site member"); + SiteMember retSiteMember = SiteMember.parseSiteMember(siteId, (JSONObject)response.getJsonResponse().get("entry")); + return retSiteMember; + } - public FavouriteSite createFavouriteSite(String personId, FavouriteSite site) throws PublicApiException - { - HttpResponse response = create("people", personId, "favorite-sites", null, site.toJSON().toString(), "Failed to create favourite site"); - FavouriteSite favouriteSite = FavouriteSite.parseFavouriteSite((JSONObject)response.getJsonResponse().get("entry")); - return favouriteSite; - } + public SiteMember updateSiteMember(String siteId, SiteMember siteMember) throws PublicApiException + { + HttpResponse response = update("sites", siteId, "members", siteMember.getMemberId(), siteMember.toJSON().toString(), "Failed to update site member"); + SiteMember retSiteMember = SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); + return retSiteMember; + } - public void removeFavouriteSite(String personId, FavouriteSite site) throws PublicApiException - { - remove("people", personId, "favorite-sites", site.getSiteId(), "Failed to remove favourite site"); - } - } - - public class SiteMembershipRequests extends AbstractProxy - { - public SiteMembershipRequest getSiteMembershipRequest(String personId, String siteId) throws PublicApiException, ParseException - { - HttpResponse response = getSingle("people", personId, "site-membership-requests", siteId, "Failed to get siteMembershipRequest"); - return SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry")); - } + public SiteMember createSiteMember(String siteId, SiteMember siteMember) throws PublicApiException + { + HttpResponse response = create("sites", siteId, "members", null, siteMember.toJSON().toString(), "Failed to create site member"); + SiteMember retSiteMember = SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject)response.getJsonResponse().get("entry")); + return retSiteMember; + } - public ListResponse getSiteMembershipRequests(String personId, Map params) throws PublicApiException, ParseException - { - HttpResponse response = getAll("people", personId, "site-membership-requests", null, params, "Failed to get siteMembershipRequests"); - return SiteMembershipRequest.parseSiteMembershipRequests(personId, response.getJsonResponse()); - } - - public SiteMembershipRequest createSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException - { - HttpResponse response = create("people", personId, "site-membership-requests", null, siteMembershipRequest.toJSON().toString(), "Failed to create siteMembershipRequest"); - SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry")); - return ret; - } + public void removeSiteMember(String siteId, SiteMember siteMember) throws PublicApiException + { + remove("sites", siteId, "members", siteMember.getMemberId(), "Failed to remove site member"); + } - public SiteMembershipRequest updateSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException - { - HttpResponse response = update("people", personId, "site-membership-requests", siteMembershipRequest.getId(), siteMembershipRequest.toJSON().toString(), "Failed to update siteMembershipRequest"); - SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry")); - return ret; - } - - public void cancelSiteMembershipRequest(String personId, String siteMembershipRequestId) throws PublicApiException - { - remove("people", personId, "site-membership-requests", siteMembershipRequestId, "Failed to cancel siteMembershipRequest"); - } - } - - public class RawProxy extends AbstractProxy - { - } - - public class Favourites extends AbstractProxy - { - public ListResponse getFavourites(String personId, Map params) throws PublicApiException, ParseException - { - HttpResponse response = getAll("people", personId, "favorites", null, params, "Failed to get favourites"); - return Favourite.parseFavourites(response.getJsonResponse()); - } - - public Favourite getFavourite(String personId, String favouriteId) throws PublicApiException, ParseException - { - HttpResponse response = getSingle("people", personId, "favorites", favouriteId, "Failed to get favourite " + favouriteId); - return Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry")); - } + public ListResponse getPersonSites(String personId, Map params) throws PublicApiException + { + HttpResponse response = getAll("people", personId, "sites", null, params, "Failed to get person sites"); + return MemberOfSite.parseMemberOfSites(response.getJsonResponse()); + } + + public MemberOfSite getPersonSite(String personId, String siteId) throws PublicApiException + { + HttpResponse response = getSingle("people", personId, "sites", siteId, "Failed to get person site" + siteId); + return MemberOfSite.parseMemberOfSite((JSONObject)response.getJsonResponse().get("entry")); + } + + public MemberOfSite updatePersonSite(String personId, SiteMember siteMember) throws PublicApiException + { + HttpResponse response = update("people", personId, "sites", siteMember.getSiteId(), siteMember.toJSON().toString(), "Failed to update person site"); + MemberOfSite retSiteMember = MemberOfSite.parseMemberOfSite((JSONObject)response.getJsonResponse().get("entry")); + return retSiteMember; + } + + public MemberOfSite createPersonSite(String personId, SiteMember siteMember) throws PublicApiException + { + HttpResponse response = create("people", personId, "sites", null, siteMember.toJSON().toString(), "Failed to create person site"); + MemberOfSite retSiteMember = MemberOfSite.parseMemberOfSite((JSONObject)response.getJsonResponse().get("entry")); + return retSiteMember; + } + + public void removePersonSite(String personId, SiteMember siteMember) throws PublicApiException + { + remove("people", personId, "sites", siteMember.getSiteId(), "Failed to remove person site"); + } + + public ListResponse getFavouriteSites(String personId, Map params) throws PublicApiException + { + HttpResponse response = getAll("people", personId, "favorite-sites", null, params, "Failed to get favourite sites"); + return FavouriteSite.parseFavouriteSites(response.getJsonResponse()); + } + + public FavouriteSite getSingleFavouriteSite(String personId, String siteId) throws PublicApiException + { + HttpResponse response = getSingle("people", personId, "favorite-sites", siteId, "Failed to get favourite site"); + FavouriteSite favouriteSite = FavouriteSite.parseFavouriteSite((JSONObject)response.getJsonResponse().get("entry")); + return favouriteSite; + } + + public FavouriteSite updateFavouriteSite(String personId, FavouriteSite site) throws PublicApiException + { + HttpResponse response = update("people", personId, "favorite-sites", site.getSiteId(), site.toJSON().toString(), "Failed to update favourite site"); + FavouriteSite favouriteSite = FavouriteSite.parseFavouriteSite((JSONObject)response.getJsonResponse().get("entry")); + return favouriteSite; + } + + public FavouriteSite createFavouriteSite(String personId, FavouriteSite site) throws PublicApiException + { + HttpResponse response = create("people", personId, "favorite-sites", null, site.toJSON().toString(), "Failed to create favourite site"); + FavouriteSite favouriteSite = FavouriteSite.parseFavouriteSite((JSONObject)response.getJsonResponse().get("entry")); + return favouriteSite; + } + + public void removeFavouriteSite(String personId, FavouriteSite site) throws PublicApiException + { + remove("people", personId, "favorite-sites", site.getSiteId(), "Failed to remove favourite site"); + } + } + + public class SiteMembershipRequests extends AbstractProxy + { + public SiteMembershipRequest getSiteMembershipRequest(String personId, String siteId) throws PublicApiException, ParseException + { + HttpResponse response = getSingle("people", personId, "site-membership-requests", siteId, "Failed to get siteMembershipRequest"); + return SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry")); + } + + public ListResponse getSiteMembershipRequests(String personId, Map params) throws PublicApiException, ParseException + { + HttpResponse response = getAll("people", personId, "site-membership-requests", null, params, "Failed to get siteMembershipRequests"); + return SiteMembershipRequest.parseSiteMembershipRequests(personId, response.getJsonResponse()); + } + + public SiteMembershipRequest createSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException + { + HttpResponse response = create("people", personId, "site-membership-requests", null, siteMembershipRequest.toJSON().toString(), "Failed to create siteMembershipRequest"); + SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry")); + return ret; + } + + public SiteMembershipRequest updateSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException + { + HttpResponse response = update("people", personId, "site-membership-requests", siteMembershipRequest.getId(), siteMembershipRequest.toJSON().toString(), "Failed to update siteMembershipRequest"); + SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry")); + return ret; + } + + public void cancelSiteMembershipRequest(String personId, String siteMembershipRequestId) throws PublicApiException + { + remove("people", personId, "site-membership-requests", siteMembershipRequestId, "Failed to cancel siteMembershipRequest"); + } + } + + public class RawProxy extends AbstractProxy + { + } + + public class Favourites extends AbstractProxy + { + public ListResponse getFavourites(String personId, Map params) throws PublicApiException, ParseException + { + HttpResponse response = getAll("people", personId, "favorites", null, params, "Failed to get favourites"); + return Favourite.parseFavourites(response.getJsonResponse()); + } + + public Favourite getFavourite(String personId, String favouriteId) throws PublicApiException, ParseException + { + HttpResponse response = getSingle("people", personId, "favorites", favouriteId, "Failed to get favourite " + favouriteId); + return Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry")); + } public Favourite getFavourite(String personId, String favouriteId, Map params) throws PublicApiException, ParseException { @@ -1092,12 +1092,12 @@ public class PublicApiClient return Favourite.parseFavourite((JSONObject) response.getJsonResponse().get("entry")); } - public Favourite createFavourite(String personId, Favourite favourite) throws PublicApiException, ParseException - { - HttpResponse response = create("people", personId, "favorites", null, favourite.toJSON().toString(), "Failed to create favourite"); - Favourite ret = Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry")); - return ret; - } + public Favourite createFavourite(String personId, Favourite favourite) throws PublicApiException, ParseException + { + HttpResponse response = create("people", personId, "favorites", null, favourite.toJSON().toString(), "Failed to create favourite"); + Favourite ret = Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry")); + return ret; + } public Favourite createFavourite(String personId, Favourite favourite, Map params) throws PublicApiException, ParseException { @@ -1106,285 +1106,285 @@ public class PublicApiClient return ret; } - public void removeFavourite(String personId, String favouriteId) throws PublicApiException - { - remove("people", personId, "favorites", favouriteId, "Failed to remove favourite"); - } - } + public void removeFavourite(String personId, String favouriteId) throws PublicApiException + { + remove("people", personId, "favorites", favouriteId, "Failed to remove favourite"); + } + } - public class People extends AbstractProxy - { - public ListResponse getPeople(Map params) throws PublicApiException - { - HttpResponse response = getAll("people", null, null, null, params, "Failed to get people"); - return Person.parsePeople(response.getJsonResponse()); - } + public class People extends AbstractProxy + { + public ListResponse getPeople(Map params) throws PublicApiException + { + HttpResponse response = getAll("people", null, null, null, params, "Failed to get people"); + return Person.parsePeople(response.getJsonResponse()); + } - public Person getPerson(String personId) throws PublicApiException - { - return getPerson(personId, 200); - } - - public Person getPerson(String personId, int expectedStatus) throws PublicApiException - { - HttpResponse response = getSingle("people", personId, null, null, "Failed to get person", expectedStatus); - - if(logger.isDebugEnabled()) - { - logger.debug(response); - } - System.out.println(response); - - if (response != null && response.getJsonResponse() != null) - { - JSONObject entry = (JSONObject) response.getJsonResponse().get("entry"); - if (entry != null) - { - return Person.parsePerson(entry); - } - } - return null; - } + public Person getPerson(String personId) throws PublicApiException + { + return getPerson(personId, 200); + } - public Person update(String personId, Person person) throws PublicApiException - { - return update(personId, person, 200); - } - - public Person update(String personId, Person person, int expectedStatus) throws PublicApiException - { - return update(personId, person.toJSON(true).toString(), expectedStatus); - } + public Person getPerson(String personId, int expectedStatus) throws PublicApiException + { + HttpResponse response = getSingle("people", personId, null, null, "Failed to get person", expectedStatus); - public Person update(String personId, String json, int expectedStatus) throws PublicApiException - { - return update(personId, json, null, expectedStatus); - } + if(logger.isDebugEnabled()) + { + logger.debug(response); + } + System.out.println(response); - public Person update(String personId, String json, Map params, int expectedStatus) throws PublicApiException - { - HttpResponse response = update("people", personId, null, null, json, params, "Failed to update person", expectedStatus); - if (response != null && response.getJsonResponse() != null) - { - JSONObject entry = (JSONObject) response.getJsonResponse().get("entry"); - if (entry != null) - { - return Person.parsePerson(entry); - } - } - return null; - } - - public Person create(Person person) throws PublicApiException - { - return create(person, 201); - } + if (response != null && response.getJsonResponse() != null) + { + JSONObject entry = (JSONObject) response.getJsonResponse().get("entry"); + if (entry != null) + { + return Person.parsePerson(entry); + } + } + return null; + } - public Person create(Person person, int expectedStatus) throws PublicApiException - { - TestPeople.PersonJSONSerializer jsonizer = new TestPeople.PersonJSONSerializer(person) ; - HttpResponse response = create("people", null, null, null, jsonizer.toJSON().toString(), "Failed to create person", expectedStatus); - if ((response != null) && (response.getJsonResponse() != null)) - { - JSONObject entry = (JSONObject) response.getJsonResponse().get("entry"); - if (entry != null) - { - return Person.parsePerson(entry); - } - } - return null; - } + public Person update(String personId, Person person) throws PublicApiException + { + return update(personId, person, 200); + } - public void remove(Person person) throws PublicApiException - { - remove("people", person.getId(), null, null, "Failed to remove person"); - } - - public ListResponse getPreferences(String personId, Map params) throws PublicApiException - { - HttpResponse response = getAll("people", personId, "preferences", null, params, "Failed to get person preferences"); - return Preference.parsePreferences(response.getJsonResponse()); - } + public Person update(String personId, Person person, int expectedStatus) throws PublicApiException + { + return update(personId, person.toJSON(true).toString(), expectedStatus); + } - public Preference getPreference(String personId, String preferenceId) throws PublicApiException - { - HttpResponse response = getSingle("people", personId, "preferences", preferenceId, "Failed to get person preference"); - Preference pref = Preference.parsePreference((JSONObject)response.getJsonResponse().get("entry")); - return pref; - } + public Person update(String personId, String json, int expectedStatus) throws PublicApiException + { + return update(personId, json, null, expectedStatus); + } - public Person updatePreference(String personId, Preference preference) throws PublicApiException - { - HttpResponse response = update("people", personId, "preferences", preference.getId(), preference.toJSON().toString(), "Failed to update person preference"); - Person retSite = Person.parsePerson((JSONObject)response.getJsonResponse().get("entry")); - return retSite; - } + public Person update(String personId, String json, Map params, int expectedStatus) throws PublicApiException + { + HttpResponse response = update("people", personId, null, null, json, params, "Failed to update person", expectedStatus); + if (response != null && response.getJsonResponse() != null) + { + JSONObject entry = (JSONObject) response.getJsonResponse().get("entry"); + if (entry != null) + { + return Person.parsePerson(entry); + } + } + return null; + } - public Person createPreference(String personId, Preference preference) throws PublicApiException - { - HttpResponse response = create("people", personId, "preferences", null, preference.toJSON().toString(), "Failed to create person preference"); - Person retSite = Person.parsePerson((JSONObject)response.getJsonResponse().get("entry")); - return retSite; - } + public Person create(Person person) throws PublicApiException + { + return create(person, 201); + } - public void removePreference(String personId, Preference preference) throws PublicApiException - { - remove("people", personId, "preferences", preference.getId(), "Failed to remove person preference"); - } - - public ListResponse getNetworkMemberships(String personId, Map params) throws PublicApiException - { - HttpResponse response = getAll("people", personId, "networks", null, params, "Failed to get network members"); - return PersonNetwork.parseNetworkMembers(response.getJsonResponse()); - } - - public PersonNetwork getNetworkMembership(String personId, String networkId) throws PublicApiException - { - HttpResponse response = getSingle("people", personId, "networks", networkId, "Failed to get network member"); - PersonNetwork networkMember = PersonNetwork.parseNetworkMember((JSONObject)response.getJsonResponse().get("entry")); - return networkMember; - } - - public PersonNetwork updateNetworkMembership(String personId, PersonNetwork networkMember) throws PublicApiException - { - HttpResponse response = update("people", personId, "networks", networkMember.getId(), networkMember.toJSON().toString(), "Failed to update network member"); - PersonNetwork retNetwork = PersonNetwork.parseNetworkMember((JSONObject)response.getJsonResponse().get("entry")); - return retNetwork; - } + public Person create(Person person, int expectedStatus) throws PublicApiException + { + TestPeople.PersonJSONSerializer jsonizer = new TestPeople.PersonJSONSerializer(person) ; + HttpResponse response = create("people", null, null, null, jsonizer.toJSON().toString(), "Failed to create person", expectedStatus); + if ((response != null) && (response.getJsonResponse() != null)) + { + JSONObject entry = (JSONObject) response.getJsonResponse().get("entry"); + if (entry != null) + { + return Person.parsePerson(entry); + } + } + return null; + } - public PersonNetwork createNetworkMembership(String personId, PersonNetwork network) throws PublicApiException - { - HttpResponse response = create("people", personId, "networks", null, network.toJSON().toString(), "Failed to create network member"); - PersonNetwork retNetwork = PersonNetwork.parseNetworkMember((JSONObject)response.getJsonResponse().get("entry")); - return retNetwork; - } + public void remove(Person person) throws PublicApiException + { + remove("people", person.getId(), null, null, "Failed to remove person"); + } - public void removeNetworkMembership(String personId, PersonNetwork networkMember) throws PublicApiException - { - remove("people", personId, "networks", networkMember.getId(), "Failed to remove network member"); - } + public ListResponse getPreferences(String personId, Map params) throws PublicApiException + { + HttpResponse response = getAll("people", personId, "preferences", null, params, "Failed to get person preferences"); + return Preference.parsePreferences(response.getJsonResponse()); + } - public ListResponse getActivities(String personId, Map params) throws PublicApiException - { - HttpResponse response = getAll("people", personId, "activities", null, params, "Failed to get activities"); - return Activities.parseActivities(response.getJsonResponse()); - } + public Preference getPreference(String personId, String preferenceId) throws PublicApiException + { + HttpResponse response = getSingle("people", personId, "preferences", preferenceId, "Failed to get person preference"); + Preference pref = Preference.parsePreference((JSONObject)response.getJsonResponse().get("entry")); + return pref; + } - public Activity getSingleActivity(String personId, String activityId) throws PublicApiException - { - HttpResponse response = getSingle("people", personId, "activities", activityId, "Failed to get activities"); - Activity activity = Activity.parseActivity((JSONObject)response.getJsonResponse().get("entry")); - return activity; - } + public Person updatePreference(String personId, Preference preference) throws PublicApiException + { + HttpResponse response = update("people", personId, "preferences", preference.getId(), preference.toJSON().toString(), "Failed to update person preference"); + Person retSite = Person.parsePerson((JSONObject)response.getJsonResponse().get("entry")); + return retSite; + } - public Activity update(String personId, Activity activity) throws PublicApiException - { - HttpResponse response = update("people", personId, "activities", String.valueOf(activity.getId()), activity.toJSON().toString(), "Failed to update activity"); - Activity retActivity = Activity.parseActivity((JSONObject)response.getJsonResponse().get("entry")); - return retActivity; - } + public Person createPreference(String personId, Preference preference) throws PublicApiException + { + HttpResponse response = create("people", personId, "preferences", null, preference.toJSON().toString(), "Failed to create person preference"); + Person retSite = Person.parsePerson((JSONObject)response.getJsonResponse().get("entry")); + return retSite; + } - public Activity create(String personId, Activity activity) throws PublicApiException - { - HttpResponse response = create("people", personId, "activities", String.valueOf(activity.getId()), activity.toJSON().toString(), "Failed to create activity"); - Activity retActivity = Activity.parseActivity((JSONObject)response.getJsonResponse().get("entry")); - return retActivity; - } + public void removePreference(String personId, Preference preference) throws PublicApiException + { + remove("people", personId, "preferences", preference.getId(), "Failed to remove person preference"); + } - public void remove(String personId, Activity activity) throws PublicApiException - { - remove("people", personId, "activities", String.valueOf(activity.getId()), "Failed to remove activity"); - } - } + public ListResponse getNetworkMemberships(String personId, Map params) throws PublicApiException + { + HttpResponse response = getAll("people", personId, "networks", null, params, "Failed to get network members"); + return PersonNetwork.parseNetworkMembers(response.getJsonResponse()); + } - public class Comments extends AbstractProxy - { - public ListResponse getTenantComments(Map params) throws PublicApiException - { - HttpResponse response = getAll("comments", null, null, null, params, "Failed to get comments"); - return Comment.parseComments(null, response.getJsonResponse()); - } - - public Comment getTenantComment(String commentId) throws PublicApiException - { - HttpResponse response = getSingle("comments", commentId, null, null, "Failed to get comment"); - Comment comment = Comment.parseComment(null, (JSONObject)response.getJsonResponse().get("entry")); - return comment; - } - - public Comment updateTenantComment(Comment comment) throws PublicApiException - { - HttpResponse response = update("comments", comment.getId(), null, null, comment.toJSON(true).toString(), "Failed to update comment"); - Comment retComment = Comment.parseComment(null, (JSONObject)response.getJsonResponse().get("entry")); - return retComment; - } + public PersonNetwork getNetworkMembership(String personId, String networkId) throws PublicApiException + { + HttpResponse response = getSingle("people", personId, "networks", networkId, "Failed to get network member"); + PersonNetwork networkMember = PersonNetwork.parseNetworkMember((JSONObject)response.getJsonResponse().get("entry")); + return networkMember; + } - public Comment createTenantComment(Comment comment) throws PublicApiException - { - HttpResponse response = create("comments", null, null, null, comment.toJSON(true).toString(), "Failed to create comment"); - Comment retComment = Comment.parseComment(null, (JSONObject)response.getJsonResponse().get("entry")); - return retComment; - } + public PersonNetwork updateNetworkMembership(String personId, PersonNetwork networkMember) throws PublicApiException + { + HttpResponse response = update("people", personId, "networks", networkMember.getId(), networkMember.toJSON().toString(), "Failed to update network member"); + PersonNetwork retNetwork = PersonNetwork.parseNetworkMember((JSONObject)response.getJsonResponse().get("entry")); + return retNetwork; + } - public void removeTenantComment(Comment comment) throws PublicApiException - { - remove("comments", comment.getId(), null, null, "Failed to remove comment"); - } + public PersonNetwork createNetworkMembership(String personId, PersonNetwork network) throws PublicApiException + { + HttpResponse response = create("people", personId, "networks", null, network.toJSON().toString(), "Failed to create network member"); + PersonNetwork retNetwork = PersonNetwork.parseNetworkMember((JSONObject)response.getJsonResponse().get("entry")); + return retNetwork; + } - public ListResponse getNodeComments(String nodeId, Map params) throws PublicApiException - { - HttpResponse response = getAll("nodes", nodeId, "comments", null, params, "Failed to get comments"); - return Comment.parseComments(nodeId, response.getJsonResponse()); - } - - public Comment getNodeComment(String nodeId) throws PublicApiException - { - HttpResponse response = getSingle("nodes", nodeId, null, null, "Failed to get comment"); - Comment comment = Comment.parseComment(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - return comment; - } - - public Comment updateNodeComment(String nodeId, String commentId, Comment comment) throws PublicApiException - { - HttpResponse response = update("nodes", nodeId, "comments", commentId, comment.toJSON(true).toString(), "Failed to update comment"); - Comment retComment = Comment.parseComment(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - return retComment; - } + public void removeNetworkMembership(String personId, PersonNetwork networkMember) throws PublicApiException + { + remove("people", personId, "networks", networkMember.getId(), "Failed to remove network member"); + } - public Comment createNodeComment(String nodeId, Comment comment) throws PublicApiException - { - HttpResponse response = create("nodes", nodeId, "comments", null, comment.toJSON(true).toString(), "Failed to create comment"); - Comment retComment = Comment.parseComment(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - return retComment; - } + public ListResponse getActivities(String personId, Map params) throws PublicApiException + { + HttpResponse response = getAll("people", personId, "activities", null, params, "Failed to get activities"); + return Activities.parseActivities(response.getJsonResponse()); + } - public void removeNodeComment(String nodeId, String commentId) throws PublicApiException - { - remove("nodes", nodeId, "comments", commentId, "Failed to remove comment"); - } - } - - public class Tags extends AbstractProxy - { - public ListResponse getTags(Map params) throws PublicApiException - { - HttpResponse response = getAll("tags", null, null, null, params, "Failed to get tags"); - return Tag.parseTags(null, response.getJsonResponse()); - } - - public Tag getSingle(String tagId) throws PublicApiException - { - HttpResponse response = getSingle("tags", tagId, null, null, "Failed to get tag"); - Tag tag = Tag.parseTag(null, (JSONObject)response.getJsonResponse().get("entry")); - return tag; - } - - public Tag update(Tag tag) throws PublicApiException - { - HttpResponse response = update("tags", tag.getId(), null, null, tag.toJSON().toString(), "Failed to update tag"); - Tag retTag = Tag.parseTag(null, (JSONObject)response.getJsonResponse().get("entry")); - return retTag; - } + public Activity getSingleActivity(String personId, String activityId) throws PublicApiException + { + HttpResponse response = getSingle("people", personId, "activities", activityId, "Failed to get activities"); + Activity activity = Activity.parseActivity((JSONObject)response.getJsonResponse().get("entry")); + return activity; + } + + public Activity update(String personId, Activity activity) throws PublicApiException + { + HttpResponse response = update("people", personId, "activities", String.valueOf(activity.getId()), activity.toJSON().toString(), "Failed to update activity"); + Activity retActivity = Activity.parseActivity((JSONObject)response.getJsonResponse().get("entry")); + return retActivity; + } + + public Activity create(String personId, Activity activity) throws PublicApiException + { + HttpResponse response = create("people", personId, "activities", String.valueOf(activity.getId()), activity.toJSON().toString(), "Failed to create activity"); + Activity retActivity = Activity.parseActivity((JSONObject)response.getJsonResponse().get("entry")); + return retActivity; + } + + public void remove(String personId, Activity activity) throws PublicApiException + { + remove("people", personId, "activities", String.valueOf(activity.getId()), "Failed to remove activity"); + } + } + + public class Comments extends AbstractProxy + { + public ListResponse getTenantComments(Map params) throws PublicApiException + { + HttpResponse response = getAll("comments", null, null, null, params, "Failed to get comments"); + return Comment.parseComments(null, response.getJsonResponse()); + } + + public Comment getTenantComment(String commentId) throws PublicApiException + { + HttpResponse response = getSingle("comments", commentId, null, null, "Failed to get comment"); + Comment comment = Comment.parseComment(null, (JSONObject)response.getJsonResponse().get("entry")); + return comment; + } + + public Comment updateTenantComment(Comment comment) throws PublicApiException + { + HttpResponse response = update("comments", comment.getId(), null, null, comment.toJSON(true).toString(), "Failed to update comment"); + Comment retComment = Comment.parseComment(null, (JSONObject)response.getJsonResponse().get("entry")); + return retComment; + } + + public Comment createTenantComment(Comment comment) throws PublicApiException + { + HttpResponse response = create("comments", null, null, null, comment.toJSON(true).toString(), "Failed to create comment"); + Comment retComment = Comment.parseComment(null, (JSONObject)response.getJsonResponse().get("entry")); + return retComment; + } + + public void removeTenantComment(Comment comment) throws PublicApiException + { + remove("comments", comment.getId(), null, null, "Failed to remove comment"); + } + + public ListResponse getNodeComments(String nodeId, Map params) throws PublicApiException + { + HttpResponse response = getAll("nodes", nodeId, "comments", null, params, "Failed to get comments"); + return Comment.parseComments(nodeId, response.getJsonResponse()); + } + + public Comment getNodeComment(String nodeId) throws PublicApiException + { + HttpResponse response = getSingle("nodes", nodeId, null, null, "Failed to get comment"); + Comment comment = Comment.parseComment(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + return comment; + } + + public Comment updateNodeComment(String nodeId, String commentId, Comment comment) throws PublicApiException + { + HttpResponse response = update("nodes", nodeId, "comments", commentId, comment.toJSON(true).toString(), "Failed to update comment"); + Comment retComment = Comment.parseComment(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + return retComment; + } + + public Comment createNodeComment(String nodeId, Comment comment) throws PublicApiException + { + HttpResponse response = create("nodes", nodeId, "comments", null, comment.toJSON(true).toString(), "Failed to create comment"); + Comment retComment = Comment.parseComment(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + return retComment; + } + + public void removeNodeComment(String nodeId, String commentId) throws PublicApiException + { + remove("nodes", nodeId, "comments", commentId, "Failed to remove comment"); + } + } + + public class Tags extends AbstractProxy + { + public ListResponse getTags(Map params) throws PublicApiException + { + HttpResponse response = getAll("tags", null, null, null, params, "Failed to get tags"); + return Tag.parseTags(null, response.getJsonResponse()); + } + + public Tag getSingle(String tagId) throws PublicApiException + { + HttpResponse response = getSingle("tags", tagId, null, null, "Failed to get tag"); + Tag tag = Tag.parseTag(null, (JSONObject)response.getJsonResponse().get("entry")); + return tag; + } + + public Tag update(Tag tag) throws PublicApiException + { + HttpResponse response = update("tags", tag.getId(), null, null, tag.toJSON().toString(), "Failed to update tag"); + Tag retTag = Tag.parseTag(null, (JSONObject)response.getJsonResponse().get("entry")); + return retTag; + } // public Tag create(Tag tag) throws PublicApiException // { @@ -1393,782 +1393,782 @@ public class PublicApiClient // return retTag; // } - public void remove(Tag tag) throws PublicApiException - { - remove("tags", tag.getId(), null, null, "Failed to remove tag"); - } - } + public void remove(Tag tag) throws PublicApiException + { + remove("tags", tag.getId(), null, null, "Failed to remove tag"); + } + } - public class Nodes extends AbstractProxy - { - public ListResponse getNodeTags(String nodeId, Map params) throws PublicApiException - { - HttpResponse response = getAll("nodes", nodeId, "tags", null, params, "Failed to get node tags"); - return Tag.parseTags(nodeId, response.getJsonResponse()); - } + public class Nodes extends AbstractProxy + { + public ListResponse getNodeTags(String nodeId, Map params) throws PublicApiException + { + HttpResponse response = getAll("nodes", nodeId, "tags", null, params, "Failed to get node tags"); + return Tag.parseTags(nodeId, response.getJsonResponse()); + } - public void removeNodeTag(String nodeId, String tagId) throws PublicApiException - { - remove("nodes", nodeId, "tags", tagId, "Failed to remove node tag"); - } + public void removeNodeTag(String nodeId, String tagId) throws PublicApiException + { + remove("nodes", nodeId, "tags", tagId, "Failed to remove node tag"); + } - public Tag createNodeTag(String nodeId, Tag tag) throws PublicApiException - { - HttpResponse response = create("nodes", nodeId, "tags", null, tag.toJSON().toString(), "Failed to create node tag"); - Tag tagRet = Tag.parseTag(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - return tagRet; - } + public Tag createNodeTag(String nodeId, Tag tag) throws PublicApiException + { + HttpResponse response = create("nodes", nodeId, "tags", null, tag.toJSON().toString(), "Failed to create node tag"); + Tag tagRet = Tag.parseTag(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + return tagRet; + } - public NodeRating getNodeRating(String nodeId, String ratingId) throws PublicApiException - { - HttpResponse response = getSingle("nodes", nodeId, "ratings", ratingId, "Failed to get node ratings"); - return NodeRating.parseNodeRating(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - } + public NodeRating getNodeRating(String nodeId, String ratingId) throws PublicApiException + { + HttpResponse response = getSingle("nodes", nodeId, "ratings", ratingId, "Failed to get node ratings"); + return NodeRating.parseNodeRating(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + } - public ListResponse getNodeRatings(String nodeId, Map params) throws PublicApiException - { - HttpResponse response = getAll("nodes", nodeId, "ratings", null, params, "Failed to get node ratings"); - return NodeRating.parseNodeRatings(nodeId, response.getJsonResponse()); - } - - public NodeRating updateNodeRating(String nodeId, NodeRating nodeRating) throws PublicApiException - { - HttpResponse response = update("nodes", nodeId, "ratings", nodeRating.getId(), nodeRating.toJSON().toString(), "Failed to update node rating"); - NodeRating nodeRatingRet = NodeRating.parseNodeRating(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - return nodeRatingRet; - } + public ListResponse getNodeRatings(String nodeId, Map params) throws PublicApiException + { + HttpResponse response = getAll("nodes", nodeId, "ratings", null, params, "Failed to get node ratings"); + return NodeRating.parseNodeRatings(nodeId, response.getJsonResponse()); + } - public NodeRating createNodeRating(String nodeId, NodeRating nodeRating) throws PublicApiException - { - HttpResponse response = create("nodes", nodeId, "ratings", null, nodeRating.toJSON().toString(), "Failed to create node rating"); - NodeRating nodeRatingRet = NodeRating.parseNodeRating(nodeId, (JSONObject)response.getJsonResponse().get("entry")); - return nodeRatingRet; - } + public NodeRating updateNodeRating(String nodeId, NodeRating nodeRating) throws PublicApiException + { + HttpResponse response = update("nodes", nodeId, "ratings", nodeRating.getId(), nodeRating.toJSON().toString(), "Failed to update node rating"); + NodeRating nodeRatingRet = NodeRating.parseNodeRating(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + return nodeRatingRet; + } - public void removeNodeRating(String nodeId, NodeRating rating) throws PublicApiException - { - remove("nodes", nodeId, "ratings", rating.getId(), "Failed to remove node rating"); - } - } - - public static class ExpectedPaging - { - private int skipCount; - private int maxItems; - private Integer totalItems; - private boolean hasMoreItems; - private int count; + public NodeRating createNodeRating(String nodeId, NodeRating nodeRating) throws PublicApiException + { + HttpResponse response = create("nodes", nodeId, "ratings", null, nodeRating.toJSON().toString(), "Failed to create node rating"); + NodeRating nodeRatingRet = NodeRating.parseNodeRating(nodeId, (JSONObject)response.getJsonResponse().get("entry")); + return nodeRatingRet; + } - public ExpectedPaging() - { - } + public void removeNodeRating(String nodeId, NodeRating rating) throws PublicApiException + { + remove("nodes", nodeId, "ratings", rating.getId(), "Failed to remove node rating"); + } + } - public ExpectedPaging(int skipCount, int maxItems, Integer totalItems, boolean hasMoreItems, int count) - { - super(); - this.skipCount = skipCount; - this.maxItems = maxItems; - this.totalItems = totalItems; - this.hasMoreItems = hasMoreItems; - this.count = count; - } + public static class ExpectedPaging + { + private int skipCount; + private int maxItems; + private Integer totalItems; + private boolean hasMoreItems; + private int count; - public Integer getSkipCount() - { - return skipCount; - } + public ExpectedPaging() + { + } - public Integer getMaxItems() - { - return maxItems; - } + public ExpectedPaging(int skipCount, int maxItems, Integer totalItems, boolean hasMoreItems, int count) + { + super(); + this.skipCount = skipCount; + this.maxItems = maxItems; + this.totalItems = totalItems; + this.hasMoreItems = hasMoreItems; + this.count = count; + } - public Integer getTotalItems() - { - return totalItems; - } + public Integer getSkipCount() + { + return skipCount; + } - public Boolean getHasMoreItems() - { - return hasMoreItems; - } + public Integer getMaxItems() + { + return maxItems; + } - public Integer getCount() - { - return count; - } + public Integer getTotalItems() + { + return totalItems; + } - public void setCount(Integer count) - { - this.count = count; - } + public Boolean getHasMoreItems() + { + return hasMoreItems; + } - public void setHasMoreItems(Boolean hasMoreItems) - { - this.hasMoreItems = hasMoreItems; - } - - public void setTotalItems(Integer totalItems) - { - this.totalItems = totalItems; - } + public Integer getCount() + { + return count; + } - public void setSkipCount(Integer skipCount) - { - this.skipCount = skipCount; - } + public void setCount(Integer count) + { + this.count = count; + } - public void setMaxItems(Integer maxItems) - { - this.maxItems = maxItems; - } + public void setHasMoreItems(Boolean hasMoreItems) + { + this.hasMoreItems = hasMoreItems; + } - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + count; - result = prime * result + (hasMoreItems ? 1231 : 1237); - result = prime * result + maxItems; - result = prime * result + skipCount; - result = prime * result - + ((totalItems == null) ? 0 : totalItems.hashCode()); - return result; - } + public void setTotalItems(Integer totalItems) + { + this.totalItems = totalItems; + } - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ExpectedPaging other = (ExpectedPaging) obj; - if (count != other.count) - return false; - if (hasMoreItems != other.hasMoreItems) - return false; - if (maxItems != other.maxItems) - return false; - if (skipCount != other.skipCount) - return false; - if (totalItems == null) { - if (other.totalItems != null) - return false; - } else if (!totalItems.equals(other.totalItems)) - return false; - return true; - } + public void setSkipCount(Integer skipCount) + { + this.skipCount = skipCount; + } - @Override - public String toString() - { - return "ExpectedPaging [skipCount=" - + skipCount - + ", maxItems=" - + maxItems - + ", " - + (totalItems != null ? "totalItems=" + totalItems + ", " - : "") + "hasMoreItems=" + hasMoreItems + ", count=" - + count + "]"; - } + public void setMaxItems(Integer maxItems) + { + this.maxItems = maxItems; + } - public static ExpectedPaging parsePagination(JSONObject jsonList) - { - ExpectedPaging paging = new ExpectedPaging(); - JSONObject jsonPagination = (JSONObject)jsonList.get("pagination"); - if(jsonPagination != null) - { - Long count = (Long)jsonPagination.get("count"); - paging.setCount(count.intValue()); - - Boolean hasMoreItems = (Boolean)jsonPagination.get("hasMoreItems"); - paging.setHasMoreItems(hasMoreItems); - - Long totalItems = (Long)jsonPagination.get("totalItems"); - if(totalItems != null) - { - paging.setTotalItems(totalItems.intValue()); - } - - Long maxItems = (Long)jsonPagination.get("maxItems"); - paging.setMaxItems(maxItems.intValue()); - - Long skipCount = (Long)jsonPagination.get("skipCount"); - paging.setSkipCount(skipCount.intValue()); - } - return paging; - } - - public static ExpectedPaging getExpectedPaging(Integer skipCount, Integer maxItems, int total, Integer expectedTotal) - { - int skip = skipCount != null ? skipCount : org.alfresco.rest.framework.resource.parameters.Paging.DEFAULT_SKIP_COUNT; - int max = maxItems != null ? maxItems : org.alfresco.rest.framework.resource.parameters.Paging.DEFAULT_MAX_ITEMS; - int expectedCount = -1; - int end = skip + max; - if(end < 0 || end > total) - { - // overflow or greater than the total - expectedCount = total - skip; - end = total; - } - else - { - expectedCount = max; - } - if(expectedCount < 0) - { - expectedCount = 0; - } - boolean hasMore = end < total; - ExpectedPaging expectedPaging = new ExpectedPaging(skip, max, expectedTotal, hasMore, expectedCount); - return expectedPaging; - } - } + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + count; + result = prime * result + (hasMoreItems ? 1231 : 1237); + result = prime * result + maxItems; + result = prime * result + skipCount; + result = prime * result + + ((totalItems == null) ? 0 : totalItems.hashCode()); + return result; + } - public class CmisSession - { - private Session session; - - public CmisSession(Session session) - { - this.session = session; - } - - public Session getCMISSession() - { - return session; - } + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ExpectedPaging other = (ExpectedPaging) obj; + if (count != other.count) + return false; + if (hasMoreItems != other.hasMoreItems) + return false; + if (maxItems != other.maxItems) + return false; + if (skipCount != other.skipCount) + return false; + if (totalItems == null) { + if (other.totalItems != null) + return false; + } else if (!totalItems.equals(other.totalItems)) + return false; + return true; + } - public CmisObject getObject(String objectId) - { - RequestContext rc = getRequestContext(); - OperationContext ctx = rc.getCmisOperationCtxOverride(); - if(ctx == null) - { - ctx = new OperationContextImpl(); - } + @Override + public String toString() + { + return "ExpectedPaging [skipCount=" + + skipCount + + ", maxItems=" + + maxItems + + ", " + + (totalItems != null ? "totalItems=" + totalItems + ", " + : "") + "hasMoreItems=" + hasMoreItems + ", count=" + + count + "]"; + } - CmisObject res = session.getObject(objectId, ctx); - return res; - } + public static ExpectedPaging parsePagination(JSONObject jsonList) + { + ExpectedPaging paging = new ExpectedPaging(); + JSONObject jsonPagination = (JSONObject)jsonList.get("pagination"); + if(jsonPagination != null) + { + Long count = (Long)jsonPagination.get("count"); + paging.setCount(count.intValue()); - public CmisObject getObjectByPath(String path) - { - OperationContextImpl ctx = new OperationContextImpl(); - CmisObject res = session.getObjectByPath(path, ctx); - return res; - } - - public List getObjectParents(String objectId) - { - CmisObject o = session.getObject(objectId); - if(o instanceof FileableCmisObject) - { - FileableCmisObject f = (FileableCmisObject)o; - - OperationContextImpl ctx = new OperationContextImpl(); - List res = f.getParents(ctx); - return res; - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a fileable cmis object"); - } - } - - public void deleteContent(String objectId, boolean refresh) - { - CmisObject o = getObject(objectId); + Boolean hasMoreItems = (Boolean)jsonPagination.get("hasMoreItems"); + paging.setHasMoreItems(hasMoreItems); - if(o instanceof Document) - { - Document d = (Document)o; - d.deleteContentStream(refresh); - } - else - { - throw new IllegalArgumentException("Object does not exists or is not a document"); - } - } - - public ContentData getContent(String objectId) throws IOException - { - CmisObject o = getObject(objectId); - if(o instanceof Document) - { - Document d = (Document)o; - ContentStream res = d.getContentStream(); - ContentData c = new ContentData(res); - return c; - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a document"); - } - } - - public void putContent(String objectId, String filename, BigInteger length, String mimetype, InputStream content, boolean overwrite) - { - CmisObject o = getObject(objectId); - if(o instanceof Document) - { - Document d = (Document)o; - ContentStream contentStream = new ContentStreamImpl(filename, length, mimetype, content); - try - { - d.setContentStream(contentStream, overwrite); - } - finally - { - try - { - contentStream.getStream().close(); - } - catch (Exception e) - { - } - } - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a document"); - } - } - - public void addChildren(FolderNode f, Tree t) - { - FileableCmisObject fco = t.getItem(); - CMISNode child = CMISNode.createNode(fco); + Long totalItems = (Long)jsonPagination.get("totalItems"); + if(totalItems != null) + { + paging.setTotalItems(totalItems.intValue()); + } - if(child instanceof FolderNode) - { - f.addFolder((FolderNode)child); - for(Tree c : t.getChildren()) - { - addChildren((FolderNode)child, c); - } - } - else - { - f.addNode(child); - } - } + Long maxItems = (Long)jsonPagination.get("maxItems"); + paging.setMaxItems(maxItems.intValue()); - public boolean objectExists(String objectId) - { - CmisObject o = getObject(objectId); - return(o != null); - } - - public FolderNode getRootFolder() - { - Folder rootFolder = session.getRootFolder(); - - FolderNode ret = (FolderNode)CMISNode.createNode(rootFolder); - return ret; - } - - public FolderNode getDescendants(String folderId, int depth) - { - Session session = getCMISSession(); + Long skipCount = (Long)jsonPagination.get("skipCount"); + paging.setSkipCount(skipCount.intValue()); + } + return paging; + } - CmisObject o = session.getObject(folderId); - if(o instanceof Folder) - { - Folder f = (Folder)o; + public static ExpectedPaging getExpectedPaging(Integer skipCount, Integer maxItems, int total, Integer expectedTotal) + { + int skip = skipCount != null ? skipCount : org.alfresco.rest.framework.resource.parameters.Paging.DEFAULT_SKIP_COUNT; + int max = maxItems != null ? maxItems : org.alfresco.rest.framework.resource.parameters.Paging.DEFAULT_MAX_ITEMS; + int expectedCount = -1; + int end = skip + max; + if(end < 0 || end > total) + { + // overflow or greater than the total + expectedCount = total - skip; + end = total; + } + else + { + expectedCount = max; + } + if(expectedCount < 0) + { + expectedCount = 0; + } + boolean hasMore = end < total; + ExpectedPaging expectedPaging = new ExpectedPaging(skip, max, expectedTotal, hasMore, expectedCount); + return expectedPaging; + } + } - OperationContextImpl ctx = new OperationContextImpl(); - List> res = f.getDescendants(depth, ctx); - FolderNode ret = (FolderNode)CMISNode.createNode(f); - for(Tree t : res) - { - addChildren(ret, t); - } + public class CmisSession + { + private Session session; - return ret; - } - else - { - throw new IllegalArgumentException("Folder does not exist or is not a folder"); - } - } - - public ItemIterable getTypeChildren(String typeId, boolean includePropertyDefinitions) - { - ItemIterable res = session.getTypeChildren(typeId, includePropertyDefinitions); - return res; - } - - public List> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions) - { - List> res = session.getTypeDescendants(typeId, depth, includePropertyDefinitions); - return res; - } - - public ObjectType getTypeDefinition(String typeId) - { - ObjectType res = session.getTypeDefinition(typeId); - return res; - } - - public void removeAllVersions(String objectId) - { - CmisObject o = getObject(objectId); - if(o instanceof Document) - { - Document d = (Document)o; - d.deleteAllVersions(); - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a document"); - } - } - - public List query(String query, boolean searchAllVersions, long skipCount, int maxItems) - { - OperationContext ctx = new OperationContextImpl(); - ItemIterable res = session.query(query, searchAllVersions, ctx); - res = res.skipTo(skipCount); - res = res.getPage(maxItems); + public CmisSession(Session session) + { + this.session = session; + } - List results = new ArrayList((int)res.getPageNumItems()); + public Session getCMISSession() + { + return session; + } - for(QueryResult r : res) - { - CMISNode n = CMISNode.createNode(r); - results.add(n); - } - - return results; - } - - public void removeObject(String objectId, boolean allVersions) - { - CmisObject o = getObject(objectId); - if(o != null) - { - o.delete(allVersions); - } - else - { - throw new IllegalArgumentException("Object does not exist"); - } - } - - public List removeTree(String objectId, boolean allVersions, UnfileObject unfile, boolean continueOnFailure) - { - CmisObject o = getObject(objectId); - if(o instanceof Folder) - { - Folder f = (Folder)o; - List res = f.deleteTree(allVersions, unfile, continueOnFailure); - return res; - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a folder"); - } - } - - public void updateProperties(String objectId, Map properties, boolean refresh) - { - CmisObject o = getObject(objectId); - if(o != null) - { - o.updateProperties(properties, refresh); - } - else - { - throw new IllegalArgumentException("Object does not exist"); - } - } - - public List> getFolderTree(String folderId, int depth) - { - CmisObject o = session.getObject(folderId); - if(o instanceof Folder) - { - Folder f = (Folder)o; - - OperationContextImpl ctx = new OperationContextImpl(); - List> res = f.getFolderTree(depth, ctx); - return res; - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a folder"); - } - } - - public FolderNode getChildren(String folderId, int skipCount, int maxItems) - { - CmisObject o = session.getObject(folderId); - if(o instanceof Folder) - { - Folder f = (Folder)o; - FolderNode ret = (FolderNode)CMISNode.createNode(f); + public CmisObject getObject(String objectId) + { + RequestContext rc = getRequestContext(); + OperationContext ctx = rc.getCmisOperationCtxOverride(); + if(ctx == null) + { + ctx = new OperationContextImpl(); + } - OperationContextImpl ctx = new OperationContextImpl(); - ItemIterable res = f.getChildren(ctx); - res.skipTo(skipCount); - ItemIterable l = res.getPage(maxItems); - for(CmisObject c : l) - { - CMISNode child = null; - if(c.getBaseType() instanceof FolderTypeDefinition) - { - child = (FolderNode)CMISNode.createNode(c); - ret.addFolder((FolderNode)child); - } - else - { - child = CMISNode.createNode(c); - ret.addNode(child); - } - } + CmisObject res = session.getObject(objectId, ctx); + return res; + } - return ret; - } - else - { - throw new IllegalArgumentException("Folder does not exist or is not a folder"); - } - } - - public ItemIterable getCheckedOutDocs() - { - OperationContextImpl ctx = new OperationContextImpl(); - ItemIterable res = session.getCheckedOutDocs(ctx); - return res; - } - - public List getAllVersions(String objectId) - { - CmisObject o = getObject(objectId); - if(o instanceof Document) - { - Document d = (Document)o; - OperationContext ctx = new OperationContextImpl(); - List res = d.getAllVersions(ctx); - return res; - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a document"); - } - } - - public AllowableActions getAllowableActions(String objectId) - { - CmisObject o = getObject(objectId); - AllowableActions res = o.getAllowableActions(); - return res; - } - - public Document createDocument(String parentId, String name, Map properties, ContentStream contentStream, VersioningState versioningState) - { - CmisObject o = getObject(parentId); + public CmisObject getObjectByPath(String path) + { + OperationContextImpl ctx = new OperationContextImpl(); + CmisObject res = session.getObjectByPath(path, ctx); + return res; + } - if(o instanceof Folder) - { - Folder f = (Folder)o; - - if(properties == null) - { - properties = new HashMap(); - } - String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID); - String type = "cmis:document"; - if(objectTypeId == null) - { - objectTypeId = type; - } - if(objectTypeId.indexOf(type) == -1) - { - StringBuilder sb = new StringBuilder(objectTypeId); - if(sb.length() > 0) - { - sb.append(","); - } - sb.append(type); - objectTypeId = sb.toString(); - } + public List getObjectParents(String objectId) + { + CmisObject o = session.getObject(objectId); + if(o instanceof FileableCmisObject) + { + FileableCmisObject f = (FileableCmisObject)o; - properties.put(PropertyIds.NAME, name); - properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId); + OperationContextImpl ctx = new OperationContextImpl(); + List res = f.getParents(ctx); + return res; + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a fileable cmis object"); + } + } - Document res = f.createDocument(properties, contentStream, versioningState); - return res; - } - else - { - throw new IllegalArgumentException("Parent does not exists or is not a folder"); - } - } - - public Folder createFolder(String folderId, String name, Map properties) - { - CmisObject o = getObject(folderId); + public void deleteContent(String objectId, boolean refresh) + { + CmisObject o = getObject(objectId); - if(o instanceof Folder) - { - Folder f = (Folder)o; + if(o instanceof Document) + { + Document d = (Document)o; + d.deleteContentStream(refresh); + } + else + { + throw new IllegalArgumentException("Object does not exists or is not a document"); + } + } - if(properties == null) - { - properties = new HashMap(); - } - String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID); - String type = "cmis:folder"; - if(objectTypeId == null) - { - objectTypeId = type; - } - if(objectTypeId.indexOf(type) == -1) - { - StringBuilder sb = new StringBuilder(objectTypeId); - if(sb.length() > 0) - { - sb.append(","); - } - sb.append(type); - objectTypeId = sb.toString(); - } + public ContentData getContent(String objectId) throws IOException + { + CmisObject o = getObject(objectId); + if(o instanceof Document) + { + Document d = (Document)o; + ContentStream res = d.getContentStream(); + ContentData c = new ContentData(res); + return c; + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a document"); + } + } - properties.put(PropertyIds.NAME, name); - properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId); + public void putContent(String objectId, String filename, BigInteger length, String mimetype, InputStream content, boolean overwrite) + { + CmisObject o = getObject(objectId); + if(o instanceof Document) + { + Document d = (Document)o; + ContentStream contentStream = new ContentStreamImpl(filename, length, mimetype, content); + try + { + d.setContentStream(contentStream, overwrite); + } + finally + { + try + { + contentStream.getStream().close(); + } + catch (Exception e) + { + } + } + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a document"); + } + } - Folder res = f.createFolder(properties); - return res; - } - else - { - throw new IllegalArgumentException("Parent does not exist or is not a folder"); - } - } - - public ObjectId createRelationship(String sourceObjectId, String targetObjectId) - { - Map relProps = new HashMap(); - relProps.put("cmis:sourceId", sourceObjectId); - relProps.put("cmis:targetId", targetObjectId); - relProps.put("cmis:objectTypeId", "cmis:relationship"); - ObjectId res = session.createRelationship(relProps); - return res; - } - - public ObjectId checkoutObject(String objectId) - { - CmisObject o = getObject(objectId); - if(o instanceof Document) - { - Document d = (Document)o; - ObjectId res = d.checkOut(); - return res; - } - else - { - throw new IllegalArgumentException("Object does not exist or is not a document"); - } - } - } + public void addChildren(FolderNode f, Tree t) + { + FileableCmisObject fco = t.getItem(); + CMISNode child = CMISNode.createNode(fco); - public static class Paging - { - private Integer skipCount; - private Integer maxItems; - private ExpectedPaging expectedPaging; + if(child instanceof FolderNode) + { + f.addFolder((FolderNode)child); + for(Tree c : t.getChildren()) + { + addChildren((FolderNode)child, c); + } + } + else + { + f.addNode(child); + } + } - public Paging() - { - } - - public Paging(Integer skipCount, Integer maxItems, ExpectedPaging expectedPaging) - { - super(); - this.skipCount = skipCount; - this.maxItems = maxItems; - this.expectedPaging = expectedPaging; - } + public boolean objectExists(String objectId) + { + CmisObject o = getObject(objectId); + return(o != null); + } - public ExpectedPaging getExpectedPaging() - { - return expectedPaging; - } + public FolderNode getRootFolder() + { + Folder rootFolder = session.getRootFolder(); - public void setExpectedPaging(ExpectedPaging expectedPaging) - { - this.expectedPaging = expectedPaging; - } + FolderNode ret = (FolderNode)CMISNode.createNode(rootFolder); + return ret; + } - public Integer getSkipCount() - { - return skipCount; - } + public FolderNode getDescendants(String folderId, int depth) + { + Session session = getCMISSession(); - public Integer getMaxItems() - { - return maxItems; - } + CmisObject o = session.getObject(folderId); + if(o instanceof Folder) + { + Folder f = (Folder)o; - public void setSkipCount(Integer skipCount) - { - this.skipCount = skipCount; - } + OperationContextImpl ctx = new OperationContextImpl(); + List> res = f.getDescendants(depth, ctx); + FolderNode ret = (FolderNode)CMISNode.createNode(f); + for(Tree t : res) + { + addChildren(ret, t); + } - public void setMaxItems(Integer maxItems) - { - this.maxItems = maxItems; - } + return ret; + } + else + { + throw new IllegalArgumentException("Folder does not exist or is not a folder"); + } + } - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result - + ((maxItems == null) ? 0 : maxItems.hashCode()); - result = prime * result - + ((skipCount == null) ? 0 : skipCount.hashCode()); - return result; - } + public ItemIterable getTypeChildren(String typeId, boolean includePropertyDefinitions) + { + ItemIterable res = session.getTypeChildren(typeId, includePropertyDefinitions); + return res; + } - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Paging other = (Paging) obj; - if (maxItems == null) { - if (other.maxItems != null) - return false; - } else if (!maxItems.equals(other.maxItems)) - return false; - if (skipCount == null) { - if (other.skipCount != null) - return false; - } else if (!skipCount.equals(other.skipCount)) - return false; - return true; - } + public List> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions) + { + List> res = session.getTypeDescendants(typeId, depth, includePropertyDefinitions); + return res; + } - @Override - public String toString() - { - return "Paging [" - + (skipCount != null ? "skipCount=" + skipCount + ", " : "") - + (maxItems != null ? "maxItems=" + maxItems : "") + "]"; - } - } + public ObjectType getTypeDefinition(String typeId) + { + ObjectType res = session.getTypeDefinition(typeId); + return res; + } + + public void removeAllVersions(String objectId) + { + CmisObject o = getObject(objectId); + if(o instanceof Document) + { + Document d = (Document)o; + d.deleteAllVersions(); + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a document"); + } + } + + public List query(String query, boolean searchAllVersions, long skipCount, int maxItems) + { + OperationContext ctx = new OperationContextImpl(); + ItemIterable res = session.query(query, searchAllVersions, ctx); + res = res.skipTo(skipCount); + res = res.getPage(maxItems); + + List results = new ArrayList((int)res.getPageNumItems()); + + for(QueryResult r : res) + { + CMISNode n = CMISNode.createNode(r); + results.add(n); + } + + return results; + } + + public void removeObject(String objectId, boolean allVersions) + { + CmisObject o = getObject(objectId); + if(o != null) + { + o.delete(allVersions); + } + else + { + throw new IllegalArgumentException("Object does not exist"); + } + } + + public List removeTree(String objectId, boolean allVersions, UnfileObject unfile, boolean continueOnFailure) + { + CmisObject o = getObject(objectId); + if(o instanceof Folder) + { + Folder f = (Folder)o; + List res = f.deleteTree(allVersions, unfile, continueOnFailure); + return res; + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a folder"); + } + } + + public void updateProperties(String objectId, Map properties, boolean refresh) + { + CmisObject o = getObject(objectId); + if(o != null) + { + o.updateProperties(properties, refresh); + } + else + { + throw new IllegalArgumentException("Object does not exist"); + } + } + + public List> getFolderTree(String folderId, int depth) + { + CmisObject o = session.getObject(folderId); + if(o instanceof Folder) + { + Folder f = (Folder)o; + + OperationContextImpl ctx = new OperationContextImpl(); + List> res = f.getFolderTree(depth, ctx); + return res; + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a folder"); + } + } + + public FolderNode getChildren(String folderId, int skipCount, int maxItems) + { + CmisObject o = session.getObject(folderId); + if(o instanceof Folder) + { + Folder f = (Folder)o; + FolderNode ret = (FolderNode)CMISNode.createNode(f); + + OperationContextImpl ctx = new OperationContextImpl(); + ItemIterable res = f.getChildren(ctx); + res.skipTo(skipCount); + ItemIterable l = res.getPage(maxItems); + for(CmisObject c : l) + { + CMISNode child = null; + if(c.getBaseType() instanceof FolderTypeDefinition) + { + child = (FolderNode)CMISNode.createNode(c); + ret.addFolder((FolderNode)child); + } + else + { + child = CMISNode.createNode(c); + ret.addNode(child); + } + } + + return ret; + } + else + { + throw new IllegalArgumentException("Folder does not exist or is not a folder"); + } + } + + public ItemIterable getCheckedOutDocs() + { + OperationContextImpl ctx = new OperationContextImpl(); + ItemIterable res = session.getCheckedOutDocs(ctx); + return res; + } + + public List getAllVersions(String objectId) + { + CmisObject o = getObject(objectId); + if(o instanceof Document) + { + Document d = (Document)o; + OperationContext ctx = new OperationContextImpl(); + List res = d.getAllVersions(ctx); + return res; + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a document"); + } + } + + public AllowableActions getAllowableActions(String objectId) + { + CmisObject o = getObject(objectId); + AllowableActions res = o.getAllowableActions(); + return res; + } + + public Document createDocument(String parentId, String name, Map properties, ContentStream contentStream, VersioningState versioningState) + { + CmisObject o = getObject(parentId); + + if(o instanceof Folder) + { + Folder f = (Folder)o; + + if(properties == null) + { + properties = new HashMap(); + } + String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID); + String type = "cmis:document"; + if(objectTypeId == null) + { + objectTypeId = type; + } + if(objectTypeId.indexOf(type) == -1) + { + StringBuilder sb = new StringBuilder(objectTypeId); + if(sb.length() > 0) + { + sb.append(","); + } + sb.append(type); + objectTypeId = sb.toString(); + } + + properties.put(PropertyIds.NAME, name); + properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId); + + Document res = f.createDocument(properties, contentStream, versioningState); + return res; + } + else + { + throw new IllegalArgumentException("Parent does not exists or is not a folder"); + } + } + + public Folder createFolder(String folderId, String name, Map properties) + { + CmisObject o = getObject(folderId); + + if(o instanceof Folder) + { + Folder f = (Folder)o; + + if(properties == null) + { + properties = new HashMap(); + } + String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID); + String type = "cmis:folder"; + if(objectTypeId == null) + { + objectTypeId = type; + } + if(objectTypeId.indexOf(type) == -1) + { + StringBuilder sb = new StringBuilder(objectTypeId); + if(sb.length() > 0) + { + sb.append(","); + } + sb.append(type); + objectTypeId = sb.toString(); + } + + properties.put(PropertyIds.NAME, name); + properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId); + + Folder res = f.createFolder(properties); + return res; + } + else + { + throw new IllegalArgumentException("Parent does not exist or is not a folder"); + } + } + + public ObjectId createRelationship(String sourceObjectId, String targetObjectId) + { + Map relProps = new HashMap(); + relProps.put("cmis:sourceId", sourceObjectId); + relProps.put("cmis:targetId", targetObjectId); + relProps.put("cmis:objectTypeId", "cmis:relationship"); + ObjectId res = session.createRelationship(relProps); + return res; + } + + public ObjectId checkoutObject(String objectId) + { + CmisObject o = getObject(objectId); + if(o instanceof Document) + { + Document d = (Document)o; + ObjectId res = d.checkOut(); + return res; + } + else + { + throw new IllegalArgumentException("Object does not exist or is not a document"); + } + } + } + + public static class Paging + { + private Integer skipCount; + private Integer maxItems; + private ExpectedPaging expectedPaging; + + public Paging() + { + } + + public Paging(Integer skipCount, Integer maxItems, ExpectedPaging expectedPaging) + { + super(); + this.skipCount = skipCount; + this.maxItems = maxItems; + this.expectedPaging = expectedPaging; + } + + public ExpectedPaging getExpectedPaging() + { + return expectedPaging; + } + + public void setExpectedPaging(ExpectedPaging expectedPaging) + { + this.expectedPaging = expectedPaging; + } + + public Integer getSkipCount() + { + return skipCount; + } + + public Integer getMaxItems() + { + return maxItems; + } + + public void setSkipCount(Integer skipCount) + { + this.skipCount = skipCount; + } + + public void setMaxItems(Integer maxItems) + { + this.maxItems = maxItems; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + + ((maxItems == null) ? 0 : maxItems.hashCode()); + result = prime * result + + ((skipCount == null) ? 0 : skipCount.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Paging other = (Paging) obj; + if (maxItems == null) { + if (other.maxItems != null) + return false; + } else if (!maxItems.equals(other.maxItems)) + return false; + if (skipCount == null) { + if (other.skipCount != null) + return false; + } else if (!skipCount.equals(other.skipCount)) + return false; + return true; + } + + @Override + public String toString() + { + return "Paging [" + + (skipCount != null ? "skipCount=" + skipCount + ", " : "") + + (maxItems != null ? "maxItems=" + maxItems : "") + "]"; + } + } /** * Representation of an error response. @@ -2239,8 +2239,8 @@ public class PublicApiClient } public void setLogId(String logId) { - this.logId = logId; - } + this.logId = logId; + } public String getStackTrace() { @@ -2353,7 +2353,7 @@ public class PublicApiClient public void deleteGroupMembership(String groupId, String groupMemberId, int expectedStatus) throws PublicApiException { - remove("groups", groupId, "members", groupMemberId, null, "Failed to remove group member", expectedStatus); + remove("groups", groupId, "members", groupMemberId, null, "Failed to remove group member", expectedStatus); } private Group parseGroupEntity(HttpResponse response) diff --git a/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteDocument.java b/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteDocument.java index 72c935c84f..bef239b640 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteDocument.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteDocument.java @@ -49,127 +49,127 @@ import org.json.simple.JSONObject; */ public class FavouriteDocument extends FavouriteNode implements ExpectedComparison, JSONAble { - private static final long serialVersionUID = -5890002728061039516L; + private static final long serialVersionUID = -5890002728061039516L; - private String mimeType; - private BigInteger sizeInBytes; - private String versionLabel; + private String mimeType; + private BigInteger sizeInBytes; + private String versionLabel; - /** - * For POSTs - * @param guid String - */ - public FavouriteDocument(String guid) - { - super(guid); - } + /** + * For POSTs + * @param guid String + */ + public FavouriteDocument(String guid) + { + super(guid); + } - public FavouriteDocument(String id, String guid) - { - super(id, guid); - } + public FavouriteDocument(String id, String guid) + { + super(id, guid); + } -// public Document(String id, String guid, Map properties) -// { -// super(id, guid, properties); -// } +// public Document(String id, String guid, Map properties) +// { +// super(id, guid, properties); +// } - public static FavouriteDocument getDocument(String id, String guid, Properties props) - { - FavouriteDocument document = new FavouriteDocument(id, guid); + public static FavouriteDocument getDocument(String id, String guid, Properties props) + { + FavouriteDocument document = new FavouriteDocument(id, guid); - Map> properties = props.getProperties(); - document.setName((String)properties.get(PropertyIds.NAME).getFirstValue()); - document.setTitle((String)properties.get(ContentModel.PROP_TITLE.toString()).getFirstValue()); - document.setCreatedBy((String)properties.get(PropertyIds.CREATED_BY).getFirstValue()); - document.setModifiedBy((String)properties.get(PropertyIds.LAST_MODIFIED_BY).getFirstValue()); - GregorianCalendar modifiedAt = (GregorianCalendar)properties.get(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); - document.setModifiedAt(modifiedAt.getTime()); - GregorianCalendar createdAt = (GregorianCalendar)properties.get(PropertyIds.CREATION_DATE).getFirstValue(); - document.setCreatedAt(createdAt.getTime()); - //document.setDescription((String)props.get(PropertyIds.DE).getFirstValue()); - document.setMimeType((String)properties.get(PropertyIds.CONTENT_STREAM_MIME_TYPE).getFirstValue()); - document.setSizeInBytes((BigInteger)properties.get(PropertyIds.CONTENT_STREAM_LENGTH).getFirstValue()); - document.setVersionLabel((String)properties.get(PropertyIds.VERSION_LABEL).getFirstValue()); - return document; - } + Map> properties = props.getProperties(); + document.setName((String)properties.get(PropertyIds.NAME).getFirstValue()); + document.setTitle((String)properties.get(ContentModel.PROP_TITLE.toString()).getFirstValue()); + document.setCreatedBy((String)properties.get(PropertyIds.CREATED_BY).getFirstValue()); + document.setModifiedBy((String)properties.get(PropertyIds.LAST_MODIFIED_BY).getFirstValue()); + GregorianCalendar modifiedAt = (GregorianCalendar)properties.get(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); + document.setModifiedAt(modifiedAt.getTime()); + GregorianCalendar createdAt = (GregorianCalendar)properties.get(PropertyIds.CREATION_DATE).getFirstValue(); + document.setCreatedAt(createdAt.getTime()); + //document.setDescription((String)props.get(PropertyIds.DE).getFirstValue()); + document.setMimeType((String)properties.get(PropertyIds.CONTENT_STREAM_MIME_TYPE).getFirstValue()); + document.setSizeInBytes((BigInteger)properties.get(PropertyIds.CONTENT_STREAM_LENGTH).getFirstValue()); + document.setVersionLabel((String)properties.get(PropertyIds.VERSION_LABEL).getFirstValue()); + return document; + } - public String getMimeType() - { - return mimeType; - } + public String getMimeType() + { + return mimeType; + } - public BigInteger getSizeInBytes() - { - return sizeInBytes; - } + public BigInteger getSizeInBytes() + { + return sizeInBytes; + } - public String getVersionLabel() - { - return versionLabel; - } - - public void setMimeType(String mimeType) - { - this.mimeType = mimeType; - } + public String getVersionLabel() + { + return versionLabel; + } - public void setSizeInBytes(BigInteger sizeInBytes) - { - this.sizeInBytes = sizeInBytes; - } + public void setMimeType(String mimeType) + { + this.mimeType = mimeType; + } - public void setVersionLabel(String versionLabel) - { - this.versionLabel = versionLabel; - } + public void setSizeInBytes(BigInteger sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } - public JSONObject toJSON() - { - JSONObject json = super.toJSON(); - return json; - } - - @Override - public void expected(Object o) - { - super.expected(o); + public void setVersionLabel(String versionLabel) + { + this.versionLabel = versionLabel; + } - assertTrue(o instanceof FavouriteDocument); + public JSONObject toJSON() + { + JSONObject json = super.toJSON(); + return json; + } - FavouriteDocument other = (FavouriteDocument)o; - - AssertUtil.assertEquals("mimeType", mimeType, other.getMimeType()); - AssertUtil.assertEquals("sizeInBytes", sizeInBytes, other.getSizeInBytes()); - AssertUtil.assertEquals("versionLabel", versionLabel, other.getVersionLabel()); - } + @Override + public void expected(Object o) + { + super.expected(o); - public static FavouriteDocument parseDocument(JSONObject jsonObject) throws ParseException - { - String id = (String)jsonObject.get("id"); - String guid = (String)jsonObject.get("guid"); - String name = (String)jsonObject.get("name"); - String title = (String)jsonObject.get("title"); - String description = (String)jsonObject.get("description"); - Date createdAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("createdAt")); - Date modifiedAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("modifiedAt")); - String createdBy = (String)jsonObject.get("createdBy"); - String modifiedBy = (String)jsonObject.get("modifiedBy"); - String mimeType = (String)jsonObject.get("mimeType"); - Long sizeInBytes = (Long)jsonObject.get("sizeInBytes"); - String versionLabel = (String)jsonObject.get("versionLabel"); + assertTrue(o instanceof FavouriteDocument); - FavouriteDocument document = new FavouriteDocument(id, guid); - document.setName(name); - document.setTitle(title); - document.setCreatedBy(createdBy); - document.setModifiedBy(modifiedBy); - document.setModifiedAt(modifiedAt); - document.setCreatedAt(createdAt); - document.setDescription(description); - document.setMimeType(mimeType); - document.setSizeInBytes(BigInteger.valueOf(sizeInBytes)); - document.setVersionLabel(versionLabel); + FavouriteDocument other = (FavouriteDocument)o; + + AssertUtil.assertEquals("mimeType", mimeType, other.getMimeType()); + AssertUtil.assertEquals("sizeInBytes", sizeInBytes, other.getSizeInBytes()); + AssertUtil.assertEquals("versionLabel", versionLabel, other.getVersionLabel()); + } + + public static FavouriteDocument parseDocument(JSONObject jsonObject) throws ParseException + { + String id = (String)jsonObject.get("id"); + String guid = (String)jsonObject.get("guid"); + String name = (String)jsonObject.get("name"); + String title = (String)jsonObject.get("title"); + String description = (String)jsonObject.get("description"); + Date createdAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("createdAt")); + Date modifiedAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("modifiedAt")); + String createdBy = (String)jsonObject.get("createdBy"); + String modifiedBy = (String)jsonObject.get("modifiedBy"); + String mimeType = (String)jsonObject.get("mimeType"); + Long sizeInBytes = (Long)jsonObject.get("sizeInBytes"); + String versionLabel = (String)jsonObject.get("versionLabel"); + + FavouriteDocument document = new FavouriteDocument(id, guid); + document.setName(name); + document.setTitle(title); + document.setCreatedBy(createdBy); + document.setModifiedBy(modifiedBy); + document.setModifiedAt(modifiedAt); + document.setCreatedAt(createdAt); + document.setDescription(description); + document.setMimeType(mimeType); + document.setSizeInBytes(BigInteger.valueOf(sizeInBytes)); + document.setVersionLabel(versionLabel); // set path if available document.parseAndSetPath(jsonObject); return document; diff --git a/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteFolder.java b/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteFolder.java index 2d2fdf5170..afdd7cf3cd 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteFolder.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteFolder.java @@ -46,80 +46,80 @@ import org.json.simple.JSONObject; */ public class FavouriteFolder extends FavouriteNode implements ExpectedComparison, JSONAble { - private static final long serialVersionUID = 5020819866533183524L; + private static final long serialVersionUID = 5020819866533183524L; - /** - * For POSTs - * @param guid String - */ - public FavouriteFolder(String guid) - { - super(guid); - } - - public FavouriteFolder(String id, String guid) - { - super(id, guid); - } + /** + * For POSTs + * @param guid String + */ + public FavouriteFolder(String guid) + { + super(guid); + } -// public Folder(String id, String guid, Map properties) -// { -// super(id, guid, properties); -// } + public FavouriteFolder(String id, String guid) + { + super(id, guid); + } - public static FavouriteFolder getFolder(String id, String guid, Properties props) - { - FavouriteFolder folder = new FavouriteFolder(id, guid); +// public Folder(String id, String guid, Map properties) +// { +// super(id, guid, properties); +// } - Map> properties = props.getProperties(); - folder.setName((String)properties.get(PropertyIds.NAME).getFirstValue()); - folder.setTitle((String)properties.get(ContentModel.PROP_TITLE.toString()).getFirstValue()); - folder.setCreatedBy((String)properties.get(PropertyIds.CREATED_BY).getFirstValue()); - folder.setModifiedBy((String)properties.get(PropertyIds.LAST_MODIFIED_BY).getFirstValue()); - GregorianCalendar modifiedAt = (GregorianCalendar)properties.get(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); - folder.setModifiedAt(modifiedAt.getTime()); - GregorianCalendar createdAt = (GregorianCalendar)properties.get(PropertyIds.CREATION_DATE).getFirstValue(); - folder.setCreatedAt(createdAt.getTime()); - //document.setDescription((String)props.get(PropertyIds.DE).getFirstValue()); - return folder; - } - - public JSONObject toJSON() - { - JSONObject json = super.toJSON(); - return json; - } + public static FavouriteFolder getFolder(String id, String guid, Properties props) + { + FavouriteFolder folder = new FavouriteFolder(id, guid); - public static FavouriteFolder parseFolder(JSONObject jsonObject) throws ParseException - { - String id = (String)jsonObject.get("id"); - String guid = (String)jsonObject.get("guid"); - String name = (String)jsonObject.get("name"); - String title = (String)jsonObject.get("title"); - String description = (String)jsonObject.get("description"); - Date createdAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("createdAt")); - Date modifiedAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("modifiedAt")); - String createdBy = (String)jsonObject.get("createdBy"); - String modifiedBy = (String)jsonObject.get("modifiedBy"); + Map> properties = props.getProperties(); + folder.setName((String)properties.get(PropertyIds.NAME).getFirstValue()); + folder.setTitle((String)properties.get(ContentModel.PROP_TITLE.toString()).getFirstValue()); + folder.setCreatedBy((String)properties.get(PropertyIds.CREATED_BY).getFirstValue()); + folder.setModifiedBy((String)properties.get(PropertyIds.LAST_MODIFIED_BY).getFirstValue()); + GregorianCalendar modifiedAt = (GregorianCalendar)properties.get(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); + folder.setModifiedAt(modifiedAt.getTime()); + GregorianCalendar createdAt = (GregorianCalendar)properties.get(PropertyIds.CREATION_DATE).getFirstValue(); + folder.setCreatedAt(createdAt.getTime()); + //document.setDescription((String)props.get(PropertyIds.DE).getFirstValue()); + return folder; + } - FavouriteFolder folder = new FavouriteFolder(id, guid); - folder.setName(name); - folder.setTitle(title); - folder.setCreatedBy(createdBy); - folder.setModifiedBy(modifiedBy); - folder.setModifiedAt(modifiedAt); - folder.setCreatedAt(createdAt); - folder.setDescription(description); + public JSONObject toJSON() + { + JSONObject json = super.toJSON(); + return json; + } + + public static FavouriteFolder parseFolder(JSONObject jsonObject) throws ParseException + { + String id = (String)jsonObject.get("id"); + String guid = (String)jsonObject.get("guid"); + String name = (String)jsonObject.get("name"); + String title = (String)jsonObject.get("title"); + String description = (String)jsonObject.get("description"); + Date createdAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("createdAt")); + Date modifiedAt = PublicApiDateFormat.getDateFormat().parse((String)jsonObject.get("modifiedAt")); + String createdBy = (String)jsonObject.get("createdBy"); + String modifiedBy = (String)jsonObject.get("modifiedBy"); + + FavouriteFolder folder = new FavouriteFolder(id, guid); + folder.setName(name); + folder.setTitle(title); + folder.setCreatedBy(createdBy); + folder.setModifiedBy(modifiedBy); + folder.setModifiedAt(modifiedAt); + folder.setCreatedAt(createdAt); + folder.setDescription(description); // set path if available folder.parseAndSetPath(jsonObject); return folder; } - @Override - public void expected(Object o) - { - super.expected(o); - } + @Override + public void expected(Object o) + { + super.expected(o); + } @Override public String toString() diff --git a/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteNode.java b/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteNode.java index aa7b73744a..643ab517e5 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteNode.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/data/FavouriteNode.java @@ -43,138 +43,138 @@ import org.json.simple.JSONObject; */ public class FavouriteNode implements Serializable, ExpectedComparison { - private static final long serialVersionUID = -6881545732441221372L; + private static final long serialVersionUID = -6881545732441221372L; - protected String nodeId; - protected String guid; - protected String name; - protected String title; - protected String description; - protected Date createdAt; - protected Date modifiedAt; - protected String createdBy; - protected String modifiedBy; - protected PathInfo path; + protected String nodeId; + protected String guid; + protected String name; + protected String title; + protected String description; + protected Date createdAt; + protected Date modifiedAt; + protected String createdBy; + protected String modifiedBy; + protected PathInfo path; - public FavouriteNode() - { - } + public FavouriteNode() + { + } - /** - * For POSTs - * - * @param guid String - */ - public FavouriteNode(String guid) - { - this.guid = guid; - } + /** + * For POSTs + * + * @param guid String + */ + public FavouriteNode(String guid) + { + this.guid = guid; + } - public FavouriteNode(String id, String guid) - { - this.nodeId = id; - this.guid = guid; - } + public FavouriteNode(String id, String guid) + { + this.nodeId = id; + this.guid = guid; + } - public void setGuid(String guid) - { - this.guid = guid; - } + public void setGuid(String guid) + { + this.guid = guid; + } - public String getGuid() - { - return guid; - } + public String getGuid() + { + return guid; + } - public String getRawNodeId() - { - return nodeId; - } + public String getRawNodeId() + { + return nodeId; + } - public String getNodeId() - { - return nodeId; - } + public String getNodeId() + { + return nodeId; + } - public boolean isFolder() - { - return false; - } - - public String getName() - { - return name; - } + public boolean isFolder() + { + return false; + } - public void setName(String name) - { - this.name = name; - } + public String getName() + { + return name; + } - public String getTitle() - { - return title; - } + public void setName(String name) + { + this.name = name; + } - public void setTitle(String title) - { - this.title = title; - } + public String getTitle() + { + return title; + } - public String getDescription() - { - return description; - } + public void setTitle(String title) + { + this.title = title; + } - public void setDescription(String description) - { - this.description = description; - } + public String getDescription() + { + return description; + } - public Date getCreatedAt() - { - return createdAt; - } + public void setDescription(String description) + { + this.description = description; + } - public void setCreatedAt(Date createdAt) - { - this.createdAt = createdAt; - } + public Date getCreatedAt() + { + return createdAt; + } - public Date getModifiedAt() - { - return modifiedAt; - } + public void setCreatedAt(Date createdAt) + { + this.createdAt = createdAt; + } - public void setModifiedAt(Date modifiedAt) - { - this.modifiedAt = modifiedAt; - } + public Date getModifiedAt() + { + return modifiedAt; + } - public String getCreatedBy() - { - return createdBy; - } + public void setModifiedAt(Date modifiedAt) + { + this.modifiedAt = modifiedAt; + } - public void setCreatedBy(String createdBy) - { - this.createdBy = createdBy; - } + public String getCreatedBy() + { + return createdBy; + } - public String getModifiedBy() - { - return modifiedBy; - } + public void setCreatedBy(String createdBy) + { + this.createdBy = createdBy; + } - public void setModifiedBy(String modifiedBy) - { - this.modifiedBy = modifiedBy; - } + public String getModifiedBy() + { + return modifiedBy; + } - public void setNodeId(String nodeId) - { - this.nodeId = nodeId; - } + public void setModifiedBy(String modifiedBy) + { + this.modifiedBy = modifiedBy; + } + + public void setNodeId(String nodeId) + { + this.nodeId = nodeId; + } public PathInfo getPath() { @@ -203,66 +203,66 @@ public class FavouriteNode implements Serializable, ExpectedComparison } @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); - return result; - } + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); + return result; + } - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FavouriteNode other = (FavouriteNode) obj; - if (nodeId == null) - { - if (other.nodeId != null) - return false; - } else if (!nodeId.equals(other.nodeId)) - return false; - return true; - } + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FavouriteNode other = (FavouriteNode) obj; + if (nodeId == null) + { + if (other.nodeId != null) + return false; + } else if (!nodeId.equals(other.nodeId)) + return false; + return true; + } - @SuppressWarnings("unchecked") - public JSONObject toJSON() - { - JSONObject json = new JSONObject(); - json.put("guid", getGuid()); - json.put("id", getNodeId()); - return json; - } + @SuppressWarnings("unchecked") + public JSONObject toJSON() + { + JSONObject json = new JSONObject(); + json.put("guid", getGuid()); + json.put("id", getNodeId()); + return json; + } - @Override - public void expected(Object o) - { - assertTrue(o instanceof FavouriteNode); + @Override + public void expected(Object o) + { + assertTrue(o instanceof FavouriteNode); - FavouriteNode other = (FavouriteNode) o; + FavouriteNode other = (FavouriteNode) o; - AssertUtil.assertEquals("id", nodeId, other.getNodeId()); - AssertUtil.assertEquals("guid", guid, other.getGuid()); - AssertUtil.assertEquals("name", name, other.getName()); - AssertUtil.assertEquals("title", title, other.getTitle()); - AssertUtil.assertEquals("description", description, other.getDescription()); - AssertUtil.assertEquals("createdAt", createdAt, other.getCreatedAt()); - if(modifiedAt != null) - { - assertTrue(modifiedAt.before(other.getModifiedAt()) || modifiedAt.equals(other.getModifiedAt())); - } - AssertUtil.assertEquals("createdBy", createdBy, other.getCreatedBy()); - AssertUtil.assertEquals("modifiedBy", modifiedBy, other.getModifiedBy()); - if(path != null) + AssertUtil.assertEquals("id", nodeId, other.getNodeId()); + AssertUtil.assertEquals("guid", guid, other.getGuid()); + AssertUtil.assertEquals("name", name, other.getName()); + AssertUtil.assertEquals("title", title, other.getTitle()); + AssertUtil.assertEquals("description", description, other.getDescription()); + AssertUtil.assertEquals("createdAt", createdAt, other.getCreatedAt()); + if(modifiedAt != null) + { + assertTrue(modifiedAt.before(other.getModifiedAt()) || modifiedAt.equals(other.getModifiedAt())); + } + AssertUtil.assertEquals("createdBy", createdBy, other.getCreatedBy()); + AssertUtil.assertEquals("modifiedBy", modifiedBy, other.getModifiedBy()); + if(path != null) { path.expected(other.path); } - } + } @Override public String toString()