Search in sources :

Example 11 with PropertyData

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;
}
Also used : PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) IUserObject(com.pogeyan.cmis.api.auth.IUserObject) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Example 12 with PropertyData

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;
}
Also used : PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) FrameworkException(org.structr.common.error.FrameworkException) ConfigurationProvider(org.structr.schema.ConfigurationProvider) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 13 with PropertyData

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;
        }
    });
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 14 with PropertyData

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();
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) Collection(java.util.Collection) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 15 with PropertyData

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);
}
Also used : PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Aggregations

PropertyData (org.apache.chemistry.opencmis.commons.data.PropertyData)18 ArrayList (java.util.ArrayList)9 List (java.util.List)7 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)6 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)6 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)6 CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 ObjectInFolderList (org.apache.chemistry.opencmis.commons.data.ObjectInFolderList)5 Properties (org.apache.chemistry.opencmis.commons.data.Properties)5 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)5 PropertiesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl)5 PropertyStringImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 Serializable (java.io.Serializable)3 Map (java.util.Map)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3