use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method query.
@SuppressWarnings("unchecked")
public ObjectList query(String statement, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount) /*, CmisVersion cmisVersion*/
{
// prepare results
ObjectListImpl result = new ObjectListImpl();
result.setObjects(new ArrayList<ObjectData>());
// prepare query
CMISQueryOptions options = new CMISQueryOptions(statement, getRootStoreRef());
CmisVersion cmisVersion = getRequestCmisVersion();
options.setCmisVersion(cmisVersion);
options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
int skip = 0;
if ((skipCount != null) && (skipCount.intValue() >= 0)) {
skip = skipCount.intValue();
options.setSkipCount(skip);
}
if ((maxItems != null) && (maxItems.intValue() >= 0)) {
options.setMaxItems(maxItems.intValue());
}
boolean fetchObject = includeAllowableActions || (includeRelationships != IncludeRelationships.NONE) || (!RENDITION_NONE.equals(renditionFilter));
// query
CMISResultSet rs = getOpenCMISQueryService().query(options);
try {
CMISResultSetColumn[] columns = rs.getMetaData().getColumns();
for (CMISResultSetRow row : rs) {
NodeRef nodeRef = row.getNodeRef();
if (!nodeService.exists(nodeRef) || filter(nodeRef)) {
continue;
}
TypeDefinitionWrapper type = getType(nodeRef);
if (type == null) {
continue;
}
ObjectDataImpl hit = new ObjectDataImpl();
PropertiesImpl properties = new PropertiesImpl();
hit.setProperties(properties);
Map<String, Serializable> values = row.getValues();
for (CMISResultSetColumn column : columns) {
AbstractPropertyData<?> property = getProperty(column.getCMISDataType(), column.getCMISPropertyDefinition(), values.get(column.getName()));
property.setQueryName(column.getName());
properties.addProperty(property);
}
if (fetchObject) {
// set allowable actions
if (includeAllowableActions) {
CMISNodeInfoImpl nodeInfo = createNodeInfo(nodeRef);
if (!nodeInfo.getObjectVariant().equals(CMISObjectVariant.NOT_EXISTING)) {
hit.setAllowableActions(getAllowableActions(nodeInfo));
}
}
// set relationships
if (includeRelationships != IncludeRelationships.NONE) {
hit.setRelationships(getRelationships(nodeRef, includeRelationships));
}
// set renditions
if (!RENDITION_NONE.equals(renditionFilter)) {
List<RenditionData> renditions = getRenditions(nodeRef, renditionFilter, null, null);
if ((renditions != null) && (!renditions.isEmpty())) {
hit.setRenditions(renditions);
} else {
hit.setRenditions(Collections.EMPTY_LIST);
}
}
}
result.getObjects().add(hit);
}
long numberFound = rs.getNumberFound();
if (numberFound != -1) {
result.setNumItems(BigInteger.valueOf(numberFound));
}
result.setHasMoreItems(rs.hasMore());
} finally {
rs.close();
}
return result;
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method removePolicy.
@Override
public void removePolicy(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?");
}
throw new CmisConstraintException("Object is not policy controllable!");
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method create.
// --- object service ---
@Override
public String create(String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List<String> policies, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// check properties
if (properties == null || properties.getProperties() == null) {
throw new CmisInvalidArgumentException("Properties must be set!");
}
// get the type
String objectTypeId = connector.getObjectTypeIdProperty(properties);
// find the type
TypeDefinitionWrapper type = connector.getOpenCMISDictionaryService().findType(objectTypeId);
if (type == null) {
throw new CmisInvalidArgumentException("Type '" + objectTypeId + "' is unknown!");
}
// create object
String newId = null;
switch(type.getBaseTypeId()) {
case CMIS_DOCUMENT:
versioningState = getDocumentDefaultVersioningState(versioningState, type);
newId = createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, null, null, extension);
break;
case CMIS_FOLDER:
newId = createFolder(repositoryId, properties, folderId, policies, null, null, extension);
break;
case CMIS_POLICY:
newId = createPolicy(repositoryId, properties, folderId, policies, null, null, extension);
break;
case CMIS_ITEM:
newId = createItem(repositoryId, properties, folderId, policies, null, null, extension);
break;
default:
break;
}
// check new object id
if (newId == null) {
throw new CmisRuntimeException("Creation failed!");
}
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
try {
getObjectInfo(repositoryId, newId, "*", IncludeRelationships.NONE);
} catch (InvalidNodeRefException e) {
throw new CmisRuntimeException("Creation failed! New object not found!");
}
}
// return the new object id
return newId;
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method createRelationship.
@Override
public String createRelationship(String repositoryId, Properties properties, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get type
String objectTypeId = connector.getObjectTypeIdProperty(properties);
final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_RELATIONSHIP);
// get source object
String sourceId = connector.getSourceIdProperty(properties);
CMISNodeInfo sourceInfo = getOrCreateNodeInfo(sourceId, "Source");
if (!sourceInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !sourceInfo.isVariant(CMISObjectVariant.FOLDER) && !sourceInfo.isVariant(CMISObjectVariant.ITEM)) {
throw new CmisInvalidArgumentException("Source is not the latest version of a document, a folder or an item object!");
}
final NodeRef sourceNodeRef = sourceInfo.getNodeRef();
// get target object
String targetId = connector.getTargetIdProperty(properties);
CMISNodeInfo targetInfo = getOrCreateNodeInfo(targetId, "Target");
if (!targetInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !targetInfo.isVariant(CMISObjectVariant.FOLDER) && !targetInfo.isVariant(CMISObjectVariant.ITEM)) {
throw new CmisInvalidArgumentException("Target is not the latest version of a document, a folder or an item object!!");
}
final NodeRef targetNodeRef = targetInfo.getNodeRef();
// check policies and ACLs
if ((policies != null) && (!policies.isEmpty())) {
throw new CmisConstraintException("Relationships are not policy controllable!");
}
if ((addAces != null) && (addAces.getAces() != null) && (!addAces.getAces().isEmpty())) {
throw new CmisConstraintException("Relationships are not ACL controllable!");
}
if ((removeAces != null) && (removeAces.getAces() != null) && (!removeAces.getAces().isEmpty())) {
throw new CmisConstraintException("Relationships are not ACL controllable!");
}
// create relationship
// ALF-10085 : disable auditing behaviour for this use case
// Lasts for txn
boolean wasEnabled = connector.disableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
try {
AssociationRef assocRef = connector.getNodeService().createAssociation(sourceNodeRef, targetNodeRef, type.getAlfrescoClass());
return CMISConnector.ASSOC_ID_PREFIX + assocRef.getId();
} finally {
if (wasEnabled) {
connector.enableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
}
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getTypesDescendants.
/**
* Gathers the type descendants tree.
*/
private TypeDefinitionContainer getTypesDescendants(int depth, TypeDefinitionWrapper tdw, boolean includePropertyDefinitions) {
TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl();
result.setTypeDefinition(tdw.getTypeDefinition(includePropertyDefinitions));
if (depth != 0) {
String typeId = tdw.getTypeId();
List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId);
if (children != null) {
result.setChildren(new ArrayList<TypeDefinitionContainer>());
for (TypeDefinitionWrapper tdc : children) {
result.getChildren().add(getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions));
}
}
}
return result;
}
Aggregations