title: Is it possible to create a folder on the Alfresco site by using OpenCMIS API?
body: <p>I have the <a href="http://docs.alfresco.com/5.2/concepts/ws-types-presentation.html" rel="nofollow noreferrer">Presentation Web Script</a> (<code>script A</code>) and the <a href="http://docs.alfresco.com/5.2/concepts/ws-types-data.html" rel="nofollow noreferrer">Data Web Script</a> (<code>script B</code>).</p>
  
  <p>In the <code>script A</code> I build the dialog that interacts with the <code>script B</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/1W7ae.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1W7ae.jpg" alt="enter image description here"></a></p>
  
  <p>Here I am forming some path where the some file will be uploaded (<code>group</code>, <code>year</code> and <code>number</code> parameters define this path):</p>
  
  <pre><code>...
  var submitHandler = function() {
      var dataWebScriptUrl = window.location.protocol + '//' + 
          window.location.host + "/alfresco/s/ms-ws/script-b?guest=true";
  
      var yearCombo = document.getElementById("year");
      var year = yearCombo.options[yearCombo.selectedIndex].value;
  
      var groupCombo = document.getElementById("group");
      var group = groupCombo.options[groupCombo.selectedIndex].value;
  
      var numberCombo = document.getElementById("number");
      var number = numberCombo.value;
  
      var uploadedFile = document.getElementById("uploadedFile");
      var file = uploadedFile.files[0];
  
      var formData = new FormData();
      formData.append("year", year);
      formData.append("group", group);
      formData.append("number", number);
      formData.append("uploadedFile", file);      
  
      var xhr = new XMLHttpRequest();
      xhr.open("POST", dataWebScriptUrl);
      xhr.send(formData);
  };
  ...
  </code></pre>
  
  <p>In <code>script B</code>, I'm using the <a href="https://chemistry.apache.org/java/opencmis.html" rel="nofollow noreferrer">Apache Chemistry OpenCMIS API</a> to create a path in the <a href="https://en.wikipedia.org/wiki/Content_Management_Interoperability_Services" rel="nofollow noreferrer">CMIS</a>-compatible Alfresco repository:</p>
  
  <pre><code>public class CustomFileUploader extends DeclarativeWebScript implements OpenCmisConfig {
      ...
      private void retrievePostRequestParams(WebScriptRequest req) {
          String groupName = null, year = null, number = null;
  
          FormData formData = (FormData) req.parseContent();
          FormData.FormField[] fields = formData.getFields();
          for(FormData.FormField field : fields) {
              String fieldName = field.getName();
              String fieldValue = field.getValue();
  
              if(fieldName.equalsIgnoreCase("group")) {
                  if(fieldValue.equalsIgnoreCase("services")) {
                      groupName = "Услуги";
                  ...                         
          }
  
          firstLevelFolderName = "/" + groupName;
          secondLevelFolderName = groupName + " " + year; 
          thirdLevelFolderName = number;
      }
  
      ...
  
      Folder firstLevelFolder = 
                  createFolderIfNotExists(cmisSession, docLibFolder, firstLevelFolderName);
  
      ...
  
      private Folder createFolderIfNotExists(Session cmisSession, 
              Folder parentFolder, String folderName) {
          Folder subFolder = null;
          for(CmisObject child : parentFolder.getChildren()) {
              if(folderName.equalsIgnoreCase(child.getName())) {
                  subFolder = (Folder) child;
              }
          }
  
          if(subFolder == null) {
              Map&lt;String, Object&gt; props = new HashMap&lt;&gt;();
              props.put("cmis:objectTypeId", "cmis:folder");
              props.put("cmis:name", folderName);
  
              subFolder = parentFolder.createFolder(props);
          }
          return subFolder; 
      }
  
      private Folder getDocLibFolder(Session cmisSession, String siteName) {
          String path = "/Sites/" + siteName + "/documentLibrary";
          return (Folder) cmisSession.getObjectByPath(path);
      }
  
      private Session getCmisSession() {
          SessionFactory factory = SessionFactoryImpl.newInstance();
          Map&lt;String, String&gt; conf = new HashMap&lt;&gt;();
  
          // http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom
          conf.put(SessionParameter.ATOMPUB_URL, ATOMPUB_URL);
          conf.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
          conf.put(SessionParameter.USER, USER_NAME);
          conf.put(SessionParameter.PASSWORD, PASSWORD);
  
          // "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"
          conf.put(SessionParameter.OBJECT_FACTORY_CLASS, OBJECT_FACTORY_CLASS);
          conf.put(SessionParameter.REPOSITORY_ID, "-default-");
  
          Session session = factory.createSession(conf);
  
          return session;
      }
  
      ...
  </code></pre>
  
  <p>It's all works well... But I need to create the directory structure on a specific site, e.g. "contracts-site", here:</p>
  
  <pre><code>/site/contracts-site/documentlibrary
  </code></pre>
  
  <p>When I specifying the following:</p>
  
  <pre><code>/Sites/contracts-site/documentLibrary/Услуги
  /Sites/contracts-site/Услуги
  /site/contracts-site/documentlibrary/Услуги
  </code></pre>
  
  <p>I get the following exception (depending on the path):</p>
  
  <pre><code>org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Object not found: /Sites/contracts-site/Услуги
  </code></pre>
  
  <p>When I specifying the following:</p>
  
  <pre><code>"/Услуги"
  </code></pre>
  
  <p>Everything works, but the directory structure is created outside the site...</p>
  
  <p>How to create a folder on the Alfresco site by using OpenCMIS API?</p>