use of org.alfresco.repo.service.ServiceDescriptorRegistry in project alfresco-remote-api by Alfresco.
the class SharedLinkApiTest method testSharedLinkFindIncludeNodeProperties.
@Test
public void testSharedLinkFindIncludeNodeProperties() throws Exception {
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
ServiceDescriptorRegistry serviceRegistry = applicationContext.getBean("ServiceRegistry", ServiceDescriptorRegistry.class);
SearchService mockSearchService = mock(SearchService.class);
serviceRegistry.setMockSearchService(mockSearchService);
// As user 1 ...
setRequestContext(user1);
Paging paging = getPaging(0, 100);
String content = "The quick brown fox jumps over the lazy dog.";
String fileName1 = "fileOne_" + RUNID + ".txt";
String fileName2 = "fileTwo_" + RUNID + ".txt";
// As user 1 create 2 text files in -my- folder (i.e. User's Home)
setRequestContext(user1);
Map<String, String> file1Props = new HashMap<>();
file1Props.put("cm:title", "File one title");
file1Props.put("cm:lastThumbnailModification", "doclib:1549351708998");
String file1Id = createTextFile(getMyNodeId(), fileName1, content, "UTF-8", file1Props).getId();
String file2Id = createTextFile(getMyNodeId(), fileName2, content).getId();
// Create shared links to file 1 and 2
QuickShareLink body = new QuickShareLink();
body.setNodeId(file1Id);
HttpResponse response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String shared1Id = resp.getId();
body = new QuickShareLink();
body.setNodeId(file2Id);
post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
// Lock text file 1
LockInfo lockInfo = new LockInfo();
lockInfo.setTimeToExpire(60);
lockInfo.setType("FULL");
lockInfo.setLifetime("PERSISTENT");
post(getNodeOperationUrl(file1Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
// Find shared links without include=properties
ResultSet mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
when(mockSearchService.query(any())).thenReturn(mockResultSet);
quickShareLinks.afterPropertiesSet();
response = getAll(URL_SHARED_LINKS, paging, null, 200);
List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
QuickShareLink resQuickShareLink1 = sharedLinks.get(0);
QuickShareLink resQuickShareLink2 = sharedLinks.get(1);
assertNull("Properties were not requested therefore they should not be included", resQuickShareLink1.getProperties());
assertNull("Properties were not requested therefore they should not be included", resQuickShareLink2.getProperties());
// Find the shared links with include=properties
mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
when(mockSearchService.query(any())).thenReturn(mockResultSet);
quickShareLinks.afterPropertiesSet();
Map<String, String> params = new HashMap<>();
params.put("include", "properties,allowableOperations");
response = getAll(URL_SHARED_LINKS, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
resQuickShareLink1 = sharedLinks.get(0);
// Check the 1st shared link and properties (properties should include a title, lastThumbnailModification and lock info)
assertEquals(shared1Id, resQuickShareLink1.getId());
assertEquals(file1Id, resQuickShareLink1.getNodeId());
Map<String, Object> resQuickShareLink1Props = resQuickShareLink1.getProperties();
assertNotNull("Properties were requested to be included but are null.", resQuickShareLink1Props);
assertNotNull("Properties should include cm:lockType", resQuickShareLink1Props.get("cm:lockType"));
assertNotNull("Properties should include cm:lockOwner", resQuickShareLink1Props.get("cm:lockOwner"));
assertNotNull("Properties should include cm:lockLifetime", resQuickShareLink1Props.get("cm:lockLifetime"));
assertNotNull("Properties should include cm:title", resQuickShareLink1Props.get("cm:title"));
assertNotNull("Properties should include cm:versionType", resQuickShareLink1Props.get("cm:versionType"));
assertNotNull("Properties should include cm:versionLabel", resQuickShareLink1Props.get("cm:versionLabel"));
assertNotNull("Properties should include cm:lastThumbnailModification", resQuickShareLink1Props.get("cm:lastThumbnailModification"));
// Properties that should be excluded
assertNull("Properties should NOT include cm:name", resQuickShareLink1Props.get("cm:name"));
assertNull("Properties should NOT include qshare:sharedBy", resQuickShareLink1Props.get("qshare:sharedBy"));
assertNull("Properties should NOT include qshare:sharedId", resQuickShareLink1Props.get("qshare:sharedId"));
assertNull("Properties should NOT include cm:content", resQuickShareLink1Props.get("cm:content"));
assertNull("Properties should NOT include cm:created", resQuickShareLink1Props.get("cm:created"));
assertNull("Properties should NOT include cm:creator", resQuickShareLink1Props.get("cm:creator"));
assertNull("Properties should NOT include cm:modifier", resQuickShareLink1Props.get("cm:modifier"));
assertNull("Properties should NOT include cm:modified", resQuickShareLink1Props.get("cm:modified"));
assertNull("Properties should NOT include cm:autoVersion", resQuickShareLink1Props.get("cm:autoVersion"));
assertNull("Properties should NOT include cm:initialVersion", resQuickShareLink1Props.get("cm:initialVersion"));
assertNull("Properties should NOT include cm:autoVersionOnUpdateProps", resQuickShareLink1Props.get("cm:autoVersionOnUpdateProps"));
// System properties should be excluded
boolean foundSysProp = resQuickShareLink1Props.keySet().stream().anyMatch((s) -> s.startsWith("sys:"));
assertFalse("System properties should be excluded", foundSysProp);
serviceRegistry.setMockSearchService(null);
quickShareLinks.afterPropertiesSet();
}
use of org.alfresco.repo.service.ServiceDescriptorRegistry in project alfresco-remote-api by Alfresco.
the class SharedLinkApiTest method testSharedLinkFindIncludeAspects.
@Test
public void testSharedLinkFindIncludeAspects() throws Exception {
PublicApiClient.Favourites favouritesProxy = publicApiClient.favourites();
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
ServiceDescriptorRegistry serviceRegistry = applicationContext.getBean("ServiceRegistry", ServiceDescriptorRegistry.class);
SearchService mockSearchService = mock(SearchService.class);
serviceRegistry.setMockSearchService(mockSearchService);
// As user 1 ...
setRequestContext(user1);
Paging paging = getPaging(0, 100);
String content = "The quick brown fox jumps over the lazy dog.";
String fileName1 = "fileOne_" + RUNID + ".txt";
String fileName2 = "fileTwo_" + RUNID + ".txt";
// As user 1 create 2 text files in -my- folder (i.e. User's Home)
setRequestContext(user1);
String file1Id = createTextFile(getMyNodeId(), fileName1, content).getId();
String file2Id = createTextFile(getMyNodeId(), fileName2, content).getId();
// Create shared links to file 1 and 2
QuickShareLink body = new QuickShareLink();
body.setNodeId(file1Id);
post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
body = new QuickShareLink();
body.setNodeId(file2Id);
post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
// Favourite file with file1Id file as user 1
Favourite file1Favourite = makeFileFavourite(file1Id);
favouritesProxy.createFavourite(user1, file1Favourite, null);
// Find shared links without include=isFavorite
ResultSet mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
when(mockSearchService.query(any())).thenReturn(mockResultSet);
quickShareLinks.afterPropertiesSet();
HttpResponse response = getAll(URL_SHARED_LINKS, paging, null, 200);
List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
QuickShareLink resQuickShareLink1 = sharedLinks.get(0);
QuickShareLink resQuickShareLink2 = sharedLinks.get(1);
assertNull("aspectNames was not requested therefore it should not be included", resQuickShareLink1.getAspectNames());
assertNull("aspectNames was not requested therefore it should not be included", resQuickShareLink2.getAspectNames());
// Find shared links with include=isFavorite
mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
when(mockSearchService.query(any())).thenReturn(mockResultSet);
quickShareLinks.afterPropertiesSet();
Map<String, String> params = new HashMap<>();
params.put("include", "aspectNames");
response = getAll(URL_SHARED_LINKS, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
resQuickShareLink1 = sharedLinks.get(0);
resQuickShareLink2 = sharedLinks.get(1);
assertNotNull("aspectNames was not requested therefore it should not be included", resQuickShareLink1.getAspectNames());
assertNotNull("aspectNames was not requested therefore it should not be included", resQuickShareLink2.getAspectNames());
serviceRegistry.setMockSearchService(null);
quickShareLinks.afterPropertiesSet();
}
use of org.alfresco.repo.service.ServiceDescriptorRegistry in project alfresco-remote-api by Alfresco.
the class SharedLinkApiTest method testSharedLinkFindIncludeIsFavorite.
@Test
public void testSharedLinkFindIncludeIsFavorite() throws Exception {
PublicApiClient.Favourites favouritesProxy = publicApiClient.favourites();
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
ServiceDescriptorRegistry serviceRegistry = applicationContext.getBean("ServiceRegistry", ServiceDescriptorRegistry.class);
SearchService mockSearchService = mock(SearchService.class);
serviceRegistry.setMockSearchService(mockSearchService);
// As user 1 ...
setRequestContext(user1);
Paging paging = getPaging(0, 100);
String content = "The quick brown fox jumps over the lazy dog.";
String fileName1 = "fileOne_" + RUNID + ".txt";
String fileName2 = "fileTwo_" + RUNID + ".txt";
// As user 1 create 2 text files in -my- folder (i.e. User's Home)
setRequestContext(user1);
String file1Id = createTextFile(getMyNodeId(), fileName1, content).getId();
String file2Id = createTextFile(getMyNodeId(), fileName2, content).getId();
// Create shared links to file 1 and 2
QuickShareLink body = new QuickShareLink();
body.setNodeId(file1Id);
post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
body = new QuickShareLink();
body.setNodeId(file2Id);
post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
// Favourite file with file1Id file as user 1
Favourite file1Favourite = makeFileFavourite(file1Id);
favouritesProxy.createFavourite(user1, file1Favourite, null);
// Find shared links without include=isFavorite
ResultSet mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
when(mockSearchService.query(any())).thenReturn(mockResultSet);
quickShareLinks.afterPropertiesSet();
HttpResponse response = response = getAll(URL_SHARED_LINKS, paging, null, 200);
List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
QuickShareLink resQuickShareLink1 = sharedLinks.get(0);
QuickShareLink resQuickShareLink2 = sharedLinks.get(1);
assertNull("isFavorite was not requested therefore it should not be included", resQuickShareLink1.getIsFavorite());
assertNull("isFavorite was not requested therefore it should not be included", resQuickShareLink2.getIsFavorite());
// Find shared links with include=isFavorite
mockResultSet = mockResultSet(Arrays.asList(file1Id, file2Id));
when(mockSearchService.query(any())).thenReturn(mockResultSet);
quickShareLinks.afterPropertiesSet();
Map<String, String> params = new HashMap<>();
params.put("include", "isFavorite");
response = getAll(URL_SHARED_LINKS, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
resQuickShareLink1 = sharedLinks.get(0);
resQuickShareLink2 = sharedLinks.get(1);
assertTrue("Document should be marked as favorite.", resQuickShareLink1.getIsFavorite());
assertFalse("Document should not be marked as favorite.", resQuickShareLink2.getIsFavorite());
serviceRegistry.setMockSearchService(null);
quickShareLinks.afterPropertiesSet();
}
Aggregations