Search in sources :

Example 1 with JSONArray

use of org.apache.chemistry.opencmis.commons.impl.json.JSONArray in project SearchServices by Alfresco.

the class AbstractAlfrescoSolrTests method assertQueryCollection.

/**
 * Builds and asserts that query returns a collection in the correct order by
 * checking the dbid value of each document is in the correct order.
 *
 * @author Michael Suzuki
 * @param query query used to search
 * @param dbids collection of dbids to compare
 * @throws Exception if error
 */
public static void assertQueryCollection(String query, Integer[] dbids) throws Exception {
    SolrQueryRequest solrReq = req(params("rows", "20", "qt", "/cmis", "q", query, "wt", "json"));
    try {
        String response = h.query(solrReq);
        JSONObject json = (JSONObject) JSONValue.parse(response);
        JSONObject res = (JSONObject) json.get("response");
        JSONArray docs = (JSONArray) res.get("docs");
        Assert.assertTrue(dbids.length == docs.size());
        int count = 0;
        for (Object doc : docs) {
            JSONObject item = (JSONObject) doc;
            BigInteger val = (BigInteger) item.get("DBID");
            Assert.assertEquals(dbids[count].intValue(), val.intValue());
            count++;
        }
    } finally {
        solrReq.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject)

Example 2 with JSONArray

use of org.apache.chemistry.opencmis.commons.impl.json.JSONArray in project copper-cms by PogeyanOSS.

the class ObjectActor method bulkUpdate.

private JSONArray bulkUpdate(PostRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    // get object ids and change tokens
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken = new ArrayList<BulkUpdateObjectIdAndChangeToken>();
    List<String> objectIds = request.getObjectIds();
    List<String> changeTokens = request.getChangeTokens();
    if (CmisPropertyConverter.Impl.isNullOrEmpty(objectIds)) {
        throw new CmisInvalidArgumentException("No object ids provided!");
    }
    int n = objectIds.size();
    for (int i = 0; i < n; i++) {
        String id = objectIds.get(i);
        String changeToken = (changeTokens != null && changeTokens.size() > i ? changeTokens.get(i) : null);
        if (changeToken != null && changeToken.length() == 0) {
            changeToken = null;
        }
        objectIdAndChangeToken.add(new BulkUpdateObjectIdAndChangeTokenImpl(id, changeToken));
    }
    // get secondary type ids
    List<String> addSecondaryTypes = request.getAddSecondaryTypes();
    List<String> removeSecondaryTypes = request.getRemoveSecondaryTypes();
    Properties properties = CmisPropertyConverter.Impl.createUpdateProperties(request.getPropertyData(), null, addSecondaryTypes, objectIds, request.getRepositoryId(), null);
    List<BulkUpdateObjectIdAndChangeToken> result = CmisObjectService.Impl.bulkUpdateProperties(request.getRepositoryId(), objectIdAndChangeToken, properties, addSecondaryTypes, removeSecondaryTypes, null, request.getUserObject());
    // return result
    JSONArray jsonList = new JSONArray();
    if (result != null) {
        for (BulkUpdateObjectIdAndChangeToken oc : result) {
            if (oc != null) {
                jsonList.add(JSONConverter.convert(oc));
            }
        }
    }
    return jsonList;
}
Also used : BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) BulkUpdateObjectIdAndChangeTokenImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl) ArrayList(java.util.ArrayList) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Example 3 with JSONArray

use of org.apache.chemistry.opencmis.commons.impl.json.JSONArray in project copper-cms by PogeyanOSS.

the class ObjectActor method getRenditions.

private JSONArray getRenditions(QueryGetRequest t) throws CmisInvalidArgumentException, CmisRuntimeException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    String renditionFilter = t.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    BigInteger maxItems = t.getBigIntegerParameter(QueryGetRequest.PARAM_MAX_ITEMS);
    BigInteger skipCount = t.getBigIntegerParameter(QueryGetRequest.PARAM_SKIP_COUNT);
    List<RenditionData> renditions = CmisObjectService.Impl.getRenditions(t.getRepositoryId(), objectId, renditionFilter, maxItems, skipCount, null);
    JSONArray resultRenditions = new JSONArray();
    if (renditions != null) {
        for (RenditionData rendition : renditions) {
            resultRenditions.add(JSONConverter.convert(rendition));
        }
    }
    return resultRenditions;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Example 4 with JSONArray

use of org.apache.chemistry.opencmis.commons.impl.json.JSONArray in project copper-cms by PogeyanOSS.

the class RepositoryActor method getTypeDescendants.

private JSONArray getTypeDescendants(QueryGetRequest request) throws IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeId = request.getParameter(QueryGetRequest.PARAM_TYPE_ID);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    BigInteger depth = request.getBigIntegerParameter(QueryGetRequest.PARAM_DEPTH);
    boolean includePropertyDefinitions = request.getBooleanParameter(QueryGetRequest.PARAM_PROPERTY_DEFINITIONS, false);
    List<TypeDefinitionContainer> typeTree = CmisTypeServices.Impl.getTypeDescendants(request.getRepositoryId(), typeId, depth, includePropertyDefinitions, null);
    if (typeTree == null) {
        throw new CmisRuntimeException("Type tree is null!");
    }
    JSONArray jsonTypeTree = new JSONArray();
    for (TypeDefinitionContainer container : typeTree) {
        jsonTypeTree.add(JSONConverter.convert(container, dateTimeFormat));
    }
    return jsonTypeTree;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 5 with JSONArray

use of org.apache.chemistry.opencmis.commons.impl.json.JSONArray in project copper-cms by PogeyanOSS.

the class NavigationActor method getFolderTree.

private JSONArray getFolderTree(QueryGetRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId();
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    BigInteger depth = request.getBigIntegerParameter(QueryGetRequest.PARAM_DEPTH);
    Boolean includeAllowableActions = request.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    IncludeRelationships includeRelationships = request.getEnumParameter(QueryGetRequest.PARAM_RELATIONSHIPS, IncludeRelationships.class);
    String renditionFilter = request.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    Boolean includePathSegment = request.getBooleanParameter(QueryGetRequest.PARAM_PATH_SEGMENT);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    List<ObjectInFolderContainer> folderTree = CmisNavigationService.Impl.getFolderTree(request.getRepositoryId(), folderId, depth, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, null, request.getUserObject());
    if (folderTree == null) {
        throw new CmisRuntimeException("Folder Tree are null!");
    }
    JSONArray jsonDescendants = new JSONArray();
    for (ObjectInFolderContainer descendant : folderTree) {
        jsonDescendants.add(JSONConverter.convert(descendant, CmisTypeCacheService.get(request.getRepositoryId()), succinct, dateTimeFormat));
    }
    return jsonDescendants;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Aggregations

JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)13 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)8 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)6 BigInteger (java.math.BigInteger)5 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)5 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)3 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 ObjectInFolderContainer (org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 BulkUpdateObjectIdAndChangeToken (org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken)1 ObjectParentData (org.apache.chemistry.opencmis.commons.data.ObjectParentData)1 Properties (org.apache.chemistry.opencmis.commons.data.Properties)1 RenditionData (org.apache.chemistry.opencmis.commons.data.RenditionData)1 TypeDefinitionContainer (org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1