//params[1] = PasswordService.encrypt(passWordInPlainText);
personMap = (Map) queryRunner.query(sql, rshMap);
// Person could not be found, but there are already persons present
if (personMap != null) {
throw new FinderException();
}
// Add admin user
personMap = new HashMap();
int uniqueKey = nz.co.transparent.client.db.SQL.getUniqueKey("person", "person_id");
personMap.put("person_id", new Integer(uniqueKey));
personMap.put("user_name" , userName);
personMap.put("comment" , "Added by system on " + new java.util.Date());
personMap.put("updater_person_id" , new Integer(uniqueKey));
GenericController genericController = GenericController.getInstance();
genericController.insertRecord("person", "person_id", personMap);
Map personRoleMap = new HashMap();
// Add admin
personRoleMap.put("person_role_id", null);
personRoleMap.put("person_id", personMap.get("person_id"));
personRoleMap.put("role_id",new Integer(1));
personRoleMap.put("updater_person_id",new Integer(0));
genericController.insertRecord("person_role", "person_role_id", personRoleMap);
// Add operator
personRoleMap.put("person_role_id", null);
personRoleMap.put("role_id",new Integer(2));
genericController.insertRecord("person_role", "person_role_id", personRoleMap);
// Grant all premission to person table
sql = "grant ALL on APP.person to " + userName + " with grant option";
int result = queryRunner.update(sql);
}
sql =
"select role_id from person_role where person_id = "
+ personMap.get("person_id");
List personRoleList =
(List) queryRunner.query(sql, rshList);
Iterator iterator = personRoleList.iterator();
Map personRoleMap = null;
Map roleMap = null;
Integer roleID = null;
ArrayList roleList = new ArrayList(personRoleList.size());
while (iterator.hasNext()) {
personRoleMap = (Map) iterator.next();
roleID = (Integer) personRoleMap.get("role_id");
sql =
"select role_code from role where role_id = "
+ roleID.intValue();
roleMap = (Map) queryRunner.query(sql, rshMap);
roleList.add(roleMap.get("role_code"));
}
personMap.put("role_list", roleList);
// Update login
sql =
"update login"
+ " set login_date=CURRENT_TIMESTAMP"
+ " where ("
+ " (person_id=?)"
+ " )";
Integer personID = (Integer) personMap.get("person_id");
int result = queryRunner.update(sql, personID);
if (result == 0) {
sql =
"insert into login"
+ " set user_name="
+ SQL.getUniqueKey("login", "user_name")
+ " ,person_id=?";
result = queryRunner.update(sql, personID);
}
return;
} catch (SQLException se) {
String message =
"LoginController: SQL Exception: " + se.getMessage();
log.warning(message);
if (message.indexOf("Cannot create PoolableConnectionFactory") > -1) {
throw new FinderException(se);
} else {
throw new ControllerException(message);
}
}
}