use of org.alfresco.opencmis.dictionary.CMISNodeInfo 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.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method moveObject.
@Override
public void moveObject(String repositoryId, Holder<String> objectId, String targetFolderId, String sourceFolderId, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get object and source and target parent
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
final NodeRef nodeRef = info.getCurrentNodeNodeRef();
final CMISNodeInfo sourceInfo = getOrCreateFolderInfo(sourceFolderId, "Source Folder");
final CMISNodeInfo targetInfo = getOrCreateFolderInfo(targetFolderId, "Target Folder");
connector.checkChildObjectType(targetInfo, info.getType().getTypeId());
ChildAssociationRef primaryParentRef = connector.getNodeService().getPrimaryParent(nodeRef);
// if this is a primary child node, move it
if (primaryParentRef.getParentRef().equals(sourceInfo.getNodeRef())) {
connector.getNodeService().moveNode(nodeRef, targetInfo.getNodeRef(), primaryParentRef.getTypeQName(), primaryParentRef.getQName());
} else {
boolean found = false;
// otherwise, reparent it
for (ChildAssociationRef parent : connector.getNodeService().getParentAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL)) {
if (parent.getParentRef().equals(sourceInfo.getNodeRef())) {
connector.getNodeService().removeChildAssociation(parent);
connector.getNodeService().addChild(targetInfo.getNodeRef(), nodeRef, ContentModel.ASSOC_CONTAINS, parent.getQName());
found = true;
}
}
if (!found) {
throw new IllegalArgumentException(new CmisInvalidArgumentException("Document is not a child of the source folder that was specified!"));
}
}
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method addObjectToFolder.
// --- multifiling service ---
@Override
public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean allVersions, ExtensionsData extension) {
checkRepositoryId(repositoryId);
if (!allVersions) {
throw new CmisInvalidArgumentException("Only allVersions=true supported!");
}
// 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 CMISNodeInfo folderInfo = getOrCreateFolderInfo(folderId, "Folder");
connector.checkChildObjectType(folderInfo, info.getType().getTypeId());
final QName name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) connector.getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME)));
connector.getNodeService().addChild(folderInfo.getNodeRef(), nodeRef, ContentModel.ASSOC_CONTAINS, name);
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getOrCreateNodeInfo.
protected CMISNodeInfo getOrCreateNodeInfo(String objectId) {
CMISNodeInfo result = nodeInfoMap.get(objectId);
if (result == null) {
result = connector.createNodeInfo(objectId);
nodeInfoMap.put(objectId, result);
}
return result;
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getFolderParent.
@Override
public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get the node ref
CMISNodeInfo info = getOrCreateFolderInfo(folderId, "Folder");
// the root folder has no parent
if (info.isRootFolder()) {
throw new CmisInvalidArgumentException("Root folder has no parent!");
}
// get the parent
List<CMISNodeInfo> parentInfos = info.getParents();
if (parentInfos.isEmpty()) {
throw new CmisRuntimeException("Folder has no parent and is not the root folder?!");
}
CMISNodeInfo parentInfo = addNodeInfo(parentInfos.get(0));
ObjectData result = connector.createCMISObject(parentInfo, filter, false, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false);
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, parentInfo.getObjectId(), IncludeRelationships.NONE);
}
return result;
}
Aggregations