use of org.alfresco.rest.api.tests.client.data.Favourite in project alfresco-remote-api by Alfresco.
the class TestFavourites method testPUBLICAPI156.
@Test
public void testPUBLICAPI156() throws Exception {
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// person1's public site
final TestSite publicSite1 = person1PublicSites.get(1);
// person1's folder
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file in the folder
final NodeRef nodeRef = person1PublicDocs.get(1);
final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
// invite to another user's public site
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(publicSite.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
// favourite other users site, folder and file
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
favouritesProxy.createFavourite(person14Id, folderFavourite);
expectedFavourites.add(folderFavourite);
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
favouritesProxy.createFavourite(person14Id, fileFavourite);
expectedFavourites.add(fileFavourite);
final Favourite siteFavourite = makeSiteFavourite(publicSite);
favouritesProxy.createFavourite(person14Id, siteFavourite);
expectedFavourites.add(siteFavourite);
final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
favouritesProxy.createFavourite(person14Id, siteFavourite1);
expectedFavourites.add(siteFavourite1);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// remove the folder and file
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
repoService.deleteNode(nodeRef);
repoService.deleteNode(folderNodeRef);
return null;
}
}, person11Id, network1.getId());
expectedFavourites.remove(folderFavourite);
expectedFavourites.remove(fileFavourite);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// GETs should not return the favourites nor error
{
try {
favouritesProxy.getFavourite(person14Id, folderFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
favouritesProxy.getFavourite(person14Id, fileFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person14Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
}
use of org.alfresco.rest.api.tests.client.data.Favourite in project alfresco-remote-api by Alfresco.
the class TestFavourites method testCreateAndGetFavouriteWithPath.
/**
* 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");
// person1's folder (Test Folder1)
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file in the site's document library (Test Doc1)
final NodeRef nodeRef1 = person1PublicDocs.get(0);
// a file (Test Doc2) in the folder (Test Folder1)
final NodeRef nodeRef2 = person1PublicDocs.get(1);
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// 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);
// Check the basic properties (REPO-2827)
assertEquals("Test Doc1", node.getName());
assertEquals("Test Doc1 Title", node.getTitle());
assertEquals("Test Doc1 Description", node.getDescription());
// 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"));
}
use of org.alfresco.rest.api.tests.client.data.Favourite in project alfresco-remote-api by Alfresco.
the class TestFavourites method testPUBLICAPI141.
@Test
public void testPUBLICAPI141() throws Exception {
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// person1's public site
final TestSite publicSite1 = person1PublicSites.get(1);
// person1's private site
final TestSite privateSite = person1PrivateSites.get(0);
// person1's folder
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file in the folder
final NodeRef nodeRef = person1PublicDocs.get(1);
final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
// invite to another user's public site
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(publicSite.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person12Id, siteMembershipRequest);
// favourite other users site, folder and file
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
favouritesProxy.createFavourite(person12Id, folderFavourite);
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
favouritesProxy.createFavourite(person12Id, fileFavourite);
final Favourite siteFavourite = makeSiteFavourite(publicSite);
favouritesProxy.createFavourite(person12Id, siteFavourite);
expectedFavourites.add(siteFavourite);
final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
favouritesProxy.createFavourite(person12Id, siteFavourite1);
expectedFavourites.add(siteFavourite1);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// move the folder and file to person1's private site
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
NodeRef documentLibraryNodeRef = privateSite.getContainerNodeRef("documentLibrary");
repoService.moveNode(folderNodeRef, documentLibraryNodeRef);
return null;
}
}, person11Id, network1.getId());
try {
favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
favouritesProxy.getFavourite(person12Id, fileFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// make the public sites private
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
publicSite.setSiteVisibility(SiteVisibility.PRIVATE);
publicSite1.setSiteVisibility(SiteVisibility.PRIVATE);
return null;
}
}, person11Id, network1.getId());
expectedFavourites.remove(siteFavourite1);
// Given that person2Id is still a member of 'publicSite', they should still have access and therefore
// it should show up in their favourites. But person2Id is not a member of 'publicSite1', they should
// not have access and therefore it should not show up in their favourites.
{
Favourite actual = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid());
siteFavourite.expected(actual);
try {
favouritesProxy.getFavourite(person12Id, siteFavourite1.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
}
use of org.alfresco.rest.api.tests.client.data.Favourite in project alfresco-remote-api by Alfresco.
the class TestFavourites method getFavourites.
private ListResponse<Favourite> getFavourites(String networkId, String runAsUserId, String personId, int skipCount, int maxItems, Integer total, Integer expectedTotal, TARGET_TYPE type) throws PublicApiException, ParseException {
publicApiClient.setRequestContext(new RequestContext(networkId, runAsUserId));
Paging paging = null;
if (total == null && expectedTotal == null) {
paging = getPaging(skipCount, maxItems);
} else {
paging = getPaging(skipCount, maxItems, total, expectedTotal);
}
Map<String, String> params = null;
if (type != null) {
params = Collections.singletonMap("where", "(EXISTS(target/" + type + "))");
}
ListResponse<Favourite> resp = favouritesProxy.getFavourites(personId, createParams(paging, params));
return resp;
}
use of org.alfresco.rest.api.tests.client.data.Favourite in project alfresco-remote-api by Alfresco.
the class TestFavourites method makeFileFavourite.
private Favourite makeFileFavourite(String targetGuid) throws ParseException {
FavouriteDocument document = new FavouriteDocument(targetGuid);
FileFavouriteTarget target = new FileFavouriteTarget(document);
Date creationData = new Date();
Favourite favourite = new Favourite(creationData, null, target);
return favourite;
}
Aggregations