use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method appendContentStream.
@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken, ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) {
if ((contentStream == null) || (contentStream.getStream() == null)) {
throw new CmisInvalidArgumentException("No content!");
}
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
// ALF-21852 - Separated appendContent and objectId.setValue in two different transactions because
// after executing appendContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
try {
connector.appendContent(info, contentStream, isLastChunk);
} catch (IOException e) {
throw new ContentIOException("", e);
}
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 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.CMISNodeInfo 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);
}
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method setContentStream.
@Override
public void setContentStream(String repositoryId, Holder<String> objectId, Boolean overwriteFlag, Holder<String> changeToken, final ContentStream contentStream, 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 set on private working copies or current versions.");
}
final NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
if (existed && !overwriteFlag) {
throw new CmisContentAlreadyExistsException("Content already exists!");
}
if ((contentStream == null) || (contentStream.getStream() == null)) {
throw new CmisInvalidArgumentException("No content!");
}
// ALF-21852 - Separated setContent and objectId.setValue in two different transactions because
// after executing setContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
String mimeType = parseMimeType(contentStream);
String encoding = getEncoding(contentStream.getStream(), mimeType);
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(mimeType);
writer.setEncoding(encoding);
writer.putContent(contentStream.getStream());
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 createFolder.
@Override
public String createFolder(String repositoryId, final Properties properties, String folderId, 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, "Folder");
// get name and type
final String name = connector.getNameProperty(properties, null);
final String objectTypeId = connector.getObjectTypeIdProperty(properties);
final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_FOLDER);
connector.checkChildObjectType(parentInfo, type.getTypeId());
// run transaction
FileInfo fileInfo = connector.getFileFolderService().create(parentInfo.getNodeRef(), name, type.getAlfrescoClass());
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.getActivityPoster().postFileFolderAdded(nodeRef);
String objectId = connector.createObjectId(nodeRef);
return objectId;
}
Aggregations