use of org.apache.chemistry.opencmis.commons.data.PropertyData in project alfresco-repository by Alfresco.
the class CMISTest method testCheckIn.
/**
* Test for MNT-9203.
*/
@Test
public void testCheckIn() {
String repositoryId = null;
ObjectData objectData = null;
Holder<String> objectId = null;
CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
final String folderName = "testfolder." + GUID.generate();
final String docName = "testdoc.txt." + GUID.generate();
final String customModel = "cmistest.model";
final QName testCustomTypeQName = QName.createQName(customModel, "sop");
final QName authorisedByQname = QName.createQName(customModel, "authorisedBy");
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {
@Override
public FileInfo execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, testCustomTypeQName);
Map<QName, Serializable> customProperties = new HashMap<QName, Serializable>();
customProperties.put(authorisedByQname, "customPropertyString");
customProperties.put(ContentModel.PROP_NAME, docName);
nodeService.setProperties(fileInfo.getNodeRef(), customProperties);
return fileInfo;
}
});
CmisService service = factory.getService(context);
try {
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
repositoryId = repo.getId();
objectData = service.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
// checkout
objectId = new Holder<String>(objectData.getId());
service.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
} finally {
service.close();
}
try {
service = factory.getService(context);
PropertyStringImpl prop = new PropertyStringImpl();
prop.setId("abc:" + authorisedByQname.toPrefixString());
prop.setValue(null);
Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
propsList.add(prop);
Properties properties = new PropertiesImpl(propsList);
// checkIn on pwc
service.checkIn(repositoryId, objectId, false, properties, null, null, null, null, null, null);
} finally {
service.close();
}
// check that value is null
assertTrue(nodeService.getProperty(fileInfo.getNodeRef(), authorisedByQname) == null);
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.data.PropertyData in project alfresco-repository by Alfresco.
the class CMISTest method testCancelCheckout.
/**
* Test for ALF-16310.
*
* Check that, for AtomPub binding, cancel checkout on the originating checked out document i.e. not the working
* copy throws an exception and does not delete the document.
*/
@SuppressWarnings("unchecked")
@Test
public void testCancelCheckout() {
final TestContext testContext = new TestContext();
final String folderName = "testfolder." + GUID.generate();
final String docName = "testdoc.txt." + GUID.generate();
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
final FileInfo folderInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {
@Override
public FileInfo execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
return folderInfo;
}
});
final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
testContext.setRepositoryId(repositoryId);
ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
testContext.setObjectData(objectData);
// checkout
Holder<String> objectId = new Holder<String>(objectData.getId());
testContext.setObjectId(objectId);
cmisService.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
return objectData;
}
});
// AtomPub cancel checkout
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
try {
// check allowable actions
ObjectData originalDoc = cmisService.getObject(testContext.getRepositoryId(), objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
AllowableActions allowableActions = originalDoc.getAllowableActions();
assertNotNull(allowableActions);
assertFalse(allowableActions.getAllowableActions().contains(Action.CAN_DELETE_OBJECT));
// try to cancel the checkout
cmisService.deleteObjectOrCancelCheckOut(testContext.getRepositoryId(), objectData.getId(), Boolean.TRUE, null);
fail();
} catch (CmisConstraintException e) {
// expected
}
return null;
}
});
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
// cancel checkout on pwc
cmisService.deleteObjectOrCancelCheckOut(testContext.getRepositoryId(), testContext.getObjectId().getValue(), Boolean.TRUE, null);
return null;
}
});
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
// get original document
ObjectData originalDoc = cmisService.getObject(testContext.getRepositoryId(), objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
Map<String, PropertyData<?>> properties = originalDoc.getProperties().getProperties();
PropertyData<Boolean> isVersionSeriesCheckedOutProp = (PropertyData<Boolean>) properties.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
assertNotNull(isVersionSeriesCheckedOutProp);
Boolean isVersionSeriesCheckedOut = isVersionSeriesCheckedOutProp.getFirstValue();
assertNotNull(isVersionSeriesCheckedOut);
assertEquals(Boolean.FALSE, isVersionSeriesCheckedOut);
return null;
}
});
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
// delete original document
cmisService.deleteObject(testContext.getRepositoryId(), objectData.getId(), true, null);
return null;
}
});
List<FileInfo> children = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<FileInfo>>() {
@Override
public List<FileInfo> execute() throws Throwable {
List<FileInfo> children = fileFolderService.list(folderInfo.getNodeRef());
return children;
}
});
assertEquals(0, children.size());
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.data.PropertyData in project alfresco-repository by Alfresco.
the class CMISConnector method setProperties.
/**
* Sets property values.
*/
@SuppressWarnings({ "rawtypes" })
public void setProperties(NodeRef nodeRef, TypeDefinitionWrapper type, Properties properties, String... exclude) {
if (properties == null) {
return;
}
Map<String, PropertyData<?>> incomingPropsMap = properties.getProperties();
if (incomingPropsMap == null) {
return;
}
// extract property data into an easier to use form
Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsMap = new HashMap<String, Pair<TypeDefinitionWrapper, Serializable>>();
for (String propertyId : incomingPropsMap.keySet()) {
PropertyData<?> property = incomingPropsMap.get(propertyId);
PropertyDefinitionWrapper propDef = type.getPropertyById(property.getId());
if (propDef == null) {
propDef = getOpenCMISDictionaryService().findProperty(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
}
}
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if (!isUpdatable(updatability, isOnWorkingCopy)) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
}
TypeDefinitionWrapper propType = propDef.getOwningType();
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
propsMap.put(propertyId, pair);
}
// Need to do deal with secondary types first
Pair<TypeDefinitionWrapper, Serializable> pair = propsMap.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
Serializable secondaryTypesProperty = (pair != null ? pair.getSecond() : null);
if (secondaryTypesProperty != null) {
if (!(secondaryTypesProperty instanceof List)) {
throw new CmisInvalidArgumentException("Secondary types must be a list!");
}
List secondaryTypes = (List) secondaryTypesProperty;
if (secondaryTypes != null && secondaryTypes.size() > 0) {
// add/remove secondary types/aspects
processSecondaryTypes(nodeRef, secondaryTypes, propsMap);
}
}
for (String propertyId : propsMap.keySet()) {
if (propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
// already handled above
continue;
}
pair = propsMap.get(propertyId);
TypeDefinitionWrapper propType = pair.getFirst();
Serializable value = pair.getSecond();
if (Arrays.binarySearch(exclude, propertyId) < 0) {
setProperty(nodeRef, propType, propertyId, value);
}
}
List<CmisExtensionElement> extensions = properties.getExtensions();
if (extensions != null) {
boolean isNameChanging = properties.getProperties().containsKey(PropertyIds.NAME);
for (CmisExtensionElement extension : extensions) {
if (ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace()) && SET_ASPECTS.equals(extension.getName())) {
setAspectProperties(nodeRef, isNameChanging, extension);
break;
}
}
}
}
Aggregations