Package net.sf.basedb.core
Class News
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.News
- All Implemented Interfaces:
AccessControlled
,Controlled
,Identifiable
,Nameable
,Registered
,Removable
,Validatable
This class represents news items.
- Version:
- 2.0
- Author:
- Nicklas
- Last modified
- $Date: 2017-06-09 09:33:19 +0200 (fr, 09 jun 2017) $
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final QueryRuntimeFilter
This filter limits the returned news items to those where todays date falls between the start and end dates unless the logged in user has generic read permission.static final Item
The type of item represented by this class.Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic News
Get aNews
item when you know the ID.(package private) NewsData
getData()
Get theBasicData
object that holds all data for this item.Get the description for the item.Get the end date and time for this news item to be published.Get the date that the item was registered in the database.getName()
Get the name of the item.static News
Create a newNews
item.Get the date that is shown in listings.getQuery()
Get a query configured to retrieve news.Get the user that flagged this item for removal.Get the start date and time for this news item to be published.getType()
Get the type of item represented by the object.(package private) void
initPermissions
(int granted, int denied) Read permission is granted if today is between the start and end date.boolean
Check if the removed flag is set for this item.boolean
isSticky()
Sticky news items should be sorted before non-sticky ones, but that is up to the client application to implement.void
setDescription
(String description) Set the description for the item.void
setEndDate
(Date endDate) Set the end date and time for this item to be published.void
setEntryDate
(Date entryDate) Set the date the entry was registered in the database.void
Set the name of the item.void
setNewsDate
(Date newsDate) Set the date that is shown in listings.void
setRemoved
(boolean removed) Set the removed flag for this item.void
setStartDate
(Date startDate) Set the start date and time for this item to be published.void
setSticky
(boolean sticky) Set the sticky flag for this news item.(package private) void
validate()
Check that startDate is before newsDate is before endDate.Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
-
Field Details
-
Constructor Details
-
News
News(NewsData newsData)
-
-
Method Details
-
getNew
Create a newNews
item.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database accessstartDate
- The first day this news item should be shownnewsDate
- The date appearing in listings of news- Returns:
- The new
News
item - Throws:
BaseException
- If there is an error
-
getById
public static News getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException Get aNews
item when you know the ID.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.id
- The ID of the item to load- Returns:
- The
News
item - Throws:
ItemNotFoundException
- If an item with the specified ID is not foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemBaseException
- If there is another error
-
getQuery
Get a query configured to retrieve news. If the logged in user doesn't have generic permission to all news, or if no user is logged in, only news which have a start date before today and an end date after today are returned.- Returns:
- An
ItemQuery
object
-
getData
NewsData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this item. -
getType
Description copied from interface:Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in theItem
enumeration.- Specified by:
getType
in interfaceIdentifiable
- Returns:
- A value indicating the type of item
-
getName
Description copied from interface:Nameable
Get the name of the item. -
setName
Description copied from interface:Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by theNameable.MAX_NAME_LENGTH
constant.- Specified by:
setName
in interfaceNameable
- Parameters:
name
- The new name for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the name is null or longer than specified by theNameable.MAX_NAME_LENGTH
constant
-
getDescription
Description copied from interface:Nameable
Get the description for the item.- Specified by:
getDescription
in interfaceNameable
- Returns:
- A
String
with a description of the item
-
setDescription
public void setDescription(String description) throws PermissionDeniedException, InvalidDataException Description copied from interface:Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by theNameable.MAX_DESCRIPTION_LENGTH
constant.- Specified by:
setDescription
in interfaceNameable
- Parameters:
description
- The new description for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the description longer than specified by theNameable.MAX_DESCRIPTION_LENGTH
constant
-
isRemoved
public boolean isRemoved()Description copied from interface:Removable
Check if the removed flag is set for this item. -
setRemoved
Description copied from interface:Removable
Set the removed flag for this item.- Specified by:
setRemoved
in interfaceRemovable
- Parameters:
removed
- TRUE if the item should be flagged as removed, FALSE otherwise- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.DELETE
permission for setting the flag to TRUE orPermission.WRITE
permission for setting the flag to FALSE
-
getRemovedBy
Description copied from interface:Removable
Get the user that flagged this item for removal.- Specified by:
getRemovedBy
in interfaceRemovable
- Returns:
- A User object, or null if this item has not been flagged
- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission for the userItemNotFoundException
- If the user that removed this item can't be found
-
getEntryDate
Description copied from interface:Registered
Get the date that the item was registered in the database.- Specified by:
getEntryDate
in interfaceRegistered
- Returns:
- A date or null if this is not known
-
setEntryDate
Description copied from interface:Registered
Set the date the entry was registered in the database. Implementations should only allow this property to be set before the item is first stored in the database. The intention of this method is to facilitate export/import of data between server.- Specified by:
setEntryDate
in interfaceRegistered
- Parameters:
entryDate
- A date or null to use today's date
-
validate
Check that startDate is before newsDate is before endDate.- Overrides:
validate
in classBasicItem
- Throws:
BaseException
- If there is an errorInvalidDataException
- See Also:
-
initPermissions
Read permission is granted if today is between the start and end date.- Overrides:
initPermissions
in classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass- Throws:
BaseException
- If the permissions couldn't be initialised
-
getStartDate
Get the start date and time for this news item to be published.- Returns:
- The date and time
-
setStartDate
Set the start date and time for this item to be published.- Parameters:
startDate
- The new date and time- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.WRITE
permissionInvalidDataException
- If the date is null
-
getNewsDate
Get the date that is shown in listings.- Returns:
- The date and time
-
setNewsDate
Set the date that is shown in listings.- Parameters:
newsDate
- The new date and time- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.WRITE
permissionInvalidDataException
- If the date is null
-
getEndDate
Get the end date and time for this news item to be published. If this value is null, the new item is published forever.- Returns:
- The date and time
-
setEndDate
Set the end date and time for this item to be published.- Parameters:
endDate
- The new date and time, or null to publish this new item forever- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.WRITE
permission
-
isSticky
public boolean isSticky()Sticky news items should be sorted before non-sticky ones, but that is up to the client application to implement.- Returns:
- TRUE if the item is sticky, FALSE if not
- Since:
- 3.12
-
setSticky
Set the sticky flag for this news item.- Parameters:
sticky
- TRUE to make the new item sticky- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.WRITE
permission- Since:
- 3.12
-