use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl in project alfresco-repository by Alfresco.
the class CMISConnector method getContentChanges.
/**
* Returns content changes.
*/
public ObjectList getContentChanges(Holder<String> changeLogToken, BigInteger maxItems) {
final ObjectListImpl result = new ObjectListImpl();
result.setObjects(new ArrayList<ObjectData>());
// Collect entryIds to use a counter and a way to find the last changeLogToken
final List<Long> entryIds = new ArrayList<Long>();
EntryIdCallback changeLogCollectingCallback = new EntryIdCallback(true) {
@Override
public boolean handleAuditEntry(Long entryId, String user, long time, Map<String, Serializable> values) {
entryIds.add(entryId);
result.getObjects().addAll(createChangeEvents(time, values));
return super.handleAuditEntry(entryId, user, time, values);
}
};
Long from = null;
if ((changeLogToken != null) && (changeLogToken.getValue() != null)) {
try {
from = Long.parseLong(changeLogToken.getValue());
} catch (NumberFormatException e) {
throw new CmisInvalidArgumentException("Invalid change log token: " + changeLogToken.getValue());
}
}
AuditQueryParameters params = new AuditQueryParameters();
params.setApplicationName(CMIS_CHANGELOG_AUDIT_APPLICATION);
params.setForward(true);
params.setFromId(from);
// So we have a BigInteger. We need to ensure that we cut it down to an integer smaller than Integer.MAX_VALUE
int maxResults = (maxItems == null ? contentChangesDefaultMaxItems : maxItems.intValue());
// Just a double check of the unbundled contents
maxResults = maxResults < 1 ? contentChangesDefaultMaxItems : maxResults;
// cut it down
maxResults = maxResults > contentChangesDefaultMaxItems ? contentChangesDefaultMaxItems : maxResults;
// Query for 1 more so that we know if there are more results
int queryFor = maxResults + 1;
auditService.auditQuery(changeLogCollectingCallback, params, queryFor);
int resultSize = result.getObjects().size();
// Use the entryIds as a counter is more reliable then the result.getObjects().
// result.getObjects() can be more or less then the requested maxResults, because it is filtered based on the content.
boolean hasMoreItems = entryIds.size() >= maxResults;
result.setHasMoreItems(hasMoreItems);
// Check if we got more than the client requested
if (hasMoreItems && resultSize >= maxResults) {
// We are assuming there are there is only one extra document now in line with how it used to behave
// Remove extra item that was not actually requested
result.getObjects().remove(resultSize - 1);
entryIds.remove(resultSize - 1);
}
if (changeLogToken != null) {
// Update the changelog after removing the last item if there are more items.
Long newChangeLogToken = entryIds.isEmpty() ? from : entryIds.get(entryIds.size() - 1);
changeLogToken.setValue(String.valueOf(newChangeLogToken));
}
return result;
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl 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.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl in project iaf by ibissource.
the class CmisUtils method xml2ObjectList.
public static ObjectList xml2ObjectList(Element result, PipeLineSession context) {
ObjectListImpl objectList = new ObjectListImpl();
objectList.setNumItems(CmisUtils.parseBigIntegerAttr(result, "numberOfItems"));
objectList.setHasMoreItems(CmisUtils.parseBooleanAttr(result, "hasMoreItems"));
List<ObjectData> objects = new ArrayList<ObjectData>();
Element objectsElem = XmlUtils.getFirstChildTag(result, "objects");
for (Node type : XmlUtils.getChildTags(objectsElem, "objectData")) {
ObjectData objectData = xml2ObjectData((Element) type, context);
objects.add(objectData);
}
objectList.setObjects(objects);
return objectList;
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl in project alfresco-repository by Alfresco.
the class CMISConnector method getObjectRelationships.
public ObjectList getObjectRelationships(NodeRef nodeRef, RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount) {
ObjectListImpl result = new ObjectListImpl();
result.setHasMoreItems(false);
result.setNumItems(BigInteger.ZERO);
result.setObjects(new ArrayList<ObjectData>());
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
// relationships from and to versions are not preserved
return result;
}
// get relationships
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
if (relationshipDirection == RelationshipDirection.SOURCE || relationshipDirection == RelationshipDirection.EITHER) {
assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
}
if (relationshipDirection == RelationshipDirection.TARGET || relationshipDirection == RelationshipDirection.EITHER) {
assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
}
int skip = (skipCount == null ? 0 : skipCount.intValue());
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int counter = 0;
boolean hasMore = false;
if (max > 0) {
// filter relationships that not map the CMIS domain model
for (AssociationRef assocRef : assocs) {
TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName());
if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null || getType(assocRef.getTargetRef()) == null) {
continue;
}
if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId)) {
continue;
}
counter++;
if (skip > 0) {
skip--;
continue;
}
max--;
if (max > 0) {
try {
result.getObjects().add(createCMISObject(createNodeInfo(assocRef), filter, includeAllowableActions, IncludeRelationships.NONE, RENDITION_NONE, false, false));
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
} else {
hasMore = true;
}
}
}
result.setNumItems(BigInteger.valueOf(counter));
result.setHasMoreItems(hasMore);
return result;
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getObjectRelationships.
// --- relationship service ---
@Override
public ObjectList getObjectRelationships(String repositoryId, String objectId, Boolean includeSubRelationshipTypes, RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
if (info.isVariant(CMISObjectVariant.ASSOC)) {
throw new CmisInvalidArgumentException("Object is a relationship!");
}
if (info.isVariant(CMISObjectVariant.VERSION)) {
throw new CmisInvalidArgumentException("Object is a document version!");
}
// check if the relationship base type is requested
if (BaseTypeId.CMIS_RELATIONSHIP.value().equals(typeId)) {
boolean isrt = (includeSubRelationshipTypes == null ? false : includeSubRelationshipTypes.booleanValue());
if (isrt) {
// all relationships are a direct subtype of the base type in
// Alfresco -> remove filter
typeId = null;
} else {
// there are no relationships of the base type in Alfresco ->
// return empty list
ObjectListImpl result = new ObjectListImpl();
result.setHasMoreItems(false);
result.setNumItems(BigInteger.ZERO);
result.setObjects(new ArrayList<ObjectData>());
return result;
}
}
return connector.getObjectRelationships(info.getNodeRef(), relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount);
}
Aggregations