use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testAspects.
@Test
public void testAspects() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final List<NodeRef> folders = new ArrayList<NodeRef>();
final List<NodeRef> documents = new ArrayList<NodeRef>();
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + System.currentTimeMillis();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
folders.add(folderNodeRef);
for (int i = 0; i < 3; i++) {
name = GUID.generate();
NodeRef docNodeRef = repoService.createDocument(folderNodeRef, name, "test content");
assertFalse(repoService.getAspects(docNodeRef).contains(ContentModel.ASPECT_TITLED));
documents.add(docNodeRef);
}
return null;
}
}, person1Id, network1.getId());
final NodeRef doc1NodeRef = documents.get(0);
final NodeRef doc2NodeRef = documents.get(1);
final NodeRef doc3NodeRef = documents.get(2);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
CmisSession atomCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
CmisSession browserCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11);
// Test that adding aspects works for both 1.0 and 1.1
// 1.0
{
AlfrescoDocument doc = (AlfrescoDocument) atomCmisSession10.getObject(doc1NodeRef.getId());
doc = (AlfrescoDocument) doc.addAspect("P:cm:titled");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc1NodeRef);
assertTrue("Missing aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
return null;
}
}, person1Id, network1.getId());
doc.removeAspect("P:cm:titled");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc1NodeRef);
assertFalse("Unexpected aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
return null;
}
}, person1Id, network1.getId());
}
// 1.1 atom (secondary types)
{
final Document doc = (Document) atomCmisSession11.getObject(doc2NodeRef.getId());
final List<SecondaryType> secondaryTypesList = doc.getSecondaryTypes();
final List<String> secondaryTypes = new ArrayList<String>();
if (secondaryTypesList != null) {
for (SecondaryType secondaryType : secondaryTypesList) {
secondaryTypes.add(secondaryType.getId());
}
}
secondaryTypes.add("P:sys:temporary");
secondaryTypes.add("P:cm:titled");
Map<String, Object> properties = new HashMap<String, Object>();
{
// create a document with 2 secondary types
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
}
Document doc1 = (Document) doc.updateProperties(properties);
checkSecondaryTypes(doc1, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled" })), null);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc2NodeRef);
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
return null;
}
}, person1Id, network1.getId());
secondaryTypes.add("P:cm:author");
properties = new HashMap<String, Object>();
{
// create a document with 2 secondary types
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
}
Document doc2 = (Document) doc1.updateProperties(properties);
checkSecondaryTypes(doc2, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled", "P:cm:author" })), null);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc2NodeRef);
String title = (String) repoService.getProperty(doc2NodeRef, ContentModel.PROP_TITLE);
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
assertEquals(null, title);
return null;
}
}, person1Id, network1.getId());
// remove a secondary type
secondaryTypes.remove("P:cm:titled");
properties = new HashMap<String, Object>();
{
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
}
Document doc3 = (Document) doc2.updateProperties(properties);
checkSecondaryTypes(doc3, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:author" })), new HashSet<String>(Arrays.asList(new String[] { "P:cm:titled" })));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc2NodeRef);
String title = (String) repoService.getProperty(doc2NodeRef, ContentModel.PROP_TITLE);
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
assertFalse("Unexpected aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
assertEquals(null, title);
return null;
}
}, person1Id, network1.getId());
}
// 1.1 browser (secondary types)
{
Document doc = (Document) browserCmisSession11.getObject(doc3NodeRef.getId());
final List<SecondaryType> secondaryTypesList = doc.getSecondaryTypes();
final List<String> secondaryTypes = new ArrayList<String>();
if (secondaryTypesList != null) {
for (SecondaryType secondaryType : secondaryTypesList) {
secondaryTypes.add(secondaryType.getId());
}
}
secondaryTypes.add("P:sys:temporary");
secondaryTypes.add("P:cm:titled");
Map<String, Object> properties = new HashMap<String, Object>();
{
// create a document with 2 secondary types
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
}
Document doc1 = (Document) doc.updateProperties(properties);
checkSecondaryTypes(doc1, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled" })), null);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc3NodeRef);
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
return null;
}
}, person1Id, network1.getId());
secondaryTypes.add("P:cm:author");
properties = new HashMap<String, Object>();
{
// create a document with 2 secondary types
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
}
Document doc2 = (Document) doc1.updateProperties(properties);
checkSecondaryTypes(doc2, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled", "P:cm:author" })), null);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc3NodeRef);
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
return null;
}
}, person1Id, network1.getId());
secondaryTypes.remove("P:cm:titled");
properties = new HashMap<String, Object>();
{
// create a document with 2 secondary types
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
}
Document doc3 = (Document) doc2.updateProperties(properties);
checkSecondaryTypes(doc3, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:author" })), new HashSet<String>(Arrays.asList(new String[] { "P:cm:titled" })));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Set<QName> aspects = repoService.getAspects(doc3NodeRef);
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
assertFalse("Unexpected aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
return null;
}
}, person1Id, network1.getId());
}
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testSecondaryTypes.
@Test
public void testSecondaryTypes() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
return folderNodeRef;
}
}, person1Id, network1.getId());
// Create a document...
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
String name = "mydoc-" + GUID.generate() + ".txt";
final List<String> secondaryTypes = new ArrayList<String>();
secondaryTypes.add("P:cm:summarizable");
Map<String, Object> properties = new HashMap<String, Object>();
{
// create a document with 2 aspects
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
properties.put("cm:summary", "My summary");
properties.put(PropertyIds.NAME, name);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
{
// check that the secondary types and properties are present
{
checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
String summary = (String) doc.getProperty("cm:summary").getFirstValue();
assertEquals("My summary", summary);
}
{
doc = (Document) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + name);
checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
String summary = (String) doc.getProperty("cm:summary").getFirstValue();
assertEquals("My summary", summary);
}
}
// update property and check
{
properties = new HashMap<String, Object>();
{
properties.put("cm:summary", "My updated summary");
}
doc.updateProperties(properties);
{
doc = (Document) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + name);
checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
String summary = (String) doc.getProperty("cm:summary").getFirstValue();
assertEquals("My updated summary", summary);
}
{
checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
String summary = (String) doc.getProperty("cm:summary").getFirstValue();
assertEquals("My updated summary", summary);
}
}
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT_13057.
@Test
public void testMNT_13057() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
String guid = GUID.generate();
String name = guid + "_KRUIS_LOGO_100%_PMS.txt";
String urlFileName = guid + "_KRUIS_LOGO_100%25_PMS.txt";
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
return folderNodeRef;
}
}, person1Id, network1.getId());
// Create a document...
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
Map<String, Object> properties = new HashMap<String, Object>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
/* Create document */
Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
String id = doc.getId();
assertNotNull(id);
Map<String, String> params = new HashMap<String, String>();
params.put("id", URLEncoder.encode(id));
urlFileName += "?id=" + URLEncoder.encode(id);
HttpResponse response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content/" + urlFileName, null);
assertEquals(200, response.getStatusCode());
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT_10687.
/* MNT-10687 related test - appendContent to PWC CMIS 1.1 */
@Test
public void testMNT_10687() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
return folderNodeRef;
}
}, person1Id, network1.getId());
// Create a document...
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
String name = "mydoc-" + GUID.generate() + ".txt";
Map<String, Object> properties = new HashMap<String, Object>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
/* Create document */
Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
/* Checkout document */
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
/* append content to PWC */
fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(" and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
pwc.appendContentStream(fileContent, true);
pwc.checkIn(false, null, null, "Check In");
ContentStream contentStream = doc.getObjectOfLatestVersion(false).getContentStream();
InputStream in = contentStream.getStream();
StringWriter writer = new StringWriter();
IOUtils.copy(in, writer, "UTF-8");
String content = writer.toString();
assertEquals("Ipsum and so on", content);
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testGetXmlWithIncorrectDescription.
/**
* 1) Creating a file with incorrect char in description property
* 2) Get xml with incorrect char in description
* 3) Check xml
* @throws Exception
*/
@Test
public void testGetXmlWithIncorrectDescription() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final String siteName = "site" + System.currentTimeMillis();
NodeRef fileNode = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
final TestSite site = network1.createSite(siteInfo);
NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "testdoc \u0010.txt", "Test Doc1 Title \u0010", "d\u0010", "Test Content");
return resNode;
}
}, person1Id, network1.getId());
String cmisId = fileNode.getId();
HashMap<String, String> reqParams = new HashMap<String, String>();
reqParams.put("id", cmisId + ";1.0");
reqParams.put("filter", "*");
reqParams.put("includeAllowableActions", "true");
reqParams.put("includeACL", "true");
reqParams.put("includePolicyIds", "true");
reqParams.put("includeRelationships", "both");
reqParams.put("renditionFilter", "*");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
HttpResponse resp = publicApiClient.get(Binding.atom, CMIS_VERSION_11, "id", reqParams);
String xml = resp.getResponse();
// Response hasn't full info at error - writer just stops at incorrect character.
// Therefore we can check end tag of root element
assertTrue("No end tag was found", xml.endsWith("</atom:entry>"));
}
Aggregations