Data Access Session
FirstSpirit Developer API Interface: de.espirit.firstspirit.client.plugin.dataaccess.DataAccessSession
Developer API documentation: DataAccessSession<D>
The data access session provides the plug-in set's core functionality, performing tasks which associate data objects with storable identifiers and creating objects which handle provision of data objects from some source as well as extracting information from data objects for display in UI representations of these data objects.
public class MyDataAccessSession implements DataAccessSession<MyDataObject> {
private final BaseContext _context;
private final SessionAspectMap _aspects;
public MyDataAccessSession(@NotNull final BaseContext context) {
_context = context;
_aspects = new SessionAspectMap();
}
@Nullable
@Override
public <A> A getAspect(@NotNull final SessionAspectType<A> type) {
return _aspects.get(type);
}
/**
* Instantiate and return a data stream builder object.
*/
@NotNull
@Override
public DataStreamBuilder<MyDataObject> createDataStreamBuilder() {
return new MyDataStreamBuilder();
}
/**
* Instantiate and return a data snippet provider object.
*/
@NotNull
@Override
public DataSnippetProvider<MyDataObject> createDataSnippetProvider() {
return new MyDataSnippetProvider(_context);
}
/**
* Obtain a data stream object and query it for MyDataObject objects. Return the first
* whose header text (MyDataObject#getHeader()) matches the given identifier. If no
* data object from the stream matches the identifier, throw an exception.
*/
@NotNull
@Override
public MyDataObject getData(@NotNull final String identifier) {
final MyDataStream myDataStream = (MyDataStream) createDataStreamBuilder().createDataStream();
while (myDataStream.hasNext()) {
final List<MyDataObject> dataObjects = myDataStream.getNext(10);
for (final MyDataObject dataObject : dataObjects) {
if (identifier.equals(dataObject.getHeader())) {
return dataObject;
}
}
}
throw new NoSuchElementException("Could not find a data object for identifier '" + identifier + "'.");
}
/**
* Obtain a data stream object and query it for MyDataObject objects. Return a list of
* MyDataObject objects matching the size and order of the given identifier list. If a data object
* can be found for a given identifier, add it to the list. If no data object can be found for an
* identifier, add a 'null' object to the list.
*/
@NotNull
@Override
public List<MyDataObject> getData(@NotNull final Collection<String> identifiers) {
final List<MyDataObject> foundDataObjects = new ArrayList<MyDataObject>();
final MyDataStream myDataStream = (MyDataStream) createDataStreamBuilder().createDataStream();
findDataObjects:
for (final String identifier : identifiers) {
while (myDataStream.hasNext()) {
final List<MyDataObject> dataObjects = myDataStream.getNext(10);
for (final MyDataObject dataObject : dataObjects) {
if (identifier.equals(dataObject.getHeader())) {
foundDataObjects.add(dataObject);
continue findDataObjects;
}
}
}
foundDataObjects.add(null);
}
return foundDataObjects;
}
/**
* Obtain a data stream object and query it for MyDataObject objects. Return an identifier
* for the first data object returned by the data stream that matches the given data object.
* If the given data object doesn't match any one from the stream, throw an exception.
*/
@NotNull
@Override
public String getIdentifier(@NotNull final MyDataObject object) {
final MyDataStream myDataStream = (MyDataStream) createDataStreamBuilder().createDataStream();
while (myDataStream.hasNext()) {
final List<MyDataObject> dataObjects = myDataStream.getNext(10);
for (final MyDataObject dataObject : dataObjects) {
if ((object.getHeader()).equals(dataObject.getHeader())) {
return dataObject.getHeader();
}
}
}
throw new NoSuchElementException("Could not find an identifier for object '" + object + "'.");
}
}
Providing Aspects
FirstSpirit occasionally calls the method getAspect(...) with various aspect types as a parameter to identify which input components support a given aspect. If the data access session class supports the requested aspect, the method should return an object which implements that aspect; otherwise, it should return null.
Data Access Session Aspects | ||
---|---|---|
Reporting | ||
Aspect | Description | Methods / Notes |
Provides an HTML template and parameters which may be inserted into the template. The resulting HTML will be shown in ContentCreator reports in fly-outs associated with individual report entries. | String getTemplate(D, Language) | |
Data Object Identification | ||
Aspect | Description | Methods / Notes |
Attempts to produce a String identifier for a valid data object based upon the given input data. | String getIdentifier(Object) | |
Search-Related | ||
Aspect | Description | Methods / Notes |
Provides support for FirstSpirit's indexing functionality. | void appendIndexData(String, Language, boolean, ValueIndexer) | |
Provides matches based on given requests in order to highlight these matches in search results. | Match getMatch(String, Request, Language) | |
Drag-and-Drop | ||
Aspect | Description | Methods / Notes |
Provides handler functionality for inbound drag-and-drop operations (a data access plug-in-enabled component is the drop target). | void registerHandlers(HandlerHost<D>) | |
Provides supplier functionality for outbound drag-and-drop operations (a data access plug-in-enabled component is the drag-and-drop source). | void registerSuppliers(SupplierHost<D>) | |