Is the function PHP getProperty of a document not yet implemented?

Am I correct that this function in the PHP library/client for REST automation has not been implemented yet?

$docVersion = $this->documents[$index]->getProperty('dc:version') ;

Where documents[] is the resultset of a call : `$this->answer = $this->session->newRequest(“Document.Query”)

                                    ->set('params', 'query', $query)
                                    ->setSchema($this->propertiesSchema)
                                    ->sendRequest();

`

0 votes

2 answers

1257 views

ANSWER



Thanks for the feedback. I did some further testing.

Function:

    /**
      *  Generialised PropertyGet function
      *
      *  @param string propertyName
      *  @param string propertyDescription
      *  @param int index
      *
      *  @return string value
      *  or
      *  @return boolean false
      */
    private function getDocumentProperty($name, $desc, $index) {
        global $logdebug;
        if ($index > $this->getNumberOfDocumentsInResultset() ) {
            if ($logdebug) {
                $this->logger->addInfo($desc . " : the index provided (".$index.") is beyond the scope of the document list (".$this->getNumberOfDocumentsInResultset().")");
            }
            $value = false ;
        }
        else {
            $value = $this->documents[$index]->getProperty($name) ; // deviation from regular property queries
            //$value = $this->documents[$index]->getProperty("'".$name."'") ;
            //$value = $this->documents[$index]->getProperty("'dc:creator'") ;
            if ($logdebug) {
                $this->logger->addInfo("Get property ".$name);
                $docname = $this->getDocumentTitle($index);
                $this->logger->addInfo("Getting property from document titled '" . $docname . "'");
            }
            if ($logdebug) {
                $this->logger->addDebug("Get ".$desc . " index = ".$index);
                $this->logger->addDebug("Get ".$desc . " resultsetsize = ".$this->getNumberOfDocumentsInResultset());
                $this->logger->addDebug($desc . " = ".$value);
            }
        }
        return ($value) ;
    }

It should be called like: $this->getDocumentProperty('dc:creator', "DocumentCreator", 0) Result is an empty string. This is regardless of the property. This is a bit weird as a direct call like: $this->documents[$index]->getTitle() produces a proper result.

This is especially hard to debug as I see no exceptions or errors, just an empty result string. Any pointers much appreciated.

0 votes



This code works fine for me.

  /**
   *  Generialised PropertyGet function
   *
   * @param string propertyName
   * @param string propertyDescription
   * @param int index
   *
   * @return string value
   *  or
   * @return boolean false
   */
  public function getDocumentProperty($name, $desc, $index) {
      $value = $this->documents[$index]->getProperty($name); // deviation from regular property queries
    return ($value);
  }

You may have some warning or error somewhere, did you try activate some debug ?

05/18/2016

I added the following line to my code the make my monolog debugging more verbose:

$this->logger->addInfo(var_export($this->documents[$index], true));

which gave interesting results. Facets is filled as expected etc etc BUT the property array is empty! This is especially weird as when I play around with a local installation of the playground I do get proper results.

To give an idea of what I (do not) get:

NuxeoAutomationClientNuxeoDocument::__set_state(array( 'object' => array ( 'entity-type' => 'document', 'repository' => 'default', 'uid' => 'eed85afa-bbb4-47e1-86f4-6b125f2256d2', 'path' => '/default-domain/workspaces/Trial workspace/Olympia', 'type' => 'Collection', 'state' => 'project', 'parentRef' => '6c47f32b-37f9-46f2-80e8-6ec363b88cc9', 'isCheckedOut' => true, 'changeToken' => '1463495454433', 'title' => 'Olympia', 'lastModified' => '2016-05-17T14:30:54.43Z', 'properties' => array ( ), 'facets' => array ( 0 => 'Versionable', 1 => 'DocumentsSizeStatistics', 2 => 'Collection', 3 => 'NotCollectionMember', ), ), 'properties' => array ( ), ))

Also notable: it does not mater what type of document it is: collection, document etc: the properties are always empty.

05/19/2016

Have you tried to perform the query manually or at least debug the raw response of the Nuxeo server ? https://doc.nuxeo.com/display/NXDOC/Command+Endpoint
05/20/2016

I did test on/with the local nuxeo playground. But that was not an exact test of the querry so I did some further testing which provided more questions than answers :-(

Python code: from pprint import pprint

URL = "http://localhost:8080/nuxeo/site/automation/" USER = 'Administrator' PASSWD = 'Administrator'

cookie_processor = urllib2.HTTPCookieProcessor() opener = urllib2.build_opener(cookie_processor) urllib2.install_opener(opener)

def execute(command, input=None, **params):

auth = 'Basic %s' % base64.b64encode(USER + ":" + PASSWD).strip()
headers = {
    "Content-Type": "application/json+nxrequest",
    "Authorization": auth}
d = {}
if params:
    d['params'] = params
if input:
    d['input'] = input
if d:
    data = json.dumps(d)
else:
    data = None
req = urllib2.Request(URL + command, data, headers)

try:
    resp = opener.open(req)
except Exception, e:
    exc = json.load(e.fp)
    print exc['message']
    print exc['stack']
    sys.exit()
s = resp.read()
if s:
    return json.loads(s)
else:
    return None

print " Cartilage.pdf " doc = execute("Document.Query", query="SELECT * FROM Document WHERE ecm:primaryType='File' AND ecm:path='/default-domain/workspaces/Trial workspace/mydoc.pdf'") pprint(doc) print print " test.pdf " print " (a file which is the result of a copy/paste/rename operation in Nuxeo on the document above) " doc = execute("Document.Query", query="SELECT * FROM Document WHERE ecm:primaryType='File' AND ecm:path='/default-domain/workspaces/Trial workspace/test.pdf'")

This resulted in: mydoc.pdf {'currentPageIndex': 0, 'currentPageSize': 1, 'entity-type': 'documents', 'entries': [{'changeToken': '1460645157000',

          'entity-type': 'document',
          'facets': ['Versionable',
                     'DocumentsSizeStatistics',
                     'Publishable',
                     'Commentable',
                     'HasRelatedText',
                     'Thumbnail',
                     'Downloadable'],
          'isCheckedOut': True,
          'lastModified': '2016-04-14T14:45:57.00Z',
          'parentRef': '6c47f32b-37f9-46f2-80e8-6ec363b88cc9',
          'path': '/default-domain/workspaces/Trial workspace/mydoc.pdf',
          'repository': 'default',
          'state': 'project',
          'title': 'mydoc.pdf',
          'type': 'File',
          'uid': '96b6c4be-009a-4c24-88be-661a4460f4b5'}],

'errorMessage': None, 'hasError': False, 'isLastPageAvailable': False, 'isNextPageAvailable': False, 'isPaginable': True, 'isPreviousPageAvailable': False, 'isSortable': True, 'maxPageSize': 1000, 'numberOfPages': 1, 'pageCount': 1, 'pageIndex': 0, 'pageSize': 0, 'resultsCount': 1, 'totalSize': 1}

test.pdf (a file which is the result of a copy/paste/rename operation in Nuxeo on the document above) {'currentPageIndex': 0, 'currentPageSize': 0, 'entity-type': 'documents', 'entries': [], 'errorMessage': None, 'hasError': False, 'isLastPageAvailable': False, 'isNextPageAvailable': False, 'isPaginable': True, 'isPreviousPageAvailable': False, 'isSortable': True, 'maxPageSize': 1000, 'numberOfPages': 1, 'pageCount': 1, 'pageIndex': 0, 'pageSize': 0, 'resultsCount': 0, 'totalSize': 0}

Leaving me with questions: a) why do I get empty properties as a result from my query on 'mydoc.pdf' while properties exist within Nuxeo and within the playground? b) why do I get less info on my second query while the docs are identical in above example c) above example shows an empty resultset entries[] for some reason, but no errors. Is this intentional and correct? Why? (the file does exist at te location specified in the query)

05/20/2016

About your original question and a), make sure to query for at least any schema (*) to get the properties (setSchema method with the PHP Client) as I don't see it in your python sample.

  $answer = $session->newRequest("Document.Query")
    ->set('params', 'query', $query)
    ->setSchema("*")
    ->sendRequest();

You can see it is sent by the playground when looking at the headers tab. https://doc.nuxeo.com/display/NXDOC710/Special+HTTP+Headers#SpecialHTTPHeaders-X-NXRepository

About b) and c), note that the path or your copied/renamed document is not /default-domain/workspaces/Trial workspace/test.pdf, see the comment on the following https://jira.nuxeo.com/browse/SUPNXP-13310. Use the export function to see the real path of your document and you should see the properties.

05/23/2016

Thanks. It turned out that in the PHP code the headers were not set properly. $schema='"'"; versus $schema=''; made the difference. Obviously the schema was not set at all in the Python code.

The link to SUBNXP-13310 gives an "issue not found" error btw.

05/23/2016


Hi Olaf,

Try :

$this->documents[$index]->getProperty('uid:major_version');
$this->documents[$index]->getProperty('uid:minor_version');
0 votes