contentbox.modules.contentbox-api.modules.contentbox-api-v1.handlers

Class baseHandler

lucee.Component
    extended by coldbox.system.FrameworkSupertype
      extended by coldbox.system.EventHandler
        extended by coldbox.system.RestHandler
          extended by cborm.models.resources.BaseHandler
            extended by contentbox.modules.contentbox-api.modules.contentbox-api-v1.handlers.baseHandler
Direct Known Subclasses:
auth , authors , baseContentHandler , categories , comments , contentTemplates , echo , menus , relocations , settings , siteSettings , sites , versions

This is our base handler for our API which is bassed off the cborm resources base handler. ## Pre-Requisites - You will be injecting Virtual Entity services - Your entities need to inherit from ActiveEntity - You will need to register the routes using ColdBox resources() method - You will need mementifier active ## Requirements In order for this to work, you will create a handler that inherits from this base and make sure that you inject the appropriate virtual entity service using the variable name: ormService Also populate the variables as needed

component extends="BaseOrmResource"{
// Inject the correct virtual entity service to use
property name="ormService" inject="RoleService"
property name="ormService" inject="PermissionService"
// The default sorting order string: permission, name, data desc, etc.
variables.sortOrder = "";
// The name of the entity this resource handler controls. Singular name please.
variables.entity 	= "Permission";
}
That's it! All resource methods: index, create, show, update, delete will be implemented for you. You can create more actions or override them as needed.

Class Attributes:
  • synchronized : false
  •  
  • see : https://coldbox-orm.ortusbooks.com/orm-events/automatic-rest-crud
  •  
  • accessors : false
  •  
  • persistent : false
  •  
    Property Summary
    type property default serializable required
    any cb


    • access = public
    • returntype = any
    • inject = CBHelper@contentbox
    true false
    any settings


    • access = public
    • returntype = any
    • inject = coldbox:moduleSettings:cborm
    true false
    any siteService


    • access = public
    • returntype = any
    • inject = siteService@contentbox
    true false
    Method Summary
    private any autoCast(any propertyName, any value)
         Coverts a value to the correct javaType for the property passed in.
    any create([any event], [any rc], [any prc], [struct populate='[runtime expression]'], [struct validate='[runtime expression]'], [string saveMethod='[runtime expression]'])
         Create a resource.
    any delete([any event], [any rc], [any prc], [string deleteMethod='[runtime expression]'])
         Delete a resource by id or slug.
    private any getByIdOrSlugOrFail(any id, any prc)
         This utility tries to get the incoming resource by id or slug or fails.
    private any getMaxRows([any event='[runtime expression]'])
         Get the max number of rows to retrieve according to global settings.
    private any getPageOffset([any page='1'])
         Calculate the starting offset for the incoming page.
    private any getSiteByIdOrSlugOrFail(any id)
         This utility tries to get a site by id or slug.
    any index([any event], [any rc], [any prc], [any criteria], [struct results])
         Display all resource records with pagination.
    private any newCriteria([boolean useQueryCaching='false'], [string queryCacheRegion=''], [any datasource])
         Get a brand new criteria builder object.
    any show([any event], [any rc], [any prc])
         Display a resource by incoming ID or slug.
    any update([any event], [any rc], [any prc], [struct populate='[runtime expression]'], [struct validate='[runtime expression]'], [string saveMethod='[runtime expression]'])
         Update a resource.
     
    Methods inherited from class cborm.models.resources.BaseHandler
    None
     
    Methods inherited from class coldbox.system.RestHandler
    aroundHandler, onAnyOtherException, onAuthenticationFailure, onAuthorizationFailure, onEntityNotFoundException, onError, onExpectationFailed, onInvalidHTTPMethod, onInvalidRoute, onMissingAction, onValidationException
     
    Methods inherited from class coldbox.system.EventHandler
    _actionExists, _actionMetadata, _privateInvoker, init, onHandlerDIComplete
     
    Methods inherited from class coldbox.system.FrameworkSupertype
    announce, announceInterception, async, back, externalView, forAttribute, getCache, getCachebox, getColdBoxSetting, getController, getDateTimeHelper, getEnv, getFlash, getFlow, getInstance, getIsoTime, getJsonUtil, getLog, getLogBox, getModuleConfig, getModuleSettings, getRenderer, getRequestCollection, getRequestContext, getRootWireBox, getSetting, getSystemProperty, getSystemSetting, getUserSessionIdentifier, getWirebox, ifNull, ifPresent, inDebugMode, includeUDF, isDevelopment, isProduction, isTesting, layout, listen, loadApplicationHelpers, locateDirectoryPath, locateFilePath, persistVariables, populate, populateModel, relocate, renderExternalView, renderLayout, renderview, runEvent, runRoute, setCachebox, setController, setEnv, setFlash, setFlow, setJsonUtil, setLog, setLogBox, setSetting, setWirebox, settingExists, throwIf, throwUnless, toJson, unless, view, when
     
    Methods inherited from class lucee.Component
    None

    Property Detail

    cb

    property any cb

    Attributes:
    access - public
    required - false
    returntype - any
    inject - CBHelper@contentbox
    serializable - true

    settings

    property any settings

    Attributes:
    access - public
    required - false
    returntype - any
    inject - coldbox:moduleSettings:cborm
    serializable - true

    siteService

    property any siteService

    Attributes:
    access - public
    required - false
    returntype - any
    inject - siteService@contentbox
    serializable - true

    Method Detail

    autoCast

    private any autoCast(any propertyName, any value)

    Coverts a value to the correct javaType for the property passed in.

    Overrides:
    autoCast in class cborm.models.resources.BaseHandler
    Parameters:
    propertyName - The property name
    value - The property value

    create

    public any create([any event], [any rc], [any prc], [struct populate='[runtime expression]'], [struct validate='[runtime expression]'], [string saveMethod='[runtime expression]'])

    Create a resource

    Overrides:
    create in class cborm.models.resources.BaseHandler
    Parameters:
    event
    rc
    prc
    populate
    validate
    saveMethod

    delete

    public any delete([any event], [any rc], [any prc], [string deleteMethod='[runtime expression]'])

    Delete a resource by id or slug

    Overrides:
    delete in class cborm.models.resources.BaseHandler
    Parameters:
    event
    rc
    prc
    deleteMethod

    getByIdOrSlugOrFail

    private any getByIdOrSlugOrFail(any id, any prc)

    This utility tries to get the incoming resource by id or slug or fails

    Parameters:
    id - The id/slug identifier to retrieve the entity
    prc - The ColdBox PRC
    Returns:
    The found entity
    Throws:
    EntityNotFound

    getMaxRows

    private any getMaxRows([any event='[runtime expression]'])

    Get the max number of rows to retrieve according to global settings or passed in through RC

    Overrides:
    getMaxRows in class cborm.models.resources.BaseHandler
    Parameters:
    event

    getPageOffset

    private any getPageOffset([any page='1'])

    Calculate the starting offset for the incoming page

    Overrides:
    getPageOffset in class cborm.models.resources.BaseHandler
    Parameters:
    page - The page to lookup on
    Returns:
    The page start offset

    getSiteByIdOrSlugOrFail

    private any getSiteByIdOrSlugOrFail(any id)

    This utility tries to get a site by id or slug

    Parameters:
    id
    Returns:
    The found site
    Throws:
    EntityNotFound

    index

    public any index([any event], [any rc], [any prc], [any criteria], [struct results])

    Display all resource records with pagination GET /api/v1/{resource}

    Overrides:
    index in class cborm.models.resources.BaseHandler
    Parameters:
    event
    rc
    prc
    criteria - If you pass a criteria object, then we will use that instead of creating a new one
    results - If you pass in a results struct, it must contain the following: { count:numeric, records: array of objects }

    newCriteria

    private any newCriteria([boolean useQueryCaching='false'], [string queryCacheRegion=''], [any datasource])

    Get a brand new criteria builder object

    Overrides:
    newCriteria in class cborm.models.resources.BaseHandler
    Parameters:
    useQueryCaching - Activate query caching for the list operations
    queryCacheRegion - The query cache region to use, which defaults to criterias.{entityName}
    datasource
    Returns:
    cborm.models.criterion.CriteriaBuilder

    show

    public any show([any event], [any rc], [any prc])

    Display a resource by incoming ID or slug

    Overrides:
    show in class cborm.models.resources.BaseHandler
    Parameters:
    event
    rc
    prc

    update

    public any update([any event], [any rc], [any prc], [struct populate='[runtime expression]'], [struct validate='[runtime expression]'], [string saveMethod='[runtime expression]'])

    Update a resource

    Overrides:
    update in class cborm.models.resources.BaseHandler
    Parameters:
    event
    rc
    prc
    populate
    validate
    saveMethod