Class MemberImportManager

  • All Implemented Interfaces:
    JcmsConstants, JaliosConstants

    public class MemberImportManager
    extends java.lang.Object
    implements JcmsConstants

    A manager to be instanciated to import Members from a CSV input file.

    CSV File's expected format:

     Name, First name, Email, Login, Organization, Department, JobTitle, Phone, Mobile, custom optional columns ...
     # First line must contain headers
     # Use '#' caracter to comment a line
     FOO, John, john.foo@example.com, , Acme, Sales, Manager, 0102030405, 0605040302
     

    The limit controller is checked only if account activation mails is chosen.

    Since:
    jcms-8
    Version:
    $Revision: 135458 $
    Author:
    Sylvain Devaux
    • Field Detail

      • MEMBER_DC_SRC_COLUMNS_KEY

        public static final java.lang.String MEMBER_DC_SRC_COLUMNS_KEY
        A DataController contextMap key, which stores the sources columns of the csv file, as a String[].
        See Also:
        Constant Field Values
      • MAX_MEMBER_PER_IMPORT_PROP

        public static final java.lang.String MAX_MEMBER_PER_IMPORT_PROP
        Property key to indicate the max member per import.
        See Also:
        Constant Field Values
      • EMAIL_BATCH_DEFERR_SECONDS_PROP

        public static final java.lang.String EMAIL_BATCH_DEFERR_SECONDS_PROP
        Property key to indicate the time to wait before sending Email. (in seconds)
        See Also:
        Constant Field Values
      • MAX_ERROR_PER_IMPORT_PROP

        public static final java.lang.String MAX_ERROR_PER_IMPORT_PROP
        Property key to indicate the max number of errors to show per import.
        See Also:
        Constant Field Values
      • WORKSPACE_ROOT_CATEGORY_VID_PROP

        public static final java.lang.String WORKSPACE_ROOT_CATEGORY_VID_PROP
        Property key to indicate the root Category's virtual id of the Workspace Category tree.
        The Workspaces under this Category will be proposed in the Workspaces step.
        See Also:
        Constant Field Values
      • COMMENT_CHARACTER

        public static final java.lang.String COMMENT_CHARACTER
        A character to use at start of a line to comment.
        Since:
        jcms-8
        See Also:
        Constant Field Values
      • DEFAULT_USAGE

        public static int DEFAULT_USAGE
        Since:
        jcms-8.0.1
      • DEFAULT_AS_GUESTS

        public static boolean DEFAULT_AS_GUESTS
        Since:
        jcms-10.0.5
      • DEFAULT_DBMEMBER

        public static boolean DEFAULT_DBMEMBER
        The default use of DBMember class.
        Since:
        jcms-8.0.1
      • isSimulation

        protected boolean isSimulation
      • request

        protected javax.servlet.http.HttpServletRequest request
      • response

        protected javax.servlet.http.HttpServletResponse response
      • importPropertyKey

        protected java.lang.String importPropertyKey
      • groupIds

        protected java.util.Collection<java.lang.String> groupIds
      • csvFile

        protected java.io.File csvFile
      • LANG_PROPERTY_PREFIX

        public static final java.lang.String LANG_PROPERTY_PREFIX
        Property key prefix.
        See Also:
        Constant Field Values
      • expectedColumnCount

        protected int expectedColumnCount
        Expected headers columns number. Used to check the file format.
      • importAuthor

        protected Member importAuthor
      • hasToSendEmail

        protected boolean hasToSendEmail
      • startTime

        protected long startTime
        For debug purpose.
      • endTime

        protected long endTime
        For debug purpose.
      • previousTime

        protected long previousTime
        For debug purpose.
      • csvReader

        protected com.csvreader.CsvReader csvReader
        the reader that makes the parsing.
      • separator

        public java.lang.String separator
        The separator to use, may be selected by UI.
      • userLang

        protected java.lang.String userLang
      • lineInfoMap

        protected java.util.Map<java.lang.Integer,​MemberImport> lineInfoMap
        This map contains the Member objects parsed from CSV.
        The key is the csv line.
        It is used in the UI to print informations about the file format.
      • memberImportList

        protected java.util.List<MemberImport> memberImportList
        The list containing each line.
      • emailInfoMap

        protected java.util.Map<java.lang.String,​MemberImport> emailInfoMap
        This map contains the Member objects parsed from CSV.
        The key is the member email.
        It allows to avoid 2 lines on same email.
        This map will be iterated again, to perform operation (C or U).
      • loginTempInfoMap

        protected java.util.Map<java.lang.String,​MemberImport> loginTempInfoMap
        This map contains the logins encountered or computed during preparation. It is used to prevent use of duplicate logins.
        Since:
        jcms-9.0.1
      • loginInfoMap

        protected java.util.Map<java.lang.String,​MemberImport> loginInfoMap
        This map contains the new computed logins.
        It is used to keep trace to new logins on DBMembers especially, which are not persisted before end of import.
        Since:
        jcms-8.0.1
      • createCount

        protected int createCount
        The count of created Members.
        Since:
        jcms-8
      • updateCount

        protected int updateCount
        The count of updated Members.
        Since:
        jcms-8
      • createActiveCount

        protected int createActiveCount
        Count of active members (may not yet be activated).
        Since:
        jcms-8.0.1
      • activeMemberCountBase

        protected int activeMemberCountBase
        Count of active Members at start of import.
        Since:
        jcms-8.0.1
      • dbOperationsCount

        protected int dbOperationsCount
        Used to count operations on DBData, to perform periodical commit / begin transaction.
        Since:
        jcms-8.0.1
      • invalidCount

        protected int invalidCount
      • isBlockingError

        protected boolean isBlockingError
        True if an error should block the processing.
        Since:
        jcms-8
      • isAnyError

        protected boolean isAnyError
        Is there any error during checking the csv file ?
      • createdMembersIdList

        protected java.util.List<java.lang.String> createdMembersIdList
        The created members id list. Used to show infos after import.
      • updatedMembersIdList

        protected java.util.List<java.lang.String> updatedMembersIdList
        The update members id list. Used to show infos after import.
      • DEFAULT_DEFERR_EMAILS

        public static final int DEFAULT_DEFERR_EMAILS
        The default duration of derring the sending of emails.
        Since:
        jcms-8.0.1
        See Also:
        Constant Field Values
    • Constructor Detail

      • MemberImportManager

        public MemberImportManager​(JcmsContext jcmsContext)
        Parameters:
        jcmsContext - the JcmsContext
        Since:
        jcms-8
    • Method Detail

      • isSimulation

        public boolean isSimulation()
        Returns:
        the isSimulation
        Since:
        jcms-8
      • setSimulation

        public void setSimulation​(boolean isSimulation)
        Parameters:
        isSimulation - the isSimulation to set
        Since:
        jcms-8
      • getCsvFile

        public java.io.File getCsvFile()
        Returns:
        the csvFile
        Since:
        jcms-8
      • setCsvFile

        public void setCsvFile​(java.io.File csvFile)
        Parameters:
        csvFile - the csvFile to set
        Since:
        jcms-8
      • getMemberInfoList

        public java.util.List<MemberImport> getMemberInfoList()
        Get the list of all MemberImport used during import. (May be creation, and updates).
        Returns:
        the memberInfoList
        Since:
        jcms-8
      • isAnyError

        public boolean isAnyError()
        Returns:
        the isAnyError
        Since:
        jcms-8
      • getCreateCount

        public int getCreateCount()
        Returns:
        the createCount
        Since:
        jcms-8
      • getUpdateCount

        public int getUpdateCount()
        Returns:
        the updateCount
        Since:
        jcms-8
      • getInvalidCount

        public int getInvalidCount()
        Returns:
        the invalidCount
        Since:
        jcms-8
      • getSeparator

        public java.lang.String getSeparator()
        Returns:
        the separator
        Since:
        jcms-8
      • isBlockingError

        public boolean isBlockingError()
        Returns:
        the isBlockingError
        Since:
        jcms-8
      • setRequest

        public void setRequest​(javax.servlet.http.HttpServletRequest request)
        Parameters:
        request - the request to set
        Since:
        jcms-8
      • setResponse

        public void setResponse​(javax.servlet.http.HttpServletResponse response)
        Parameters:
        response - the response to set
        Since:
        jcms-8
      • setSeparator

        public void setSeparator​(java.lang.String separator)
        Parameters:
        separator - the separator to set
        Since:
        jcms-8
      • isEnabled

        public static boolean isEnabled()
        Returns:
        true if Member CSV import is enabled.
        Since:
        jcms-8
      • hasToSendEmail

        public boolean hasToSendEmail()
        Returns:
        the hasToSendEmail
        Since:
        jcms-8
      • setHasToSendEmail

        public void setHasToSendEmail​(boolean hasToSendEmail)
        Parameters:
        hasToSendEmail - the hasToSendEmail to set
        Since:
        jcms-8
      • setGroupIds

        public void setGroupIds​(java.util.Collection<java.lang.String> groupIds)
        Parameters:
        groupIds - the groupIds to set
        Since:
        jcms-8
      • isUseMemberClass

        public boolean isUseMemberClass()
        Returns:
        the useMemberClass
        Since:
        jcms-8.0.1
      • setUseMemberClass

        public void setUseMemberClass​(boolean useMemberClass)
        Set true to create Member in JStore. False, to create DBMembers.
        Only used for creation, not for updates.
        Parameters:
        useMemberClass - the useMemberClass to set
        Since:
        jcms-8.0.1
      • getUsage

        public int getUsage()
        Returns:
        the usage (Account or contact) for members to create.
        Since:
        jcms-8.0.1
      • setUsage

        public void setUsage​(int usage)
        Parameters:
        usage - the usage (Account or contact) for members to create to set.
        Since:
        jcms-8.0.1
      • isAccountImport

        public boolean isAccountImport()
        Returns:
        true is usage for creation is Account.
        Since:
        jcms-8.0.1
      • isContactImport

        public boolean isContactImport()
        Returns:
        true is usage for creation is Contact.
        Since:
        jcms-8.0.1
      • isGuest

        public boolean isGuest()
      • setGuest

        public void setGuest​(boolean guest)
      • prepareImport

        public void prepareImport()
                           throws java.io.IOException
        May be called for simulation (in this case isSimulation is true).
        May be called by performImport (in this case, isSimulation is false).

        If isSimulation is true, a warning message about memberLimitController may be added to jcmsContext. Else, this message should be managed by performImport().
        Throws:
        java.io.IOException - IOException which can be thrown by import process
        Since:
        jcms-8
      • performImport

        public boolean performImport()
        Iterate on memberImportList, and create or update each member.
        Returns:
        true if import was successfull.
        Since:
        jcms-8
      • performImport

        protected void performImport​(MemberImport mbrImport)
        Perform save of the Member object if possible.
        Checks limit controller if needed (when accounts are activated).
        Updates counters.
        Parameters:
        mbrImport - the mock Member to be imported.
        Since:
        jcms-8.0.1
      • validateCsvFile

        public ControllerStatus validateCsvFile()
                                         throws java.io.IOException
        Returns:
        true if CSV file has correct headers.
        Throws:
        java.io.IOException - IOException which can be thrown when validate is done
        Since:
        jcms-8
      • filterGroupsToProposedWorkspaces

        public java.lang.String[] filterGroupsToProposedWorkspaces​(java.lang.String[] chosenGroupIds,
                                                                   java.util.Set<Workspace> wsSet)
        Utility method to control that all chosen groups belongs to given workspace Set.
        Parameters:
        chosenGroupIds - the Group ids to validate.
        wsSet - the workspace Set of the loggedMember.
        Returns:
        the controlled group list.
        Since:
        jcms-8
      • computeLogin

        protected void computeLogin​(MemberImport memberImport)

        Computes login from email : remove right part after '@'.

        Updates the given memberImport if needed.
        If a Member is found under given memberImport's email, does nothing.
        Else, while computed login exists, increment a suffix integer to find a free login.
        Parameters:
        memberImport - the mock Member to create to compute its login.
        Since:
        jcms-8.0.1
      • internalGetMemberFromLogin

        protected Member internalGetMemberFromLogin​(java.lang.String login)
        Searches Member from login from persisted Members, and in temporary login Map.
        This login map is used for performances purpose. (because we don't want to persist DBMember (=commitTransaction) after each iteration (but only once, at end of import)). Thus, freshly created DBMembers are not known yet by JCMS.
        Parameters:
        login - the login to retrieve the associated Member.
        Returns:
        a member found by given login, or null.
        Since:
        jcms-8.0.1
      • setImportAuthor

        public void setImportAuthor​(Member importAuthor)
        For use of loggedMember as opAuthor.
        Parameters:
        importAuthor - the importAuthor to set
        Since:
        10.0.7 JCMS-9383
      • getImportAuthor

        public Member getImportAuthor()
        Get the member to use as opAuthor.

        Returns the custom member that has been set (see setImportAuthor(Member).
        Else if null, the member bound to property $id.import-mgr.import-author.
        Else if null, site default admin.

        Returns:
        the importAuthor
        Since:
        10.0.7 JCMS-9383