Class UGCServiceImpl<T extends UGC>
- All Implemented Interfaces:
UGCService,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.craftercms.commons.entitlements.validator.EntitlementValidator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.craftercms.commons.mongo.FileInfoaddAttachment(String ugcId, String contextId, InputStream attachment, String fileName, String contentType) Adds and Attachment Information to the given UGC.protected TbuildUgcTree(List<T> ugs) Given a list of results Builds A UGC Tree.buildUgcTreeList(List<T> ugs, int childrenPerLevel) Given a list of results Builds A UGC Tree.longCounts all the First Level ugc of a target.longcountChildren(String ugcId, String contextId) create(String contextId, String ugcParentId, String targetId, String textContent, String subject, Map attrs, boolean isAnonymous) Creates an UGC.voiddeleteAttribute(String ugcId, String[] attributesName, String contextId) Deletes a attribute of the given UGC.booleanDeletes a UGC If the Ugc is a parent it will delete the whole treeprotected voidfindMyParent(Collection<T> possibleParents, UGC orphanChild) Finds the parent of the orphanChild in the list of possible parents.protected booleanfindRelatives(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.Gets a UGC with the given Id.Finds a single UGC.read(String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel) org.craftercms.commons.mongo.FileInforeadAttachment(String ugcId, String contextId, String attachmentId) readByTargetId(String targetId, String contextId) readChildren(String ugcId, String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel) voidremoveAttachment(String ugcId, String contextId, String attachmentId) Deletes an attachment of the given UGC.Finds All UGC that match the given criteria.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetArraySortFields(String arraySortFields) voidsetAttributes(String ugcId, String contextId, Map attributes) Sets an attribute to the given UGC Creates if does not existvoidsetEntitlementValidator(org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator) voidsetInvalidQueryKeys(String invalidQueryKeysPattern) voidsetNotificationServiceImpl(NotificationService notificationService) voidsetPipeline(UgcPipeline pipeline) voidsetProfileService(org.craftercms.profile.api.services.ProfileService profileService) voidsetSocialUgcFactory(UgcFactory ugcFactory) voidsetTenantConfigurationService(TenantConfigurationService tenantConfigurationService) voidsetUGCRepositoryImpl(UGCRepository UGCRepositoryImpl) voidsetVirusScanner(VirusScanner virusScanner) Updates the given UGC with the given information.org.craftercms.commons.mongo.FileInfoupdateAttachment(String ugcId, String contextId, String attachmentId, InputStream newAttachment)
-
Field Details
-
entitlementValidator
protected org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator
-
-
Constructor Details
-
UGCServiceImpl
public UGCServiceImpl()
-
-
Method Details
-
create
public UGC create(String contextId, String ugcParentId, String targetId, String textContent, String subject, Map attrs, boolean isAnonymous) throws SocialException Description copied from interface:UGCServiceCreates an UGC.
Implementers must check if the current user is allow to create UGC for that contextId
- Specified by:
createin 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.attrs-isAnonymous-- Returns:
- A new Public (secure) UGC.
- Throws:
SocialException- If UGC can't be created.
-
setNotificationServiceImpl
-
setAttributes
public void setAttributes(String ugcId, String contextId, Map attributes) throws SocialException, UGCNotFound Description copied from interface:UGCServiceSets 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:
setAttributesin 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:UGCServiceDeletes 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:
deleteAttributein 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
Description copied from interface:UGCServiceDeletes 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:
deleteUgcin 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:UGCServiceUpdates 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:
updatein 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).contextId-- 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:UGCServiceGets 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:
readin 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- If is unable to get the UGC.
-
readByTargetId
- Specified by:
readByTargetIdin 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:UGCServiceFinds All UGC that match the given criteria.- Specified by:
searchin 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:UGCServiceAdds and Attachment Information to the given UGC.- Specified by:
addAttachmentin 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.FileExistsExceptionUGCException
-
removeAttachment
public void removeAttachment(String ugcId, String contextId, String attachmentId) throws UGCException, FileNotFoundException Description copied from interface:UGCServiceDeletes an attachment of the given UGC.- Specified by:
removeAttachmentin 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:
updateAttachmentin interfaceUGCService<T extends UGC>- Throws:
UGCExceptionFileNotFoundException
-
readAttachment
public org.craftercms.commons.mongo.FileInfo readAttachment(String ugcId, String contextId, String attachmentId) throws FileNotFoundException, UGCException - Specified by:
readAttachmentin interfaceUGCService<T extends UGC>- Throws:
FileNotFoundExceptionUGCException
-
read
public List<T> read(String targetId, String contextId, int start, int limit, List sortOrder, int upToLevel, int childrenPerLevel) throws UGCException - Specified by:
readin 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:
readChildrenin interfaceUGCService<T extends UGC>- Throws:
UGCExceptionUGCNotFound
-
read
Description copied from interface:UGCServiceFinds a single UGC.- Specified by:
readin 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
Description copied from interface:UGCServiceCounts all the First Level ugc of a target.- Specified by:
countin 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
- Specified by:
countChildrenin interfaceUGCService<T extends UGC>- Throws:
UGCException
-
buildUgcTreeList
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
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).
-
setUGCRepositoryImpl
-
setPipeline
-
setInvalidQueryKeys
-
setArraySortFields
-
setSocialUgcFactory
-
setVirusScanner
-
buildUgcTree
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
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
-
setProfileService
public void setProfileService(org.craftercms.profile.api.services.ProfileService profileService) -
setEntitlementValidator
public void setEntitlementValidator(org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator) -
setApplicationContext
public void setApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-