use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper 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.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getTypeDescendants.
@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
checkRepositoryId(repositoryId);
List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
// check depth
int d = (depth == null ? -1 : depth.intValue());
if (d == 0) {
throw new CmisInvalidArgumentException("Depth must not be 0!");
}
if (typeId == null) {
for (TypeDefinitionWrapper tdw : connector.getOpenCMISDictionaryService().getBaseTypes(true)) {
result.add(getTypesDescendants(d, tdw, includePropertyDefinitions));
}
} else {
TypeDefinitionWrapper tdw = connector.getOpenCMISDictionaryService().findType(typeId);
if (tdw == null) {
throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
}
List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId);
if (children != null) {
for (TypeDefinitionWrapper child : children) {
result.add(getTypesDescendants(d, child, includePropertyDefinitions));
}
}
}
return result;
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method applyPolicy.
// --- policy service ---
@Override
public void applyPolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
TypeDefinitionWrapper type = info.getType();
if (type == null) {
throw new CmisObjectNotFoundException("No corresponding type found! Not a CMIS object?");
}
connector.applyPolicies(info.getNodeRef(), type, Collections.singletonList(policyId));
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getDescendantsTree.
private void getDescendantsTree(String repositoryId, NodeRef folderNodeRef, int depth, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, boolean foldersOnly, List<ObjectInFolderContainer> list) {
// get the children references
List<ChildAssociationRef> childrenList = connector.getNodeService().getChildAssocs(folderNodeRef);
for (ChildAssociationRef child : childrenList) {
try {
TypeDefinitionWrapper type = connector.getType(child.getChildRef());
if (type == null) {
continue;
}
boolean isFolder = (type instanceof FolderTypeDefintionWrapper);
if (foldersOnly && !isFolder) {
continue;
}
if (isFolder && type.getAlfrescoClass().equals(ContentModel.TYPE_SYSTEM_FOLDER)) {
continue;
}
if (connector.isHidden(child.getChildRef())) {
continue;
}
if (connector.filter(child.getChildRef())) {
continue;
}
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
// create a child CMIS object
ObjectInFolderDataImpl object = new ObjectInFolderDataImpl();
// note: checkExists=false (don't need to check again)
CMISNodeInfo ni = createNodeInfo(child.getChildRef(), null, false);
object.setObject(connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false));
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
}
if (includePathSegment) {
object.setPathSegment(connector.getName(child.getChildRef()));
}
// create the container
ObjectInFolderContainerImpl container = new ObjectInFolderContainerImpl();
container.setObject(object);
if ((depth != 1) && isFolder) {
container.setChildren(new ArrayList<ObjectInFolderContainer>());
getDescendantsTree(repositoryId, child.getChildRef(), depth - 1, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, foldersOnly, container.getChildren());
}
// add it
list.add(container);
} catch (InvalidNodeRefException e) {
// ignore invalid children
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method createDocumentFromSource.
@Override
public String createDocumentFromSource(String repositoryId, String sourceId, final Properties properties, String folderId, VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get the parent folder node ref
final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "Parent folder");
// get source
CMISNodeInfo info = getOrCreateNodeInfo(sourceId, "Source");
// check source
if (info.isVariant(CMISObjectVariant.ASSOC)) {
throw new CmisConstraintException("Source object is not a document!");
}
final NodeRef sourceNodeRef = info.getNodeRef();
if (!info.isDocument()) {
throw new CmisConstraintException("Source object is not a document!");
}
// get name and type
final String name = connector.getNameProperty(properties, info.getName());
final TypeDefinitionWrapper type = info.getType();
connector.checkChildObjectType(parentInfo, type.getTypeId());
versioningState = getDocumentDefaultVersioningState(versioningState, type);
try {
FileInfo fileInfo = connector.getFileFolderService().copy(sourceNodeRef, parentInfo.getNodeRef(), name);
NodeRef nodeRef = fileInfo.getNodeRef();
connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
connector.extractMetadata(nodeRef);
connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
connector.applyVersioningState(nodeRef, versioningState);
connector.getActivityPoster().postFileFolderAdded(nodeRef);
return connector.createObjectId(nodeRef);
} catch (FileNotFoundException e) {
throw new CmisContentAlreadyExistsException("An object with this name already exists!", e);
}
}
Aggregations