Testing Alfresco from command line with CURL and CMIS Browser

Recently, I’ve been working to automate ALF_NODE_PROPERTIES table partition process in PostgreSQL for Alfresco. This process creates several partitions for the table, including older contents in the first partition and new contents in the last one. Once the table has been partitioned is required to test CRUD for properties belonging to nodes in every segment to ensure that every partition has been properly set up.

Using CMIS Browser protocol to access Alfresco, simple CURL sentences can perform such operations.

Modifying a property for an existing content

Alfresco provides the same sample files on every installation, so a property of one of this sample files can be created or modified to test CRUD in the first partition.

Following command will modify cmis:description property value to “test” at Data Dictionary > scripts > alfresco docs.js.sample file.


$ curl -X POST \
'http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Data%20Dictionary/scripts/alfresco%20docs.js.sample?cmisSelector=object' \
-H 'authorization: Basic YWRtaW46dGVtcG9yYWw= \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'cmisaction=update&propertyId%5B0%5D=cmis%3Adescription&propertyValue%5B0%5D=testok&succinct=true'

Content for every intermediate partition can be selected to perform the same command.

Creating a new content

Every new content will be created in the last partition, so to test CRUD in this partition an upload command can be used.

Following command will create a file named “test.txt” at Shared repository folder.

$ curl -X POST \
  http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared \
  -H 'authorization: Basic YWRtaW46dGVtcG9yYWw=' \
  -H 'content-type: multipart/form-data' \
  -F cmisaction=createDocument \
  -F 'propertyId[0]=cmis:objectTypeId' \
  -F 'propertyValue[0]=cmis:document' \
  -F 'propertyId[1]=cmis:name' \
  -F 'propertyValue[1]=test.txt' \
  -F file=@/tmp/test.txt \
  -F succinct=true

Removing a content

Partition testing does not require this additional command, but it has been included to clear our operations in the server.

Following command will remove the file “test.txt” we’ve just created at Shared repository folder.

curl -X POST\
  http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared/test.txt \
  -H 'authorization: Basic YWRtaW46dGVtcG9yYWw=' \
  -H 'content-type: multipart/form-data' \
  -F cmisaction=delete \
  -F succinct=true 

Alfresco makes it so simple to automate our operations!

Anuncios

Node templates by Site in Alfresco

Alfresco provides a feature to set files as templates. However, every file uploaded to Repository > Data Dictionary > Node Templates will be available as template for every user in every site.

Let’s see how can we tweak permissions in order to have different templates for different sites.

Initial situation

We are using two sites in this sample with following properties:

  • Accounting and Finance
    • Short name: accounting-and-finance
    • Internal group name: GROUP_site_accounting-and-finance
    • Required template: CV.docx
  • Purchasing
    • Short name: purchasing
    • Internal group name: GROUP_purchasing
    • Required template: PO.xlxs

Both CV.docx and PO.xlxs files are uploaded to Repository > Data Dictionary > Node Templates by using Share uploading feature.

Manage Permissions

As Share web interface does not expose internal groups to actions, it’s required to use a tool like JavaScript Console to make this setting.

For document CV.docx following sentences are executed:

document.setPermission("Read", "GROUP_site_accounting-and-finance");
document.save();

For document PO.xlxs following sentences are executed:

document.setPermission("Read", "GROUP_site_purchasing");
document.save();

After executing these operations, regular Manage Permissions action is used to unset Inherit Permissions.

Testing

From this point users from site Accounting and Finance will only have available CV.docx from Create document from template option and users from site Purchasing will only have available PO.xlsx from Create document from template option.

This is a so simple approach, that I’ve been internally forced to create a new addon available at https://github.com/keensoft/alfresco-site-node-templates

Check it out!

Extracting simple stats from Alfresco 5

How many documents are created in Alfresco by user?

Someone asked me the question this morning and I remembered that there was a simple SOLR REST service to recover such information from Alfresco 5.

The service can be invoked without parameters by using the following URL

http://localhost:8080/alfresco/s/api/solrstats

and a raw count of document and storage is produced

{
    "resultset": [
    ],
    "queryInfo": {
      "numberFound": "30758"
      ,"totalRows": "0"
         ,"sum": "37910306685"
         ,"max": "2706931488"
         ,"mean": "1239830"
    },
    "metadata": [
        {
            "colIndex": 0,
            "colType": "String",
            "colName": "name"
        },
        {
            "colIndex": 1,
            "colType": "Numeric",
            "colName": "sum"
        },
        {
            "colIndex": 2,
            "colType": "Numeric",
            "colName": "count"
        },
        {
            "colIndex": 3,
            "colType": "Numeric",
            "colName": "min"
        },
        {
            "colIndex": 4,
            "colType": "Numeric",
            "colName": "max"
        },
        {
            "colIndex": 5,
            "colType": "Numeric",
            "colName": "mean"
        }
    ]
}

However, using the listFacets parameter a list of available filters is obtained

http://localhost:8080/alfresco/s/api/solrstats?listFacets=true

[
      "content.mimetype",
      "content.creator",
      "content.modifier",
      "content.created.datetime",
      "content.modified.datetime",
      "content.encoding",
      "content.locale",
      "content.versionLabel",
      "exif.model",
      "exif.manufacturer",
      "exif.iso",
      "exif.focalLength",
      "exif.software"
]

And providing the right filter to the service, created contents by user stats are shown

http://localhost:8080/alfresco/s/api/solrstats?facet=content.creator

{
    "resultset": [
         ...
         ,
         ["angel.borroy",2195237313, 2515, 0, 101617524, 872857]
         ,
         ...
    ],
    "queryInfo": {
      "numberFound": "30758"
      ,"totalRows": "29"
         ,"sum": "37910306685"
         ,"max": "2706931488"
         ,"mean": "1239830"
    },
    "metadata": [
        {
            "colIndex": 0,
            "colType": "String",
            "colName": "name"
        },
        {
            "colIndex": 1,
            "colType": "Numeric",
            "colName": "sum"
        },
        {
            "colIndex": 2,
            "colType": "Numeric",
            "colName": "count"
        },
        {
            "colIndex": 3,
            "colType": "Numeric",
            "colName": "min"
        },
        {
            "colIndex": 4,
            "colType": "Numeric",
            "colName": "max"
        },
        {
            "colIndex": 5,
            "colType": "Numeric",
            "colName": "mean"
        }
    ]
}

It looks like I’ve created 2,515 documents at that Alfresco server installation.

Results may not be exact, as it’s based in SOLR indexation. However they are fine for general stats and comparative studies.