class SingleRepositoryServiceImpl implements SingleRepositoryService {

    @Override
    public Resource createResource(Resource serverResource, String parentUri, boolean createFolders, boolean dryRun) throws ErrorDescriptorException {
        if (createFolders) {
            if(!dryRun) ensureFolderUri(parentUri);
        } else if (!repositoryService.folderExists(null, parentUri)) {
            throw new FolderNotFoundException(parentUri);
        }

        serverResource.setParentFolder(parentUri);
        if (serverResource.getName() == null || "".equals(serverResource.getName())) {
            serverResource.setName(generateName(parentUri, serverResource.getLabel()));
        }
        if(!dryRun) {
            try {
                if (serverResource instanceof Folder) {
                    repositoryService.saveFolder(null, (Folder) serverResource);
                } else {
                    repositoryService.saveResource(null, serverResource);
                }
            } catch (JSDuplicateResourceException e) {
                throw new AccessDeniedException(e.getMessage(), new String[]{serverResource.getName(), parentUri});
            } catch (JSExceptionWrapper w) {
                throw getRootException(w);
            }
        }

        return dryRun ? serverResource : getResource(serverResource.getURIString());
    }

}