Startseite / Plugin-Entwicklung / Universelle Erweiterungen / Datenzugriff / Datenzugriff-Session

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

DataTemplating<D>

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)
provide an HTML template based on the object of type D and a Language. Optionally, parameter identifiers using the form ${parameter_name} may be embedded in the template; if #registerParameters(...) registers a parameter of the name parameter_name, the identifier in the template will be replaced with the parameter's value.

void registerParameters(ParameterSet, D, Language)
registers arbitrarily named parameters with the given ParameterSet. Parameters matching the parameter identifiers given in the template (#getTemplate(...)) will be inserted into the template.

Data Object Identification

Aspect

Description

Methods / Notes

Identifying

Attempts to produce a String identifier for a valid data object based upon the given input data.

String getIdentifier(Object)
attempts to return a String identifier for the given Object. If no valid identifier can be produced, returns a NoSuchElementException.

Search-Related

Aspect

Description

Methods / Notes

ValueIndexing

Provides support for FirstSpirit's indexing functionality.

void appendIndexData(String, Language, boolean, ValueIndexer)
appends data to the indexer so that FirstSpirit elements referencing a data object can be found by searching for indexed data of that object. The data object is indicated by the String parameter.

RequestMatching

Provides matches based on given requests in order to highlight these matches in search results.

Match getMatch(String, Request, Language)
provides a match for the data object indicated by the String parameter based upon the given Request and Language.

Drag-and-Drop

Aspect

Description

Methods / Notes

TransferHandling<D>

Provides handler functionality for inbound drag-and-drop operations (a data access plug-in-enabled component is the drop target).

void registerHandlers(HandlerHost<D>)
registers handler objects that can process drag-and-drop data of various commodity types.

TransferSupplying<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>)
registers supplier objects that can process data objects and provide drag-and-drop data in various commodity types.

   

© 2005 - 2022 Crownpeak Technology GmbH | Alle Rechte vorbehalten. | FirstSpirit 2023.1 | Datenschutz