ImportManager class

From Catglobe Wiki
Jump to: navigation, search

ImportManager



Import data and users.

Parent class

Inherits from object

Constructors

  • (array Headers "A list of string that are the header names", array data "Data to import. An array of arrays of equal length as the headers", bool advancedMode "Enable setting advanced settings - Requires special navigation access", int groupResourceId "Group to add users to new users to and/or sample rule. Set to 0 to not add to group") - Make a new import with the given data

Methods

  • array GetPossibleAutoMasForData() - Get default automaps. First value is column name, second is actual import field
  • array GetPossibleAutoMasForUser() - Get default automaps. First value is column name, second is actual import field
  • Dictionary Import() - Run the Import. Note that this will commit any pending changes
  • Dictionary SetDataImportOptions(int projectQuestionnaireResourceId "The resource Id of where the data should be added/updated", int type "How to treat when already have existing answer sheets. 1 for Zero or One AnswerSheet, 2 for delete existing and create new, 3 for mapping to rpqIdColumnName", string idColumnName "Mapping for column name in case type is 3 or 4", bool isCommaSeparatedFormat "Import multi questions as comma separated format", Dictionary mapping "Mapping between header names and import names. If empty, automapping is used") - Set specific options for importing data or altering existing data
  • Empty SetDefaultNewUser(string languageIso "Default language", string cultureIso "Default culture", string currency "Default currency") - Defaults for new users. If empty or not set, uses the global defaults
  • Empty SetUserImportOptions(string userIdColumnName "The header name of the userId column", string userNameMask "The mask used to create new usernames - an advanced setting", bool generatePasswords "OBSOLETE. Always false. Generate passwords during import", bool importUserInfo "Import or Update users", bool importPhoneNumber "Import or Update phonenumbers", bool importAddress "Import or Update addresses", bool importPoints "Import or Update points", bool importQualification "Import or Update qualifications", array permissions "Determine which groups should have access to the new users", Dictionary mapping "Mapping between header names and import names. If empty, automapping is used") - OBSOLETE. Use the new overload with parentResourceId.
  • Dictionary SetUserImportOptions(string userIdColumnName "The header name of the userId column", string userNameMask "The mask used to create new usernames - an advanced setting", bool generatePasswords "OBSOLETE. Always false. Generate passwords during import", bool importUserInfo "Import or Update users", bool importPhoneNumber "Import or Update phonenumbers", bool importAddress "Import or Update addresses", bool importPoints "Import or Update points", bool importQualification "Import or Update qualifications", int parentResourceId "Resource Id of the parent of the new users. Ignored if updating users", Dictionary mapping "Mapping between header names and import names. If empty, automapping is used") - Set specific options for importing new users or altering existing users
  • (From object) string ToString() - The string representation of the object.
  • string Validate() - Same as Validate(true)
  • string Validate(bool errorOnSemiOpenQuestion "Set to false if you need to import to questions with open parts and know that it may partially delete existing data") - Validate prior to actual importing. Throws if errors, otherwise returns warning.

Properties

  • string Culture { get; set; } - Get/set the culture used during import in case we don't want to use the logged-in-user's one (UseLoggedInUsersCultureDuringImport = false)
  • string Language { get; set; } - Get/set the language used when importing text
  • string ObjectTypeName { get; } - The name of the type of object.
  • (From object) TypeInformation TypeInformation { get; } - Get information about this class.
  • bool UseLoggedInUsersCultureDuringImport { get; set; } - Get/set if the culture used during import is the same as the logged in user or invariant culture. Default is invariant


Examples

// EX for making import qnaire data without user (acreate new qas with no user)
array Headers={"Q2","Q4","Q5","TextValue","NumberValue"};
array Data={{1,"q4",1,"Text1",1}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15546533;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();


//EX for import data to an existing answer sheet
array Headers={"RPQId","Q2","Q4","Q5","TextValue","NumberValue"};
array Data={{1742872963,1,"q4",1,"Text1",1}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15546533;
number type=3;
string rpqIdColumnName="RPQId";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();


//EX for import new user info and phone number
array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode"};
array Data={{"An","test","an@maysunshine.vn","da-DK","da-DK","12345678","dk"}};
Bool advancedMode=false;
number groupResourceId =15548117;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
string userIdColumnName="";
string userNameMask="";
bool generatePasswords=true; 
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary();
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
iM.Validate();
iM.Import();


//EX for importing new user and new qas
array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode","Q2","Q4","Q5","TextValue","NumberValue"};
array Data={{"An","test2111_01","an@maysunshine.vn","da-DK","da-DK","12345678","dk",1,"q4",1,"Text1",1}};
Bool advancedMode=false;
number groupResourceId =15548117; 
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); 
string userIdColumnName="";
string userNameMask="";
bool generatePasswords=true; 
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary(); 
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
number qnaireRId = 15546533;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
//Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping); 
iM.Validate();
iM.Import();


//Using SetDefaultNewUser
array Headers={"First name","Last name","User_Email"};
array Data={{"An","test2211","an@maysunshine.vn"}};
Bool advancedMode=false;
number groupResourceId =15548117; 
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); 
string userIdColumnName="";
string userNameMask="";
bool generatePasswords=true; 
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary(); 
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
string languageIso="da-DK";
string cultureIso="da-DK";
string currency="USD";
iM.SetDefaultNewUser(languageIso, cultureIso,currency ); 
iM.Validate();
iM.Import();


//Update an existing user
array Headers={"userId","Language","Culture","Currency"};
array Data={{"90414076","da-DK","da-DK","USD"}};
Bool advancedMode=false;
number groupResourceId =15548117;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); 
string userIdColumnName="userId";
string userNameMask="";
bool generatePasswords=true; 
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary();
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
iM.Validate();
iM.Import();


//update an existing qas by CustomerId (using SetDataImportOptions with type 4)
//CustomerID must be a text field, not numeric
array Headers={"CustomerID","Q1","Age"};
array Data={{"AB123",2,1}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15562388;
number type=4;
string idColumnName="CustomerID";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,idColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//Set culture while import. If not set will use "." format, example: "45.967"
//Set Culture work combine with UseLoggedInUsersCultureDuringImport=false
array Headers={"qNumber"};
array Data={{"45,967"}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15636598;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
//iM.UseLoggedInUsersCultureDuringImport=false;
iM.Culture = "da-DK";
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//set language while import. If don't set, will use login user language
array Headers={"RPQ_StartDato","RPQ_SlutDato","RPQ_Status", "Q1"};
array Data={{"2018-06-18 02:49:06","2018-06-18 02:51:44","Successfuldt interview", "1"}};
Bool advancedMode=true;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15636646;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.Language = "da-DK";
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();