Search in sources :

Example 6 with TypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition 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 7 with TypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.

the class RepositoryActor method createType.

private JSONObject createType(PostRequest request) throws IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    if (typeStr == null) {
        throw new CmisInvalidArgumentException("Type definition missing!");
    }
    // convert type definition
    JSONParser parser = new JSONParser();
    Object typeJson = null;
    try {
        typeJson = parser.parse(typeStr);
    } catch (JSONParseException e) {
        LOG.error("JSON Parser error: {}", ExceptionUtils.getStackTrace(e));
    }
    if (!(typeJson instanceof Map)) {
        throw new CmisInvalidArgumentException("Invalid type definition!");
    }
    @SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
    TypeDefinition typeOut = CmisTypeServices.Impl.createType(request.getRepositoryId(), typeIn, null, request.getUserName());
    JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
    return jsonType;
}
Also used : JSONParseException(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONParser(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 8 with TypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.

the class RepositoryActor method updateType.

private JSONObject updateType(PostRequest request) throws CmisInvalidArgumentException, IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    if (typeStr == null) {
        throw new CmisInvalidArgumentException("Type definition missing!");
    }
    // convert type definition
    JSONParser parser = new JSONParser();
    Object typeJson = null;
    try {
        typeJson = parser.parse(typeStr);
    } catch (JSONParseException e) {
        LOG.error("JSON parse exception: {}", ExceptionUtils.getStackTrace(e));
    }
    if (!(typeJson instanceof Map)) {
        throw new CmisInvalidArgumentException("Invalid type definition!");
    }
    @SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
    TypeDefinition typeOut = CmisTypeServices.Impl.updateType(request.getRepositoryId(), typeIn, null);
    JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
    return jsonType;
}
Also used : JSONParseException(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONParser(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 9 with TypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.

the class BaseTypesTest method runTypeChecks.

private int runTypeChecks(Session session, List<Tree<ObjectType>> types) {
    if (types == null) {
        return 0;
    }
    int numOfTypes = 0;
    CmisTestResult failure;
    for (Tree<ObjectType> tree : types) {
        failure = createResult(FAILURE, "Types tree contains null leaf!");
        addResult(assertNotNull(tree, null, failure));
        if (tree != null) {
            numOfTypes++;
            addResult(checkTypeDefinition(session, tree.getItem(), "Type spec compliance: " + tree.getItem().getId()));
            // clear the cache to ensure that the type definition is
            // reloaded from the repository
            session.clear();
            try {
                TypeDefinition reloadedType = session.getTypeDefinition(tree.getItem().getId());
                addResult(checkTypeDefinition(session, reloadedType, "Type spec compliance: " + (reloadedType == null ? "?" : reloadedType.getId())));
                failure = createResult(FAILURE, "Type fetched via getTypeDescendants() is does not macth type fetched via getTypeDefinition(): " + tree.getItem().getId());
                addResult(assertEquals(tree.getItem(), reloadedType, null, failure));
            } catch (CmisObjectNotFoundException e) {
                addResult(createResult(FAILURE, "Type fetched via getTypeDescendants() is not available via getTypeDefinition(): " + tree.getItem().getId(), e, false));
            }
            // clear the cache again to ensure that the type definition
            // children are reloaded from the repository
            session.clear();
            try {
                ItemIterable<ObjectType> reloadedTypeChildren = session.getTypeChildren(tree.getItem().getId(), true);
                // check type children
                Map<String, ObjectType> typeChilden = new HashMap<String, ObjectType>();
                for (ObjectType childType : reloadedTypeChildren) {
                    if (childType == null) {
                        addResult(createResult(FAILURE, "The list of types contains a null entry!"));
                        continue;
                    }
                    addResult(checkTypeDefinition(session, childType, "Type spec compliance: " + childType.getId()));
                    typeChilden.put(childType.getId(), childType);
                }
                // compare type children and type descendants
                if (tree.getChildren() == null) {
                    failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
                    addResult(assertEquals(0, typeChilden.size(), null, failure));
                } else {
                    // collect the children
                    Map<String, ObjectType> typeDescendants = new HashMap<String, ObjectType>();
                    for (Tree<ObjectType> childType : tree.getChildren()) {
                        if ((childType != null) && (childType.getItem() != null)) {
                            typeDescendants.put(childType.getItem().getId(), childType.getItem());
                        }
                    }
                    failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
                    addResult(assertEquals(typeDescendants.size(), typeChilden.size(), null, failure));
                    for (ObjectType compareType : typeDescendants.values()) {
                        failure = createResult(FAILURE, "Type fetched via getTypeDescendants() doesn't match type fetched via getTypeChildren(): " + tree.getItem().getId());
                        addResult(assertEquals(compareType, typeChilden.get(compareType.getId()), null, failure));
                    }
                }
            } catch (CmisObjectNotFoundException e) {
                addResult(createResult(FAILURE, "Type children fetched via getTypeDescendants() are not available via getTypeChildren(): " + tree.getItem().getId(), e, false));
            }
            numOfTypes += runTypeChecks(session, tree.getChildren());
        }
    }
    return numOfTypes;
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) HashMap(java.util.HashMap) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 10 with TypeDefinition

use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.

the class CreateBigDocument method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String name = "bigdoc";
        String objectTypeId = getDocumentTestTypeId();
        String mimetype = "application/octet-stream";
        // 10 MiB
        final long size = 10 * 1024 * 1024;
        InputStream in = new InputStream() {

            private int counter = -1;

            @Override
            public int read() throws IOException {
                counter++;
                if (counter >= size) {
                    return -1;
                }
                return '0' + (counter / 10);
            }
        };
        // create stream and properties
        ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        // check type
        TypeDefinition type = session.getTypeDefinition(objectTypeId);
        if (!(type instanceof DocumentTypeDefinition)) {
            addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
            return;
        }
        DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
        VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
        // create and fetch the document
        ObjectId id = session.createDocument(properties, testFolder, contentStream, versioningState);
        Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
        // check the new document
        addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
        // check the size
        f = createResult(FAILURE, "Content stream length doesn't match the uploaded content!", true);
        assertEquals(size, doc.getContentStreamLength(), null, f);
    // delete it
    // doc.delete(true);
    } finally {
    // delete the test folder
    // deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) InputStream(java.io.InputStream) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState)

Aggregations

TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)11 LinkedList (java.util.LinkedList)4 MutableDocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition)4 MutableFolderTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition)4 MutableItemTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableItemTypeDefinition)4 MutablePolicyTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutablePolicyTypeDefinition)4 MutableRelationshipTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition)4 MutableSecondaryTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition)4 MutableTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4 HashMap (java.util.HashMap)3 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)3 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)3 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2