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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations