Class UGCServiceImpl<T extends UGC>

java.lang.Object
org.craftercms.social.services.ugc.impl.UGCServiceImpl<T>
All Implemented Interfaces:
UGCService, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class UGCServiceImpl<T extends UGC> extends Object implements UGCService, org.springframework.context.ApplicationContextAware
  • 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: UGCService

      Creates an UGC.

      Implementers must check if the current user is allow to create UGC for that contextId

      Specified by:
      create in interface UGCService<T extends UGC>
      Parameters:
      contextId - Context ID of the UGC
      ugcParentId - 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

      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 interface UGCService<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 interface UGCService<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 interface UGCService<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 removeWatcher

      Implementers 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 interface UGCService<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: 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 interface UGCService<T extends UGC>
      Parameters:
      ugcId - Id of the desire UGC
      includeChildren - True to include the children of this UGC.
      childCount - Amount of children to be include.negative Numbers to all
      contextId - contextId owner of the UGC
      Returns:
      The UGC (and its children).
      Throws:
      UGCException - If is unable to get the UGC.
    • readByTargetId

      public Iterable<T> readByTargetId(String targetId, String contextId) throws UGCException
      Specified by:
      readByTargetId in interface UGCService<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 interface UGCService<T extends UGC>
      Parameters:
      contextId - Context ID of the UGC
      query - 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 interface UGCService<T extends UGC>
      Parameters:
      ugcId - Id of the desire UGC to attach a file.
      contextId - Context ID of the UGC
      attachment - 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 interface UGCService<T extends UGC>
      Parameters:
      ugcId - UGC id to delete the attachment.
      contextId - Context ID of the UGC
      attachmentId - 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 interface UGCService<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 interface UGCService<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 interface UGCService<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 interface UGCService<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 interface UGCService<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 interface UGCService<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 interface UGCService<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).
    • 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 orphanChild
      orphanChild - 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)
    • setApplicationContext

      public void setApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException