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:
Jamal Kaabi-Mofrad
2017-05-15 15:29:26 +00:00
parent b69b6463c0
commit ea8994f297
8 changed files with 549 additions and 224 deletions

View File

@@ -1,28 +1,28 @@
/* /*
* #%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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api; package org.alfresco.rest.api;
import org.alfresco.rest.api.model.Favourite; import org.alfresco.rest.api.model.Favourite;
@@ -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);
} }

View File

@@ -1,24 +1,24 @@
/* /*
* #%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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
@@ -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);
target = new DocumentTarget(document); setPathInfo(document, parameters.getInclude());
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))
@@ -136,18 +141,18 @@ 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;
} }
@@ -178,58 +183,65 @@ public class FavouritesImpl implements Favourites
@Override @Override
public Favourite addFavourite(String personId, Favourite favourite) public Favourite addFavourite(String personId, Favourite favourite)
{ {
Favourite ret = null; Parameters parameters = getDefaultParameters(personId, null);
return addFavourite(personId, favourite, parameters);
}
personId = people.validatePerson(personId, true); @Override
Target target = favourite.getTarget(); public Favourite addFavourite(String personId, Favourite favourite, Parameters parameters)
if(target == null) {
{ Favourite ret = null;
throw new InvalidArgumentException("target is missing");
}
else if(target instanceof SiteTarget)
{
SiteTarget siteTarget = (SiteTarget)target;
String guid = siteTarget.getSite().getGuid();
SiteInfo siteInfo = sites.validateSite(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, guid));
NodeRef siteNodeRef = siteInfo.getNodeRef();
String siteId = siteInfo.getShortName();
try personId = people.validatePerson(personId, true);
{ Target target = favourite.getTarget();
PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef); if(target == null)
ret = getFavourite(personFavourite); {
} throw new InvalidArgumentException("target is missing");
catch(SiteDoesNotExistException e) }
{ else if(target instanceof SiteTarget)
throw new RelationshipResourceNotFoundException(personId, siteId); {
} SiteTarget siteTarget = (SiteTarget)target;
} String guid = siteTarget.getSite().getGuid();
else if(target instanceof DocumentTarget) SiteInfo siteInfo = sites.validateSite(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, guid));
{ NodeRef siteNodeRef = siteInfo.getNodeRef();
DocumentTarget documentTarget = (DocumentTarget)target; String siteId = siteInfo.getShortName();
NodeRef nodeRef = documentTarget.getFile().getGuid();
if(!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null))
{
throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
}
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
ret = getFavourite(personFavourite);
}
else if(target instanceof FolderTarget)
{
FolderTarget folderTarget = (FolderTarget)target;
NodeRef nodeRef = folderTarget.getFolder().getGuid();
if(!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), Collections.singleton(SiteModel.TYPE_SITE)))
{
throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
}
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef); try
ret = getFavourite(personFavourite); {
} PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
ret = getFavourite(personFavourite, parameters);
}
catch(SiteDoesNotExistException e)
{
throw new RelationshipResourceNotFoundException(personId, siteId);
}
}
else if(target instanceof DocumentTarget)
{
DocumentTarget documentTarget = (DocumentTarget)target;
NodeRef nodeRef = documentTarget.getFile().getGuid();
if(!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null))
{
throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
}
return ret; PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
ret = getFavourite(personFavourite, parameters);
}
else if(target instanceof FolderTarget)
{
FolderTarget folderTarget = (FolderTarget)target;
NodeRef nodeRef = folderTarget.getFolder().getGuid();
if(!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), Collections.singleton(SiteModel.TYPE_SITE)))
{
throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
}
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
ret = getFavourite(personFavourite, parameters);
}
return ret;
} }
@Override @Override
@@ -263,25 +275,33 @@ public class FavouritesImpl implements Favourites
throw new RelationshipResourceNotFoundException(personId, id); throw new RelationshipResourceNotFoundException(personId, id);
} }
} }
@Override
public Favourite getFavourite(String personId, String favouriteId) public Favourite getFavourite(String personId, String favouriteId)
{ {
NodeRef nodeRef = nodes.validateNode(favouriteId); Parameters parameters = getDefaultParameters(personId, favouriteId);
personId = people.validatePerson(personId, true); return getFavourite(personId, favouriteId, parameters);
PersonFavourite personFavourite = favouritesService.getFavourite(personId, nodeRef);
if(personFavourite != null)
{
Favourite favourite = getFavourite(personFavourite);
return favourite;
}
else
{
throw new RelationshipResourceNotFoundException(personId, favouriteId);
}
} }
@Override @Override
public Favourite getFavourite(String personId, String favouriteId, Parameters parameters)
{
NodeRef nodeRef = nodes.validateNode(favouriteId);
personId = people.validatePerson(personId, true);
PersonFavourite personFavourite = favouritesService.getFavourite(personId, nodeRef);
if(personFavourite != null)
{
Favourite favourite = getFavourite(personFavourite, parameters);
return favourite;
}
else
{
throw new RelationshipResourceNotFoundException(personId, favouriteId);
}
}
@Override
public CollectionWithPagingInfo<Favourite> getFavourites(String personId, final Parameters parameters) public CollectionWithPagingInfo<Favourite> getFavourites(String personId, final Parameters parameters)
{ {
personId = people.validatePerson(personId, true); personId = people.validatePerson(personId, true);
@@ -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;
} }
} }

View File

@@ -1,28 +1,28 @@
/* /*
* #%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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.people; package org.alfresco.rest.api.people;
import java.util.ArrayList; import java.util.ArrayList;
@@ -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);
} }
} }

View File

@@ -1,33 +1,34 @@
/* /*
* #%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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; 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;
@@ -59,13 +61,15 @@ import org.alfresco.rest.api.tests.client.PublicApiException;
import org.alfresco.rest.api.tests.client.RequestContext; import org.alfresco.rest.api.tests.client.RequestContext;
import org.alfresco.rest.api.tests.client.data.Comment; 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
{ {
@@ -291,7 +295,7 @@ public class TestFavourites extends EnterpriseTestApi
this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests(); this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests();
} }
private void sort(List<Favourite> favourites, final List<Pair<FavouritesService.SortFields, Boolean>> sortProps) private void sort(List<Favourite> favourites, final List<Pair<FavouritesService.SortFields, Boolean>> sortProps)
{ {
Comparator<Favourite> comparator = new Comparator<Favourite>() Comparator<Favourite> comparator = new Comparator<Favourite>()
{ {
@@ -501,7 +505,7 @@ public class TestFavourites extends EnterpriseTestApi
private Favourite makeFolderFavourite(String targetGuid) throws ParseException private Favourite makeFolderFavourite(String targetGuid) throws ParseException
{ {
FavouriteFolder folder = new FavouriteFolder(targetGuid); FavouriteFolder folder = new FavouriteFolder(targetGuid);
FolderFavouriteTarget target = new FolderFavouriteTarget(folder); FolderFavouriteTarget target = new FolderFavouriteTarget(folder);
Date creationData = new Date(); Date creationData = new Date();
Favourite favourite = new Favourite(creationData, null, target); Favourite favourite = new Favourite(creationData, null, target);
@@ -510,7 +514,7 @@ public class TestFavourites extends EnterpriseTestApi
private Favourite makeFileFavourite(String targetGuid) throws ParseException private Favourite makeFileFavourite(String targetGuid) throws ParseException
{ {
FavouriteDocument document = new FavouriteDocument(targetGuid); FavouriteDocument document = new FavouriteDocument(targetGuid);
FileFavouriteTarget target = new FileFavouriteTarget(document); FileFavouriteTarget target = new FileFavouriteTarget(document);
Date creationData = new Date(); Date creationData = new Date();
Favourite favourite = new Favourite(creationData, null, target); Favourite favourite = new Favourite(creationData, null, target);
@@ -613,7 +617,7 @@ public class TestFavourites extends EnterpriseTestApi
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
String siteGuid = person1PublicSites.get(0).getGuid(); String siteGuid = person1PublicSites.get(0).getGuid();
FavouriteDocument document = new FavouriteDocument(siteGuid); FavouriteDocument document = new FavouriteDocument(siteGuid);
Favourite favourite = makeFileFavourite(document.getGuid()); Favourite favourite = makeFileFavourite(document.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret); favourite.expected(ret);
@@ -630,7 +634,7 @@ public class TestFavourites extends EnterpriseTestApi
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
String siteGuid = person1PublicSites.get(0).getGuid(); String siteGuid = person1PublicSites.get(0).getGuid();
FavouriteFolder folder = new FavouriteFolder(siteGuid); FavouriteFolder folder = new FavouriteFolder(siteGuid);
Favourite favourite = makeFolderFavourite(folder.getGuid()); Favourite favourite = makeFolderFavourite(folder.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret); favourite.expected(ret);
@@ -647,7 +651,7 @@ public class TestFavourites extends EnterpriseTestApi
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteFolder folder = new FavouriteFolder(person1PublicDocs.get(0).getId()); FavouriteFolder folder = new FavouriteFolder(person1PublicDocs.get(0).getId());
Favourite favourite = makeFolderFavourite(folder.getGuid()); Favourite favourite = makeFolderFavourite(folder.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret); favourite.expected(ret);
@@ -664,7 +668,7 @@ public class TestFavourites extends EnterpriseTestApi
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteDocument document = new FavouriteDocument(person1PublicFolders.get(0).getId()); FavouriteDocument document = new FavouriteDocument(person1PublicFolders.get(0).getId());
Favourite favourite = makeFileFavourite(document.getGuid()); Favourite favourite = makeFileFavourite(document.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret); favourite.expected(ret);
@@ -684,8 +688,8 @@ public class TestFavourites extends EnterpriseTestApi
try try
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId());
Favourite favourite = makeFileFavourite(document.getGuid()); Favourite favourite = makeFileFavourite(document.getGuid());
favouritesProxy.createFavourite(person11Id, favourite); favouritesProxy.createFavourite(person11Id, favourite);
@@ -780,8 +784,8 @@ public class TestFavourites extends EnterpriseTestApi
try try
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteDocument document = new FavouriteDocument(GUID.generate()); FavouriteDocument document = new FavouriteDocument(GUID.generate());
Favourite favourite = makeFileFavourite(document.getGuid()); Favourite favourite = makeFileFavourite(document.getGuid());
favouritesProxy.createFavourite(person10Id, favourite); favouritesProxy.createFavourite(person10Id, favourite);
@@ -800,8 +804,8 @@ public class TestFavourites extends EnterpriseTestApi
try try
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteFolder folder = new FavouriteFolder(GUID.generate()); FavouriteFolder folder = new FavouriteFolder(GUID.generate());
Favourite favourite = makeFolderFavourite(folder.getGuid()); Favourite favourite = makeFolderFavourite(folder.getGuid());
favouritesProxy.createFavourite(person10Id, favourite); favouritesProxy.createFavourite(person10Id, favourite);
@@ -835,7 +839,7 @@ public class TestFavourites extends EnterpriseTestApi
} }
catch(PublicApiException e) catch(PublicApiException e)
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
} }
try try
@@ -852,10 +856,10 @@ public class TestFavourites extends EnterpriseTestApi
} }
catch(PublicApiException e) catch(PublicApiException e)
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
} }
FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId());
try try
{ {
@@ -889,8 +893,8 @@ public class TestFavourites extends EnterpriseTestApi
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} }
FavouriteFolder folder = new FavouriteFolder(person1PublicFolders.get(0).getId()); FavouriteFolder folder = new FavouriteFolder(person1PublicFolders.get(0).getId());
try try
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
@@ -958,11 +962,11 @@ public class TestFavourites extends EnterpriseTestApi
log("cloud-2467"); log("cloud-2467");
Favourite siteFavourite1 = makeSiteFavourite(person1PublicSites.get(0)); Favourite siteFavourite1 = makeSiteFavourite(person1PublicSites.get(0));
FavouriteDocument document = repoService.getDocument(network1.getId(), person1PublicDocs.get(0)); FavouriteDocument document = repoService.getDocument(network1.getId(), person1PublicDocs.get(0));
Favourite fileFavourite1 = makeFileFavourite(document.getGuid()); Favourite fileFavourite1 = makeFileFavourite(document.getGuid());
FavouriteFolder folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(0)); FavouriteFolder folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(0));
Favourite folderFavourite1 = makeFolderFavourite(folder.getGuid()); Favourite folderFavourite1 = makeFolderFavourite(folder.getGuid());
Favourite siteFavourite2 = makeSiteFavourite(person1PublicSites.get(1)); Favourite siteFavourite2 = makeSiteFavourite(person1PublicSites.get(1));
@@ -1091,7 +1095,7 @@ public class TestFavourites extends EnterpriseTestApi
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
FavouriteDocument document1 = new FavouriteDocument(person1PrivateDocs.get(0).getId()); FavouriteDocument document1 = new FavouriteDocument(person1PrivateDocs.get(0).getId());
Favourite favourite = makeFileFavourite(document1.getGuid()); Favourite favourite = makeFileFavourite(document1.getGuid());
try try
{ {
@@ -1123,7 +1127,7 @@ public class TestFavourites extends EnterpriseTestApi
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
FavouriteFolder folder1 = new FavouriteFolder(person1PrivateFolders.get(0).getId()); FavouriteFolder folder1 = new FavouriteFolder(person1PrivateFolders.get(0).getId());
Favourite favourite = makeFolderFavourite(folder1.getGuid()); Favourite favourite = makeFolderFavourite(folder1.getGuid());
try try
{ {
@@ -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";
}
} }

View File

@@ -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");

View File

@@ -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);
return document; // set path if available
} document.parseAndSetPath(jsonObject);
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();
}
} }

View File

@@ -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,8 +110,10 @@ 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);
return folder; // set path if available
} folder.parseAndSetPath(jsonObject);
return folder;
}
@Override @Override
public void expected(Object o) public void expected(Object o)
@@ -119,13 +121,21 @@ public class FavouriteFolder extends FavouriteNode implements ExpectedComparison
super.expected(o); super.expected(o);
} }
@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();
}
} }

View File

@@ -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,7 +176,33 @@ public class FavouriteNode implements Serializable, ExpectedComparison
this.nodeId = nodeId; this.nodeId = nodeId;
} }
@Override 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
public int hashCode() public int hashCode()
{ {
final int prime = 31; final int prime = 31;
@@ -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();
}
} }