public class AnyToAny extends BasicItem implements Nameable, Transactional
All any-to-any links from an item has a name which must be unique for that item.
Transactional.Action
Modifier and Type | Field and Description |
---|---|
private BasicItem |
from |
private BasicItem |
to |
static Item |
TYPE
The type of item represented by this class.
|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
Constructor and Description |
---|
AnyToAny(AnyToAnyData data)
Creates a new link item from the given data.
|
AnyToAny(AnyToAnyData data,
BasicItem from)
Special constructor when the from item is known.
|
Modifier and Type | Method and Description |
---|---|
static int |
deleteStrayLinks(ProgressReporter progress)
Delete all links that are linking to non-existing items.
|
static boolean |
exists(DbControl dc,
BasicItem from,
String name)
Check if an item has a link with a given name.
|
static AnyToAny |
getById(DbControl dc,
int id)
Get an
AnyToAny link when you know the id. |
static AnyToAny |
getByName(DbControl dc,
BasicItem from,
String name)
Get an
AnyToAny link when you know the item
it is linking from and the name of the link. |
(package private) AnyToAnyData |
getData()
Get the
BasicData object that holds all data for this item. |
(package private) static AnyToAnyData |
getDataByName(Session session,
int fromId,
Item fromType,
String name)
Get an any-to-any link.
|
String |
getDescription()
Get the description for the item.
|
BasicItem |
getFrom()
Get the item this link is linking from.
|
int |
getFromId()
Get the ID of the item this link is linking from.
|
Item |
getFromType()
Get the type of the item this link is linking from.
|
static ItemQuery<AnyToAny> |
getLinksFrom(BasicItem from)
Get a query that returns all links linking from the specified item.
|
static ItemQuery<AnyToAny> |
getLinksTo(BasicItem to)
Get a query that returns all links linking to the specified item.
|
String |
getName()
Get the name of the item.
|
static AnyToAny |
getNew(DbControl dc,
BasicItem from,
BasicItem to,
String name,
boolean usingTo)
Create a new
AnyToAny link |
static AnyToAny |
getNewOrExisting(DbControl dc,
BasicItem from,
String name,
BasicItem to,
boolean usingTo)
Get a new or existing
AnyToAny link. |
(package private) PluginPermission |
getPluginPermissions() |
BasicItem |
getTo()
Get the item this link is linking to.
|
int |
getToId()
Get the ID of the item this link is linking to.
|
Item |
getToType()
Get the type of the item this link is linking to.
|
Item |
getType()
Get the type of item represented by the object.
|
(package private) void |
initPermissions(int granted,
int denied)
Permissions are granted based on the permission on the
from item.
|
boolean |
isUsed()
Always FALSE.
|
boolean |
isUsingTo()
If this link counts as using the destination item.
|
(package private) void |
onBeforeCommit(Transactional.Action action)
We may have to set the
getFromId() and/or getToId()
values if those items are also created in the same transaction. |
void |
setDescription(String description)
Set the description for the item.
|
private void |
setFrom(BasicItem from) |
void |
setName(String name)
Set the name of the item.
|
void |
setTo(BasicItem to)
Set the destination item of the link.
|
void |
setUsingTo(boolean usesTo)
If this link counts as using the destination item.
|
static int |
unlinkAllFrom(DbControl dc,
BasicItem from)
Delete all links linking from the specified item.
|
static void |
unlinkFrom(DbControl dc,
BasicItem from,
String name) |
addUsingItems, addUsingItems, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getId, getVersion
checkPermission, getPermissions, hasPermission
public static final Item TYPE
Item.ANYTOANY
,
getType()
private BasicItem from
private BasicItem to
AnyToAny(AnyToAnyData data)
AnyToAny(AnyToAnyData data, BasicItem from)
public static AnyToAny getNew(DbControl dc, BasicItem from, BasicItem to, String name, boolean usingTo) throws InvalidDataException
AnyToAny
linkdc
- The DbControl
which will be used for
permission checking and database accessfrom
- The item to create the link fromto
- The item to link toname
- The name of the link, must be unique among all links for the from
itemusingTo
- TRUE if the link counts as using the to
item,
FALSE otherwise (see BasicItem.isUsed()
)AnyToAny
linkInvalidDataException
- If any of the items are null, or if the
items are equal or if any of the items is an AnyToAny itemBaseException
- If there is an errorpublic static AnyToAny getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
AnyToAny
link when you know the id.dc
- The DbControl
which will be used for
permission checking and database accessid
- The id of the item to loadAnyToAnyLink
itemItemNotFoundException
- If an item with the specified
id is not foundPermissionDeniedException
- If the logged in user doesn't
have read permission to the itemBaseException
- If there is another errorpublic static AnyToAny getByName(DbControl dc, BasicItem from, String name) throws InvalidDataException, ItemNotFoundException, BaseException
AnyToAny
link when you know the item
it is linking from and the name of the link.dc
- The DbControl
which will be used for
permission checking and database access.from
- The item the link is linking fromname
- The name of the linkAnyToAnyLink
itemInvalidDataException
- If the from or name parameter is nullItemNotFoundException
- If a link with the specified
name is not foundBaseException
- If there is another errorstatic AnyToAnyData getDataByName(Session session, int fromId, Item fromType, String name)
session
- An open Hibernate sessionfromId
- The id of the source itemfromType
- The type of the source itemname
- The name of the linkpublic static AnyToAny getNewOrExisting(DbControl dc, BasicItem from, String name, BasicItem to, boolean usingTo)
AnyToAny
link. If a link
already exists it's destination item will be updated to link
to the to
parameter. If a new link was created
you must call DbControl.saveItem(BasicItem)
to save
the link in the database. Otherwise, you don't have to do anything.dc
- The DbControl
which will be used for
permission checking and database accessfrom
- The item to create/get the link fromto
- The item to link toname
- The name of the link, must be unique among all links for the from
itemusingTo
- TRUE if the link counts as using the to
item,
FALSE otherwise (see BasicItem.isUsed()
)AnyToAny
linkInvalidDataException
- If any of the items are null, or if the
items are equal or if any of the items is an AnyToAny itemBaseException
- If there is an errorpublic static ItemQuery<AnyToAny> getLinksFrom(BasicItem from) throws InvalidDataException
from
- The source of the linksItemQuery
objectInvalidDataException
- If the from parameter is nullpublic static ItemQuery<AnyToAny> getLinksTo(BasicItem to)
to
- The destination of the linksItemQuery
objectInvalidDataException
- If the to parameter is nullpublic static void unlinkFrom(DbControl dc, BasicItem from, String name) throws PermissionDeniedException, InvalidDataException, BaseException
dc
- DbControl to use when accessing the databasefrom
- BasicItem to unlink from.name
- Name of the link.PermissionDeniedException
- If the logged in user doesn't have
WRITE permission for the itemInvalidDataException
- If the from or name parameter is nullBaseException
- If there is another errorpublic static int unlinkAllFrom(DbControl dc, BasicItem from) throws PermissionDeniedException, InvalidDataException, BaseException
dc
- The DbControl
which will be used for
permission checking and database accessfrom
- The source of the linksPermissionDeniedException
- If the logged in user doesn't have
WRITE permission for the itemInvalidDataException
- If the from parameter is nullBaseException
- If there is another errorpublic static boolean exists(DbControl dc, BasicItem from, String name) throws InvalidDataException, BaseException
dc
- The DbControl
which will be used for
permission checking and database access.from
- The item the link is linking fromname
- The name of the linkInvalidDataException
- If the from or name parameter is nullBaseException
- If there is another errorpublic static int deleteStrayLinks(ProgressReporter progress)
BasicItem.onBeforeCommit(Transactional.Action)
method
tries to delete as many links as it can, it will not not delete links
leading to items that have been deleted by Hibernate cascade.progress
- An optional progress reporterAnyToAnyData getData()
BasicItem
BasicData
object that holds all data for this item.public Item getType()
Identifiable
Item
enumeration.getType
in interface Identifiable
public boolean isUsed() throws BaseException
isUsed
in class BasicItem
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
void onBeforeCommit(Transactional.Action action) throws BaseException
getFromId()
and/or getToId()
values if those items are also created in the same transaction.onBeforeCommit
in class BasicItem
BaseException
- If there is an errorTransactional
,
Developer documentation: Transactions,
Developer documentation: Coding rules and guidelines for item classesvoid initPermissions(int granted, int denied) throws BaseException
initPermissions
in class BasicItem
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem
public String getName()
Nameable
public void setName(String name) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_NAME_LENGTH
constant.setName
in interface Nameable
name
- The new name for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the name is null or longer
than specified by the Nameable.MAX_NAME_LENGTH
constantpublic String getDescription()
Nameable
getDescription
in interface Nameable
String
with a description of the itempublic void setDescription(String description) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_DESCRIPTION_LENGTH
constant.setDescription
in interface Nameable
description
- The new description for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the description longer
than specified by the Nameable.MAX_DESCRIPTION_LENGTH
constantprivate void setFrom(BasicItem from) throws InvalidDataException, PermissionDeniedException
public int getFromId()
public Item getFromType()
public BasicItem getFrom() throws PermissionDeniedException, BaseException
BasicItem
itemPermissionDeniedException
- If the logged in user doesn't have
read permission to the itemBaseException
- If there is another errorpublic int getToId()
public Item getToType()
public BasicItem getTo() throws PermissionDeniedException, BaseException
BasicItem
itemPermissionDeniedException
- If the logged in user doesn't have
read permission to the itemBaseException
- If there is another errorpublic void setTo(BasicItem to) throws InvalidDataException, PermissionDeniedException
to
- The destination itemInvalidDataException
- If the item is null or is an AnyToAny
linkPermissionDeniedException
- If the logged in user doesn't have write permission
for the link and use permission for the itempublic boolean isUsingTo()
public void setUsingTo(boolean usesTo) throws PermissionDeniedException
usesTo
- TRUE if this counts as using the item, FALSE otherwise.PermissionDeniedException
- If the logged in user doesn't
have write permission