public abstract class BaseSession extends Object implements Session, EntrySource
Modifier and Type | Class and Description |
---|---|
static class |
BaseSession.FieldDetector
Visitor for a query to check if it contains a reference to a given field.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoincrementId |
protected boolean |
computeMultiTenantId |
protected Directory |
directory |
protected String |
directoryName |
protected static String |
MULTI_TENANT_ID_FORMAT |
protected String |
passwordHashAlgorithm |
protected PermissionDescriptor[] |
permissions |
protected static String |
POWER_USERS_GROUP |
protected boolean |
readAllColumns |
protected static String |
READONLY_ENTRY_FLAG |
protected Class<? extends Reference> |
referenceClass |
protected String |
schemaName |
protected BaseDirectoryDescriptor.SubstringMatchType |
substringMatchType |
protected static String |
TENANT_ID_FIELD |
Modifier | Constructor and Description |
---|---|
protected |
BaseSession(Directory directory,
Class<? extends Reference> referenceClass) |
Modifier and Type | Method and Description |
---|---|
protected QueryBuilder |
addTenantId(QueryBuilder queryBuilder)
Adds the tenant id to the query if needed.
|
DocumentModelList |
applyQueryLimits(DocumentModelList results,
int limit,
int offset)
Applies offset and limit to a DocumentModelList
|
<T> List<T> |
applyQueryLimits(List<T> list,
int limit,
int offset)
Applies offset and limit to a List.
|
protected boolean |
canDeleteMultiTenantEntry(String entryId) |
void |
checkDeleteConstraints(String entryId)
Checks that there are no constraints for deleting the given entry id.
|
void |
checkPermission(String permission)
Checks the current user rights for the given permission against the read-only flag and the permission descriptor.
|
static String |
computeMultiTenantDirectoryId(String tenantId,
String id)
Compute a multi tenant directory id based on the given
tenantId . |
DocumentModel |
createEntry(DocumentModel documentModel)
Creates an entry in a directory.
|
DocumentModel |
createEntry(Map<String,Object> fieldMap)
Creates an entry in a directory.
|
static DocumentModel |
createEntryModel(String sessionId,
String schema,
String id,
Map<String,Object> values)
Returns a bare document model suitable for directory implementations.
|
static DocumentModel |
createEntryModel(String sessionId,
String schema,
String id,
Map<String,Object> values,
boolean readOnly)
Returns a bare document model suitable for directory implementations.
|
protected abstract DocumentModel |
createEntryWithoutReferences(Map<String,Object> fieldMap)
To be implemented for specific creation.
|
void |
deleteEntry(DocumentModel docModel)
Deletes a directory entry.
|
void |
deleteEntry(String id)
Deletes a directory entry by id.
|
void |
deleteEntry(String id,
Map<String,String> map)
Deprecated.
|
protected abstract void |
deleteEntryWithoutReferences(String id)
To be implemented for specific deletion.
|
protected String |
getCurrentTenantId()
Returns the tenant id of the logged user if any,
null otherwise. |
abstract Directory |
getDirectory()
To be implemented with a more specific return type.
|
DocumentModelList |
getEntries()
Retrieves all the entries in the directory.
|
DocumentModel |
getEntry(String id)
Retrieves a directory entry using its id.
|
DocumentModel |
getEntry(String id,
boolean fetchReferences)
Retrieves a directory entry using its id.
|
DocumentModel |
getEntryFromSource(String id,
boolean fetchReferences) |
String |
getIdField()
The Id field is the name of the field that is used a primary key: unique and not null value in the whole
directory.
|
String |
getPasswordField() |
List<String> |
getProjection(Map<String,Serializable> filter,
Set<String> fulltext,
String columnName) |
List<String> |
getProjection(Map<String,Serializable> filter,
String columnName)
Executes a query using filter and return only the column columnName.
|
boolean |
hasPermission(String permission)
Checks the current user rights for the given permission against the read-only flag and the permission descriptor.
|
protected boolean |
hasPermission(String permission,
String username,
List<String> groups) |
boolean |
isAuthenticating()
Tells whether the directory implementation can be used as an authenticating backend for the UserManager (based on
login / password check).
|
protected boolean |
isMultiTenant()
Returns
true if this directory supports multi tenancy, false otherwise. |
boolean |
isReadOnly() |
static boolean |
isReadOnlyEntry(DocumentModel entry)
Test whether entry comes from a read-only back-end directory.
|
DocumentModelList |
query(Map<String,Serializable> filter)
Executes a simple query.
|
DocumentModelList |
query(Map<String,Serializable> filter,
Set<String> fulltext)
Executes a simple query.
|
DocumentModelList |
query(Map<String,Serializable> filter,
Set<String> fulltext,
Map<String,String> orderBy)
Executes a simple query.
|
DocumentModelList |
query(Map<String,Serializable> filter,
Set<String> fulltext,
Map<String,String> orderBy,
boolean fetchReferences)
Executes a query with the possibility to fetch references
|
void |
setReadAllColumns(boolean readAllColumns)
For test framework.
|
static void |
setReadOnlyEntry(DocumentModel entry)
Set the read-only flag of a directory entry.
|
static void |
setReadWriteEntry(DocumentModel entry)
Unset the read-only flag of a directory entry.
|
static List<String> |
toStringList(Object value) |
void |
updateEntry(DocumentModel docModel)
Updates a directory entry.
|
protected abstract List<String> |
updateEntryWithoutReferences(DocumentModel docModel)
To be implemented for specific update.
|
protected static final String POWER_USERS_GROUP
protected static final String READONLY_ENTRY_FLAG
protected static final String MULTI_TENANT_ID_FORMAT
protected static final String TENANT_ID_FIELD
protected PermissionDescriptor[] permissions
protected boolean readAllColumns
protected String schemaName
protected String directoryName
protected BaseDirectoryDescriptor.SubstringMatchType substringMatchType
protected Class<? extends Reference> referenceClass
protected String passwordHashAlgorithm
protected boolean autoincrementId
protected boolean computeMultiTenantId
protected BaseSession(Directory directory, Class<? extends Reference> referenceClass)
public abstract Directory getDirectory()
public void setReadAllColumns(boolean readAllColumns)
Session
setReadAllColumns
in interface Session
readAllColumns
- whether to read all columnspublic String getIdField()
Session
getIdField
in interface Session
public String getPasswordField()
getPasswordField
in interface Session
public boolean isAuthenticating()
Session
isAuthenticating
in interface Session
public boolean isReadOnly()
isReadOnly
in interface Session
public void checkPermission(String permission)
Throws DirectorySecurityException
if the user does not have adequate privileges.
DirectorySecurityException
- if access is deniedpublic void checkDeleteConstraints(String entryId)
public boolean hasPermission(String permission)
Returns false
if the user does not have adequate privileges.
false
if access is deniedprotected boolean hasPermission(String permission, String username, List<String> groups)
public static DocumentModel createEntryModel(String sessionId, String schema, String id, Map<String,Object> values) throws PropertyException
Can be used for creation screen.
PropertyException
public static DocumentModel createEntryModel(String sessionId, String schema, String id, Map<String,Object> values, boolean readOnly) throws PropertyException
Allow setting the readonly entry flag to Boolean.TRUE
. See Session#isReadOnlyEntry(DocumentModel)
PropertyException
public static boolean isReadOnlyEntry(DocumentModel entry)
public static void setReadOnlyEntry(DocumentModel entry)
public static void setReadWriteEntry(DocumentModel entry)
public static String computeMultiTenantDirectoryId(String tenantId, String id)
tenantId
.public DocumentModel getEntry(String id)
Session
TODO what happens when the entry is not found? return null if not found?
public DocumentModel getEntry(String id, boolean fetchReferences)
Session
public DocumentModelList getEntries()
Session
DocumentModelList#totalsize
on the returned list will return
-2 as a special marker for truncated results.getEntries
in interface Session
public DocumentModel getEntryFromSource(String id, boolean fetchReferences)
getEntryFromSource
in interface EntrySource
public DocumentModel createEntry(DocumentModel documentModel)
Session
createEntry
in interface Session
documentModel
- the document model representing the entry to createpublic DocumentModel createEntry(Map<String,Object> fieldMap)
Session
createEntry
in interface Session
fieldMap
- A map with keys and values that should be stored in a directory
Note: The values in the map should be of type String
public void updateEntry(DocumentModel docModel)
Session
updateEntry
in interface Session
docModel
- The entry to updatepublic static List<String> toStringList(Object value)
public void deleteEntry(DocumentModel docModel)
Session
deleteEntry
in interface Session
docModel
- The entry to delete@Deprecated public void deleteEntry(String id, Map<String,String> map)
Session
This is used for hierarchical vocabularies, where the actual unique key is the couple (parent, id).
deleteEntry
in interface Session
id
- the id of the entry to delete.map
- a map of secondary key values.public void deleteEntry(String id)
Session
deleteEntry
in interface Session
id
- the id of the entry to deleteprotected boolean canDeleteMultiTenantEntry(String entryId)
public DocumentModelList applyQueryLimits(DocumentModelList results, int limit, int offset)
results
- the query results without limit and offetlimit
- maximum number of results ignored if less than 1offset
- number of rows skipped before starting, will be 0 if less than 0.Session.query(Map, Set, Map, boolean, int, int)
public <T> List<T> applyQueryLimits(List<T> list, int limit, int offset)
list
- the original listlimit
- maximum number of results, ignored if less than 1offset
- number of rows skipped before starting, will be 0 if less than 0public DocumentModelList query(Map<String,Serializable> filter)
Session
Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated
results.public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext)
Session
fieldNames present in the fulltext set are treated as a fulltext match. Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated
results.public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy)
Session
fieldNames present in the fulltext set are treated as a fulltext match. Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated
results.query
in interface Session
filter
- a filter to apply to entries in directoryfulltext
- a set of field that should be treated as a fulltext searchorderBy
- a LinkedHashMap with the 'order by' criterias.The key of an entry of this map represents the
column name and the value of the same entry represent the column order,which may be 'asc' or 'desc'.public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences)
Session
query
in interface Session
Session.query(Map, Set, Map)
public List<String> getProjection(Map<String,Serializable> filter, String columnName)
Session
getProjection
in interface Session
filter
- the filter for the querycolumnName
- the column whose content should be returnedpublic List<String> getProjection(Map<String,Serializable> filter, Set<String> fulltext, String columnName)
getProjection
in interface Session
protected boolean isMultiTenant()
true
if this directory supports multi tenancy, false
otherwise.protected QueryBuilder addTenantId(QueryBuilder queryBuilder)
protected String getCurrentTenantId()
null
otherwise.protected abstract DocumentModel createEntryWithoutReferences(Map<String,Object> fieldMap)
protected abstract List<String> updateEntryWithoutReferences(DocumentModel docModel)
protected abstract void deleteEntryWithoutReferences(String id)
Copyright © 2019 Nuxeo. All rights reserved.