Search in sources :

Example 1 with CmisExtensionElementImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.

the class CMISConnector method createCMISObjectImpl.

@SuppressWarnings("unchecked")
private ObjectData createCMISObjectImpl(final CMISNodeInfo info, Properties nodeProps, String filter, boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, boolean includePolicyIds, boolean includeAcl) {
    final ObjectDataImpl result = new ObjectDataImpl();
    // set allowable actions
    if (includeAllowableActions) {
        result.setAllowableActions(getAllowableActions(info));
    }
    // set policy ids
    if (includePolicyIds) {
        result.setPolicyIds(new PolicyIdListImpl());
    }
    if (info.isRelationship()) {
        // set properties
        result.setProperties(getAssocProperties(info, filter));
        // set ACL
        if (includeAcl) {
            // association have no ACL - return an empty list of ACEs
            result.setAcl(new AccessControlListImpl((List<Ace>) Collections.EMPTY_LIST));
            result.setIsExactAcl(Boolean.FALSE);
        }
    } else {
        // set properties
        result.setProperties(nodeProps);
        // set relationships
        if (includeRelationships != IncludeRelationships.NONE) {
            result.setRelationships(getRelationships(info.getNodeRef(), includeRelationships));
        }
        // set renditions
        if (!RENDITION_NONE.equals(renditionFilter)) {
            List<RenditionData> renditions = getRenditions(info.getNodeRef(), renditionFilter, null, null);
            if ((renditions != null) && (!renditions.isEmpty())) {
                result.setRenditions(renditions);
            } else {
                result.setRenditions(Collections.EMPTY_LIST);
            }
        }
        // set ACL
        if (includeAcl) {
            AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    Acl acl = getACL(info.getCurrentNodeNodeRef(), false);
                    if (acl != null) {
                        result.setAcl(acl);
                        result.setIsExactAcl(acl.isExact());
                    }
                    return null;
                }
            });
        }
        // add aspects
        List<CmisExtensionElement> extensions = getAspectExtensions(info, filter, result.getProperties().getProperties().keySet());
        if (!extensions.isEmpty()) {
            result.getProperties().setExtensions(Collections.singletonList((CmisExtensionElement) new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, ASPECTS, null, extensions)));
        }
    }
    return result;
}
Also used : PolicyIdListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyIdListImpl) CapabilityAcl(org.apache.chemistry.opencmis.commons.enums.CapabilityAcl) Acl(org.apache.chemistry.opencmis.commons.data.Acl) ObjectDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) InvalidAspectException(org.alfresco.service.cmr.dictionary.InvalidAspectException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) AccessControlListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Example 2 with CmisExtensionElementImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.

the class CMISTest method testMNT9090.

@Test
public void testMNT9090() throws Exception {
    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();
                String folderName = GUID.generate();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                assertNotNull(folderInfo);
                String docName = GUID.generate();
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                assertNotNull(fileInfo);
                nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
                QName ASPECT_AUDIO = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "audio");
                Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
                nodeService.addAspect(fileInfo.getNodeRef(), ASPECT_AUDIO, aspectProperties);
                return fileInfo;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                // get repository id
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                String objectIdStr = fileInfo.getNodeRef().toString();
                Holder<String> objectId = new Holder<String>(objectIdStr);
                // try to overflow the value
                Object value = BigInteger.valueOf(Integer.MAX_VALUE + 1l);
                Properties properties = new PropertiesImpl();
                List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
                CmisExtensionElement valueElem = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "value", null, value.toString());
                List<CmisExtensionElement> valueElems = new ArrayList<CmisExtensionElement>();
                valueElems.add(valueElem);
                List<CmisExtensionElement> children = new ArrayList<CmisExtensionElement>();
                Map<String, String> attributes = new HashMap<String, String>();
                attributes.put("propertyDefinitionId", "audio:trackNumber");
                children.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "propertyInteger", attributes, valueElems));
                List<CmisExtensionElement> propertyValuesExtension = new ArrayList<CmisExtensionElement>();
                propertyValuesExtension.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.PROPERTIES, null, children));
                CmisExtensionElement setAspectsExtension = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.SET_ASPECTS, null, propertyValuesExtension);
                extensions.add(setAspectsExtension);
                properties.setExtensions(extensions);
                // should throw a CMISConstraintException
                cmisService.updateProperties(repositoryId, objectId, null, properties, null);
                fail();
                return null;
            }
        }, CmisVersion.CMIS_1_0);
    } catch (CmisConstraintException e) {
        assertTrue(e.getMessage().startsWith("Value is out of range for property"));
    // ok
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) Properties(org.apache.chemistry.opencmis.commons.data.Properties) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) 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) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) 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 3 with CmisExtensionElementImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.

the class CMISConnector method getAspectExtensions.

/**
 * Builds aspect extension.
 */
public List<CmisExtensionElement> getAspectExtensions(CMISNodeInfo info, String filter, Set<String> alreadySetProperties) {
    List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
    Set<String> propertyIds = new HashSet<String>(alreadySetProperties);
    List<CmisExtensionElement> propertyExtensionList = new ArrayList<CmisExtensionElement>();
    Set<String> filterSet = splitFilter(filter);
    Set<QName> aspects = info.getNodeAspects();
    for (QName aspect : aspects) {
        TypeDefinitionWrapper aspectType = getOpenCMISDictionaryService().findNodeType(aspect);
        if (aspectType == null) {
            continue;
        }
        AspectDefinition aspectDefinition = dictionaryService.getAspect(aspect);
        Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> aspectProperties = aspectDefinition.getProperties();
        extensions.add(new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, APPLIED_ASPECTS, null, aspectType.getTypeId()));
        for (PropertyDefinitionWrapper propDef : aspectType.getProperties()) {
            boolean addPropertyToExtensionList = getRequestCmisVersion().equals(CmisVersion.CMIS_1_1) && aspectProperties.keySet().contains(propDef.getAlfrescoName());
            // MNT-11876 : add property to extension even if it has been returned (CMIS 1.1)
            if (propertyIds.contains(propDef.getPropertyId()) && !addPropertyToExtensionList) {
                // skip properties that have already been added
                continue;
            }
            if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName()))) {
                // skip properties that are not in the filter
                continue;
            }
            Serializable value = propDef.getPropertyAccessor().getValue(info);
            propertyExtensionList.add(createAspectPropertyExtension(propDef.getPropertyDefinition(), value));
            // mark property as 'added'
            propertyIds.add(propDef.getPropertyId());
        }
    }
    if (!propertyExtensionList.isEmpty()) {
        CmisExtensionElementImpl propertiesExtension = new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, "properties", null, propertyExtensionList);
        extensions.addAll(Collections.singletonList(propertiesExtension));
    }
    return extensions;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ArrayList(java.util.ArrayList) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) HashSet(java.util.HashSet)

Example 4 with CmisExtensionElementImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.

the class CMISConnector method createAspectPropertyExtension.

/**
 * Creates a property extension element.
 */
@SuppressWarnings("rawtypes")
private CmisExtensionElement createAspectPropertyExtension(PropertyDefinition<?> propertyDefinition, Object value) {
    String name;
    switch(propertyDefinition.getPropertyType()) {
        case BOOLEAN:
            name = "propertyBoolean";
            break;
        case DATETIME:
            name = "propertyDateTime";
            break;
        case DECIMAL:
            name = "propertyDecimal";
            break;
        case INTEGER:
            name = "propertyInteger";
            break;
        case ID:
            name = "propertyId";
            break;
        default:
            name = "propertyString";
    }
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("propertyDefinitionId", propertyDefinition.getId());
    attributes.put("queryName", propertyDefinition.getQueryName());
    // optional value
    if (propertyDefinition.getDisplayName() != null && propertyDefinition.getDisplayName().trim().length() > 0) {
        attributes.put("displayName", propertyDefinition.getDisplayName());
    }
    // optional value
    if (propertyDefinition.getLocalName() != null && propertyDefinition.getLocalName().trim().length() > 0) {
        attributes.put("localName", propertyDefinition.getLocalName());
    }
    List<CmisExtensionElement> propertyValues = new ArrayList<CmisExtensionElement>();
    if (value != null) {
        if (value instanceof List) {
            for (Object o : ((List) value)) {
                if (o != null) {
                    propertyValues.add(new CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null, convertAspectPropertyValue(o)));
                } else {
                    logger.warn("Unexpected null entry in list value for property " + propertyDefinition.getDisplayName() + ", value = " + value);
                }
            }
        } else {
            propertyValues.add(new CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null, convertAspectPropertyValue(value)));
        }
    }
    return new CmisExtensionElementImpl(CMIS_NAMESPACE, name, attributes, propertyValues);
}
Also used : CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl)

Aggregations

ArrayList (java.util.ArrayList)4 CmisExtensionElement (org.apache.chemistry.opencmis.commons.data.CmisExtensionElement)4 CmisExtensionElementImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl)4 List (java.util.List)3 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)3 Serializable (java.io.Serializable)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 QName (org.alfresco.service.namespace.QName)2 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)2 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)1 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)1 PropertyDefinitionWrapper (org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper)1 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)1