use of com.pogeyan.cmis.api.messages.QueryGetRequest in project copper-cms by PogeyanOSS.
the class ServletHelpers method queryHttpToBaseMessage.
static BaseMessage queryHttpToBaseMessage(QueryStringHttpServletRequestWrapper request, String[] pathFragments, IUserObject userObject) {
QueryGetRequest queryRequest = new QueryGetRequest();
queryRequest.setParameterMap(request.getParameterMap());
queryRequest.setBaseUrl((String) request.getAttribute(BrowserConstants.BASE_URL_ATTRIBUTE));
queryRequest.setScheme(request.getScheme());
queryRequest.setServerName(request.getServerName());
queryRequest.setServerPort(request.getServerPort());
queryRequest.setContextPath(request.getContextPath());
queryRequest.setServletPath(request.getServletPath());
queryRequest.setRange(request.getHeader("Range"));
String objectId = HttpUtils.getStringParameter(request, BrowserConstants.PARAM_OBJECT_ID);
queryRequest.setObjectId(objectId);
if (userObject != null) {
queryRequest.setUserName(userObject.getUserDN());
queryRequest.setUserObject(userObject);
}
if (pathFragments.length > 0) {
queryRequest.setRepositoryId(pathFragments[0]);
}
// selector is the actionName
String selector = HttpUtils.getStringParameter(request, BrowserConstants.PARAM_SELECTOR);
if (pathFragments.length > 1) {
queryRequest.setPathFragments(pathFragments);
// nested url
String repositoryId = pathFragments[0];
try {
ObjectData object = null;
// Example objectId format-typeID::primaryKey::primaryKeyValue
if (objectId != null && objectId.contains("::")) {
String[] inputs = objectId.split("::");
// getObjectForRestAPI method is used to get the object.
object = CmisObjectService.Impl.getObjectForRestAPI(repositoryId, inputs[0], inputs[1], inputs[2], "cmis:objectId,cmis:objectTypeId,cmis:baseTypeId", false, IncludeRelationships.NONE, "cmis:none", false, false, null, "");
} else {
object = ServletHelpers.getObjectDataFor(repositoryId, objectId, pathFragments);
}
// reset object id again here
objectId = object.getId();
queryRequest.setObjectId(objectId);
String typeId = getStringPropertyValue(object, PropertyIds.OBJECT_TYPE_ID);
queryRequest.setTypeId(typeId);
BaseTypeId baseTypeId = BaseTypeId.fromValue(getStringPropertyValue(object, PropertyIds.BASE_TYPE_ID));
queryRequest.setBaseTypeId(baseTypeId);
if (selector == null) {
switch(baseTypeId) {
case CMIS_DOCUMENT:
selector = BrowserConstants.SELECTOR_CONTENT;
break;
case CMIS_FOLDER:
selector = BrowserConstants.SELECTOR_CHILDREN;
break;
default:
selector = BrowserConstants.SELECTOR_OBJECT;
break;
}
}
} catch (Exception e) {
selector = BrowserConstants.SELECTOR_OBJECT;
}
}
selector = selector == null ? "GetRepositories".toLowerCase() : selector;
BaseMessage bm = BaseMessage.create("", selector, queryRequest);
return bm;
}
Aggregations