Search in sources :

Example 16 with PropertyData

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();
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) 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 17 with PropertyData

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();
    }
}
Also used : PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) AllowableActions(org.apache.chemistry.opencmis.commons.data.AllowableActions) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) 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 18 with PropertyData

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;
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) AbstractPropertyData(org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyData) HashMap(java.util.HashMap) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) Updatability(org.apache.chemistry.opencmis.commons.enums.Updatability) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair)

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