SiteDataStorage
An extension of UserDataStorage that is shared by all users of a portal, including anonymous users. This object exposes a number of special methods for storing data and documents in a searchable way.
Portals have an associated content project that can store documents and metadata generated by the portal. Also, each portal can have one or more searchable indexes containing arbitrary data. (Additional portal data storage capabilities for nonindexed values, counters, and lists are described under "DataStorage".)
When a portal is created, a project is automatically created and associated
with the portal as the portal content project. This project may contain
portal-generated content, and functions like any other content project. The
siteData
object provides methods for accessing portal
content items.
Indexed data can be stored and searched under user-defined index names. Each
index should hold similarly structured records. Methods for storing and
retrieving indexed data are provided in Freemarker and javascript using the
siteData
object. The administration interface also provides
access to view and download portal indexed data. IMPORTANT: The total
number of user-defined indices on the platform cannot exceed 100 at any time
(across all portals). Theme developers and platform administrators should
ensure that no more than 100 indices exist at any time.
Introduced in version 4.2.
Methods
-
Iterable searchIndexed( String index, String query, int [] paging)
- Searches the given index using the given search. Since each index can have its own record type, all indexed searches are ordered by the built-in Elasticsearch field, "_doc".
-
int deleteIndexed( String index, String query)
- Deletes records from the given index that match the given query.
-
int deleteIndexed( String index, String query, boolean waitRefresh)
-
Deletes records from the given index that match the given query. Passing
false
for thewaitRefresh
method will cause the method to return before the deletion has been fully processed. The default istrue
-
void putIndexed( String index, Object value)
- Stores a data structure in such a way that its properties can be queried using normal search syntax. The index functions as a namespace for the stored data. As a best practice, radically different data structures should be stored in different indexes.
-
boolean putIndexed( String index, Object value, boolean waitRefresh)
-
Stores a data structure in such a way that its properties can be queried
using normal search syntax. The index functions as a namespace for the
stored data. As a best practice, radically different data structures
should be stored in different indexes. Passing
false
for thewaitRefresh
method will cause the method to return before the insertion has been fully processed. The default istrue
-
void putFile( String location, String mimeType, CharSequence contents, Map metadata)
- Creates or updates a file in the portal's project. If the file already exists, its contents will be overwritten and its metadata replaced with the given hash.
-
String getFile( String location, String representation)
- Retrieve the contents of the file at the given path as a string.
-
String getFileDownloadURL( String location, String representation)
- Gets an HTTP URL at which the given file can be downloaded directly, optional with a processed representation.
-
String getFileUploadURL( String location, boolean folderMode, String itemName)
- Get a URL to add or replace a file via POST. Any existing file at the location will be overwritten.
-
boolean setFileMetadata( String location, Map metadata)
-
Sets the metadata on the given file. The existing non-intrinsic metadata
entries for the file will be replaced with those supplied. Use
updateFileMetadata(String,Map)
for adding additional metadata to a file. -
boolean updateFileMetadata( String location, Map metadata)
- Updates the metadata on the given file. The existing non-intrinsic metadata entries for the file will be updated and merged with those supplied.
-
String getProcessingPhase( String location)
- Gets the current processing phase of the item at the specified location.
-
ProjectItem[] getProjectRoots()
- List the portal project root contents.
-
ProjectItem[] getFolderContents( String location)
- List the specified folder contents.
-
void put( String dataKey, Object data)
- Stores data with a key. If the data is a string, it is stored as-is. Otherwise, it is converted to JSON and then stored.
-
Object get( String dataKey)
- Retrieves the data with the given key. Objects are encoded as JSON for storage, so the resulting object will be whatever type was stored, unless it's an object, in which case it will be represented as a map hierarchy.
-
void push( String listKey, Object value, int cap)
- Pushes a new value onto the list with the given key.
-
void pushUnique( String listKey, Object value, int cap)
- Pushes a new value onto the list with the given key. If it already exists in the list, it is removed and moved to the top.
-
boolean existsInList( String listKey, Object value)
- Determines whether the given value exists in the list with the given key.
-
void removeFromList( String listKey, Object value)
- Removes the given value from the list with the given key.
-
void incrementCounter( String key, long by)
- Increments the counter with the given key by the given amount (which may be negative). If no such counter exists, it will be created and set to the given increment value.