Book Image

Alfresco 3 Web Services

Book Image

Alfresco 3 Web Services

Overview of this book

Alfresco 3 is the leading open source enterprise content management system that offers powerful features for interacting with the content in its repository from outside the system. These include the support for the Content Management Interoperability Services (CMIS) implementation, reusable web scripts, and a Web Services API. This is the first book to show you how to use Web Services in Alfresco. Packed with examples, you'll learn how to build applications using Alfresco remote APIs based on SOAP and REST. You'll see how to use different APIs and bindings such as WebServices, WebScripts, and CMIS. Alfresco 3 Web Services starts off by showing you the services exposed by the Alfresco Web Services API, and how the API fits into the Alfresco software architecture.You learn to develop your application firstly by setting up and testing your Java development environment using the Alfresco SDK in Eclipse IDE and secondly by associating the Alfresco source code and Javadocs in Eclipse.With the help of real world practical examples, you learn how to do things like create, sort, and call Web Scripts, and invoke remote calls to Alfresco repository. To get the most from the Web Services API, you need to know about the basics of the Content Manipulation Language (CML), and the book takes you through this.Examples such as the bookshop application show you how to sign in, change user sessions, get, remove and change public and private associated contents, manage a cart for your e-commerce application, and so on.Next, by implementing a Microsoft .NET application using the Alfresco Web Services API, you see how to perform operations against the repository from your .NET application.The book provides you with REST and SOAP concepts, their comparison, basics of the FreeMarker language, Atom Publishing Protocol, JavaScript controllers, and the Apache Chemistry project.By the end of this book, you will be able to put together your knowledge about CMIS and the Apache Chemistry toolkit to develop a complete working application that uses Alfresco, via CMIS, as a back-end storage. Last but not the least, this book also covers the WebServices security profiles— the best practices for Web Services to promote better interoperability.
Table of Contents (20 chapters)
Alfresco 3 Web Services
Credits
About the Authors
About the Reviewers
Preface
Free Chapter
1
Introducing the SOAP Web Services API

Grammar of queries


The basic form of a CMIS SQL query is as follows:

SELECT <virtual columns> FROM <virtual tables> [WHERE <conditions>] [ORDER BY <sort specification>]

The SELECT clause

The SELECT clause must either specify a comma-separated list of virtual column names or the '*' token. All column names must be valid queryNames of properties defined for the object types listed in the FROM clause.

In addition to column names, it is also possible to use the SCORE() predicate function as a column name. The SCORE() predicate returns the relevance value of the search made in the CONTAINS predicate. The value is between 0 and 1, with 0 it means that the text was not found in the document and 1 indicates a perfect match. You cannot use the SCORE() function in a query that does not use the CONTAINS predicate.

Note

Content streams are not part of the relational view. Therefore, they cannot be included in the SELECT clauses.

As with SQL-92, aliases can be defined for column names using the AS keyword as follows:

SELECT book.bs:price AS price, book.bs:isbn AS isbn, book.bs:author AS author, book.bs:publisher AS publisher FROM bs:book AS book

The FROM clause

The FROM clause lists the queryNames of the virtual tables that are included in the query.

Joins

Repositories that support joins provide the capability of performing inner or possibly outer joins in queries, using the standard SQL-92 syntax. Only the equality predicate can be used on join conditions and single-valued properties.

Implicit joins as parts of the WHERE clause are not allowed in CMIS SQL. Only explicit joins as part of the FROM clause can be used, as follows:

SELECT b.cmis:name FROM bs:book AS b JOIN bs:review AS r ON r.cmis:name = b.cmis:name

The WHERE clause

The WHERE clause defines the constraints that the rows, resulting from the join of all the virtual tables listed in the FROM clause, must satisfy in order to be included in the result set of a query.

All the column names used in the WHERE clause must be valid queryNames of properties, defined for the object types included in the FROM clause, or their aliases, as defined by the SELECT clause.

Comparison operators

The comparison operators, shown in the following table, can be used depending on the types of the columns involved in the comparison. These can only be used on single-valued properties.

Property Type

Operators

String

=, <>, [NOT] LIKE, [NOT] IN

Decimal

=, <>, <, <=, >, >=, [NOT] IN

Integer

=, <>, <, <=, >, >=, [NOT] IN

Boolean

=

DateTime

=, <>, <, <=, >, >=, [NOT] IN

ID

=, <>, [NOT] IN

URI

=, <>, [NOT] LIKE, [NOT] IN

Testing multi-valued properties

The ANY quantified comparison predicate can be used to filter rows where any one of the values of a multi-valued property is equal to a reference value:

SELECT * FROM bs:book AS b WHERE ('Jerome D. Salinger' = ANY b.bs:author)

The IN/ANY predicate is an extension to SQL-92. It evaluates to true when any of the values of a multi-valued property are included in a list of reference values:

SELECT * FROM bs:book WHERE ANY bs:author IN ('Jerome D. Salinger', 'Kurt Vonnegut', 'Joseph Heller')

Full-text search using CONTAINS

If a repository provides full-text search, then document text can be queried for using the CONTAINS predicate. Its syntax is as follows:

CONTAINS([<qualifier>,] <text>)

The value of qualifier, if present, must be the name of one of the virtual tables listed in the FROM clause. It indicates which table the search applies to.

If the FROM clause lists more than one virtual table, then the qualifier must be present. Otherwise, it can be omitted, as the search is performed only on the single table named.

The value of text must be a string enclosed in quotes, specifying words and phrases to look for. Search terms can be made up of multiple words and must be enclosed in double quotes.

Terms can be negated by prefixing them with the '-' character. Separate terms are implicitly joined with the AND conjunction (which can be made explicit), unless they are explicitly joined by OR.

At most, one CONTAINS expression can be present in a WHERE clause, and, where it is present together with other predicates, it can only be joined through an AND clause. The return value of the CONTAINS function is a boolean: either true when the content is considered relevant with respect to the search text, or false otherwise. When the CONTAINS predicate is used, it is possible to use the SCORE function in the SELECT clause. Its value is a decimal number between 0 (minimum relevance) and 1 (maximum relevance).

The IN_FOLDER predicate

The IN_FOLDER predicate function, whose syntax is

IN_FOLDER([<qualifier>,] <id>)

is used to test whether or not the candidate object is a direct child of the folder identified by id. If it is, the function returns true. The value of qualifier must be the name of one of the virtual tables listed in the FROM clause and must be present if there are more than one.

The IN_TREE predicate

The IN_TREE predicate function, whose syntax is:

IN_TREE([<qualifier>,] <id>)

works much like the IN_FOLDER predicate. However, it only tests whether or not the candidate object is a descendant of the folder identified by id.

The ORDER BY clause

The ORDER BY clause lists one or more names of virtual columns (or their aliases), according to whose values the objects in the result set are ordered. All the columns listed in the ORDER BY clause must be listed in the SELECT clause and must identify orderable properties of object types listed in the FROM clause. The collation rules used for ordering are repository-specific.