use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testDeleteTree.
/**
* Test for MNT-13366.
*/
@Test
public void testDeleteTree() {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
FileInfo parentFolder = null;
FileInfo childFolder1 = null;
try {
// Create a parent folder: parentFolder:
String parentFolderName = "parentFolder" + GUID.generate();
parentFolder = createContent(parentFolderName, null, false);
final NodeRef parentFolderNodeRef = parentFolder.getNodeRef();
final String parentFolderID = parentFolderNodeRef.getId();
// Create a child folder: parentFolder -> childFolder1:
String childFolder1Name = "childFolder1" + GUID.generate();
childFolder1 = createContent(parentFolder, childFolder1Name, null, false);
final NodeRef childFolder1NodeRef = childFolder1.getNodeRef();
// Create a child folder for previous child folder, which will contain a file:
// parentFolder -> childFolder1 -> childFolder2 -> testdoc.txt
String childFolder2Name = "childFolder2" + GUID.generate();
String docName = "testdoc.txt" + GUID.generate();
final NodeRef childFolder2NodeRef = createContent(childFolder1, childFolder2Name, docName, false).getNodeRef();
// Store a reference to the file "testdoc.txt" contained by childFolder2:
List<FileInfo> childFolder2FileList = fileFolderService.list(childFolder2NodeRef);
final NodeRef childFolder2FileNodeRef = childFolder2FileList.get(0).getNodeRef();
List<RepositoryInfo> repositories = withCmisService(new CmisServiceCallback<List<RepositoryInfo>>() {
@Override
public List<RepositoryInfo> execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
return repositories;
}
});
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
final String repositoryId = repo.getId();
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
// CMIS delete tree:
FailedToDeleteData failedItems = cmisService.deleteTree(repositoryId, parentFolderID, Boolean.TRUE, UnfileObject.DELETE, Boolean.TRUE, null);
assertEquals(failedItems.getIds().size(), 0);
// Reference to the archive root node (the trash-can):
NodeRef archiveRootNode = nodeArchiveService.getStoreArchiveNode(repositoryHelper.getCompanyHome().getStoreRef());
// Get the archived ("canned") version of folders and file and check that hirarchy is correct:
// ArchiveRoot -> archivedParentFolder -> archivedChildFolder1 -> archivedChildFolder2 -> archivedChildFolder2File.
// Check parentFolder:
NodeRef archivedParentFolderNodeRef = nodeArchiveService.getArchivedNode(parentFolderNodeRef);
assertTrue(nodeService.getPrimaryParent(archivedParentFolderNodeRef).getParentRef().equals(archiveRootNode));
// Check childFolder1:
NodeRef archivedChildFolder1NodeRef = nodeArchiveService.getArchivedNode(childFolder1NodeRef);
assertTrue(nodeService.getPrimaryParent(archivedChildFolder1NodeRef).getParentRef().equals(archivedParentFolderNodeRef));
assertFalse(nodeService.getPrimaryParent(archivedChildFolder1NodeRef).getParentRef().equals(archiveRootNode));
// Check childFolder2:
NodeRef archivedChildFolder2NodeRef = nodeArchiveService.getArchivedNode(childFolder2NodeRef);
assertTrue(nodeService.getPrimaryParent(archivedChildFolder2NodeRef).getParentRef().equals(archivedChildFolder1NodeRef));
assertFalse(nodeService.getPrimaryParent(archivedChildFolder2NodeRef).getParentRef().equals(archiveRootNode));
// Check childFolder2's file ("testdoc.txt"):
NodeRef archivedChildFolder2FileNodeRef = nodeArchiveService.getArchivedNode(childFolder2FileNodeRef);
assertTrue(nodeService.getPrimaryParent(archivedChildFolder2FileNodeRef).getParentRef().equals(archivedChildFolder2NodeRef));
assertFalse(nodeService.getPrimaryParent(archivedChildFolder2FileNodeRef).getParentRef().equals(archiveRootNode));
return null;
}
});
} finally {
if (parentFolder != null && fileFolderService.exists(parentFolder.getNodeRef())) {
fileFolderService.delete(parentFolder.getNodeRef());
}
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method aPrivateCopyMustAllowTheAdditionOfAspects_CMIS_1_1_Version.
/**
* Related to REPO-4613.
* This test makes sure that once a copy is checked out, updateProperties method can be called
* and properly adds the new properties.
*/
@Test
public void aPrivateCopyMustAllowTheAdditionOfAspects_CMIS_1_1_Version() {
final String aspectName = "P:cm:summarizable";
final String propertyName = "cm:summary";
final String propertyValue = "My summary";
// get repository id
final String repositoryId = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
RepositoryInfo repo = repositories.get(0);
final String repositoryId = repo.getId();
return repositoryId;
}
}, CmisVersion.CMIS_1_1);
final Properties currentProperties = withCmisService(new CmisServiceCallback<Properties>() {
@Override
public Properties execute(CmisService cmisService) {
PropertiesImpl properties = new PropertiesImpl();
String objectTypeId = "cmis:document";
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, objectTypeId));
String fileName = "textFile" + GUID.generate();
properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, fileName));
final ContentStreamImpl contentStream = new ContentStreamImpl(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Simple text plain document");
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MAJOR, null, null);
final Holder<String> objectIdHolder = new Holder<String>(objectId);
cmisService.checkOut(repositoryId, objectIdHolder, null, null);
cmisService.getObject(repositoryId, objectIdHolder.getValue(), null, null, null, null, null, null, null);
properties = new PropertiesImpl();
properties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(aspectName)));
properties.addProperty(new PropertyStringImpl(propertyName, propertyValue));
cmisService.updateProperties(repositoryId, objectIdHolder, null, properties, null);
cmisService.checkIn(repositoryId, objectIdHolder, false, null, null, "checkin", null, null, null, null);
Properties propertiesValues = cmisService.getProperties(repositoryId, objectIdHolder.getValue(), null, null);
return propertiesValues;
}
}, CmisVersion.CMIS_1_1);
List<String> secondaryTypeIds = (List<String>) currentProperties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
assertTrue(secondaryTypeIds.contains(aspectName));
assertEquals(currentProperties.getProperties().get(propertyName).getValues().get(0), propertyValue);
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testContentMimeTypeDetection.
/**
* ALF-18006 Test content mimetype auto-detection into CmisStreamInterceptor when "Content-Type" is not defined.
*/
@Test
public void testContentMimeTypeDetection() {
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
FileFolderService ffs = serviceRegistry.getFileFolderService();
AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
final String isoEncoding = "ISO-8859-1";
final String utfEncoding = "UTF-8";
// get repository id
List<RepositoryInfo> repositories = withCmisService(new CmisServiceCallback<List<RepositoryInfo>>() {
@Override
public List<RepositoryInfo> execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
return repositories;
}
});
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
final String repositoryId = repo.getId();
// create simple text plain content
final PropertiesImpl properties = new PropertiesImpl();
String objectTypeId = "cmis:document";
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, objectTypeId));
String fileName = "textFile" + GUID.generate();
properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, fileName));
final ContentStreamImpl contentStream = new ContentStreamImpl(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Simple text plain document");
String objectId = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MAJOR, null, null);
return objectId;
}
});
final Holder<String> objectIdHolder = new Holder<String>(objectId);
final String path = "/" + fileName;
// create content stream with undefined mimetype and file name
{
final ContentStreamImpl contentStreamHTML = new ContentStreamImpl(null, null, "<html><head><title> Hello </title></head><body><p> Test html</p></body></html></body></html>");
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
cmisService.setContentStream(repositoryId, objectIdHolder, true, null, contentStreamHTML, null);
return null;
}
});
// check mimetype
ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
return cmisService.getObjectByPath(repositoryId, path, null, false, IncludeRelationships.NONE, null, false, false, null);
}
});
final String objectId1 = objectData.getId();
String contentType = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
String contentType = cmisService.getObjectInfo(repositoryId, objectId1).getContentType();
return contentType;
}
});
assertEquals("Mimetype is not defined correctly.", MimetypeMap.MIMETYPE_HTML, contentType);
// check that the encoding is detected correctly
checkEncoding(ffs, authenticationComponent, objectData, utfEncoding);
}
// create content stream with mimetype and encoding as UTF-8
{
String mimeType = MimetypeMap.MIMETYPE_TEXT_PLAIN + "; charset=" + isoEncoding;
// NOTE that we intentionally specify the wrong charset here.
// Alfresco will detect the encoding (as UTF-8 - given by the ContentStreamImpl constructor)
final ContentStreamImpl contentStreamHTML = new ContentStreamImpl(null, mimeType, "<html><head><title> Hello </title></head><body><p> Test html</p></body></html></body></html>");
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
Holder<String> latestObjectIdHolder = getHolderOfObjectOfLatestVersion(cmisService, repositoryId, objectIdHolder);
cmisService.setContentStream(repositoryId, latestObjectIdHolder, true, null, contentStreamHTML, null);
return null;
}
});
// check mimetype
final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
ObjectData objectData = cmisService.getObjectByPath(repositoryId, path, null, false, IncludeRelationships.NONE, null, false, false, null);
return objectData;
}
});
String contentType = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
String contentType = cmisService.getObjectInfo(repositoryId, objectData.getId()).getContentType();
return contentType;
}
});
assertEquals("Mimetype is not defined correctly.", MimetypeMap.MIMETYPE_TEXT_PLAIN, contentType);
// check that the encoding is detected correctly
checkEncoding(ffs, authenticationComponent, objectData, utfEncoding);
}
// create content stream with mimetype and encoding as ISO-8859-1
{
String mimeType = MimetypeMap.MIMETYPE_TEXT_PLAIN + "; charset=" + utfEncoding;
// NOTE that we intentionally specify the wrong charset here.
// Alfresco will detect the encoding (as ISO-8859-1 - given by the ContentStreamImpl with streams)
String content = "<html><head><title>aegif Mind Share Leader Generating New Paradigms by aegif corporation</title></head><body><p> Test html</p></body></html></body></html>";
byte[] buf = null;
try {
// set the encoding here for the content stream
buf = content.getBytes(isoEncoding);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
ByteArrayInputStream input = new ByteArrayInputStream(buf);
final ContentStream contentStreamHTML = new ContentStreamImpl(null, BigInteger.valueOf(buf.length), mimeType, input);
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
Holder<String> latestObjectIdHolder = getHolderOfObjectOfLatestVersion(cmisService, repositoryId, objectIdHolder);
cmisService.setContentStream(repositoryId, latestObjectIdHolder, true, null, contentStreamHTML, null);
return null;
}
});
// check mimetype
final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
ObjectData objectData = cmisService.getObjectByPath(repositoryId, path, null, false, IncludeRelationships.NONE, null, false, false, null);
return objectData;
}
});
String contentType = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
String contentType = cmisService.getObjectInfo(repositoryId, objectData.getId()).getContentType();
return contentType;
}
});
assertEquals("Mimetype is not defined correctly.", MimetypeMap.MIMETYPE_TEXT_PLAIN, contentType);
// check that the encoding is detected correctly
checkEncoding(ffs, authenticationComponent, objectData, isoEncoding);
}
// checkout/checkin object with mimetype and encoding
{
ObjectData objectDa = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
return cmisService.getObjectByPath(repositoryId, path, null, false, IncludeRelationships.NONE, null, false, false, null);
}
});
objectIdHolder.setValue(objectDa.getId());
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
cmisService.checkOut(repositoryId, objectIdHolder, null, new Holder<Boolean>());
return null;
}
});
String mimeType = MimetypeMap.MIMETYPE_HTML + "; charset=UTF-8";
final ContentStreamImpl contentStreamHTML = new ContentStreamImpl(null, mimeType, "<html><head><title> Hello </title></head><body><p> Test html</p></body></html></body></html>");
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
cmisService.checkIn(repositoryId, objectIdHolder, false, null, contentStreamHTML, "checkin", null, null, null, null);
return null;
}
});
// check mimetype
final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
ObjectData objectData = cmisService.getObjectByPath(repositoryId, path, null, false, IncludeRelationships.NONE, null, false, false, null);
return objectData;
}
});
String contentType = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
String contentType = cmisService.getObjectInfo(repositoryId, objectData.getId()).getContentType();
return contentType;
}
});
assertEquals("Mimetype is not defined correctly.", MimetypeMap.MIMETYPE_HTML, contentType);
checkEncoding(ffs, authenticationComponent, objectData, utfEncoding);
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method getAllVersionsWithNullObjectId.
/*
* REPO-3627 / MNT-19630: CMIS: Unable to call getAllVersions() if node is checked out and if binding type is WSDL
*
* For WS binding the getAllVersions call is made with null objectId
*/
@Test
public void getAllVersionsWithNullObjectId() {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// Create folder with file
String folderName = "testfolder" + GUID.generate();
String docName = "testdoc.txt" + GUID.generate();
NodeRef folderRef = createContent(folderName, docName, false).getNodeRef();
List<FileInfo> folderFileList = fileFolderService.list(folderRef);
final NodeRef fileRef = folderFileList.get(0).getNodeRef();
// Create new version for file
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// create a new version
versionService.createVersion(fileRef, null);
return null;
}
});
// Checkout document and get all versions
List<ObjectData> versions = withCmisService(new CmisServiceCallback<List<ObjectData>>() {
@Override
public List<ObjectData> execute(CmisService cmisService) {
String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
// Checkout
Holder<String> objectId = new Holder<String>(objectData.getId());
cmisService.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
// Call get all versions with null objectId
List<ObjectData> versions = cmisService.getAllVersions(repositoryId, null, fileRef.toString(), null, null, null);
return versions;
}
});
// Check that the correct versions are retrieved
assertEquals(2, versions.size());
assertEquals(versions.get(0).getProperties().getProperties().get("cmis:versionLabel").getFirstValue(), "pwc");
assertEquals(versions.get(1).getProperties().getProperties().get("cmis:versionLabel").getFirstValue(), "0.1");
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testACE3322.
/**
* ACE-3322
*/
@Test
public void testACE3322() {
final String[] types = { "cmis:document", "cmis:relationship", "cmis:folder", "cmis:item" };
CmisServiceCallback<String> callback = new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
for (int i = 0; i < types.length; i++) {
List<TypeDefinitionWrapper> baseTypes = cmisDictionaryService.getBaseTypes();
assertNotNull(baseTypes);
checkDefs(baseTypes);
List<TypeDefinitionWrapper> children = cmisDictionaryService.getChildren(types[i]);
assertNotNull(children);
// Check that children were updated
checkDefs(children);
}
return "";
}
private void checkDefs(List<TypeDefinitionWrapper> defs) {
for (TypeDefinitionWrapper def : defs) {
assertNotNull("Type definition was not updated. Please refer to ACE-3322", def.getTypeDefinition(false).getDisplayName());
assertNotNull("Type definition was not updated. Please refer to ACE-3322", def.getTypeDefinition(false).getDescription());
// Check that property's display name and description were updated
for (PropertyDefinitionWrapper property : def.getProperties()) {
assertNotNull("Display name is null", property.getPropertyDefinition().getDisplayName());
assertNotNull("Description is null", property.getPropertyDefinition().getDescription());
}
}
}
};
withCmisService(callback, CmisVersion.CMIS_1_1);
}
Aggregations