Search in sources :

Example 1 with CmisVersioningException

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

the class AlfrescoCmisServiceImpl method cancelCheckOut.

@Override
public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    // only accept a PWC
    if (!info.isVariant(CMISObjectVariant.PWC)) {
        NodeRef nodeRef = info.getNodeRef();
        NodeRef workingCopyNodeRef = connector.getCheckOutCheckInService().getWorkingCopy(nodeRef);
        info = getOrCreateNodeInfo(workingCopyNodeRef.getId());
        if (!info.isVariant(CMISObjectVariant.PWC)) {
            throw new CmisVersioningException("Object is not a PWC!");
        }
    }
    // get object
    final NodeRef nodeRef = info.getNodeRef();
    // cancel check out
    connector.getCheckOutCheckInService().cancelCheckout(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 2 with CmisVersioningException

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

the class AlfrescoCmisServiceImpl method checkIn.

@Override
public void checkIn(String repositoryId, final Holder<String> objectId, final Boolean major, final Properties properties, final ContentStream contentStream, final String checkinComment, final List<String> policies, final Acl addAces, final Acl removeAces, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    // only accept a PWC
    if (!info.isVariant(CMISObjectVariant.PWC)) {
        throw new CmisVersioningException("Object is not a PWC!");
    }
    // get object
    final NodeRef nodeRef = info.getNodeRef();
    final TypeDefinitionWrapper type = info.getType();
    // check in
    // update PWC
    connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.OBJECT_TYPE_ID });
    connector.applyPolicies(nodeRef, type, policies);
    connector.applyACL(nodeRef, type, addAces, removeAces);
    // handle content
    if (contentStream != null) {
        String mimeType = parseMimeType(contentStream);
        String encoding = getEncoding(contentStream.getStream(), mimeType);
        // write content
        ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
        writer.setMimetype(mimeType);
        writer.setEncoding(encoding);
        writer.putContent(contentStream.getStream());
    }
    // create version properties
    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(5);
    versionProperties.put(VersionModel.PROP_VERSION_TYPE, major ? VersionType.MAJOR : VersionType.MINOR);
    if (checkinComment != null) {
        versionProperties.put(VersionModel.PROP_DESCRIPTION, checkinComment);
    }
    // check in
    NodeRef newNodeRef = connector.getCheckOutCheckInService().checkin(nodeRef, versionProperties);
    connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), newNodeRef);
    objectId.setValue(connector.createObjectId(newNodeRef));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) Serializable(java.io.Serializable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Aggregations

CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 CmisVersioningException (org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1