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 likeSiteandMessageGroup.
- Author:
- Syam
-
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidConfigures and adds specific columns to the given Columns object.protected DoublecomputeConsumption(int resource, long from, long to) Computes the consumption of a resource over a specified time interval.voidComputes the consumption for all resources retrieved as a list ofResourceobjects and processes them using the specifiedTransactionManager.voidcomputeConsumption(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.voidcomputeConsumption(TransactionManager tm, Iterable<Resource> resources) Calculates the consumption of resources using the provided transaction manager.booleanconsumes(int resource) Determines whether the unit consumes a specified resource.voiddeleteConsumption(TransactionManager tm, Resource resource) Deletes the consumption data for the given resource.static BlockRetrieves 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.intRetrieves the X-coordinate for the caption.intRetrieves the Y-coordinate value for the caption.intgetCode()Retrieves the unique block code for the block.Retrieves the image name for the block.intRetrieves the layout style identifier for the block.Retrieves the layout style value for the current layoutStyle of the block.static StringgetLayoutStyleValue(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 associatedMessageGroupfor 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 inthints()Provides a hint value used for specifying a small list layout style within the system.static voidConfigures 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.voidRecomputes the consumption statistics for all resources associated with the object.voidrecomputeConsumption(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.voidRecomputes the statistical data for all units associated with this block.voidsaved()This method is invoked when the current instance is successfully saved.static String[]Retrieves a list of column names relevant to the search functionality.voidsetCaptionStyle(String captionStyle) Sets the caption style for the block.voidsetCaptionX(int captionX) Sets the X-coordinate for the caption.voidsetCaptionY(int captionY) Sets the Y-coordinate for the caption of the block.voidsetCode(int code) Sets the unique code for the block.voidsetImageName(String imageName) Sets the name of the image after trimming any leading or trailing whitespace.voidsetLayoutStyle(int layoutStyle) Sets the layout style for the block.voidsetMessageGroup(Id messageGroupId) Sets the message group associated with this block.voidsetMessageGroup(MessageGroup messageGroup) Sets the message group associated with this block by converting the providedMessageGroupobject to its corresponding identifier.voidsetMessageGroup(BigDecimal idValue) Sets the message group for the block using aBigDecimalvalue.voidSets the site for this block.voidSets the site associated with this block.voidsetSite(BigDecimal idValue) Sets the site for this block using its unique identifier represented as aBigDecimal.voidValidates 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, setActiveMethods inherited from class com.storedobject.core.Name
getName, getUniqueCondition, setName, toStringMethods 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, family, fill, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getActor, getAttachment, getAttachmentId, getChildren, getContemporaryOf, 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, listDeletedIds, 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, loadAttributesFrom, 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, 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:
savedin 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 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:
getSitein 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 aBigDecimalvalue.- Parameters:
idValue- TheBigDecimalvalue to be used to create anIdfor the message group.
-
setMessageGroup
Sets the message group associated with this block by converting the providedMessageGroupobject to its corresponding identifier. If the provided message group is null, it sets the message group identifier to null.- Parameters:
messageGroup- TheMessageGroupobject representing the message group to associate with this block, or null to clear the association.
-
getMessageGroupId
-
getMessageGroup
Retrieves the associatedMessageGroupfor this Block. If no specific MessageGroup is linked to this Block, the default MessageGroup of the current Site is returned.- Returns:
- The
MessageGroupassociated with this Block, or the defaultMessageGroupof 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 a 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:
validateDatain 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.
-
deleteConsumption
Deletes the consumption data for the given resource.- Parameters:
tm- The transaction manager to handle database transactions for the operation.resource- The resource for which the consumption needs to be deleted.- Throws:
Exception- If an error occurs during the transaction.
-
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 ofResourceobjects 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
public void computeConsumption(TransactionManager tm, Iterable<Resource> resources) throws Exception Calculates the consumption of resources using the provided transaction manager.- Parameters:
tm- the transaction manager used for processing resource consumptionresources- an iterable collection of resources for which consumption is to be computed- 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:
computeConsumptionin 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:
getBlockIdin classAbstractUnit- Returns:
- the unique identifier of the block as an
Idobject
-
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
ObjectIteratorcontaining 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:AbstractUnitDetermines whether the unit consumes a specified resource.- Overrides:
consumesin classAbstractUnit- Parameters:
resource- The resource identifier to check for consumption.- Returns:
trueif the unit consumes the specified resource;falseotherwise.
-