String user = context.getUsername();
validator.createFolder(context, repositoryId, folderId, extension);
ObjectStore fs = fStoreManager.getObjectStore(repositoryId);
StoredObject so = null;
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.isValidId(folderName)) {
throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
}
TypeValidator.validateRequiredSystemProperties(properties);
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());
}
TypeValidator.validateProperties(typeDef, properties, true);
// 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);
}
ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
Folder newFolder = objStore.createFolder(folderName);
// set default system attributes
if (user == null) {
user = "unknown";
}
newFolder.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
newFolder.setCustomProperties(properties.getProperties());
parent.addChildFolder(newFolder);
LOG.debug("stop createFolder()");
newFolder.persist();
return newFolder;
}