use of org.apache.chemistry.opencmis.commons.data.PropertyData in project copper-cms by PogeyanOSS.
the class ServletHelpers method getStringPropertyValue.
/**
* Extracts a property from an object.
*/
static String getStringPropertyValue(ObjectData object, String name) {
if (object == null) {
return null;
}
Properties propData = object.getProperties();
if (propData == null) {
return null;
}
Map<String, PropertyData<?>> properties = propData.getProperties();
if (properties == null) {
return null;
}
PropertyData<?> property = properties.get(name);
if (property == null) {
return null;
}
Object value = property.getFirstValue();
if (!(value instanceof String)) {
return null;
}
return (String) value;
}
use of org.apache.chemistry.opencmis.commons.data.PropertyData in project structr by structr.
the class PropertyMap method cmisTypeToJavaType.
public static PropertyMap cmisTypeToJavaType(final SecurityContext securityContext, final Class type, final Properties properties) throws FrameworkException {
final Map<String, PropertyData<?>> map = properties.getProperties();
final ConfigurationProvider config = StructrApp.getConfiguration();
final PropertyMap propertyMap = new PropertyMap();
for (final Entry<String, PropertyData<?>> entry : map.entrySet()) {
final PropertyData<?> propertyValue = entry.getValue();
Object value = propertyValue.getFirstValue();
String key = entry.getKey();
// convert CMIS properties to Structr properties
if (CMIS_PROPERTY_MAPPING.containsKey(key)) {
key = CMIS_PROPERTY_MAPPING.get(key);
}
final PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, key);
if (propertyKey != null) {
final PropertyConverter converter = propertyKey.inputConverter(securityContext);
if (converter != null) {
value = converter.convert(value);
}
propertyMap.put(propertyKey, value);
} else {
throw new FrameworkException(500, "Invalid property key " + key + " for type " + type.getSimpleName() + " provided.");
}
}
return propertyMap;
}
use of org.apache.chemistry.opencmis.commons.data.PropertyData in project alfresco-repository by Alfresco.
the class CMISTest method testIsLatestMajorVersion.
/**
* MNT-10223
* Check the IsLatestMajorVersion for a doc with minor version.
*/
@SuppressWarnings("unused")
@Test
public void testIsLatestMajorVersion() {
final TestContext testContext = new TestContext();
// 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");
withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MINOR, null, null);
ObjectData cmidDoc = cmisService.getObject(repositoryId, objectId, null, true, IncludeRelationships.NONE, null, false, false, null);
List<PropertyData<?>> properties = cmidDoc.getProperties().getPropertyList();
boolean found = false;
PropertyData<?> propIsLatestMajorVersion = null;
for (PropertyData<?> property : properties) {
if (property.getId().equals(PropertyIds.IS_LATEST_MAJOR_VERSION)) {
found = true;
propIsLatestMajorVersion = property;
break;
}
}
// properties..contains(CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION);
assertTrue("The CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION property was not found", found);
if (found) {
assertFalse("The CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION should be false as minor version was created", (Boolean) propIsLatestMajorVersion.getValues().get(0));
}
return objectId;
}
});
}
use of org.apache.chemistry.opencmis.commons.data.PropertyData in project alfresco-repository by Alfresco.
the class CMISTest method testVersioningPropertiesHaveDefaultValue.
/**
* Test to ensure that versioning properties have default values defined in Alfresco content model.
* Testing <b>cm:initialVersion</b>, <b>cm:autoVersion</b> and <b>cm:autoVersionOnUpdateProps</b> properties
*
* @throws Exception
*/
@Test
public void testVersioningPropertiesHaveDefaultValue() throws Exception {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
// Create document via CMIS
final NodeRef documentNodeRef = withCmisService(new CmisServiceCallback<NodeRef>() {
@Override
public NodeRef execute(CmisService cmisService) {
String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
String rootNodeId = cmisService.getObjectByPath(repositoryId, "/", null, true, IncludeRelationships.NONE, null, false, true, null).getId();
Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
propsList.add(new PropertyStringImpl(PropertyIds.NAME, "Folder-" + GUID.generate()));
propsList.add(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"));
String folderId = cmisService.createFolder(repositoryId, new PropertiesImpl(propsList), rootNodeId, null, null, null, null);
propsList = new ArrayList<PropertyData<?>>();
propsList.add(new PropertyStringImpl(PropertyIds.NAME, "File-" + GUID.generate()));
propsList.add(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:document"));
String nodeId = cmisService.createDocument(repositoryId, new PropertiesImpl(propsList), folderId, null, null, null, null, null, null);
return new NodeRef(nodeId.substring(0, nodeId.indexOf(';')));
}
}, CmisVersion.CMIS_1_1);
// check versioning properties
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>() {
@Override
public List<Void> execute() throws Throwable {
assertTrue(nodeService.exists(documentNodeRef));
assertTrue(nodeService.hasAspect(documentNodeRef, ContentModel.ASPECT_VERSIONABLE));
AspectDefinition ad = dictionaryService.getAspect(ContentModel.ASPECT_VERSIONABLE);
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> properties = ad.getProperties();
for (QName qName : new QName[] { ContentModel.PROP_INITIAL_VERSION, ContentModel.PROP_AUTO_VERSION, ContentModel.PROP_AUTO_VERSION_PROPS }) {
Serializable property = nodeService.getProperty(documentNodeRef, qName);
assertNotNull(property);
org.alfresco.service.cmr.dictionary.PropertyDefinition pd = properties.get(qName);
assertNotNull(pd.getDefaultValue());
assertEquals(property, Boolean.parseBoolean(pd.getDefaultValue()));
}
return null;
}
});
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.data.PropertyData in project alfresco-repository by Alfresco.
the class CMISTest method setProperiesToObject.
private void setProperiesToObject(CmisService cmisService, String repositoryId, String objectIdStr, String propertyStr, BigInteger bigIntValue) throws CmisConstraintException {
Properties properties = cmisService.getProperties(repositoryId, objectIdStr, null, null);
PropertyIntegerImpl pd = (PropertyIntegerImpl) properties.getProperties().get(propertyStr);
pd.setValue(bigIntValue);
Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
propsList.add(pd);
Properties newProps = new PropertiesImpl(propsList);
cmisService.updateProperties(repositoryId, new Holder<String>(objectIdStr), null, newProps, null);
}
Aggregations