create method
void
create(})
Create item, see the supporting documentation as to what this currently supports.
Implementation
void create(String name, String cmisAction,
{String? typeId,
String? parentId,
String? parentPath,
String? content,
String? mimeType,
Map<String, String>? customProperties}) {
if (repositoryId == null) {
throw CmisException('create() expects a non null repository Id');
}
var url = _getRootFolderUrl();
if (parentPath != null) {
url = '$url/$parentPath';
}
dynamic data = jsonobject.JsonObjectLite<dynamic>();
dynamic formData = _environmentSupport.formData();
var useFormData = false;
// Headers, we only create documents or folders */
final headers = <String, String>{};
if (typeId == 'cmis:folder') {
headers['content-type'] = 'application/x-www-form-urlencoded';
} else {
if (formData != null) {
useFormData = true;
}
}
// Properties for normal POST submit
if (!useFormData) {
data.cmisaction = cmisAction;
final properties = <String, String>{};
properties['cmis:name'] = name;
if (parentId != null) {
properties['objectId'] = parentId;
}
if (typeId != null) {
properties['cmis:objectTypeId'] = typeId;
}
if (content != null) {
properties['content'] = content;
}
// Add any supplied custom properties
if (customProperties != null) {
properties.addAll(customProperties);
}
// Construct the final data set
var index = 0;
final jsonMap = <String, String>{};
properties.forEach((dynamic key, dynamic value) {
final propId = 'propertyId[$index]';
final propValue = 'propertyValue[$index]';
jsonMap[propId] = key;
jsonMap[propValue] = value;
index++;
});
data.addAll(jsonMap);
formData = null;
} else {
// Form data interface for stream/content interfaces
formData.append('cmisaction', cmisAction);
formData.append('PropertyId[0]', 'cmis:name');
formData.append('PropertyValue[0]', name);
if (typeId != null) {
formData.append('PropertyId[1]', 'cmis:objectTypeId');
formData.append('PropertyValue[1]', typeId);
}
if (parentId != null) {
formData.append('PropertyId[2]', 'objectId');
formData.append('PropertyValue[2]', parentId);
}
final blobParts = <String?>[];
blobParts.add(content);
final dynamic theBlob = _environmentSupport.blob(blobParts, mimeType);
formData.appendBlob('content', theBlob);
data = null;
}
_httpRequest('POST', url, data: data, headers: headers, formData: formData);
}