mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1)
136745 jkaabimofrad: APPSREPO-147: Added an optional "include=path" parameter to the "list favorites" API as well as create and get a single favorite endpoints. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@136755 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -37,6 +37,8 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
|
|||||||
*/
|
*/
|
||||||
public interface Favourites
|
public interface Favourites
|
||||||
{
|
{
|
||||||
|
String PARAM_INCLUDE_PATH = Nodes.PARAM_INCLUDE_PATH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a favourite for user personId
|
* Add a favourite for user personId
|
||||||
*
|
*
|
||||||
@@ -45,6 +47,15 @@ public interface Favourites
|
|||||||
*/
|
*/
|
||||||
Favourite addFavourite(String personId, Favourite favourite);
|
Favourite addFavourite(String personId, Favourite favourite);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a favourite for user personId taking parameters into account
|
||||||
|
*
|
||||||
|
* @param personId the personId for which the favourite is to be added
|
||||||
|
* @param favourite the favourite to add
|
||||||
|
* @param parameters the parameters
|
||||||
|
*/
|
||||||
|
Favourite addFavourite(String personId, Favourite favourite, Parameters parameters);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a favourite for user personId
|
* Add a favourite for user personId
|
||||||
*
|
*
|
||||||
@@ -70,4 +81,14 @@ public interface Favourites
|
|||||||
* @return the favourite
|
* @return the favourite
|
||||||
*/
|
*/
|
||||||
Favourite getFavourite(String personId, String favouriteId);
|
Favourite getFavourite(String personId, String favouriteId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific favourite for user personId taking parameters into account
|
||||||
|
*
|
||||||
|
* @param personId the personId for which the favourite is to be removed
|
||||||
|
* @param favouriteId the favourite id
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the favourite
|
||||||
|
*/
|
||||||
|
Favourite getFavourite(String personId, String favouriteId, Parameters parameters);
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -46,6 +46,8 @@ import org.alfresco.rest.api.model.DocumentTarget;
|
|||||||
import org.alfresco.rest.api.model.Favourite;
|
import org.alfresco.rest.api.model.Favourite;
|
||||||
import org.alfresco.rest.api.model.Folder;
|
import org.alfresco.rest.api.model.Folder;
|
||||||
import org.alfresco.rest.api.model.FolderTarget;
|
import org.alfresco.rest.api.model.FolderTarget;
|
||||||
|
import org.alfresco.rest.api.model.Node;
|
||||||
|
import org.alfresco.rest.api.model.PathInfo;
|
||||||
import org.alfresco.rest.api.model.Site;
|
import org.alfresco.rest.api.model.Site;
|
||||||
import org.alfresco.rest.api.model.SiteTarget;
|
import org.alfresco.rest.api.model.SiteTarget;
|
||||||
import org.alfresco.rest.api.model.Target;
|
import org.alfresco.rest.api.model.Target;
|
||||||
@@ -54,6 +56,7 @@ import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundE
|
|||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||||
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
||||||
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter;
|
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter;
|
||||||
import org.alfresco.service.cmr.favourites.FavouritesService;
|
import org.alfresco.service.cmr.favourites.FavouritesService;
|
||||||
@@ -107,7 +110,7 @@ public class FavouritesImpl implements Favourites
|
|||||||
this.siteService = siteService;
|
this.siteService = siteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Target getTarget(PersonFavourite personFavourite)
|
private Target getTarget(PersonFavourite personFavourite, Parameters parameters)
|
||||||
{
|
{
|
||||||
Target target = null;
|
Target target = null;
|
||||||
NodeRef nodeRef = personFavourite.getNodeRef();
|
NodeRef nodeRef = personFavourite.getNodeRef();
|
||||||
@@ -115,11 +118,13 @@ public class FavouritesImpl implements Favourites
|
|||||||
if(type.equals(Type.FILE))
|
if(type.equals(Type.FILE))
|
||||||
{
|
{
|
||||||
Document document = nodes.getDocument(nodeRef);
|
Document document = nodes.getDocument(nodeRef);
|
||||||
|
setPathInfo(document, parameters.getInclude());
|
||||||
target = new DocumentTarget(document);
|
target = new DocumentTarget(document);
|
||||||
}
|
}
|
||||||
else if(type.equals(Type.FOLDER))
|
else if(type.equals(Type.FOLDER))
|
||||||
{
|
{
|
||||||
Folder folder = nodes.getFolder(nodeRef);
|
Folder folder = nodes.getFolder(nodeRef);
|
||||||
|
setPathInfo(folder, parameters.getInclude());
|
||||||
target = new FolderTarget(folder);
|
target = new FolderTarget(folder);
|
||||||
}
|
}
|
||||||
else if(type.equals(Type.SITE))
|
else if(type.equals(Type.SITE))
|
||||||
@@ -137,17 +142,17 @@ public class FavouritesImpl implements Favourites
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Favourite getFavourite(PersonFavourite personFavourite)
|
private Favourite getFavourite(PersonFavourite personFavourite, Parameters parameters)
|
||||||
{
|
{
|
||||||
Favourite fav = new Favourite();
|
Favourite fav = new Favourite();
|
||||||
fav.setTargetGuid(personFavourite.getNodeRef().getId());
|
fav.setTargetGuid(personFavourite.getNodeRef().getId());
|
||||||
fav.setCreatedAt(personFavourite.getCreatedAt());
|
fav.setCreatedAt(personFavourite.getCreatedAt());
|
||||||
Target target = getTarget(personFavourite);
|
Target target = getTarget(personFavourite, parameters);
|
||||||
fav.setTarget(target);
|
fav.setTarget(target);
|
||||||
return fav;
|
return fav;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollectionWithPagingInfo<Favourite> wrap(Paging paging, PagingResults<PersonFavourite> personFavourites)
|
private CollectionWithPagingInfo<Favourite> wrap(Paging paging, PagingResults<PersonFavourite> personFavourites, Parameters parameters)
|
||||||
{
|
{
|
||||||
final List<PersonFavourite> page = personFavourites.getPage();
|
final List<PersonFavourite> page = personFavourites.getPage();
|
||||||
final List<Favourite> list = new AbstractList<Favourite>()
|
final List<Favourite> list = new AbstractList<Favourite>()
|
||||||
@@ -156,7 +161,7 @@ public class FavouritesImpl implements Favourites
|
|||||||
public Favourite get(int index)
|
public Favourite get(int index)
|
||||||
{
|
{
|
||||||
PersonFavourite personFavourite = page.get(index);
|
PersonFavourite personFavourite = page.get(index);
|
||||||
Favourite fav = getFavourite(personFavourite);
|
Favourite fav = getFavourite(personFavourite, parameters);
|
||||||
return fav;
|
return fav;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +182,13 @@ public class FavouritesImpl implements Favourites
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Favourite addFavourite(String personId, Favourite favourite)
|
public Favourite addFavourite(String personId, Favourite favourite)
|
||||||
|
{
|
||||||
|
Parameters parameters = getDefaultParameters(personId, null);
|
||||||
|
return addFavourite(personId, favourite, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Favourite addFavourite(String personId, Favourite favourite, Parameters parameters)
|
||||||
{
|
{
|
||||||
Favourite ret = null;
|
Favourite ret = null;
|
||||||
|
|
||||||
@@ -197,7 +209,7 @@ public class FavouritesImpl implements Favourites
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
|
PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
|
||||||
ret = getFavourite(personFavourite);
|
ret = getFavourite(personFavourite, parameters);
|
||||||
}
|
}
|
||||||
catch(SiteDoesNotExistException e)
|
catch(SiteDoesNotExistException e)
|
||||||
{
|
{
|
||||||
@@ -214,7 +226,7 @@ public class FavouritesImpl implements Favourites
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
|
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
|
||||||
ret = getFavourite(personFavourite);
|
ret = getFavourite(personFavourite, parameters);
|
||||||
}
|
}
|
||||||
else if(target instanceof FolderTarget)
|
else if(target instanceof FolderTarget)
|
||||||
{
|
{
|
||||||
@@ -226,7 +238,7 @@ public class FavouritesImpl implements Favourites
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
|
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
|
||||||
ret = getFavourite(personFavourite);
|
ret = getFavourite(personFavourite, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -264,7 +276,15 @@ public class FavouritesImpl implements Favourites
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Favourite getFavourite(String personId, String favouriteId)
|
public Favourite getFavourite(String personId, String favouriteId)
|
||||||
|
{
|
||||||
|
Parameters parameters = getDefaultParameters(personId, favouriteId);
|
||||||
|
return getFavourite(personId, favouriteId, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Favourite getFavourite(String personId, String favouriteId, Parameters parameters)
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = nodes.validateNode(favouriteId);
|
NodeRef nodeRef = nodes.validateNode(favouriteId);
|
||||||
personId = people.validatePerson(personId, true);
|
personId = people.validatePerson(personId, true);
|
||||||
@@ -272,7 +292,7 @@ public class FavouritesImpl implements Favourites
|
|||||||
PersonFavourite personFavourite = favouritesService.getFavourite(personId, nodeRef);
|
PersonFavourite personFavourite = favouritesService.getFavourite(personId, nodeRef);
|
||||||
if(personFavourite != null)
|
if(personFavourite != null)
|
||||||
{
|
{
|
||||||
Favourite favourite = getFavourite(personFavourite);
|
Favourite favourite = getFavourite(personFavourite, parameters);
|
||||||
return favourite;
|
return favourite;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -327,6 +347,27 @@ public class FavouritesImpl implements Favourites
|
|||||||
|
|
||||||
final PagingResults<PersonFavourite> favourites = favouritesService.getPagedFavourites(personId, filterTypes, FavouritesService.DEFAULT_SORT_PROPS,
|
final PagingResults<PersonFavourite> favourites = favouritesService.getPagedFavourites(personId, filterTypes, FavouritesService.DEFAULT_SORT_PROPS,
|
||||||
Util.getPagingRequest(paging));
|
Util.getPagingRequest(paging));
|
||||||
return wrap(paging, favourites);
|
return wrap(paging, favourites, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPathInfo(Node node, List<String> includeParam)
|
||||||
|
{
|
||||||
|
if (includeParam.contains(PARAM_INCLUDE_PATH))
|
||||||
|
{
|
||||||
|
PathInfo pathInfo = nodes.lookupPathInfo(node.getNodeRef(), null);
|
||||||
|
node.setPath(pathInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@code {@link Parameters} object where almost all of its values are null.
|
||||||
|
* the non-null value is the {@literal include} and whatever value is passed for {@code personId} and {@code favouriteId}
|
||||||
|
*/
|
||||||
|
private Parameters getDefaultParameters(String personId, String favouriteId)
|
||||||
|
{
|
||||||
|
Params.RecognizedParams recognizedParams = new Params.RecognizedParams(null, null, null, null, Collections.emptyList(), null, null, null,
|
||||||
|
false);
|
||||||
|
Parameters parameters = Params.valueOf(recognizedParams, personId, favouriteId, null);
|
||||||
|
return parameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -84,7 +84,7 @@ RelationshipResourceAction.Create<Favourite>, RelationshipResourceAction.Delete
|
|||||||
List<Favourite> ret = new ArrayList<Favourite>(entity.size());
|
List<Favourite> ret = new ArrayList<Favourite>(entity.size());
|
||||||
for(Favourite favourite : entity)
|
for(Favourite favourite : entity)
|
||||||
{
|
{
|
||||||
ret.add(favourites.addFavourite(personId, favourite));
|
ret.add(favourites.addFavourite(personId, favourite, parameters));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -100,6 +100,6 @@ RelationshipResourceAction.Create<Favourite>, RelationshipResourceAction.Delete
|
|||||||
public Favourite readById(String personId, String favouriteId, Parameters parameters)
|
public Favourite readById(String personId, String favouriteId, Parameters parameters)
|
||||||
throws RelationshipResourceNotFoundException
|
throws RelationshipResourceNotFoundException
|
||||||
{
|
{
|
||||||
return favourites.getFavourite(personId, favouriteId);
|
return favourites.getFavourite(personId, favouriteId, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -28,6 +28,7 @@ package org.alfresco.rest.api.tests;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
import org.alfresco.repo.tenant.TenantUtil;
|
||||||
@@ -61,11 +63,13 @@ import org.alfresco.rest.api.tests.client.data.Comment;
|
|||||||
import org.alfresco.rest.api.tests.client.data.Favourite;
|
import org.alfresco.rest.api.tests.client.data.Favourite;
|
||||||
import org.alfresco.rest.api.tests.client.data.FavouriteDocument;
|
import org.alfresco.rest.api.tests.client.data.FavouriteDocument;
|
||||||
import org.alfresco.rest.api.tests.client.data.FavouriteFolder;
|
import org.alfresco.rest.api.tests.client.data.FavouriteFolder;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.FavouriteNode;
|
||||||
import org.alfresco.rest.api.tests.client.data.FavouritesTarget;
|
import org.alfresco.rest.api.tests.client.data.FavouritesTarget;
|
||||||
import org.alfresco.rest.api.tests.client.data.FileFavouriteTarget;
|
import org.alfresco.rest.api.tests.client.data.FileFavouriteTarget;
|
||||||
import org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget;
|
import org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget;
|
||||||
import org.alfresco.rest.api.tests.client.data.InvalidFavouriteTarget;
|
import org.alfresco.rest.api.tests.client.data.InvalidFavouriteTarget;
|
||||||
import org.alfresco.rest.api.tests.client.data.JSONAble;
|
import org.alfresco.rest.api.tests.client.data.JSONAble;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.PathInfo;
|
||||||
import org.alfresco.rest.api.tests.client.data.Site;
|
import org.alfresco.rest.api.tests.client.data.Site;
|
||||||
import org.alfresco.rest.api.tests.client.data.SiteFavouriteTarget;
|
import org.alfresco.rest.api.tests.client.data.SiteFavouriteTarget;
|
||||||
import org.alfresco.rest.api.tests.client.data.SiteImpl;
|
import org.alfresco.rest.api.tests.client.data.SiteImpl;
|
||||||
@@ -91,7 +95,7 @@ import com.google.common.collect.Lists;
|
|||||||
* @author steveglover
|
* @author steveglover
|
||||||
* @since publicapi1.0
|
* @since publicapi1.0
|
||||||
*/
|
*/
|
||||||
public class TestFavourites extends EnterpriseTestApi
|
public class TestFavourites extends AbstractBaseApiTest
|
||||||
{
|
{
|
||||||
private static enum TARGET_TYPE
|
private static enum TARGET_TYPE
|
||||||
{
|
{
|
||||||
@@ -1712,4 +1716,187 @@ public class TestFavourites extends EnterpriseTestApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests get favourites with 'include' parameter.
|
||||||
|
* <p>GET:</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites?include=path}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetFavouritesWithPath() throws Exception
|
||||||
|
{
|
||||||
|
// As person12 user
|
||||||
|
setRequestContext(network1.getId(), person12Id, "password");
|
||||||
|
|
||||||
|
final NodeRef folderNodeRef = person1PublicFolders.get(0); // person1's folder (Test Folder1)
|
||||||
|
final NodeRef nodeRef = person1PublicDocs.get(1); // a file (Test Doc2) in the folder (Test Folder1)
|
||||||
|
final TestSite publicSite = person1PublicSites.get(0); // person1's public site
|
||||||
|
|
||||||
|
// Favourite the doc (Test Doc2)
|
||||||
|
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
|
||||||
|
favouritesProxy.createFavourite(person12Id, fileFavourite);
|
||||||
|
|
||||||
|
//Favourite the folder (Test Folder1)
|
||||||
|
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
|
||||||
|
favouritesProxy.createFavourite(person12Id, folderFavourite);
|
||||||
|
|
||||||
|
// Favourite the public site
|
||||||
|
final Favourite siteFavourite = makeSiteFavourite(publicSite);
|
||||||
|
favouritesProxy.createFavourite(person12Id, siteFavourite);
|
||||||
|
|
||||||
|
Paging paging = getPaging(0, 100);
|
||||||
|
Map<String, String> otherParams = Collections.singletonMap("include", "path");
|
||||||
|
|
||||||
|
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, otherParams));
|
||||||
|
List<Favourite> actualFavouritesList = resp.getList();
|
||||||
|
assertEquals("Incorrect number of entries returned", 3, actualFavouritesList.size());
|
||||||
|
|
||||||
|
actualFavouritesList.forEach(fav ->
|
||||||
|
{
|
||||||
|
FavouriteNode node;
|
||||||
|
switch (fav.getType())
|
||||||
|
{
|
||||||
|
case FILE:
|
||||||
|
{
|
||||||
|
node = ((FileFavouriteTarget) fav.getTarget()).getDocument();
|
||||||
|
assertNotNull("node is null.", node);
|
||||||
|
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary/Test Folder1", true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FOLDER:
|
||||||
|
{
|
||||||
|
node = ((FolderFavouriteTarget) fav.getTarget()).getFolder();
|
||||||
|
assertNotNull("node is null.", node);
|
||||||
|
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SITE:
|
||||||
|
{
|
||||||
|
JSONObject siteJsonObject = fav.getTarget().toJSON();
|
||||||
|
assertNotNull("There should be a site JSON object.", siteJsonObject);
|
||||||
|
assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get favourites without 'include' option
|
||||||
|
resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
|
||||||
|
actualFavouritesList = resp.getList();
|
||||||
|
assertEquals("Incorrect number of entries returned", 3, actualFavouritesList.size());
|
||||||
|
|
||||||
|
actualFavouritesList.forEach(fav ->
|
||||||
|
{
|
||||||
|
FavouriteNode node;
|
||||||
|
switch (fav.getType())
|
||||||
|
{
|
||||||
|
case FILE:
|
||||||
|
{
|
||||||
|
node = ((FileFavouriteTarget) fav.getTarget()).getDocument();
|
||||||
|
assertNotNull("node is null.", node);
|
||||||
|
assertNull("Path info should not be returned by default", node.getPath());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FOLDER:
|
||||||
|
{
|
||||||
|
node = ((FolderFavouriteTarget) fav.getTarget()).getFolder();
|
||||||
|
assertNotNull("node is null.", node);
|
||||||
|
assertNull("Path info should not be returned by default", node.getPath());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SITE:
|
||||||
|
{
|
||||||
|
JSONObject siteJsonObject = fav.getTarget().toJSON();
|
||||||
|
assertNotNull("There should be a site JSON object.", siteJsonObject);
|
||||||
|
assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests create and get favourite with 'include' parameter.
|
||||||
|
*
|
||||||
|
* <p>POST:</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites?include=path}
|
||||||
|
*
|
||||||
|
* <p>GET:</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites/<targetId>?include=path}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCreateAndGetFavouriteWithPath() throws Exception
|
||||||
|
{
|
||||||
|
Map<String, String> includePath = Collections.singletonMap("include", "path");
|
||||||
|
|
||||||
|
// As person12 user
|
||||||
|
setRequestContext(network1.getId(), person12Id, "password");
|
||||||
|
|
||||||
|
final NodeRef folderNodeRef = person1PublicFolders.get(0); // person1's folder (Test Folder1)
|
||||||
|
final NodeRef nodeRef1= person1PublicDocs.get(0); // a file in the site's document library (Test Doc1)
|
||||||
|
final NodeRef nodeRef2 = person1PublicDocs.get(1); // a file (Test Doc2) in the folder (Test Folder1)
|
||||||
|
final TestSite publicSite = person1PublicSites.get(0); // person1's public site
|
||||||
|
|
||||||
|
// Favourite the doc (Test Doc1)
|
||||||
|
Favourite file1Favourite = makeFileFavourite(nodeRef1.getId());
|
||||||
|
file1Favourite = favouritesProxy.createFavourite(person12Id, file1Favourite, includePath);
|
||||||
|
FavouriteNode node = ((FileFavouriteTarget) file1Favourite.getTarget()).getDocument();
|
||||||
|
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
|
||||||
|
|
||||||
|
|
||||||
|
// Favourite the doc (Test Doc2)
|
||||||
|
Favourite file2Favourite = makeFileFavourite(nodeRef2.getId());
|
||||||
|
file2Favourite = favouritesProxy.createFavourite(person12Id, file2Favourite);
|
||||||
|
node = ((FileFavouriteTarget) file2Favourite.getTarget()).getDocument();
|
||||||
|
assertNull("Path info should not be returned by default", node.getPath());
|
||||||
|
|
||||||
|
//Favourite the folder (Test Folder1)
|
||||||
|
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
|
||||||
|
folderFavourite = favouritesProxy.createFavourite(person12Id, folderFavourite, includePath);
|
||||||
|
node = ((FolderFavouriteTarget) folderFavourite.getTarget()).getFolder();
|
||||||
|
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
|
||||||
|
|
||||||
|
// Favourite the public site
|
||||||
|
Favourite siteFavourite = makeSiteFavourite(publicSite);
|
||||||
|
siteFavourite = favouritesProxy.createFavourite(person12Id, siteFavourite);
|
||||||
|
JSONObject siteJsonObject = siteFavourite.getTarget().toJSON();
|
||||||
|
assertNotNull("There should be a site JSON object.", siteJsonObject);
|
||||||
|
assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
|
||||||
|
|
||||||
|
// Get single favourite (Test Doc2) with include path
|
||||||
|
Favourite favouriteResp = favouritesProxy.getFavourite(person12Id, file2Favourite.getTargetGuid(), includePath);
|
||||||
|
node = ((FileFavouriteTarget) favouriteResp.getTarget()).getDocument();
|
||||||
|
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary/Test Folder1", true);
|
||||||
|
|
||||||
|
favouriteResp = favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid(), includePath);
|
||||||
|
node = ((FolderFavouriteTarget) favouriteResp.getTarget()).getFolder();
|
||||||
|
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
|
||||||
|
|
||||||
|
favouriteResp = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid(), includePath);
|
||||||
|
siteJsonObject = favouriteResp.getTarget().toJSON();
|
||||||
|
assertNotNull("There should be a site JSON object.", siteJsonObject);
|
||||||
|
assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertPathInfo(PathInfo expectedPathInfo, String expectedPathName, boolean expectedIsComplete)
|
||||||
|
{
|
||||||
|
assertNotNull("Path info was requested.", expectedPathInfo);
|
||||||
|
assertEquals("IsComplete should have been true.", expectedIsComplete, expectedPathInfo.getIsComplete());
|
||||||
|
assertEquals("Incorrect path name.", expectedPathName, expectedPathInfo.getName());
|
||||||
|
|
||||||
|
// substring(1) -> so we can ignore the first '/'
|
||||||
|
List<String> expectedPathElements = Arrays.asList(expectedPathName.substring(1).split("/"));
|
||||||
|
assertEquals("Incorrect number of path elements.", expectedPathElements.size(), expectedPathInfo.getElements().size());
|
||||||
|
|
||||||
|
AtomicInteger i = new AtomicInteger(0);
|
||||||
|
expectedPathElements.forEach(path -> assertEquals("Incorrect path element.", path,
|
||||||
|
expectedPathInfo.getElements().get(i.getAndIncrement()).getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getScope()
|
||||||
|
{
|
||||||
|
return "public";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -1086,6 +1086,12 @@ public class PublicApiClient
|
|||||||
return Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry"));
|
return Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Favourite getFavourite(String personId, String favouriteId, Map<String, String> params) throws PublicApiException, ParseException
|
||||||
|
{
|
||||||
|
HttpResponse response = getSingle("people", personId, "favorites", favouriteId, params, "Failed to get favourite " + favouriteId, 200);
|
||||||
|
return Favourite.parseFavourite((JSONObject) response.getJsonResponse().get("entry"));
|
||||||
|
}
|
||||||
|
|
||||||
public Favourite createFavourite(String personId, Favourite favourite) throws PublicApiException, ParseException
|
public Favourite createFavourite(String personId, Favourite favourite) throws PublicApiException, ParseException
|
||||||
{
|
{
|
||||||
HttpResponse response = create("people", personId, "favorites", null, favourite.toJSON().toString(), "Failed to create favourite");
|
HttpResponse response = create("people", personId, "favorites", null, favourite.toJSON().toString(), "Failed to create favourite");
|
||||||
@@ -1093,6 +1099,13 @@ public class PublicApiClient
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Favourite createFavourite(String personId, Favourite favourite, Map<String, String> params) throws PublicApiException, ParseException
|
||||||
|
{
|
||||||
|
HttpResponse response = create("people", personId, "favorites", null, favourite.toJSON().toString(), "Failed to create favourite", 201, params);
|
||||||
|
Favourite ret = Favourite.parseFavourite((JSONObject)response.getJsonResponse().get("entry"));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public void removeFavourite(String personId, String favouriteId) throws PublicApiException
|
public void removeFavourite(String personId, String favouriteId) throws PublicApiException
|
||||||
{
|
{
|
||||||
remove("people", personId, "favorites", favouriteId, "Failed to remove favourite");
|
remove("people", personId, "favorites", favouriteId, "Failed to remove favourite");
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -170,17 +170,29 @@ public class FavouriteDocument extends FavouriteNode implements ExpectedComparis
|
|||||||
document.setMimeType(mimeType);
|
document.setMimeType(mimeType);
|
||||||
document.setSizeInBytes(BigInteger.valueOf(sizeInBytes));
|
document.setSizeInBytes(BigInteger.valueOf(sizeInBytes));
|
||||||
document.setVersionLabel(versionLabel);
|
document.setVersionLabel(versionLabel);
|
||||||
|
// set path if available
|
||||||
|
document.parseAndSetPath(jsonObject);
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "FavouriteDocument [mimeType=" + mimeType + ", sizeInBytes="
|
final StringBuilder sb = new StringBuilder(250);
|
||||||
+ sizeInBytes + ", versionLabel=" + versionLabel + ", nodeId="
|
sb.append("FavouriteDocument [nodeId=").append(nodeId)
|
||||||
+ nodeId + ", guid=" + guid + ", name=" + name + ", title="
|
.append(", guid=").append(guid)
|
||||||
+ title + ", description=" + description + ", createdAt="
|
.append(", name=").append(name)
|
||||||
+ createdAt + ", modifiedAt=" + modifiedAt + ", createdBy="
|
.append(", title=").append(title)
|
||||||
+ createdBy + ", modifiedBy=" + modifiedBy + "]";
|
.append(", description=").append(description)
|
||||||
|
.append(", createdAt=").append(createdAt)
|
||||||
|
.append(", modifiedAt=").append(modifiedAt)
|
||||||
|
.append(", createdBy=").append(createdBy)
|
||||||
|
.append(", modifiedBy=").append(modifiedBy)
|
||||||
|
.append(", mimeType=").append(mimeType)
|
||||||
|
.append(", sizeInBytes=").append(sizeInBytes)
|
||||||
|
.append(", versionLabel=").append(versionLabel)
|
||||||
|
.append(", path=").append(path)
|
||||||
|
.append(']');
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -110,6 +110,8 @@ public class FavouriteFolder extends FavouriteNode implements ExpectedComparison
|
|||||||
folder.setModifiedAt(modifiedAt);
|
folder.setModifiedAt(modifiedAt);
|
||||||
folder.setCreatedAt(createdAt);
|
folder.setCreatedAt(createdAt);
|
||||||
folder.setDescription(description);
|
folder.setDescription(description);
|
||||||
|
// set path if available
|
||||||
|
folder.parseAndSetPath(jsonObject);
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,10 +124,18 @@ public class FavouriteFolder extends FavouriteNode implements ExpectedComparison
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "Folder [nodeId=" + nodeId + ", guid=" + guid + ", name=" + name
|
final StringBuilder sb = new StringBuilder(250);
|
||||||
+ ", title=" + title + ", description=" + description
|
sb.append("FavouriteFolder [nodeId=").append(nodeId)
|
||||||
+ ", createdAt=" + createdAt + ", modifiedAt=" + modifiedAt
|
.append(", guid=").append(guid)
|
||||||
+ ", createdBy=" + createdBy + ", modifiedBy=" + modifiedBy
|
.append(", name=").append(name)
|
||||||
+ "]";
|
.append(", title=").append(title)
|
||||||
|
.append(", description=").append(description)
|
||||||
|
.append(", createdAt=").append(createdAt)
|
||||||
|
.append(", modifiedAt=").append(modifiedAt)
|
||||||
|
.append(", createdBy=").append(createdBy)
|
||||||
|
.append(", modifiedBy=").append(modifiedBy)
|
||||||
|
.append(", path=").append(path)
|
||||||
|
.append(']');
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -29,8 +29,10 @@ package org.alfresco.rest.api.tests.client.data;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,6 +54,7 @@ public class FavouriteNode implements Serializable, ExpectedComparison
|
|||||||
protected Date modifiedAt;
|
protected Date modifiedAt;
|
||||||
protected String createdBy;
|
protected String createdBy;
|
||||||
protected String modifiedBy;
|
protected String modifiedBy;
|
||||||
|
protected PathInfo path;
|
||||||
|
|
||||||
public FavouriteNode()
|
public FavouriteNode()
|
||||||
{
|
{
|
||||||
@@ -173,6 +176,32 @@ public class FavouriteNode implements Serializable, ExpectedComparison
|
|||||||
this.nodeId = nodeId;
|
this.nodeId = nodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PathInfo getPath()
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(PathInfo pathInfo)
|
||||||
|
{
|
||||||
|
this.path = pathInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void parseAndSetPath(JSONObject jsonObject) throws ParseException
|
||||||
|
{
|
||||||
|
if (jsonObject.get("path") != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PathInfo pathInfo = RestApiUtil.parsePojo("path", jsonObject, PathInfo.class);
|
||||||
|
this.setPath(pathInfo);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new ParseException(e.getMessage(), -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
@@ -229,15 +258,27 @@ public class FavouriteNode implements Serializable, ExpectedComparison
|
|||||||
}
|
}
|
||||||
AssertUtil.assertEquals("createdBy", createdBy, other.getCreatedBy());
|
AssertUtil.assertEquals("createdBy", createdBy, other.getCreatedBy());
|
||||||
AssertUtil.assertEquals("modifiedBy", modifiedBy, other.getModifiedBy());
|
AssertUtil.assertEquals("modifiedBy", modifiedBy, other.getModifiedBy());
|
||||||
|
if(path != null)
|
||||||
|
{
|
||||||
|
path.expected(other.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "Node [nodeId=" + nodeId + ", guid=" + guid + ", name=" + name
|
final StringBuilder sb = new StringBuilder(250);
|
||||||
+ ", title=" + title + ", description=" + description
|
sb.append("FavouriteNode [nodeId=").append(nodeId)
|
||||||
+ ", createdAt=" + createdAt + ", modifiedAt=" + modifiedAt
|
.append(", guid=").append(guid)
|
||||||
+ ", createdBy=" + createdBy + ", modifiedBy=" + modifiedBy
|
.append(", name=").append(name)
|
||||||
+ "]";
|
.append(", title=").append(title)
|
||||||
|
.append(", description=").append(description)
|
||||||
|
.append(", createdAt=").append(createdAt)
|
||||||
|
.append(", modifiedAt=").append(modifiedAt)
|
||||||
|
.append(", createdBy=").append(createdBy)
|
||||||
|
.append(", modifiedBy=").append(modifiedBy)
|
||||||
|
.append(", path=").append(path)
|
||||||
|
.append(']');
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user