Last active
April 6, 2016 02:23
-
-
Save anhnt/65d06b45ad3561885bc47d12a2304bad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void doProcess(Context context) { | |
Session session = SessionManager.session(); | |
rootOrg = Organisation.get(rootOrgId, session); | |
destFields = LeadManContactsImporterUtils.getDestFields(rootOrg); | |
lg = C(LeadManApp.class).getSalesGroup(session); | |
UserDao userDao = C(UserDao.class); | |
GroupManager groupMan = C(GroupManager.class); | |
TableManager tm = C(TableManager.class); | |
KademiSecurityManager ksm = C(KademiSecurityManager.class); | |
createdProfiles = new ArrayList<>(); | |
updatedProfiles = new ArrayList<>(); | |
RootFolder rf = C(CurrentRootFolderService.class).getRootFolder(rootOrg); | |
tm.processTable(hash, startRow, this, (List t) -> { | |
line++; | |
status = "Processing line " + line; | |
if (line % 100 == 0) { | |
session.flush(); | |
session.clear(); | |
rootOrg = Organisation.get(rootOrgId, session); | |
destFields = LeadManContactsImporterUtils.getDestFields(rootOrg); | |
lg = C(LeadManApp.class).getLeadsGroup(rootOrg, session); | |
} | |
String email = TableManager.valAsString(t, destFieldsMap, "email"); | |
if (StringUtils.isNotBlank(email)) { | |
email = email.toLowerCase(); | |
Profile p = userDao.findByUserNameOrEmail(rootOrg, email, session); | |
if (p == null) { | |
String firstName = TableManager.valAsString(t, destFieldsMap, "firstName"); | |
p = ksm.createProfile(rootOrg, email, firstName); | |
session.save(p); | |
createdProfiles.add(p); | |
} else { | |
updatedProfiles.add(p); | |
} | |
GroupMembership gm = groupMan.getOrCreateGroupMembership(p, lg, rootOrg, null, rf, session); | |
for (Map.Entry<String, Integer> mappedField : destFieldsMap.entrySet()) { | |
DestField df = getDestField(mappedField.getKey(), destFields); | |
df.apply(t, destFieldsMap, gm); | |
} | |
session.save(gm); | |
groupMan.updateProfile(p, session); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment