From cd53315acd6099694032450bd2ffe0486f4a294c Mon Sep 17 00:00:00 2001
From: Laurent Giovannoni <laurent.giovannoni@maarch.org>
Date: Tue, 13 Sep 2016 13:48:58 +0000
Subject: [PATCH] FEAT #4578 CMIS

---
 .../class/web_service/class_rest_server.php   | 18 +++---
 .../cmis_test/create_folder.atom.xml          | 13 ++++
 .../web_service/cmis_test/curl_query.txt      | 12 ++++
 .../class/web_service/cmis_test/query.xml     | 10 +++
 .../class/web_service/cmis_test/test_rest.php | 62 +++++++++++++++++++
 .../cmis_test/testcreatefolder.atom.xml       | 17 +++++
 6 files changed, 125 insertions(+), 7 deletions(-)
 create mode 100755 core/trunk/core/class/web_service/cmis_test/create_folder.atom.xml
 create mode 100755 core/trunk/core/class/web_service/cmis_test/curl_query.txt
 create mode 100755 core/trunk/core/class/web_service/cmis_test/query.xml
 create mode 100755 core/trunk/core/class/web_service/cmis_test/test_rest.php
 create mode 100755 core/trunk/core/class/web_service/cmis_test/testcreatefolder.atom.xml

diff --git a/core/trunk/core/class/web_service/class_rest_server.php b/core/trunk/core/class/web_service/class_rest_server.php
index 81f96025ce1..f1471b1ed0f 100644
--- a/core/trunk/core/class/web_service/class_rest_server.php
+++ b/core/trunk/core/class/web_service/class_rest_server.php
@@ -82,14 +82,15 @@ class MyRestServer extends webService
             $this->makeAtomEntryRootFolder();
         } else {
             $restRequest = explode('/', $_SERVER['QUERY_STRING']);
-            if ($restRequest[3] <> '') {
-                $this->requestedCollection = $restRequest[3];
+            //var_dump($restRequest);
+            if ($restRequest[1] <> '') {
+                $this->requestedCollection = $restRequest[1];
             }
-            if ($restRequest[4] <> '') {
-                $this->requestedResource = $restRequest[4];
+            if ($restRequest[2] <> '') {
+                $this->requestedResource = $restRequest[2];
             }
-            if ($restRequest[5] <> '') {
-                $this->requestedResourceId = $restRequest[5];
+            if ($restRequest[3] <> '') {
+                $this->requestedResourceId = $restRequest[3];
             }
             if (
                 isset($_REQUEST['atomFileContent']) 
@@ -97,7 +98,7 @@ class MyRestServer extends webService
             ) {
                 $this->atomFileContent = $_REQUEST['atomFileContent'];
             }
-            //var_dump($this);exit;
+            //var_dump($this);
         }
     }
     
@@ -108,6 +109,9 @@ class MyRestServer extends webService
      */
     public function call()
     {
+      // var_dump($this->dispatchMap);
+      // var_dump($this->requestedResource);
+      // var_dump($this->dispatchMap[$this->requestedResource]['pathToController']);
         if (
             file_exists(
                 $this->dispatchMap[$this->requestedResource]['pathToController']
diff --git a/core/trunk/core/class/web_service/cmis_test/create_folder.atom.xml b/core/trunk/core/class/web_service/cmis_test/create_folder.atom.xml
new file mode 100755
index 00000000000..aedeef56b22
--- /dev/null
+++ b/core/trunk/core/class/web_service/cmis_test/create_folder.atom.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom"
+xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
+xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/"
+xmlns:maarch="http://www.maarch.org">
+<title>Someco</title>
+<cmisra:object>
+<cmis:properties>
+<cmis:propertyId
+propertyDefinitionId="cmis:objectTypeId"><cmis:value>cmis:folder</cmis:value></cmis:propertyId>
+</cmis:properties>
+</cmisra:object>
+</entry>
diff --git a/core/trunk/core/class/web_service/cmis_test/curl_query.txt b/core/trunk/core/class/web_service/cmis_test/curl_query.txt
new file mode 100755
index 00000000000..e80f9d37659
--- /dev/null
+++ b/core/trunk/core/class/web_service/cmis_test/curl_query.txt
@@ -0,0 +1,12 @@
+#voir le document
+curl -X GET -ubblier:maarch "http://127.0.0.1/maarch_entreprise/ws_server.php?REST/res/101"
+#recherche avancée de documents
+curl -X POST -ubblier:maarch "http://127.0.0.1/maarch_entreprise/ws_server.php?REST/res" -d atomFileContent=thexmlcontentfilebase64encode
+#consulter le dossier
+curl -X GET -ubblier:maarch "http://127.0.0.1/maarch_entreprise/ws_server.php?REST/folder/RH"
+#créer un dossier
+curl -X POST -ubblier:maarch "http://127.0.0.1/maarch_entreprise/ws_server.php?REST/folder" -d atomFileContent=thexmlcontentfilebase64encode
+#voir la liste des corbeilles
+curl -X GET -ubblier:maarch "http://127.0.0.1/maarch_entreprise/ws_server.php?REST/basket"
+#Liste des documents d'une corbeille
+curl -X GET -ubblier:maarch "http://127.0.0.1/maarch_entreprise/ws_server.php?REST/basket/MesCourriersATraiter"
diff --git a/core/trunk/core/class/web_service/cmis_test/query.xml b/core/trunk/core/class/web_service/cmis_test/query.xml
new file mode 100755
index 00000000000..334deddfa07
--- /dev/null
+++ b/core/trunk/core/class/web_service/cmis_test/query.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<cmis:query xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:cmism="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:maarch="http://www.maarch.org">
+  <cmis:statement> SELECT  cmis:objectId , maarch:type , maarch:entity , maarch:dest_user   FROM cmis:document where maarch:dest_user is not null ORDER BY cmis:objectId asc </cmis:statement>
+  <cmis:searchAllVersions>false</cmis:searchAllVersions>
+  <cmis:includeAllowableActions>false</cmis:includeAllowableActions>
+  <cmis:includeRelationships>none</cmis:includeRelationships>
+  <cmis:renditionFilter>*</cmis:renditionFilter>
+  <cmis:maxItems>50</cmis:maxItems>
+  <cmis:skipCount>0</cmis:skipCount>
+</cmis:query>
diff --git a/core/trunk/core/class/web_service/cmis_test/test_rest.php b/core/trunk/core/class/web_service/cmis_test/test_rest.php
new file mode 100755
index 00000000000..249b085911c
--- /dev/null
+++ b/core/trunk/core/class/web_service/cmis_test/test_rest.php
@@ -0,0 +1,62 @@
+<?php
+
+include_once ('../../../init.php');
+if (!isset($_REQUEST['collection'])) {
+    $_REQUEST['collection']  = 'letterbox_coll';
+}
+if (!isset($_REQUEST['resource'])) {
+    $_REQUEST['resource']  = 'folder';
+}
+
+//INIT CURL
+$curl = curl_init();
+
+//BASIC AUTHENTICATION
+curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+curl_setopt($curl, CURLOPT_USERPWD, 'bblier:maarch');
+//curl_setopt($curl, CURLOPT_USERPWD, 'pparker:maarch');
+
+//WS URL
+$url = $_SESSION['config']['coreurl'] . 'ws_server.php?CMIS';
+if (isset($_REQUEST['collection']) && !empty($_REQUEST['collection'])) {
+    $url .= '/' . $_REQUEST['collection'];
+}
+if (isset($_REQUEST['resource']) && !empty($_REQUEST['resource'])) {
+    $url .= '/' . $_REQUEST['resource'];
+}
+if (isset($_REQUEST['idResource']) && !empty($_REQUEST['idResource'])) {
+    $url .= '/' . $_REQUEST['idResource'];
+}
+curl_setopt($curl, CURLOPT_URL, $url . '/');
+
+if (($_REQUEST['method'] == 'post' || !isset($_REQUEST['method']))&& isset($_REQUEST['xmlFile'])) {
+    $xmlAtomFileContent = file_get_contents('core/class/web_service/cmis_test/' . $_REQUEST['xmlFile']);
+    curl_setopt($curl, CURLOPT_POSTFIELDS, 'atomFileContent=' . $xmlAtomFileContent);
+    curl_setopt($curl, CURLOPT_POST, 1);
+}
+else {
+    //GET, PUT, DELETE METHOD
+    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($_REQUEST['method']));
+}
+//var_dump($url);
+//var_dump($_SESSION);
+
+//POST CONTENT
+//$xmlAtomFileContent = base64_encode(file_get_contents('create_folder.atom.xml'));
+//$xmlAtomFileContent = file_get_contents('query.xml');
+//$xmlAtomFileContent = file_get_contents('testcreatefolder.atom.xml');
+//curl_setopt($curl, CURLOPT_POSTFIELDS, 'atomFileContent=' . $xmlAtomFileContent);
+//HTTP METHOD
+//if ($_REQUEST['method'] == 'post' || !isset($_REQUEST['method'])) {
+//    curl_setopt($curl, CURLOPT_POST, 1);
+//} else {
+    //GET, PUT, DELETE METHOD
+    //curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($_REQUEST['method']));
+    //curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: ' . $_REQUEST['method']));
+//}
+//RESULT
+curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+$page = curl_exec($curl);
+//var_dump($curl);
+curl_close($curl);
+print($page);
diff --git a/core/trunk/core/class/web_service/cmis_test/testcreatefolder.atom.xml b/core/trunk/core/class/web_service/cmis_test/testcreatefolder.atom.xml
new file mode 100755
index 00000000000..fbb0103f7d4
--- /dev/null
+++ b/core/trunk/core/class/web_service/cmis_test/testcreatefolder.atom.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom"
+xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
+xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/"
+xmlns:maarch="http://www.maarch.org">
+  <title>Test creation folder</title>
+  <cmisra:object>
+    <cmis:properties>
+      <cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
+        <cmis:value>cmis:folder</cmis:value>
+      </cmis:propertyId>
+      <cmis:propertyId propertyDefinitionId="folderId">
+        <cmis:value>TEST</cmis:value>
+      </cmis:propertyId>
+    </cmis:properties>
+  </cmisra:object>
+</entry>
-- 
GitLab