Search in sources :

Example 1 with BaseTypeId

use of org.apache.chemistry.opencmis.commons.enums.BaseTypeId in project copper-cms by PogeyanOSS.

the class ServletHelpers method postToBaseMessage.

static BaseMessage postToBaseMessage(POSTHttpServletRequestWrapper request, String[] pathFragments, IUserObject userObject) {
    PostRequest postRequest = new PostRequest();
    ControlParser controlParser = new ControlParser(request);
    if (controlParser != null) {
        CmisRequestParameter requestParameter = new CmisRequestParameter();
        postRequest.setPropertyData(controlParser.getProperties());
        postRequest.setAddAcl(requestParameter.createAddAcl(controlParser, postRequest));
        postRequest.setRemoveAcl(requestParameter.createRemoveAcl(controlParser, postRequest));
        postRequest.setPolicies(requestParameter.createPolicies(controlParser, postRequest));
        postRequest.setMultipart(request.isMultiPart());
        postRequest.setContentStream(requestParameter.createContentStream(request));
        postRequest.setObjectIds(requestParameter.getObjectIds(controlParser, postRequest));
        postRequest.setChangeTokens(requestParameter.getChangeTokens(controlParser, postRequest));
        postRequest.setAddSecondaryTypes(requestParameter.addSecondaryTypes(controlParser, postRequest));
        postRequest.setRemoveSecondaryTypes(requestParameter.getChangeTokens(controlParser, postRequest));
        postRequest.setPolicyId(requestParameter.getPolicyId(controlParser, postRequest));
        postRequest.setAclPropagation(requestParameter.getAclPropagation(controlParser, postRequest));
    }
    postRequest.setParameterMap(request.getParameterMap());
    postRequest.setBaseUrl((String) request.getAttribute(BrowserConstants.BASE_URL_ATTRIBUTE));
    postRequest.setScheme(request.getScheme());
    postRequest.setServerName(request.getServerName());
    postRequest.setServerPort(request.getServerPort());
    postRequest.setContextPath(request.getContextPath());
    postRequest.setServletPath(request.getServletPath());
    String cmisAction = HttpUtils.getStringParameter(request, BrowserConstants.CONTROL_CMISACTION);
    postRequest.setCmisAction(cmisAction);
    String objectId = HttpUtils.getStringParameter(request, BrowserConstants.CONTROL_OBJECT_ID);
    postRequest.setObjectId(objectId);
    if (pathFragments.length > 0) {
        postRequest.setRepositoryId(pathFragments[0]);
        if (objectId != null) {
            ObjectData object = ServletHelpers.getObjectDataFor(pathFragments[0], objectId, pathFragments);
            String typeId = getStringPropertyValue(object, PropertyIds.OBJECT_TYPE_ID);
            postRequest.setTypeId(typeId);
            BaseTypeId baseTypeId = BaseTypeId.fromValue(getStringPropertyValue(object, PropertyIds.BASE_TYPE_ID));
            postRequest.setBaseTypeId(baseTypeId);
        }
    }
    String token = HttpUtils.getStringParameter(request, BrowserConstants.CONTROL_TOKEN);
    postRequest.setToken(token);
    postRequest.setRequestBody(request.getRequestBody());
    if (cmisAction == null || cmisAction.length() == 0) {
        throw new CmisNotSupportedException("Unknown action");
    }
    postRequest.setPathFragments(pathFragments);
    if (userObject != null) {
        postRequest.setUserName(userObject.getUserDN());
        postRequest.setUserObject(userObject);
    }
    BaseMessage bm = BaseMessage.create("", cmisAction, postRequest);
    return bm;
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) PostRequest(com.pogeyan.cmis.api.messages.PostRequest) BaseMessage(com.pogeyan.cmis.api.BaseMessage) ControlParser(com.pogeyan.cmis.browser.shared.ControlParser) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CmisRequestParameter(com.pogeyan.cmis.browser.shared.CmisRequestParameter)

Example 2 with BaseTypeId

use of org.apache.chemistry.opencmis.commons.enums.BaseTypeId in project structr by structr.

the class CMISObjectWrapper method wrap.

// ----- public static methods -----
public static CMISObjectWrapper wrap(final GraphObject source, final String propertyFilter, final Boolean includeAllowableActions) throws FrameworkException {
    CMISObjectWrapper wrapper = null;
    if (source != null) {
        final CMISInfo cmisInfo = source.getCMISInfo();
        if (cmisInfo != null) {
            final BaseTypeId baseTypeId = cmisInfo.getBaseTypeId();
            if (baseTypeId != null) {
                switch(baseTypeId) {
                    case CMIS_DOCUMENT:
                        wrapper = new CMISDocumentWrapper(propertyFilter, includeAllowableActions);
                        wrapper.initializeFrom(cmisInfo.getDocumentInfo());
                        break;
                    case CMIS_FOLDER:
                        wrapper = new CMISFolderWrapper(propertyFilter, includeAllowableActions);
                        wrapper.initializeFrom(cmisInfo.getFolderInfo());
                        break;
                    case CMIS_ITEM:
                        wrapper = new CMISItemWrapper(propertyFilter, includeAllowableActions);
                        wrapper.initializeFrom(cmisInfo.getItemInfo());
                        break;
                    case CMIS_POLICY:
                        wrapper = new CMISPolicyWrapper(propertyFilter, includeAllowableActions);
                        wrapper.initializeFrom(cmisInfo.getPolicyInfo());
                        break;
                    case CMIS_RELATIONSHIP:
                        wrapper = new CMISRelationshipWrapper(propertyFilter, includeAllowableActions);
                        wrapper.initializeFrom(cmisInfo.getRelationshipInfo());
                        break;
                    case CMIS_SECONDARY:
                        wrapper = new CMISSecondaryWrapper(propertyFilter, includeAllowableActions);
                        wrapper.initializeFrom(cmisInfo.getSecondaryInfo());
                        break;
                }
            }
        }
    }
    return wrapper;
}
Also used : CMISInfo(org.structr.cmis.CMISInfo) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId)

Example 3 with BaseTypeId

use of org.apache.chemistry.opencmis.commons.enums.BaseTypeId in project structr by structr.

the class CMISRepositoryService method getTypeDescendants.

@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
    // important: descendants are ALL children and children of children, i.e. the whole tree
    /*
		Id typeId: The typeId of an object-type specified in the repository.
		 - If specified, then the repository MUST return all of descendant types of the specified type.
		 - If not specified, then the Repository MUST return all types and MUST ignore the value of the depth parameter.
		*/
    final List<TypeDefinitionContainer> results = new LinkedList<>();
    if (typeId != null) {
        final BaseTypeId baseTypeId = getBaseTypeId(typeId);
        if (baseTypeId != null) {
            final TypeDefinition typeDefinition = getTypeDefinition(repositoryId, typeId, extension);
            final TypeDefinitionContainer container = getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions);
            results.add(container);
        } else {
            final Class type = StructrApp.getConfiguration().getNodeEntityClass(typeId);
            if (type != null) {
                final TypeDefinition typeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
                if (typeDefinition != null) {
                    results.add(getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions));
                } else {
                    throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
                }
            } else {
                throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
            }
        }
    } else {
        results.add(getTypeDefinitionContainer(getDocumentTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getFolderTypeDefinition(BaseTypeId.CMIS_FOLDER.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getItemTypeDefinition(BaseTypeId.CMIS_ITEM.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getPolicyTypeDefinition(BaseTypeId.CMIS_POLICY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getRelationshipTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value(), includePropertyDefinitions, true), includePropertyDefinitions));
        results.add(getTypeDefinitionContainer(getSecondaryTypeDefinition(BaseTypeId.CMIS_SECONDARY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
    }
    return results;
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer) LinkedList(java.util.LinkedList) MutableTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition) MutablePolicyTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutablePolicyTypeDefinition) MutableRelationshipTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition) MutableFolderTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) MutableDocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition) MutableSecondaryTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition) MutableItemTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableItemTypeDefinition)

Example 4 with BaseTypeId

use of org.apache.chemistry.opencmis.commons.enums.BaseTypeId in project structr by structr.

the class CMISObjectService method createDocument.

@Override
public String createDocument(final String repositoryId, final Properties properties, final String folderId, final ContentStream contentStream, final VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    File newFile = null;
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final String fileName = getStringValue(properties, PropertyIds.NAME);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_DOCUMENT, File.class);
        // check if type exists
        if (type != null) {
            // check that base type is cmis:folder
            final BaseTypeId baseTypeId = getBaseTypeId(type);
            if (baseTypeId != null && BaseTypeId.CMIS_DOCUMENT.equals(baseTypeId)) {
                final String mimeType = contentStream != null ? contentStream.getMimeType() : null;
                // create file
                newFile = FileHelper.createFile(securityContext, new byte[0], mimeType, type, fileName);
                if (newFile != null) {
                    // find and set parent if it exists
                    if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
                        final Folder parent = app.get(Folder.class, folderId);
                        if (parent != null) {
                            newFile.setParent(parent);
                        } else {
                            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                        }
                    }
                    uuid = newFile.getUuid();
                    if (contentStream != null) {
                        final InputStream inputStream = contentStream.getStream();
                        if (inputStream != null) {
                            // copy file and update metadata
                            try (final OutputStream outputStream = newFile.getOutputStream(false, false)) {
                                IOUtils.copy(inputStream, outputStream);
                            }
                            inputStream.close();
                            FileHelper.updateMetadata(newFile);
                        }
                    }
                }
            } else {
                throw new CmisConstraintException("Cannot create cmis:document of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New document could not be created: " + t.getMessage());
    }
    // start indexing after transaction is finished
    if (newFile != null) {
        newFile.notifyUploadCompletion();
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) InputStream(java.io.InputStream) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) OutputStream(java.io.OutputStream) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Example 5 with BaseTypeId

use of org.apache.chemistry.opencmis.commons.enums.BaseTypeId in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method getCMISFunctionEvaluationContext.

public CmisFunctionEvaluationContext getCMISFunctionEvaluationContext(CMISQueryMode mode, CmisVersion cmisVersion, String alternativeDictionary) {
    BaseTypeId[] validScopes = (mode == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES : CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
    CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
    functionContext.setCmisDictionaryService(getCMISDictionary(alternativeDictionary, cmisVersion));
    functionContext.setValidScopes(validScopes);
    return functionContext;
}
Also used : CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId)

Aggregations

BaseTypeId (org.apache.chemistry.opencmis.commons.enums.BaseTypeId)12 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 MutableTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition)3 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3 BaseMessage (com.pogeyan.cmis.api.BaseMessage)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 PermissionMapping (org.apache.chemistry.opencmis.commons.data.PermissionMapping)2 MutableDocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition)2 MutableFolderTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition)2 MutableItemTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableItemTypeDefinition)2 MutablePolicyTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutablePolicyTypeDefinition)2 MutableRelationshipTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition)2 MutableSecondaryTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition)2 PermissionDefinition (org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition)2 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)2