validator.createFolder(context, repositoryId, folderId, extension);
TypeValidator.validateRequiredSystemProperties(properties);
String user = context.getUsername();
ObjectStore fs = fStoreManager.getObjectStore(repositoryId);
Folder parent = null;
// get required properties
PropertyData<?> pd = properties.getProperties().get(PropertyIds.NAME);
String folderName = (String) pd.getFirstValue();
if (null == folderName || folderName.length() == 0) {
throw new CmisInvalidArgumentException("Cannot create a folder without a name.");
}
// check name syntax
if (!NameValidator.isValidName(folderName)) {
throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME + " Name is: " + folderName);
}
TypeDefinition typeDef = getTypeDefinition(repositoryId, properties);
// check if the given type is a folder type
if (!typeDef.getBaseTypeId().equals(BaseTypeId.CMIS_FOLDER)) {
throw new CmisInvalidArgumentException("Cannot create a folder, with a non-folder type: " + typeDef.getId());
}
Map<String, PropertyData<?>> propMap = properties.getProperties();
Map<String, PropertyData<?>> propMapNew = setDefaultProperties(typeDef, propMap);
if (propMapNew != propMap) {
properties = new PropertiesImpl(propMapNew.values());
}
boolean cmis11 = context.getCmisVersion() != CmisVersion.CMIS_1_0;
validateProperties(repositoryId, null, properties, false, cmis11);
// validate ACL
TypeValidator.validateAcl(typeDef, addACEs, removeACEs);
StoredObject so = null;
// create folder
try {
LOG.debug("get folder for id: " + folderId);
so = fs.getObjectById(folderId);
} catch (Exception e) {
throw new CmisObjectNotFoundException("Failed to retrieve folder.", e);
}
if (so instanceof Folder) {
parent = (Folder) so;
} else {
throw new CmisInvalidArgumentException("Can't create folder, folderId does not refer to a folder: "
+ folderId);
}
if (user == null) {
user = "unknown";
}
ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
Folder newFolder = objStore.createFolder(folderName, properties.getProperties(), user, parent,
addACEs, removeACEs);
LOG.debug("stop createFolder()");
newFolder.persist();
return newFolder;
}