The Java API is the core to exposing Alfresco functionality and normalizing operations across version. Any extensions written while depending on Alfred API can be easily ported to a new Alfresco version.
When the API is installed, all of its service are available as beans and can be wired into your own classes.
Only the most important services are described below. Full documentation is available in the generated JavaDoc.
The NodeService provides operations on nodes.
The SearchService allows searching for nodes based on an object tree.
The SearchService.query() method takes a SearchQuery object which
contains the search query to execute, as well as pagination, faceting
and ordering options.
//Imports
import eu.xenit.alfred.api.data.QName;
import eu.xenit.alfred.api.data.StoreRef;
import eu.xenit.alfred.api.search.QueryBuilder;
import eu.xenit.alfred.api.search.SearchQuery;
import eu.xenit.alfred.api.search.SearchQueryConsistency;
import eu.xenit.alfred.api.search.nodes.SearchSyntaxNode;
import eu.xenit.alfred.api.search.visitors.SearchSyntaxPrinter;
import java.io.IOException;
import java.util.Arrays;
// Setting search query options
SearchQuery searchQuery = new SearchQuery();
searchQuery.getPaging().setSkip(10); // Skip the first 10 results
searchQuery.getPaging().setLimit(
25); // Return maximum 25 results in response to the query. It defaults to 25 results, set to -1 for unlimited results
searchQuery.getFacets().setEnabled(true); // Enables faceting
searchQuery.getFacets().setMincount(10); // Show only facet values with a minimum of 10 items matching the facet
searchQuery.getFacets().setLimit(10); // Show only the top 10 facet values for each facet
// searchQuery.setWorkspace("workspace-protocol://workspace-identifier"); // Optional parameter, defaults to "workspace://SpacesStore"
// e.g. searchQuery.setWorkspace(new StoreRef("archive://SpacesStore")); // To search in deleted nodes
searchQuery.setOrderBy(Arrays.asList(
new SearchQuery.OrderBy(
SearchQuery.OrderBy.Order.ASCENDING,
new QName("{http://www.alfresco.org/model/content/1.0}modifier")
), // Order by cm:modifier ascending
new SearchQuery.OrderBy(
SearchQuery.OrderBy.Order.DESCENDING,
new QName("{http://www.alfresco.org/model/content/1.0}creator")
) // Then order by cm:creator descending
));
// Set search query consistency to transactional (defaults to eventual consistency)
searchQuery.setConsistency(SearchQueryConsistency.TRANSACTIONAL);
// searchQuery.setConsistency(SearchQueryConsistency.EVENTUAL);
//
The query itself can be constructed using the QueryBuilder, which
provides a fluent interface to build search queries.
// Building the search query
QueryBuilder queryBuilder = new QueryBuilder();
SearchSyntaxNode query = queryBuilder
.startAnd()
.property("{http://www.alfresco.org/model/content/1.0}creator", "admin",
true) // Search for cm:creator = admin with an exact match
.startOr()
.property("{http://www.alfresco.org/model/content/1.0}created", "2015-01-01T00:00:00+00:00",
"2020-08-16T00:00:00+00:00") // Date range query
.property("{http://www.alfresco.org/model/content/1.0}modified", "2015-01-01T00:00:00+00:00",
"2020-08-16T00:00:00+00:00")
.end()
.not().term("aspect",
"{http://www.alfresco.org/model/system/1.0}hidden") // Possible terms: "type", "aspect", "noderef", "path", "text", "parent", "category", "all"
.term("type", "{http://www.alfresco.org/model/content/1.0}document")
.term("path", "/app:company_home/app:shared/*") // All documents in the folder
.term("path", "/app:company_home/app:shared//*") // All documents in the folder and subfolders
.term("path", "/app:company_home/app:shared/") // Folder itself
.term("parent",
"workspace://SpacesStore/c4ebd508-b9e3-4c48-9e93-cdd774af8bbc") // All direct children of this noderef
.term("text", "xenit solutions") // Full text search
.term("all", "banana") // Search in full text, cm:name, cm:author, cm:creator, cm:modifier
.end()
.create();
searchQuery.setQuery(query);
// FTS Query: cm:creator:"admin" AND (cm:created:"2015-01-01T00:00:00+00:00".."2020-08-16T00:00:00+00:00" OR cm:modified:"2015-01-01T00:00:00+00:00".."2020-08-16T00:00:00+00:00") AND NOT ASPECT:"sys:hidden"
//
When using the REST API, a JSON payload describing the search query has
to be POST’ed to the apix/v1/search endpoint. This JSON document
reflects the node structure created by the query builder, and is shown
below:
{
"query": {
"and": [
{
"property": {
"name": "{http://www.alfresco.org/model/content/1.0}creator",
"value": "admin"
}
},
{
"or": [
{
"property": {
"name": "{http://www.alfresco.org/model/content/1.0}created",
"range": {
"start": "2015-01-01T00:00:00+00:00",
"end": "2020-08-16T00:00:00+00:00"
}
}
},
{
"property": {
"name": "{http://www.alfresco.org/model/content/1.0}modified",
"range": {
"start": "2015-01-01T00:00:00+00:00",
"end": "2020-08-16T00:00:00+00:00"
}
}
}
]
},
{
"not": {
"aspect": "{http://www.alfresco.org/model/system/1.0}hidden"
}
},
{
"type": "{http://www.alfresco.org/model/content/1.0}document"
},
{
"path": "/app:company_home/app:shared/*"
},
{
"path": "/app:company_home/app:shared//*"
},
{
"path": "/app:company_home/app:shared/"
},
{
"parent": "workspace://SpacesStore/c4ebd508-b9e3-4c48-9e93-cdd774af8bbc"
},
{
"text": "xenit solutions"
},
{
"all": "banana"
}
]
},
"paging": {
"skip": 10,
"limit": 25
},
"facets": {
"enabled": true,
"mincount": 10,
"limit": 10
},
"orderBy": [
{
"property": "{http://www.alfresco.org/model/content/1.0}modifier",
"order": "ascending"
},
{
"property": "{http://www.alfresco.org/model/content/1.0}creator",
"order": "ascending"
}
],
"consistency": "TRANSACTIONAL" // or "EVENTUAL",
"workspace": { // optional. default value workspace://SpacesStore
"value": "workspace://SpacesStore" // or any other e.g. archive://SpacesStore"
}
}
The DictionaryService provides meta-information about the metadata
model. It allows to fetch information about registered types, aspect and
properties.