Search in sources :

Example 16 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getAllVersions.

@Override
public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter, Boolean includeAllowableActions, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    if (versionSeriesId == null && objectId != null) {
        // it's a browser binding call
        versionSeriesId = connector.getCurrentVersionId(objectId);
    }
    if (versionSeriesId == null) {
        throw new CmisInvalidArgumentException("Object Id or Object Series Id must be set!");
    }
    List<ObjectData> result = new ArrayList<ObjectData>();
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(versionSeriesId, "Version Series");
    if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
        // document
        throw new CmisInvalidArgumentException("Version Series does not exist!");
    }
    // get current version and it's history
    NodeRef nodeRef = info.getNodeRef();
    VersionHistory versionHistory = ((CMISNodeInfoImpl) info).getVersionHistory();
    if (versionHistory == null) {
        // add current version
        result.add(connector.createCMISObject(info, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
        boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
        if (isObjectInfoRequired) {
            getObjectInfo(repositoryId, info.getObjectId(), IncludeRelationships.NONE);
        }
    } else {
        if (info.hasPWC()) {
            CMISNodeInfo pwcInfo = createNodeInfo(connector.getCheckOutCheckInService().getWorkingCopy(nodeRef));
            result.add(connector.createCMISObject(pwcInfo, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
            boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
            if (isObjectInfoRequired) {
                getObjectInfo(repositoryId, pwcInfo.getObjectId(), IncludeRelationships.NONE);
            }
        }
        // convert the version history
        for (Version version : versionHistory.getAllVersions()) {
            // TODO do we need to check existence ?
            CMISNodeInfo versionInfo = createNodeInfo(version.getFrozenStateNodeRef(), versionHistory, true);
            // MNT-9557 fix. Replace head version with current node info
            if (versionHistory.getHeadVersion().equals(version)) {
                versionInfo = createNodeInfo(nodeRef);
            }
            result.add(connector.createCMISObject(versionInfo, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
            boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
            if (isObjectInfoRequired) {
                getObjectInfo(repositoryId, versionInfo.getObjectId(), IncludeRelationships.NONE);
            }
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) CmisVersion(org.apache.chemistry.opencmis.commons.enums.CmisVersion) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 17 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getTypeDescendants.

@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
    // check depth
    int d = (depth == null ? -1 : depth.intValue());
    if (d == 0) {
        throw new CmisInvalidArgumentException("Depth must not be 0!");
    }
    if (typeId == null) {
        for (TypeDefinitionWrapper tdw : connector.getOpenCMISDictionaryService().getBaseTypes(true)) {
            result.add(getTypesDescendants(d, tdw, includePropertyDefinitions));
        }
    } else {
        TypeDefinitionWrapper tdw = connector.getOpenCMISDictionaryService().findType(typeId);
        if (tdw == null) {
            throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
        }
        List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId);
        if (children != null) {
            for (TypeDefinitionWrapper child : children) {
                result.add(getTypesDescendants(d, child, includePropertyDefinitions));
            }
        }
    }
    return result;
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) ArrayList(java.util.ArrayList) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer)

Example 18 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method checkOut.

// --- versioning service ---
@Override
public void checkOut(String repositoryId, final Holder<String> objectId, ExtensionsData extension, final Holder<Boolean> contentCopied) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    // Check for current version
    if (info.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
    // Good
    } else if (info.isVariant(CMISObjectVariant.VERSION)) {
        throw new CmisInvalidArgumentException("Can't check out an old version of a document");
    } else {
        throw new CmisInvalidArgumentException("Only documents can be checked out! Object was a " + info.getObjectVariant().toString());
    }
    // get object
    final NodeRef nodeRef = info.getNodeRef();
    if (!((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).isVersionable()) {
        throw new CmisConstraintException("Document is not versionable!");
    }
    // check out
    NodeRef pwcNodeRef = connector.getCheckOutCheckInService().checkout(nodeRef);
    CMISNodeInfo pwcNodeInfo = createNodeInfo(pwcNodeRef);
    objectId.setValue(pwcNodeInfo.getObjectId());
    if (contentCopied != null) {
        contentCopied.setValue(connector.getFileFolderService().getReader(pwcNodeRef) != null);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 19 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method appendContentStream.

@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken, ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) {
    if ((contentStream == null) || (contentStream.getStream() == null)) {
        throw new CmisInvalidArgumentException("No content!");
    }
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    NodeRef nodeRef = info.getNodeRef();
    if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
        throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
    }
    // ALF-21852 - Separated appendContent and objectId.setValue in two different transactions because
    // after executing appendContent, the new objectId is not visible.
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    helper.doInTransaction(new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            try {
                connector.appendContent(info, contentStream, isLastChunk);
            } catch (IOException e) {
                throw new ContentIOException("", e);
            }
            return null;
        }
    }, false, true);
    String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {

        public String execute() throws Throwable {
            return connector.createObjectId(nodeRef);
        }
    }, true, true);
    objectId.setValue(objId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) IOException(java.io.IOException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Example 20 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method setContentStream.

@Override
public void setContentStream(String repositoryId, Holder<String> objectId, Boolean overwriteFlag, Holder<String> changeToken, final ContentStream contentStream, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC)) {
        throw new CmisStreamNotSupportedException("Content can only be set on private working copies or current versions.");
    }
    final NodeRef nodeRef = info.getNodeRef();
    if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
        throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
    }
    boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
    if (existed && !overwriteFlag) {
        throw new CmisContentAlreadyExistsException("Content already exists!");
    }
    if ((contentStream == null) || (contentStream.getStream() == null)) {
        throw new CmisInvalidArgumentException("No content!");
    }
    // ALF-21852 - Separated setContent and objectId.setValue in two different transactions because
    // after executing setContent, the new objectId is not visible.
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    helper.doInTransaction(new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            String mimeType = parseMimeType(contentStream);
            String encoding = getEncoding(contentStream.getStream(), mimeType);
            ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
            writer.setMimetype(mimeType);
            writer.setEncoding(encoding);
            writer.putContent(contentStream.getStream());
            connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
            return null;
        }
    }, false, true);
    String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {

        public String execute() throws Throwable {
            return connector.createObjectId(nodeRef);
        }
    }, true, true);
    objectId.setValue(objId);
}
Also used : CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Aggregations

CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)42 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)12 ArrayList (java.util.ArrayList)11 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)10 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)9 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)8 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)6 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)6 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)6 List (java.util.List)5 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)5 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)5 IOException (java.io.IOException)4 QName (org.alfresco.service.namespace.QName)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4