use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getChildren.
// --- navigation service ---
@Override
public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter, String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
long start = System.currentTimeMillis();
checkRepositoryId(repositoryId);
// convert BigIntegers to int
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
ObjectInFolderListImpl result = new ObjectInFolderListImpl();
List<ObjectInFolderData> list = new ArrayList<ObjectInFolderData>();
result.setObjects(list);
// get the children references
NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
// convert orderBy to sortProps
List<Pair<QName, Boolean>> sortProps = null;
if (orderBy != null) {
sortProps = new ArrayList<Pair<QName, Boolean>>(1);
String[] parts = orderBy.split(",");
int len = parts.length;
final int origLen = len;
if (origLen > 0) {
int maxSortProps = GetChildrenCannedQuery.MAX_FILTER_SORT_PROPS;
if (len > maxSortProps) {
if (logger.isDebugEnabled()) {
logger.debug("Too many sort properties in 'orderBy' - ignore those above max (max=" + maxSortProps + ",actual=" + len + ")");
}
len = maxSortProps;
}
for (int i = 0; i < len; i++) {
String[] sort = parts[i].split(" +");
if (sort.length > 0) {
// MNT-10529: Leading spaces result in an empty string value after the split operation. Leading spaces may occur in the 'orderBy' statement when the
// elements of statement separated by a comma and a space(s)
int index = (sort[0].isEmpty()) ? (1) : (0);
Pair<QName, Boolean> sortProp = connector.getSortProperty(sort[index], sort.length > (index + 1) ? sort[index + 1] : null);
sortProps.add(sortProp);
}
}
}
if (sortProps.size() < origLen) {
logger.warn("Sort properties trimmed - either too many and/or not found: \n" + " orig: " + orderBy + "\n" + " final: " + sortProps);
}
}
PagingRequest pageRequest = new PagingRequest(skip, max, null);
// TODO make this optional/configurable
pageRequest.setRequestTotalCountMax(skip + 10000);
// - affects whether numItems may be returned
Set<QName> typeqnames = new HashSet<QName>();
List<TypeDefinitionWrapper> allTypes = connector.getOpenCMISDictionaryService().getAllTypes();
for (TypeDefinitionWrapper type : allTypes) {
typeqnames.add(type.getAlfrescoClass());
}
PagingResults<FileInfo> pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, typeqnames, // ignoreAspectQNames,
null, sortProps, pageRequest);
if (max > 0) {
for (FileInfo child : pageOfNodeInfos.getPage()) {
try {
// TODO this will break the paging if filtering is performed...
if (connector.filter(child.getNodeRef())) {
continue;
}
// create a child CMIS object
// note: checkExists=false (don't need to check again)
CMISNodeInfo ni = createNodeInfo(child.getNodeRef(), child.getType(), child.getProperties(), null, false);
// Skip non-cmis objects
if (ni.getObjectVariant() == CMISObjectVariant.INVALID_ID || ni.getObjectVariant() == CMISObjectVariant.NOT_EXISTING || ni.getObjectVariant() == CMISObjectVariant.NOT_A_CMIS_OBJECT || ni.getObjectVariant() == CMISObjectVariant.PERMISSION_DENIED) {
continue;
}
ObjectData object = connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false);
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
}
ObjectInFolderDataImpl childData = new ObjectInFolderDataImpl();
childData.setObject(object);
// include path segment
if (includePathSegment) {
childData.setPathSegment(child.getName());
}
// add it
list.add(childData);
} catch (InvalidNodeRefException e) {
// ignore invalid children
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
}
}
// has more ?
result.setHasMoreItems(pageOfNodeInfos.hasMoreItems());
// total count ?
Pair<Integer, Integer> totalCounts = pageOfNodeInfos.getTotalResultCount();
if (totalCounts != null) {
Integer totalCountLower = totalCounts.getFirst();
Integer totalCountUpper = totalCounts.getSecond();
if ((totalCountLower != null) && (totalCountLower.equals(totalCountUpper))) {
result.setNumItems(BigInteger.valueOf(totalCountLower));
}
}
logGetObjectsCall("getChildren", start, folderId, list.size(), filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, extension, skipCount, maxItems, orderBy, null);
return result;
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getCheckedOutDocs.
@Override
public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
long start = System.currentTimeMillis();
checkRepositoryId(repositoryId);
// convert BigIntegers to int
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
// prepare query
SearchParameters params = new SearchParameters();
params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
if (folderId == null) {
params.setQuery("+=cm:workingCopyOwner:\"" + AuthenticationUtil.getFullyAuthenticatedUser() + "\"");
params.addStore(connector.getRootStoreRef());
} else {
CMISNodeInfo folderInfo = getOrCreateFolderInfo(folderId, "Folder");
params.setQuery("+=cm:workingCopyOwner:\"" + AuthenticationUtil.getFullyAuthenticatedUser() + "\" AND +=PARENT:\"" + folderInfo.getNodeRef().toString() + "\"");
params.addStore(folderInfo.getNodeRef().getStoreRef());
}
// set up order
if (orderBy != null) {
String[] parts = orderBy.split(",");
for (int i = 0; i < parts.length; i++) {
String[] sort = parts[i].split(" +");
if (sort.length < 1) {
continue;
}
PropertyDefinitionWrapper propDef = connector.getOpenCMISDictionaryService().findPropertyByQueryName(sort[0]);
if (propDef != null) {
if (propDef.getPropertyDefinition().isOrderable()) {
QName sortProp = propDef.getPropertyAccessor().getMappedProperty();
if (sortProp != null) {
boolean sortAsc = (sort.length == 1) || sort[1].equalsIgnoreCase("asc");
params.addSort(propDef.getPropertyLuceneBuilder().getLuceneFieldName(), sortAsc);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + sort[0] + " - mapping not found");
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + sort[0] + " - not orderable");
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + sort[0] + " - query name not found");
}
}
}
}
// execute query
ResultSet resultSet = null;
List<NodeRef> nodeRefs;
try {
resultSet = connector.getSearchService().query(params);
nodeRefs = resultSet.getNodeRefs();
} finally {
if (resultSet != null) {
resultSet.close();
}
}
// collect results
ObjectListImpl result = new ObjectListImpl();
List<ObjectData> list = new ArrayList<ObjectData>();
result.setObjects(list);
int skipCounter = skip;
if (max > 0) {
for (NodeRef nodeRef : nodeRefs) {
// TODO - perhaps filter by path in the query instead?
if (connector.filter(nodeRef)) {
continue;
}
if (skipCounter > 0) {
skipCounter--;
continue;
}
if (list.size() == max) {
break;
}
try {
// create a CMIS object
CMISNodeInfo ni = createNodeInfo(nodeRef);
ObjectData object = connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false);
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
}
// add it
list.add(object);
} catch (InvalidNodeRefException e) {
// ignore invalid objects
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
}
}
// has more ?
result.setHasMoreItems(nodeRefs.size() - skip > list.size());
logGetObjectsCall("getCheckedOutDocs", start, folderId, list.size(), filter, includeAllowableActions, includeRelationships, renditionFilter, null, extension, skipCount, maxItems, orderBy, null);
return result;
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method deleteContentStream.
@Override
public void deleteContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken, ExtensionsData extension) {
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC)) {
throw new CmisStreamNotSupportedException("Content can only be deleted from ondocuments!");
}
final NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
throw new CmisInvalidArgumentException("Document type requires content!");
}
// ALF-21852 - Separated deleteContent and objectId.setValue in two different transactions because
// after executing deleteContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
connector.getNodeService().setProperty(nodeRef, ContentModel.PROP_CONTENT, null);
// connector.createVersion(nodeRef, VersionType.MINOR, "Delete content");
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
return null;
}
}, false, true);
String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
return connector.createObjectId(nodeRef);
}
}, true, true);
objectId.setValue(objId);
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method removeObjectFromFolder.
@Override
public void removeObjectFromFolder(String repositoryId, String objectId, String folderId, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get node ref
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
if (!info.isDocument()) {
throw new CmisInvalidArgumentException("Object is not a document!");
}
final NodeRef nodeRef = info.getNodeRef();
// get the folder node ref
final NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
// check primary parent
if (connector.getNodeService().getPrimaryParent(nodeRef).getParentRef().equals(folderNodeRef)) {
throw new CmisConstraintException("Unfiling from primary parent folder is not supported! Use deleteObject() instead.");
}
connector.getNodeService().removeChild(folderNodeRef, nodeRef);
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getAllVersions.
@Override
public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter, Boolean includeAllowableActions, ExtensionsData extension) {
checkRepositoryId(repositoryId);
if (versionSeriesId == null && objectId != null) {
// it's a browser binding call
versionSeriesId = connector.getCurrentVersionId(objectId);
}
if (versionSeriesId == null) {
throw new CmisInvalidArgumentException("Object Id or Object Series Id must be set!");
}
List<ObjectData> result = new ArrayList<ObjectData>();
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(versionSeriesId, "Version Series");
if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
// document
throw new CmisInvalidArgumentException("Version Series does not exist!");
}
// get current version and it's history
NodeRef nodeRef = info.getNodeRef();
VersionHistory versionHistory = ((CMISNodeInfoImpl) info).getVersionHistory();
if (versionHistory == null) {
// add current version
result.add(connector.createCMISObject(info, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, info.getObjectId(), IncludeRelationships.NONE);
}
} else {
if (info.hasPWC()) {
CMISNodeInfo pwcInfo = createNodeInfo(connector.getCheckOutCheckInService().getWorkingCopy(nodeRef));
result.add(connector.createCMISObject(pwcInfo, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, pwcInfo.getObjectId(), IncludeRelationships.NONE);
}
}
// convert the version history
for (Version version : versionHistory.getAllVersions()) {
// TODO do we need to check existence ?
CMISNodeInfo versionInfo = createNodeInfo(version.getFrozenStateNodeRef(), versionHistory, true);
// MNT-9557 fix. Replace head version with current node info
if (versionHistory.getHeadVersion().equals(version)) {
versionInfo = createNodeInfo(nodeRef);
}
result.add(connector.createCMISObject(versionInfo, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, versionInfo.getObjectId(), IncludeRelationships.NONE);
}
}
}
return result;
}
Aggregations