Package NTNU.IDATT1002.service
Class TagService
java.lang.Object
NTNU.IDATT1002.service.TagService
public class TagService
extends java.lang.Object
Tag Service. Supports common domain specific operations such as converting a list of tags to a string
and opposite.
- Version:
- 1.1 01.04.20
-
Constructor Summary
Constructors Constructor Description TagService(javax.persistence.EntityManager entityManager)
Inject entity manager instance to the repositories. -
Method Summary
Modifier and Type Method Description java.util.List<Tag>
getOrCreateTags(java.util.List<Tag> tags)
Gets or creates given tags in given list.Tag
getSingleTag(Tag tag)
Retrieve given tag.static java.lang.String
getTagsAsString(java.util.List<Tag> tags)
Retrieves tags from list of tags and converts them to a concatenated string.static java.util.List<Tag>
getTagsFromString(java.lang.String tagsAsString)
Retrieves tags from text field and converts them to a list of tag objects.
-
Constructor Details
-
TagService
public TagService(javax.persistence.EntityManager entityManager)Inject entity manager instance to the repositories.
-
-
Method Details
-
getOrCreateTags
Gets or creates given tags in given list. Ignores null values.- Parameters:
tags
- the list of tags- Returns:
- a list of persisted tags
-
getTagsFromString
Retrieves tags from text field and converts them to a list of tag objects.- Returns:
- the list of tag objects
-
getTagsAsString
Retrieves tags from list of tags and converts them to a concatenated string.- Parameters:
tags
- the list of tags- Returns:
- the tags as a string
-
getSingleTag
Retrieve given tag. Either get an existing or create it.- Parameters:
tag
- the tag to retrieve- Returns:
- the persisted tag, else a new persisted tag instance
- Throws:
java.lang.IllegalArgumentException
- if tag could not be found or created
-