Package org.intermine.api.profile
Class TagManager
- java.lang.Object
-
- org.intermine.api.profile.TagManager
-
public class TagManager extends java.lang.Object
Manager class for tags. Implements retrieving, adding and deleting tags in user profile database.- Author:
- Jakub Kulaviak
, Alex Kalderimis, Daniela Butano
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TagManager.TagException
Class for reporting exceptions from tag manipulation actions.static class
TagManager.TagNameException
Class for representing errors due to the use of illegal tag names.static class
TagManager.TagNamePermissionException
Class for representing errors due to the restricted nature of some tags.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
INVALID_NAME_MSG
What we tell users when they give us an invalid tag nameprotected ObjectStoreWriter
osWriter
-
Constructor Summary
Constructors Constructor Description TagManager(ObjectStoreWriter profileOsWriter)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Tag
addTag(java.lang.String tagName, java.lang.String objectIdentifier, java.lang.String type, Profile profile)
Add a new tag.Tag
addTag(java.lang.String tagName, WebSearchable ws, Profile profile)
Associate a websearchable obj with a certain tag.Tag
addTag(java.lang.String tagName, ClassDescriptor cld, Profile profile)
Associate a class with a certain tag.Tag
addTag(java.lang.String tagName, ReferenceDescriptor ref, Profile profile)
Associate a reference with a certain tag.void
close()
Close this TagManager.void
deleteObjectTags(java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Deletes all tags assigned to a specified object.protected void
deleteTag(java.lang.String tagName, java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Deletes a tag object from the database.void
deleteTag(java.lang.String tagName, WebSearchable ws, Profile profile)
Delete a tag by name from a web-searchable object.void
deleteTag(java.lang.String tagName, ClassDescriptor cd, Profile profile)
Delete a tag by name from a class-descriptor.void
deleteTag(java.lang.String tagName, ReferenceDescriptor rd, Profile profile)
Delete a tag by name from a reference-descriptor.void
deleteTag(Tag tag)
Delete a tag object from the database.void
deleteTags(java.lang.String tagName, java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Deletes tags object from the database.java.util.Set<java.lang.String>
getObjectTagNames(java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Returns names of tagged tags for specified object.java.util.Set<java.lang.String>
getObjectTagNames(Taggable taggable, Profile profile)
Returns names of tagged tags for specified object.java.util.List<Tag>
getObjectTags(Taggable taggable, Profile profile)
Get the tags for a specific object.java.util.Collection<java.lang.String>
getPublicTagNames(java.lang.String objectIdentifier, java.lang.String tagType)
Get the tags for an object that are visible to all users.java.util.Collection<java.lang.String>
getPublicTagNames(Taggable taggable)
Get all the tags that all users have access to.java.util.Collection<java.lang.String>
getPublicTagNames(ClassDescriptor cld)
Get all the tags that all users have access to.Tag
getTagById(int id)
Get Tag by object id.java.util.List<Tag>
getTags(java.lang.String tagName, java.lang.String taggedObjectId, java.lang.String type, java.lang.String userName)
Return a List of Tags that match all the arguments.java.util.List<Tag>
getTagsByName(java.lang.String tagName, Profile user, java.lang.String tagType)
Return all the tags with the given tag name, optionally filtered by tag-type.java.util.List<Tag>
getTagsByType(java.lang.String tagType)
Return all tags of given type.java.util.Set<java.lang.String>
getUserTagNames(java.lang.String type, java.lang.String userName)
Deprecated.It is better to use the typed methods instead.java.util.Set<java.lang.String>
getUserTagNames(java.lang.String type, Profile user)
Returns names of tags of specified user and tag type.java.util.List<Tag>
getUserTags(java.lang.String userName)
Returns tags of specified user.java.util.List<Tag>
getUserTags(Profile user)
Returns tags of specified user.boolean
hasTag(java.lang.String tagName, Taggable taggable)
Test whether a particular taggable thing has been tagged with a particular tag.boolean
hasTag(java.lang.String tagName, Taggable taggable, Profile profile)
Test whether a particular taggable thing has been tagged with a particular tag, by a particular user.static boolean
isValidTagName(java.lang.String name)
TODO this should use the same validation method the other classes use Verifies that tag name can only contain A-Z, a-z, 0-9, '_', '-', ' ', ':', '.'
-
-
-
Field Detail
-
osWriter
protected ObjectStoreWriter osWriter
-
INVALID_NAME_MSG
public static final java.lang.String INVALID_NAME_MSG
What we tell users when they give us an invalid tag name- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TagManager
public TagManager(ObjectStoreWriter profileOsWriter)
Constructor. Use TagManagerFactory for creating tag manager.- Parameters:
profileOsWriter
- user profile object store
-
-
Method Detail
-
deleteTag
public void deleteTag(Tag tag)
Delete a tag object from the database.- Parameters:
tag
- Tag object
-
hasTag
public boolean hasTag(java.lang.String tagName, Taggable taggable)
Test whether a particular taggable thing has been tagged with a particular tag. This method returns true if ANY user has tagged this object.- Parameters:
tagName
- The tag name to check.taggable
- The particular taggable thing.- Returns:
- True if the object is associated with the tag.
-
hasTag
public boolean hasTag(java.lang.String tagName, Taggable taggable, Profile profile)
Test whether a particular taggable thing has been tagged with a particular tag, by a particular user. If the profile argument is null, then that argument is treated as a wild-card.- Parameters:
tagName
- The tag name to check.taggable
- The particular taggable thing.profile
- The user who is meant to have tagged the item, or null for a wildcard.- Returns:
- True if the object is associated with the tag.
-
deleteTag
public void deleteTag(java.lang.String tagName, WebSearchable ws, Profile profile)
Delete a tag by name from a web-searchable object. This action fires a TagChange.REMOVED event.- Parameters:
tagName
- The tag to remove.ws
- The object to remove it from.profile
- The user who is meant to own the tag.
-
deleteTag
public void deleteTag(java.lang.String tagName, ClassDescriptor cd, Profile profile)
Delete a tag by name from a class-descriptor.- Parameters:
tagName
- The tag to remove.cd
- The class descriptor to remove it from.profile
- The profile the tag should be removed from.
-
deleteTag
public void deleteTag(java.lang.String tagName, ReferenceDescriptor rd, Profile profile)
Delete a tag by name from a reference-descriptor.- Parameters:
tagName
- The tag to remove.rd
- The reference descriptor to remove it from.profile
- The profile the tag should be removed from.
-
deleteTag
protected void deleteTag(java.lang.String tagName, java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Deletes a tag object from the database. If there is no such tag, an Exception will be thrown to that effect.- Parameters:
tagName
- the tag nametaggedObject
- the object identifier of the tagged objecttype
- the tag typeuserName
- the user name associated with the tag.
-
deleteTags
public void deleteTags(java.lang.String tagName, java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Deletes tags object from the database. Any null arguments will be treated as wildcards.- Parameters:
tagName
- tag nametaggedObject
- object id of tagged objecttype
- tag typeuserName
- user name
-
getUserTagNames
public java.util.Set<java.lang.String> getUserTagNames(java.lang.String type, Profile user)
Returns names of tags of specified user and tag type. For anonymous user returns empty set.- Parameters:
type
- tag typeuser
- the user. MAY NOT BE NULL.- Returns:
- tag names
-
getUserTagNames
@Deprecated public java.util.Set<java.lang.String> getUserTagNames(java.lang.String type, java.lang.String userName)
Deprecated.It is better to use the typed methods instead.Returns names of tags of specified user and tag type. For anonymous user returns empty set.Use of this method is strongly discouraged. It is better to use the typed methods instead. This method will be removed in the future.
- Parameters:
type
- tag typeuserName
- user name- Returns:
- tag names
- Throws:
UserNotFoundException
- if user doesn't exist
-
getUserTags
public java.util.List<Tag> getUserTags(java.lang.String userName)
Returns tags of specified user.Use of this method is strongly discouraged. Use typed methods instead.
- Parameters:
userName
- user name- Returns:
- tags
-
getUserTags
public java.util.List<Tag> getUserTags(Profile user)
Returns tags of specified user.- Parameters:
user
- user name- Returns:
- tags
-
getObjectTagNames
public java.util.Set<java.lang.String> getObjectTagNames(java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Returns names of tagged tags for specified object.- Parameters:
taggedObject
- tagged object, eg. template nametype
- tag type, eg. templateuserName
- user name- Returns:
- tag names
-
getObjectTagNames
public java.util.Set<java.lang.String> getObjectTagNames(Taggable taggable, Profile profile)
Returns names of tagged tags for specified object. For anonymous user returns empty set.- Parameters:
taggable
- A taggable object.profile
- The profile of the user with access to these tags.- Returns:
- tag names
-
getObjectTags
public java.util.List<Tag> getObjectTags(Taggable taggable, Profile profile)
Get the tags for a specific object.- Parameters:
taggable
- The object with the tags.profile
- The user these tags should belong to.- Returns:
- tags.
-
getTagById
public Tag getTagById(int id)
Get Tag by object id.- Parameters:
id
- intermine object id- Returns:
- Tag
-
getTagsByName
public java.util.List<Tag> getTagsByName(java.lang.String tagName, Profile user, java.lang.String tagType)
Return all the tags with the given tag name, optionally filtered by tag-type.- Parameters:
tagName
- The name of the tag. Must not be null.tagType
- The type of tags to return. May be null (with the semantics of returning all tags). If not null, this must be a valid tag type.user
- The user these tags belong to. Must not be null.- Returns:
- The tags that match these criteria.
- See Also:
TagTypes
-
getTags
public java.util.List<Tag> getTags(java.lang.String tagName, java.lang.String taggedObjectId, java.lang.String type, java.lang.String userName)
Return a List of Tags that match all the arguments. Any null arguments will be treated as wildcards.Use of this method is strongly discouraged. There are typed methods that are more suitable. Use them instead.
- Parameters:
tagName
- the tag name - any StringtaggedObjectId
- an object identifier that is appropriate for the given tag type (eg. "Department.name" for the "collection" type)type
- the tag type (eg. "collection", "reference", "attribute", "bag")userName
- the use name this tag is associated with- Returns:
- the matching Tags
-
addTag
public Tag addTag(java.lang.String tagName, java.lang.String objectIdentifier, java.lang.String type, Profile profile) throws TagManager.TagNameException, TagManager.TagNamePermissionException
Add a new tag. The format of objectIdentifier depends on the tag type. For types "attribute", "reference" and "collection" the objectIdentifier should have the form "ClassName.fieldName".- Parameters:
tagName
- the tag name - any StringobjectIdentifier
- an object identifier that is appropriate for the given tag type (eg. "Department.name" for the "collection" type)type
- the tag type (eg. "collection", "reference", "attribute", "bag")profile
- The Profile of the user to associate this tag with.- Returns:
- the new Tag
- Throws:
TagManager.TagNameException
- If the tag name is invalid.TagManager.TagNamePermissionException
- If the user does not have the required permissions to add this tag.
-
addTag
public Tag addTag(java.lang.String tagName, WebSearchable ws, Profile profile) throws TagManager.TagNameException, TagManager.TagNamePermissionException
Associate a websearchable obj with a certain tag.- Parameters:
tagName
- The tag we want to give this template.ws
- the websearchable obj to tag.profile
- The profile to associate this tag with.- Returns:
- A tag object.
- Throws:
TagManager.TagNameException
- If the name is invalid (contains illegal characters)TagManager.TagNamePermissionException
- If this tag name is restricted.
-
addTag
public Tag addTag(java.lang.String tagName, ClassDescriptor cld, Profile profile) throws TagManager.TagNameException, TagManager.TagNamePermissionException
Associate a class with a certain tag.- Parameters:
tagName
- The tag we want to give this class.cld
- The descriptor for this class.profile
- The profile to associate this tag with.- Returns:
- A tag object.
- Throws:
TagManager.TagNameException
- If the name is invalid (contains illegal characters)TagManager.TagNamePermissionException
- If this tag name is restricted.
-
addTag
public Tag addTag(java.lang.String tagName, ReferenceDescriptor ref, Profile profile) throws TagManager.TagNameException, TagManager.TagNamePermissionException
Associate a reference with a certain tag.- Parameters:
tagName
- The tag we want to give this reference.ref
- the reference.profile
- The profile to associate this tag with.- Returns:
- A tag object.
- Throws:
TagManager.TagNameException
- If the name is invalid (contains illegal characters)TagManager.TagNamePermissionException
- If this tag name is restricted.
-
isValidTagName
public static boolean isValidTagName(java.lang.String name)
TODO this should use the same validation method the other classes use Verifies that tag name can only contain A-Z, a-z, 0-9, '_', '-', ' ', ':', '.'- Parameters:
name
- tag name- Returns:
- true if the name is valid else false
-
deleteObjectTags
public void deleteObjectTags(java.lang.String taggedObject, java.lang.String type, java.lang.String userName)
Deletes all tags assigned to a specified object.- Parameters:
taggedObject
- tagged objecttype
- tag typeuserName
- user name
-
getPublicTagNames
public java.util.Collection<java.lang.String> getPublicTagNames(ClassDescriptor cld)
Get all the tags that all users have access to.- Parameters:
cld
- The class descriptor that is tagged.- Returns:
- The tag names.
-
getPublicTagNames
public java.util.Collection<java.lang.String> getPublicTagNames(Taggable taggable)
Get all the tags that all users have access to.- Parameters:
taggable
- The thing that is tagged.- Returns:
- The tag names.
-
getPublicTagNames
public java.util.Collection<java.lang.String> getPublicTagNames(java.lang.String objectIdentifier, java.lang.String tagType)
Get the tags for an object that are visible to all users. Public tags are defined as those that begin with the IM_PREFIX.- Parameters:
objectIdentifier
- The identifier for this object.tagType
- The type of thing this is.- Returns:
- The names of the tags.
-
close
public void close() throws ObjectStoreException
Close this TagManager. Only used for tests.- Throws:
ObjectStoreException
- in exceptional circumstances
-
getTagsByType
public java.util.List<Tag> getTagsByType(java.lang.String tagType)
Return all tags of given type.- Parameters:
tagType
- The type of tag to return. Must not be null.- Returns:
- A List of tags.
-
-