API Business Services - Base wheres

Implement a class extending the class com.noheto.restapi.APIBaseWhereBusinessServiceAdapter to add some where clause chunks to a query executed by an action.

Note that you have the alternative of prepared where services. It is possible to designate a context mapping of API-specific prepared where services, to have API-specific where bases.

See Bases

Methods

  • getPreparedWhere(Context context): global base where

  • getPreparedWhere(Context context, String id): this method is to associate base where clause to a base where id.

Context

The context provides some informations useful for the specific development of the base where.

  • getRequest(): returns the http request wrapper, allowing to find parameters, headers, etc

  • getSurfer(): returns the current surfer

  • getLocale(): returns the current invocation locale

  • getServiceId(): returns the service if (see class com.noheto.restapi.ServiceId)

  • getConfigId(): returns the configuration id

  • getObjectName(): returns the object name

  • getMethod(): returns the HTTP method name (resolved, including in case of method overriding)

Base where ID

This ID refers to a base where fragment identifier. It’s a feature used only by legacy service :

  • You create IDs of base where fragment (by example PUBLISHED to mean “pstatus = 6”

  • In the view configuration, you specify what IDs are needed

  • When invoking the service, the adapter is invoked with these IDs. For each ones, the method must return the fragment. The service will combine every fragments and other base wheres to get one final base where.

The method getPreparedWhere(Context)

This method is always invoked. Test the context to decide if you need to provide a prepared where in return or not (return null in that case).

The getConfigId() in the context refers to the name of resource and getObjectName() the name of the corresponding DB object.

Example:

public class ExampleBaseWhere extends APIBaseWhereBusinessServiceAdapter { @Override public PreparedWhere getPreparedWhere(Context context) { switch(context.getServiceId()) { case ServiceId.DAM_ASSET: return buildAssetPreparedWhere(context); // the code of this method is not provided default: if ( context.getServiceId().startsWith("profil/") || context.getServiceId().startsWith("massimport/") ) { return super.getPreparedWhere(context); // no base where } else if ( context.getServiceId().endsWith("/read") ) { return PreparedWhere.load("pactivated=1 and pstatus=2"); } else if ( context.getServiceId().endsWith("/create") || context.getServiceId().endsWith("/update") || context.getServiceId().endsWith("/create_or_update") ) { return super.getPreparedWhere(context); // no base where } else { return buildPreparedWhere(context); // the code of this method is not provided } } /*if ( ServiceId.DAM_ASSET.equals(context.getServiceId()) ) { return PreparedWhere.load("pactivated=1 and pstatus=2"); }*/ } // ... }