Class UGCServiceImpl<T extends UGC>

    • Field Detail

      • entitlementValidator

        protected org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator
    • Constructor Detail

      • UGCServiceImpl

        public UGCServiceImpl()
    • 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 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.
        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).
        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
      • 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
      • 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
      • 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 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)