Class UGCServiceImpl<T extends UGC>
- java.lang.Object
-
- org.craftercms.social.services.ugc.impl.UGCServiceImpl<T>
-
- All Implemented Interfaces:
UGCService
public class UGCServiceImpl<T extends UGC> extends Object implements UGCService
-
-
Field Summary
Fields Modifier and Type Field Description protected org.craftercms.commons.entitlements.validator.EntitlementValidator
entitlementValidator
-
Constructor Summary
Constructors Constructor Description UGCServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.craftercms.commons.mongo.FileInfo
addAttachment(String ugcId, String contextId, InputStream attachment, String fileName, String contentType)
Adds and Attachment Information to the given UGC.protected T
buildUgcTree(List<T> ugs)
Given a list of results Builds A UGC Tree.protected List<T>
buildUgcTreeList(List<T> ugs, int childrenPerLevel)
Given a list of results Builds A UGC Tree.long
count(String threadId, String contextId)
Counts all the First Level ugc of a target.long
countChildren(String ugcId, String contextId)
UGC
create(String contextId, String ugcParentId, String targetId, String textContent, String subject, Map attrs, boolean isAnonymous)
Creates an UGC.void
deleteAttribute(String ugcId, String[] attributesName, String contextId)
Deletes a attribute of the given UGC.boolean
deleteUgc(String ugcId, String contextId)
Deletes a UGC If the Ugc is a parent it will delete the whole treeprotected void
findMyParent(Collection<T> possibleParents, UGC orphanChild)
Finds the parent of the orphanChild in the list of possible parents.protected boolean
findRelatives(List<T> ugs, T ugcToTest, int childrenPerLevel)
Using ugcToTest goes though ugs one by one and checks if the element either it's parent or one of it's children.T
read(String ugcId, boolean includeChildren, int childCount, String contextId)
Gets a UGC with the given Id.UGC
read(String ugcId, String contextId)
Finds a single UGC.List<T>
read(String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel)
org.craftercms.commons.mongo.FileInfo
readAttachment(String ugcId, String contextId, String attachmentId)
Iterable<T>
readByTargetId(String targetId, String contextId)
List<T>
readChildren(String ugcId, String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel)
void
removeAttachment(String ugcId, String contextId, String attachmentId)
Deletes an attachment of the given UGC.Iterable<T>
search(String contextId, String query, String sort, int start, int limit)
Finds All UGC that match the given criteria.void
setArraySortFields(String arraySortFields)
void
setAttributes(String ugcId, String contextId, Map attributes)
Sets an attribute to the given UGC Creates if does not existvoid
setEntitlementValidator(org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator)
void
setInvalidQueryKeys(String invalidQueryKeysPattern)
void
setNotificationServiceImpl(NotificationService notificationService)
void
setPipeline(UgcPipeline pipeline)
void
setProfileService(org.craftercms.profile.api.services.ProfileService profileService)
void
setReactor(reactor.core.Reactor reactor)
void
setSocialUgcFactory(UgcFactory ugcFactory)
void
setTenantConfigurationService(TenantConfigurationService tenantConfigurationService)
void
setUGCRepositoryImpl(UGCRepository UGCRepositoryImpl)
void
setVirusScanner(VirusScanner virusScanner)
UGC
update(String ugcId, String body, String subject, String contextId, Map attributes)
Updates the given UGC with the given information.org.craftercms.commons.mongo.FileInfo
updateAttachment(String ugcId, String contextId, String attachmentId, InputStream newAttachment)
-
-
-
Method Detail
-
create
public UGC create(String contextId, String ugcParentId, String targetId, String textContent, String subject, Map attrs, boolean isAnonymous) throws SocialException
Description copied from interface:UGCService
Creates an UGC.
Implementers must check if the current user is allow to create UGC for that contextId
- Specified by:
create
in interfaceUGCService<T extends UGC>
- Parameters:
contextId
- Context ID of the UGCugcParentId
- Parent Id of the UGC If not null or empty will be the parent of the UGC else it wont have any parent.targetId
- Target Id of the UGC.textContent
- Actual content of the UGC Must be cleanup to prevent XSS.subject
- Subject of the UGC.- Returns:
- A new Public (secure) UGC.
- Throws:
SocialException
- If UGC can't be created.
-
setNotificationServiceImpl
public void setNotificationServiceImpl(NotificationService notificationService)
-
setAttributes
public void setAttributes(String ugcId, String contextId, Map attributes) throws SocialException, UGCNotFound
Description copied from interface:UGCService
Sets an attribute to the given UGC Creates if does not exist
Implementers must check if the current user is allow to removeWatcher UGC and that the user belongs to the same ugc contextId
.- Specified by:
setAttributes
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- Id of the Ugc to add Attribute.contextId
- Context ID of the UGC.attributes
- Attributes to set.Nested attributes Must be nested with in the map- Throws:
SocialException
- if attribute can be set.UGCNotFound
-
deleteAttribute
public void deleteAttribute(String ugcId, String[] attributesName, String contextId) throws SocialException
Description copied from interface:UGCService
Deletes a attribute of the given UGC.Implementers must check if the current user is allow to removeWatcher UGC and that the user belongs to the same ugc contextId
.- Specified by:
deleteAttribute
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- id Id of the Ugc to add Attribute.attributesName
- Attributes Name of the attribute to delete.contextId
- Context ID of the UGC- Throws:
SocialException
- if attribute can be deleted.
-
deleteUgc
public boolean deleteUgc(String ugcId, String contextId) throws SocialException
Description copied from interface:UGCService
Deletes a UGC If the Ugc is a parent it will delete the whole tree
Implementers must check if the current user is allow to delete UGC and that the user belongs to the same ugc contextId.t
. x- Specified by:
deleteUgc
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- UGC id to delete.contextId
- Context ID of the UGC- Returns:
- True if UGC (and tree) can be deleted , false other wise.
- Throws:
SocialException
- if ugc (and or tree) can be deleted)
-
update
public UGC update(String ugcId, String body, String subject, String contextId, Map attributes) throws SocialException, UGCNotFound
Description copied from interface:UGCService
Updates the given UGC with the given information. Also it will removeWatcherImplementers must check if the current user is allow to removeWatcher UGC and that the user belongs to the same ugc contextId.
.- Specified by:
update
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- Id of the Ugc to removeWatcher.body
- new Text Content (empty of null to leave current value).subject
- new subject (empty of null to leave current value).- Returns:
- the updated Public (secure) UGC.
- Throws:
SocialException
- If the UGC can be updated.UGCNotFound
-
read
public T read(String ugcId, boolean includeChildren, int childCount, String contextId) throws UGCException
Description copied from interface:UGCService
Gets a UGC with the given Id.Implementers must check if the current user is allow to read UGC and that the user belongs to the same ugc contextId.
.- Specified by:
read
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- Id of the desire UGCincludeChildren
- True to include the children of this UGC.childCount
- Amount of children to be include.negative Numbers to allcontextId
- contextId owner of the UGC- Returns:
- The UGC (and its children).
- Throws:
UGCException
-
readByTargetId
public Iterable<T> readByTargetId(String targetId, String contextId) throws UGCException
- Specified by:
readByTargetId
in interfaceUGCService<T extends UGC>
- Throws:
UGCException
-
search
public Iterable<T> search(String contextId, String query, String sort, int start, int limit) throws UGCException
Description copied from interface:UGCService
Finds All UGC that match the given criteria.- Specified by:
search
in interfaceUGCService<T extends UGC>
- Parameters:
contextId
- Context ID of the UGCquery
- Query Map.sort
- Sort Map.start
- Where to start.limit
- How many results to return.- Returns:
- A list of all UGC that match the given criteria , if sort map is empty is unsorted
- Throws:
UGCException
-
addAttachment
public org.craftercms.commons.mongo.FileInfo addAttachment(String ugcId, String contextId, InputStream attachment, String fileName, String contentType) throws org.apache.commons.io.FileExistsException, UGCException
Description copied from interface:UGCService
Adds and Attachment Information to the given UGC.- Specified by:
addAttachment
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- Id of the desire UGC to attach a file.contextId
- Context ID of the UGCattachment
- Attachment to add.- Throws:
org.apache.commons.io.FileExistsException
UGCException
-
removeAttachment
public void removeAttachment(String ugcId, String contextId, String attachmentId) throws UGCException, FileNotFoundException
Description copied from interface:UGCService
Deletes an attachment of the given UGC.- Specified by:
removeAttachment
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- UGC id to delete the attachment.contextId
- Context ID of the UGCattachmentId
- attachment Id to delete.- Throws:
UGCException
- If unable to delete the attachment or removeWatcher the UGC.FileNotFoundException
- If file is not found
-
updateAttachment
public org.craftercms.commons.mongo.FileInfo updateAttachment(String ugcId, String contextId, String attachmentId, InputStream newAttachment) throws UGCException, FileNotFoundException
- Specified by:
updateAttachment
in interfaceUGCService<T extends UGC>
- Throws:
UGCException
FileNotFoundException
-
readAttachment
public org.craftercms.commons.mongo.FileInfo readAttachment(String ugcId, String contextId, String attachmentId) throws FileNotFoundException, UGCException
- Specified by:
readAttachment
in interfaceUGCService<T extends UGC>
- Throws:
FileNotFoundException
UGCException
-
read
public List<T> read(String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel) throws UGCException
- Specified by:
read
in interfaceUGCService<T extends UGC>
- Throws:
UGCException
-
readChildren
public List<T> readChildren(String ugcId, String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel) throws UGCException, UGCNotFound
- Specified by:
readChildren
in interfaceUGCService<T extends UGC>
- Throws:
UGCException
UGCNotFound
-
read
public UGC read(String ugcId, String contextId) throws UGCException
Description copied from interface:UGCService
Finds a single UGC.- Specified by:
read
in interfaceUGCService<T extends UGC>
- Parameters:
ugcId
- Id of the Ugc.contextId
- Context ID of the UGC- Returns:
- The ugc with the given Id ,null if not found.
- Throws:
UGCException
-
count
public long count(String threadId, String contextId) throws UGCException
Description copied from interface:UGCService
Counts all the First Level ugc of a target.- Specified by:
count
in interfaceUGCService<T extends UGC>
- Parameters:
threadId
- Id ot the target.contextId
- Context ID of the UGC- Returns:
- A count of all possible first level comments.
- Throws:
UGCException
-
countChildren
public long countChildren(String ugcId, String contextId) throws UGCException
- Specified by:
countChildren
in interfaceUGCService<T extends UGC>
- Throws:
UGCException
-
buildUgcTreeList
protected List<T> buildUgcTreeList(List<T> ugs, int childrenPerLevel)
Given a list of results Builds A UGC Tree.
The main difference from
buildUgcTree(java.util.List)
is that this method allows for multiple Roots or not roots at all- Parameters:
ugs
- List of the UGS to build the tree.childrenPerLevel
- Levels of Children.- Returns:
- A List Ugcs (Roots) all roots have there children if any.
-
findRelatives
protected boolean findRelatives(List<T> ugs, T ugcToTest, int childrenPerLevel)
Using ugcToTest goes though ugs one by one and checks if the element either it's parent or one of it's children.- Parameters:
ugs
- List of UGC to check against.ugcToTest
- Ugc to check.childrenPerLevel
-- Returns:
- True if a Parent or children is found. False if is a Root (not parents , or is a leaf).
-
setReactor
public void setReactor(reactor.core.Reactor reactor)
-
setUGCRepositoryImpl
public void setUGCRepositoryImpl(UGCRepository UGCRepositoryImpl)
-
setPipeline
public void setPipeline(UgcPipeline pipeline)
-
setInvalidQueryKeys
public void setInvalidQueryKeys(String invalidQueryKeysPattern)
-
setArraySortFields
public void setArraySortFields(String arraySortFields)
-
setSocialUgcFactory
public void setSocialUgcFactory(UgcFactory ugcFactory)
-
setVirusScanner
public void setVirusScanner(VirusScanner virusScanner)
-
buildUgcTree
protected T buildUgcTree(List<T> ugs)
Given a list of results Builds A UGC Tree.
The first element of the list will be taken as the root of the tree
- Parameters:
ugs
- List of the UGS to build the tree. First Element will be the root.- Returns:
- A Ugc with its children array filled (and its children...).
-
findMyParent
protected void findMyParent(Collection<T> possibleParents, UGC orphanChild)
Finds the parent of the orphanChild in the list of possible parents. It will also go recursively to the children's children until there is nothing left. It is possible that it will never find a parent (the orphanChild will be disposed silently- Parameters:
possibleParents
- Possible parent of orphanChildorphanChild
- UGC to find it's parent.
-
setTenantConfigurationService
public void setTenantConfigurationService(TenantConfigurationService tenantConfigurationService)
-
setProfileService
public void setProfileService(org.craftercms.profile.api.services.ProfileService profileService)
-
setEntitlementValidator
public void setEntitlementValidator(org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator)
-
-