public class BizController
extends sirius.web.controller.BasicController
Provides glue logic for filling entites from WebContext
s and for resolving entities for a given id.
Modifier and Type | Class and Description |
---|---|
class |
BizController.SaveHelper
Provides a fluent API to control the process and user routing while creating or updating an entity in the
database.
|
Modifier and Type | Field and Description |
---|---|
protected sirius.db.es.Elastic |
elastic |
static sirius.kernel.health.Log |
LOG
Contains the central logger for biz-relatet messages.
|
protected sirius.db.mongo.Mango |
mango |
protected sirius.db.mixing.Mixing |
mixing |
protected sirius.db.jdbc.OMA |
oma |
protected Tenants |
tenants |
Constructor and Description |
---|
BizController() |
Modifier and Type | Method and Description |
---|---|
protected void |
assertNotNew(sirius.db.mixing.BaseEntity<?> obj)
Ensures that the given entity is already persisted in the database.
|
protected void |
assertTenant(TenantAware tenantAware)
Ensures that the tenant of the current user matches the tenant of the given entity.
|
protected <E extends sirius.db.mixing.BaseEntity<?>> |
find(Class<E> type,
String id)
Tries to find an entity of the given type with the given id.
|
protected <E extends sirius.db.mixing.BaseEntity<?>> |
findForTenant(Class<E> type,
String id)
Tries to find an entity for the given id, which belongs to the current tenant.
|
protected String |
getBaseUrl()
Returns the base URL of this instance.
|
protected void |
load(sirius.web.http.WebContext ctx,
sirius.db.mixing.BaseEntity<?> entity)
Fetches all autoloaded fields of the given entity from the given request and populates the entity.
|
protected void |
load(sirius.web.http.WebContext ctx,
sirius.db.mixing.BaseEntity<?> entity,
List<sirius.db.mixing.Mapping> properties) |
protected void |
load(sirius.web.http.WebContext ctx,
sirius.db.mixing.BaseEntity<?> entity,
sirius.db.mixing.Mapping... properties)
Reads the given properties from the given request and populates the given entity.
|
protected BizController.SaveHelper |
prepareSave(sirius.web.http.WebContext ctx)
Creates a
BizController.SaveHelper with provides a fluent API to save an entity into the database. |
protected <I,E extends sirius.db.mixing.BaseEntity<I>> |
setOrVerify(sirius.db.mixing.BaseEntity<?> owner,
sirius.db.mixing.types.BaseEntityRef<I,E> ref,
E entity)
Enusures or establishes a parent child relation.
|
protected <E extends sirius.db.mixing.BaseEntity<?>> |
tryFind(Class<E> type,
String id)
Tries to find an existing entity with the given id.
|
protected <E extends sirius.db.mixing.BaseEntity<?>> |
tryFindForTenant(Class<E> type,
String id)
Tries to find an entity for the given id, which belongs to the current tenant.
|
protected void |
validate(sirius.db.mixing.BaseEntity<?> entity)
Performs a validation and reports all warnings via the
UserContext . |
protected sirius.db.mixing.Mixing mixing
protected sirius.db.jdbc.OMA oma
protected sirius.db.mongo.Mango mango
protected sirius.db.es.Elastic elastic
protected Tenants tenants
public static final sirius.kernel.health.Log LOG
protected void assertTenant(TenantAware tenantAware)
tenantAware
- the entity to checksirius.kernel.health.HandledException
- if the tenants do no matchprotected <I,E extends sirius.db.mixing.BaseEntity<I>> void setOrVerify(sirius.db.mixing.BaseEntity<?> owner, sirius.db.mixing.types.BaseEntityRef<I,E> ref, E entity)
For new entities (owner), the given reference is initialized with the given entity. For existing entities it is verified, that the given reference points to the given entity.
E
- the generic type the the entity being referencedowner
- the entity which contains the referenceref
- the reference which is either filled or verified that it points to entityentity
- the entity the reference must point tosirius.kernel.health.HandledException
- if the entities do no matchprotected void assertNotNew(sirius.db.mixing.BaseEntity<?> obj)
obj
- the entity to checksirius.kernel.health.HandledException
- if the entity is still new and not yet persisted in the databaseprotected String getBaseUrl()
protected void load(sirius.web.http.WebContext ctx, sirius.db.mixing.BaseEntity<?> entity)
ctx
- the request to read parameters fromentity
- the entity to fillAutoloaded
protected void load(sirius.web.http.WebContext ctx, sirius.db.mixing.BaseEntity<?> entity, sirius.db.mixing.Mapping... properties)
ctx
- the request to read parameters fromentity
- the entity to fillproperties
- the list of properties to transferprotected void load(sirius.web.http.WebContext ctx, sirius.db.mixing.BaseEntity<?> entity, List<sirius.db.mixing.Mapping> properties)
protected BizController.SaveHelper prepareSave(sirius.web.http.WebContext ctx)
BizController.SaveHelper
with provides a fluent API to save an entity into the database.ctx
- the current requestprotected void validate(sirius.db.mixing.BaseEntity<?> entity)
UserContext
.entity
- the entity to validateprotected <E extends sirius.db.mixing.BaseEntity<?>> E find(Class<E> type, String id)
Note, if new is given as id, a new entity is created. This permits many editors to create a new entity simply by calling /editor-uri/new
E
- the generic type of the entity classtype
- the type of the entity to findid
- the id to lookupsirius.kernel.health.HandledException
- if either the id is unknown or a new instance cannot be createdprotected <E extends sirius.db.mixing.BaseEntity<?>> Optional<E> tryFind(Class<E> type, String id)
E
- the generic type of the entity classtype
- the type of the entity to findid
- the id of the entity to findprotected <E extends sirius.db.mixing.BaseEntity<?>> E findForTenant(Class<E> type, String id)
This behaves just like find(Class, String)
but once an existing entity was found, which also extends
TenantAware
, it is ensured (using assertTenant(TenantAware)
that it belongs to the current
tenant.
E
- the generic type of the entity classtype
- the type of the entity to findid
- the id of the entity to findprotected <E extends sirius.db.mixing.BaseEntity<?>> Optional<E> tryFindForTenant(Class<E> type, String id)
This behaves just like tryFind(Class, String)
but once an existing entity was found, which also extends
TenantAware
, it is ensured (using assertTenant(TenantAware)
that it belongs to the current
tenant.
E
- the generic type of the entity classtype
- the type of the entity to findid
- the id of the entity to findCopyright © 2018. All rights reserved.