Package com.jalios.jcms
Class MemberImportManager
- java.lang.Object
-
- com.jalios.jcms.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MemberImportManager.SendActivationMailAlarmListener
This class aims to manage activation email sending, after a batch of DB Member have been persisted.
-
Field Summary
Fields Modifier and Type Field Description protected int
activeMemberCountBase
Count of active Members at start of import.static java.lang.String
COMMENT_CHARACTER
A character to use at start of a line to comment.protected int
createActiveCount
Count of active members (may not yet be activated).protected int
createCount
The count of created Members.protected java.util.List<java.lang.String>
createdMembersIdList
The created members id list.protected java.io.File
csvFile
protected com.csvreader.CsvReader
csvReader
the reader that makes the parsing.protected int
dbOperationsCount
Used to count operations on DBData, to perform periodical commit / begin transaction.static boolean
DEFAULT_AS_GUESTS
static boolean
DEFAULT_DBMEMBER
The default use of DBMember class.static int
DEFAULT_DEFERR_EMAILS
The default duration of derring the sending of emails.static int
DEFAULT_USAGE
static java.lang.String
EMAIL_BATCH_DEFERR_SECONDS_PROP
Property key to indicate the time to wait before sending Email.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).protected long
endTime
For debug purpose.protected int
expectedColumnCount
Expected headers columns number.protected java.util.Collection<java.lang.String>
groupIds
protected boolean
hasToSendEmail
protected Member
importAuthor
protected java.lang.String
importPropertyKey
protected int
invalidCount
protected boolean
isAnyError
Is there any error during checking the csv file ?protected boolean
isBlockingError
True if an error should block the processing.protected boolean
isSimulation
protected JcmsContext
jcmsContext
static java.lang.String
LANG_PROPERTY_PREFIX
Property key prefix.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.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.protected java.util.Map<java.lang.String,MemberImport>
loginTempInfoMap
This map contains the logins encountered or computed during preparation.static java.lang.String
MAX_ERROR_PER_IMPORT_PROP
Property key to indicate the max number of errors to show per import.static java.lang.String
MAX_MEMBER_PER_IMPORT_PROP
Property key to indicate the max member per import.static java.lang.String
MEMBER_DC_SRC_COLUMNS_KEY
A DataController contextMap key, which stores the sources columns of the csv file, as a String[].protected java.util.List<MemberImport>
memberImportList
The list containing each line.protected long
previousTime
For debug purpose.protected javax.servlet.http.HttpServletRequest
request
protected javax.servlet.http.HttpServletResponse
response
static java.lang.String
REVISION
java.lang.String
separator
The separator to use, may be selected by UI.protected long
startTime
For debug purpose.protected int
updateCount
The count of updated Members.protected java.util.List<java.lang.String>
updatedMembersIdList
The update members id list.protected java.lang.String
userLang
static 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.-
Fields inherited from interface com.jalios.util.JaliosConstants
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
-
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, AJAX_MODE_ATTR, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, CLASS_PROPERTY, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, COUNTRY_SPRITE, CS_TYPOLOGY_ROOT_CAT_VID, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DEFAULT_PHOTO_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, GLYPH_ICON_PREFIX, ICON_ARCHIVE, ICON_ICON_PREFIX, ICON_LOCK, ICON_LOCK_STRONG, ICON_PREFIX_PROP, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, IS_IN_FRONT_OFFICE, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JCMS_TOASTR_COLLECTION, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LANG_SPRITE, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_CREATE_STR, OP_DEEP_COPY, OP_DEEP_COPY_STR, OP_DEEP_DELETE, OP_DEEP_DELETE_STR, OP_DELETE, OP_DELETE_STR, OP_MERGE, OP_MERGE_STR, OP_UPDATE, OP_UPDATE_STR, ORGANIZATION_ROOT_GROUP_PROP, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_PROP_PREFIX, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_PROP_PREFIX, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_PROP_PREFIX, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_PROP_PREFIX, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_PROP_PREFIX, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, RAW_CONTENT_ICON_PREFIX, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SECURITY_LOG_FILE, SESSION_AUTHORIZED_FILENAMES_SET, SPRITE_ICON_PREFIX, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, TTCARD_MEDIA_HEIGHT, TTCARD_MEDIA_WIDTH, TYPES_ICON_ALT_PROP, TYPES_ICON_SUFFIX_PROP, TYPES_ICON_TITLE_PROP, TYPES_PREFIX_PROP, TYPES_THUMB_SUFFIX_PROP, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, UPLOAD_PERMISSION_COUNT_PROP_PREFIX, UPLOAD_PERMISSION_SIZE_PROP_PREFIX, URL_REGEXP, VID_LOGGED_MEMBER, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
-
-
Constructor Summary
Constructors Constructor Description MemberImportManager(JcmsContext jcmsContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
computeLogin(MemberImport memberImport)
Computes login from email : remove right part after '@'.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.int
getCreateCount()
java.io.File
getCsvFile()
Member
getImportAuthor()
Get the member to use as opAuthor.int
getInvalidCount()
java.util.List<MemberImport>
getMemberInfoList()
Get the list of allMemberImport
used during import.java.lang.String
getSeparator()
int
getUpdateCount()
int
getUsage()
boolean
hasToSendEmail()
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.boolean
isAccountImport()
boolean
isAnyError()
boolean
isBlockingError()
boolean
isContactImport()
static boolean
isEnabled()
boolean
isGuest()
boolean
isSimulation()
boolean
isUseMemberClass()
boolean
performImport()
Iterate onmemberImportList
, and create or update each member.protected void
performImport(MemberImport mbrImport)
Perform save of the Member object if possible.
Checks limit controller if needed (when accounts are activated).
Updates counters.void
prepareImport()
May be called for simulation (in this caseisSimulation
istrue
).
May be called by performImport (in this case,isSimulation
isfalse
).
IfisSimulation
istrue
, a warning message about memberLimitController may be added to jcmsContext.void
setCsvFile(java.io.File csvFile)
void
setGroupIds(java.util.Collection<java.lang.String> groupIds)
void
setGuest(boolean guest)
void
setHasToSendEmail(boolean hasToSendEmail)
void
setImportAuthor(Member importAuthor)
For use of loggedMember as opAuthor.void
setRequest(javax.servlet.http.HttpServletRequest request)
void
setResponse(javax.servlet.http.HttpServletResponse response)
void
setSeparator(java.lang.String separator)
void
setSimulation(boolean isSimulation)
void
setUsage(int usage)
void
setUseMemberClass(boolean useMemberClass)
Set true to create Member in JStore.ControllerStatus
validateCsvFile()
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
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.
-
jcmsContext
protected JcmsContext jcmsContext
-
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
- theJcmsContext
- 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 allMemberImport
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 caseisSimulation
istrue
).
May be called by performImport (in this case,isSimulation
isfalse
).
IfisSimulation
istrue
, a warning message about memberLimitController may be added to jcmsContext. Else, this message should be managed byperformImport()
.- Throws:
java.io.IOException
- IOException which can be thrown by import process- Since:
- jcms-8
-
performImport
public boolean performImport()
Iterate onmemberImportList
, 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 givenmemberImport
if needed.
If a Member is found under givenmemberImport
'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
-
-