Package com.storedobject.iot
Class Block
java.lang.Object
com.storedobject.core.StoredObject
com.storedobject.core.Name
com.storedobject.iot.AbstractUnit
com.storedobject.iot.Block
- All Implemented Interfaces:
Displayable
,HasName
,StringFiller
,HasId
Represents a Block (or a Building or something similar), which is a specific unit of functionality or
data in the application framework,
extending the capabilities of
It also supports statistical computations, consumption computations, and validation of the block's data. The class is immutable (marked as final) and aims to encapsulate block-related business logic.
Key features:
AbstractUnit
.
This class provides various functionalities to manage blocks, such as storing and retrieving attributes
like site information, layout styles, image names, and more.
It also supports statistical computations, consumption computations, and validation of the block's data. The class is immutable (marked as final) and aims to encapsulate block-related business logic.
Key features:
- Handles block configuration including associated site, image name, captions, and layout style. - Provides mechanisms to list or retrieve blocks based on search criteria or links. - Offers utility methods for recomputing statistics and consumption of resources associated with the block. - Ensures uniqueness of key attributes, such as block codes, through validation. - Encapsulates connectivity to related entities likeSite
andMessageGroup
.
- Author:
- Syam
-
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Configures and adds specific columns to the given Columns object.protected Double
computeConsumption
(int resource, long from, long to) Computes the consumption of a resource over a specified time interval.void
Computes the consumption for all resources retrieved as a list ofResource
objects and processes them using the specifiedTransactionManager
.void
computeConsumption
(TransactionManager tm, Resource resource) Computes the consumption of a given resource by repeatedly invoking the consumption process until the operation no longer returns 1, which indicates further processing is required.boolean
consumes
(int resource) Determines whether the unit consumes a specified resource.static Block
Retrieves a Block object by searching for it using the specified name.Retrieves the unique identifier for the block.Retrieves the style applied to the caption.int
Retrieves the X-coordinate for the caption.int
Retrieves the Y-coordinate value for the caption.int
getCode()
Retrieves the unique block code for the block.Retrieves the image name for the block.int
Retrieves the layout style identifier for the block.Retrieves the layout style value for the current layoutStyle of the block.static String
getLayoutStyleValue
(int layoutStyle) Returns the layout style value corresponding to the given layout style index.static String[]
Retrieves all layout style values available in the system.Retrieves the associatedMessageGroup
for this Block.Retrieves the identifier of the message group associated with the block.getSite()
Retrieves the associated Site object for this Block instance.Retrieves the identifier of the associated site or project.static int
hints()
Provides a hint value used for specifying a small list layout style within the system.static void
Configures specific indices for the block entity.static String[]
links()
Provides an array of link definitions related to the Block entity.static ObjectIterator
<Block> Retrieves an iterator over Block objects filtered by the specified name.Lists all units, including the main units and associated independent units, while ensuring that the active status of related units is synchronized.Retrieves an iterator of units associated with the block.void
Recomputes the consumption statistics for all resources associated with the object.void
recomputeConsumption
(TransactionManager tm, Resource resource) Recomputes the consumption data for the given resource by first removing existing consumption entries associated with the resource, and then recalculating the consumption values using the current data and requirements.void
Recomputes the statistical data for all units associated with this block.void
saved()
This method is invoked when the current instance is successfully saved.static String[]
Retrieves a list of column names relevant to the search functionality.void
setCaptionStyle
(String captionStyle) Sets the caption style for the block.void
setCaptionX
(int captionX) Sets the X-coordinate for the caption.void
setCaptionY
(int captionY) Sets the Y-coordinate for the caption of the block.void
setCode
(int code) Sets the unique code for the block.void
setImageName
(String imageName) Sets the name of the image after trimming any leading or trailing whitespace.void
setLayoutStyle
(int layoutStyle) Sets the layout style for the block.void
setMessageGroup
(Id messageGroupId) Sets the message group associated with this block.void
setMessageGroup
(MessageGroup messageGroup) Sets the message group associated with this block by converting the providedMessageGroup
object to its corresponding identifier.void
setMessageGroup
(BigDecimal idValue) Sets the message group for the block using aBigDecimal
value.void
Sets the site for this block.void
Sets the site associated with this block.void
setSite
(BigDecimal idValue) Sets the site for this block using its unique identifier represented as aBigDecimal
.void
Validates the data of the Block object by performing various checks such as ensuring certain fields are populated, validating relationships, and defaulting missing attributes where necessary.Methods inherited from class com.storedobject.iot.AbstractUnit
consumes, getActive, getConsumptionCalculator, getDailyConsumption, getDailyConsumption, getDailyConsumption, getHourlyConsumption, getHourlyConsumption, getHourlyConsumption, getMonthlyConsumption, getMonthlyConsumption, getMonthlyConsumption, getWeeklyConsumption, getWeeklyConsumption, getWeeklyConsumption, getYearlyConsumption, getYearlyConsumption, getYearlyConsumption, listDailyConsumption, listDailyConsumption, listDailyConsumption, listHourlyConsumption, listHourlyConsumption, listHourlyConsumption, listMonthlyConsumption, listMonthlyConsumption, listMonthlyConsumption, listWeeklyConsumption, listWeeklyConsumption, listWeeklyConsumption, listYearlyConsumption, listYearlyConsumption, setActive
Methods inherited from class com.storedobject.core.Name
getName, getUniqueCondition, setName, toString
Methods inherited from class com.storedobject.core.StoredObject
addLink, addLink, addLink, addLink, addLink, addLink, addLink, addLink, checkCurrency, checkCurrency, checkForDuplicate, checkForDuplicate, checkTimeZone, checkTransaction, clearObjectLinks, contemporary, copy, copy, count, count, count, count, count, count, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, create, created, delete, delete, delete, deleted, directUpdate, equals, exists, exists, exists, exists, exists, existsFileData, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsMaster, existsMaster, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, family, family, family, fill, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getAttachment, getAttachmentId, getChildren, getDeleted, getDeleted, getExistsCondition, getExistsCondition, getFileData, getFileData, getHistorical, getId, getKeyIndex, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getNotExistsCondition, getNotExistsCondition, getParent, getParent, getParent, getParentId, getParentId, getParentId, getRelated, getRelated, getTransaction, getTransactionId, getTransactionIP, getUnique, hashCode, inserted, isModified, isVirtual, list, list, list, list, list, list, list, list, list, list, list, list, list, listFileData, listFileData, listHistory, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listTree, listTree, listTree, listTree, listViaQuery, listViaQuery, load, load, load, load, loaded, loading, makeNew, makeVirtual, migrate, moduleName, nextVersion, objectLink, objectLink, objectLink, objectLinks, objectLinks, old, person, previousVersion, previousVersion, query, query, query, query, query, query, query, query, query, query, query, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, reload, reload, reloaded, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeReverseLinks, removeReverseLinks, save, save, save, save, save, save, save, save, save, save, save, save, save, save, saving, setMaster, setRawValue, setTransaction, stringify, tableName, timestamp, toCode, toDisplay, transacting, undelete, undelete, undeleted, updated, user, userId, validate, validateChildAttach, validateChildDetach, validateChildUpdate, validateDelete, validateInsert, validateParentAttach, validateParentDetach, validateParentUpdate, validateUndelete, validateUpdate, valueEquals
-
Constructor Details
-
Block
public Block()Constructs a new instance of the Block class.
The constructor initializes a Block object with default values suitable for representing a Block entity. It sets up the initial state required for further operations on the Block.
-
-
Method Details
-
columns
Configures and adds specific columns to the given Columns object.- Parameters:
columns
- The Columns object to which various columns are added, specifying attributes such as name and type.
-
indices
Configures specific indices for the block entity. Adds certain predefined fields like "Code" and "Site" with corresponding configurations to the given indices.- Parameters:
indices
- The indices object where specific index configurations are added.
-
searchColumns
Retrieves a list of column names relevant to the search functionality.- Returns:
- An array of strings containing the names of the search columns: "Name", "Active", "Code", and "LayoutStyle".
-
get
-
list
Retrieves an iterator over Block objects filtered by the specified name.- Parameters:
name
- The name of the Block objects to be listed.- Returns:
- An ObjectIterator containing Block objects with the specified name.
-
links
Provides an array of link definitions related to the Block entity.- Returns:
- An array of strings where each entry represents a link definition in the format "Label|TargetClass".
-
saved
This method is invoked when the current instance is successfully saved. It performs the following actions:
1. Calls the superclass implementation of the `saved` method. 2. Resets the `site` field to `null`. 3. Registers a commit listener for the current transaction, which ensures that the `Controller.restart()` method is called once the transaction is committed.
- Overrides:
saved
in classStoredObject
- Throws:
Exception
- if an error occurs during the execution of the method.
-
hints
public static int hints()Provides a hint value used for specifying a small list layout style within the system. The returned value corresponds to a predefined constant that designates a layout suggestion.- Returns:
- the hint constant representing a small list, specifically
ObjectHint.SMALL_LIST
.
-
setSite
Sets the site for this block.- Parameters:
siteId
- The identifier of the site to be associated with the block.
-
setSite
Sets the site for this block using its unique identifier represented as aBigDecimal
.- Parameters:
idValue
- The unique identifier of the site as aBigDecimal
.
-
setSite
Sets the site associated with this block.- Parameters:
site
- The site object to associate. If null, the site ID will be set to null.
-
getSiteId
-
getSite
Retrieves the associated Site object for this Block instance. If the site has not been initialized, it fetches the related Site using the siteId.- Specified by:
getSite
in classAbstractUnit
- Returns:
- The associated Site object. If the site is not already loaded, it is fetched and initialized.
-
setImageName
Sets the name of the image after trimming any leading or trailing whitespace.- Parameters:
imageName
- The name of the image to set.
-
getImageName
-
setCaptionX
public void setCaptionX(int captionX) Sets the X-coordinate for the caption.- Parameters:
captionX
- the X-coordinate value to set for the caption
-
getCaptionX
-
setCaptionY
public void setCaptionY(int captionY) Sets the Y-coordinate for the caption of the block.- Parameters:
captionY
- the Y-coordinate value to be set for the caption
-
getCaptionY
-
setCaptionStyle
Sets the caption style for the block.- Parameters:
captionStyle
- the style to be applied to the caption, typically represented as a string.
-
getCaptionStyle
-
setCode
public void setCode(int code) Sets the unique code for the block.- Parameters:
code
- The unique integer value representing the block's code.
-
getCode
-
setMessageGroup
Sets the message group associated with this block.- Parameters:
messageGroupId
- The identifier of the message group to be set.
-
setMessageGroup
Sets the message group for the block using aBigDecimal
value.- Parameters:
idValue
- TheBigDecimal
value to be used to create anId
for the message group.
-
setMessageGroup
Sets the message group associated with this block by converting the providedMessageGroup
object to its corresponding identifier. If the provided message group is null, it sets the message group identifier to null.- Parameters:
messageGroup
- TheMessageGroup
object representing the message group to associate with this block, or null to clear the association.
-
getMessageGroupId
-
getMessageGroup
Retrieves the associatedMessageGroup
for this Block. If no specific MessageGroup is linked to this Block, the default MessageGroup of the current Site is returned.- Returns:
- The
MessageGroup
associated with this Block, or the defaultMessageGroup
of the Site if none is specifically associated.
-
setLayoutStyle
public void setLayoutStyle(int layoutStyle) Sets the layout style for the block.- Parameters:
layoutStyle
- the layout style to be set, represented as an integer. This value determines the visual or structural arrangement of the block.
-
getLayoutStyle
-
getLayoutStyleValue
Retrieves the layout style value for the current layoutStyle of the block.- Returns:
- The layout style value corresponding to the current layoutStyle.
-
getLayoutStyleValue
Returns the layout style value corresponding to the given layout style index. The method retrieves the value from the `layoutStyleValues` array using modulus operation to ensure the index remains within bounds of the array.- Parameters:
layoutStyle
- an integer representing the index of the layout style- Returns:
- a String representing the layout style value
-
getLayoutStyleValues
Retrieves all layout style values available in the system.- Returns:
- An array of strings representing the layout style values.
-
validateData
Validates the data of the Block object by performing various checks such as ensuring certain fields are populated, validating relationships, and defaulting missing attributes where necessary.- Overrides:
validateData
in className
- Parameters:
tm
- The TransactionManager instance that provides utilities for type-checking and validation of related entities.- Throws:
Exception
- If any validation rule fails during the process.
-
recomputeStatistics
Recomputes the statistical data for all units associated with this block.- Parameters:
tm
- The transaction manager to be used for accessing and updating the data.- Throws:
Exception
- If an error occurs during the statistics computation process.
-
recomputeConsumption
Recomputes the consumption statistics for all resources associated with the object.- Parameters:
tm
- The transaction manager used to handle transactional operations during the computation.- Throws:
Exception
- If an error occurs during the computation process.
-
recomputeConsumption
Recomputes the consumption data for the given resource by first removing existing consumption entries associated with the resource, and then recalculating the consumption values using the current data and requirements.- Parameters:
tm
- The transaction manager to handle database transactions for the operation.resource
- The resource for which the consumption needs to be recalculated.- Throws:
Exception
- If an error occurs during the transaction or computation process.
-
computeConsumption
Computes the consumption for all resources retrieved as a list ofResource
objects and processes them using the specifiedTransactionManager
.- Parameters:
tm
- The transaction manager used to oversee the consumption computation process.- Throws:
Exception
- If an error occurs during the computation process.
-
computeConsumption
Computes the consumption of a given resource by repeatedly invoking the consumption process until the operation no longer returns 1, which indicates further processing is required.- Parameters:
tm
- The TransactionManager instance used to manage transactions during computation.resource
- The Resource object for which consumption is to be computed.- Throws:
Exception
- If an error occurs during the consumption computation process.
-
computeConsumption
Computes the consumption of a resource over a specified time interval.- Overrides:
computeConsumption
in classAbstractUnit
- Parameters:
resource
- The identifier of the resource for which the consumption is to be calculated.from
- The start time of the interval, represented as a timestamp in milliseconds.to
- The end time of the interval, represented as a timestamp in milliseconds.- Returns:
- The consumption value as a Double, representing the amount of resource consumed during the specified interval.
- Throws:
SORuntimeException
- if the computation cannot be performed.
-
getBlockId
Retrieves the unique identifier for the block.- Specified by:
getBlockId
in classAbstractUnit
- Returns:
- the unique identifier of the block as an
Id
object
-
listUnits
Retrieves an iterator of units associated with the block.- Returns:
- An ObjectIterator of Unit entities that are linked to this block.
-
listAllUnits
Lists all units, including the main units and associated independent units, while ensuring that the active status of related units is synchronized.- Returns:
- An
ObjectIterator
containing all the units, including the main units and additional independent units after processing their active states.
-
consumes
public boolean consumes(int resource) Description copied from class:AbstractUnit
Determines whether the unit consumes a specified resource.- Overrides:
consumes
in classAbstractUnit
- Parameters:
resource
- The resource identifier to check for consumption.- Returns:
true
if the unit consumes the specified resource;false
otherwise.
-