Index: lams_admin/build.xml
===================================================================
diff -u -rfc3cd3130621924cf6acd0ee229d2463d350fa96 -r0892350e28ca67031ad97e624f167dccd6272871
--- lams_admin/build.xml (.../build.xml) (revision fc3cd3130621924cf6acd0ee229d2463d350fa96)
+++ lams_admin/build.xml (.../build.xml) (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -183,6 +183,7 @@
+
Index: lams_admin/conf/language/ApplicationResources.properties
===================================================================
diff -u -r609c620db1e0d4695fdf7c6d218cf78efc5c0a93 -r0892350e28ca67031ad97e624f167dccd6272871
--- lams_admin/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 609c620db1e0d4695fdf7c6d218cf78efc5c0a93)
+++ lams_admin/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -27,11 +27,11 @@
errors.prefix=
errors.suffix=
error.system = Oops! An unexpected exception thrown by the system. Contact your System Administrator.
-error.org.invalid = Invalid Organisation Id.
+error.org.invalid = Invalid Organisation Id. {0}
error.orgtype.invalid = Invalid operation for this type of organisation.
error.name.required = Name is required.
error.login.required = Login is required.
-error.login.unique = Login is already taken.
+error.login.unique = Login is already taken. {0}
error.password.required = Password is required.
error.authorisation=You are not authorised to do this.
error.newpassword.mismatch=Your new password does not match.
@@ -46,12 +46,19 @@
error.email.required = Email address is required.
error.valid.email.required = Valid email address is required.
error.required = {0} is required.
-error.not.unique = {0} is not unique.
+error.not.unique = {0} is not unique.
+error.roles.invalid = One or more roles are invalid. {0}
+error.fail.add = Failed to add user.
+error.authmethod.invalid = Invalid authentication method. {0}
+error.flash.theme.invalid = Invalid flash theme. {0}
+error.html.theme.invalid = Invalid html theme. {0}
+error.locale.invalid = Invalid locale. {0}
#======================= Warning Messages ==========================#
msg.user.add.to.parent.group = User/s marked with a '*' will be automatically added to the parent group with the same roles.
msg.add.to.org = User will be added to {0}.
msg.results.none = No results matched your query.
+msg.users.added = {0} users were added successfully.
#======================= Organisation State =======================#
organisation.state.ACTIVE=Active
@@ -93,6 +100,10 @@
admin.user.disable = Disable User
admin.user.delete = Delete User
admin.user.actions = Actions
+admin.user.import = Import Users
+label.excel.spreadsheet = Excel Spreadsheet
+label.spreadsheet = spreadsheet
+label.download.template = Download the template
role.AUTHOR = Author
role.GROUP.ADMIN = Group Admin
role.GROUP.MANAGER = Group Manager
@@ -170,4 +181,4 @@
#==================== Configuration Screen ========================#
admin.config.key=Key
-admin.config.value=Value
+admin.config.value=Value
\ No newline at end of file
Index: lams_admin/conf/xdoclet/web-settings.xml
===================================================================
diff -u -r2af5a2df2a43cc97c39014d7b2c8476aced294b1 -r0892350e28ca67031ad97e624f167dccd6272871
--- lams_admin/conf/xdoclet/web-settings.xml (.../web-settings.xml) (revision 2af5a2df2a43cc97c39014d7b2c8476aced294b1)
+++ lams_admin/conf/xdoclet/web-settings.xml (.../web-settings.xml) (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -17,3 +17,7 @@
+
+ xls
+ excel/ms-excel
+
\ No newline at end of file
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/util/ExcelUserImportFileParser.java
===================================================================
diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r0892350e28ca67031ad97e624f167dccd6272871
--- lams_admin/src/java/org/lamsfoundation/lams/admin/util/ExcelUserImportFileParser.java (.../ExcelUserImportFileParser.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/util/ExcelUserImportFileParser.java (.../ExcelUserImportFileParser.java) (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -23,31 +23,35 @@
/* $$Id$$ */
package org.lamsfoundation.lams.admin.util;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.HashSet;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.io.IOException;
-
import org.apache.commons.fileupload.FileItem;
+import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
-import org.lamsfoundation.lams.usermanagement.Role;
-import org.lamsfoundation.lams.usermanagement.User;
-import org.lamsfoundation.lams.usermanagement.UserOrganisation;
-import org.lamsfoundation.lams.usermanagement.UserOrganisationRole;
+import org.apache.struts.upload.FormFile;
+import org.lamsfoundation.lams.themes.CSSThemeVisualElement;
import org.lamsfoundation.lams.usermanagement.AuthenticationMethod;
import org.lamsfoundation.lams.usermanagement.Organisation;
+import org.lamsfoundation.lams.usermanagement.Role;
+import org.lamsfoundation.lams.usermanagement.SupportedLocale;
+import org.lamsfoundation.lams.usermanagement.User;
import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
+import org.lamsfoundation.lams.util.Configuration;
+import org.lamsfoundation.lams.util.ConfigurationKeys;
+import org.lamsfoundation.lams.util.HashUtil;
+import org.lamsfoundation.lams.util.MessageService;
/**
* TODO Add description here
+ * TODO add existing users to an org?
+ * TODO write audit log
*
*
* View Source
@@ -56,284 +60,338 @@
* @author Fei Yang
*/
public class ExcelUserImportFileParser implements IUserImportFileParser{
+
+ private static Logger log = Logger.getLogger(ExcelUserImportFileParser.class);
+ private static IUserManagementService service;
+ private static MessageService messageService;
- public String parseUsersInOrganisation(FileItem fileItem, Organisation org, String adminLogin, boolean existingUsersOnly) throws IOException {
- return null;
- }
-
-/*
- * start of definition of property keys used in the excel file
-
+ // spreadsheet column indexes
private static final short LOGIN = 0;
private static final short PASSWORD = 1;
- private static final short AUTH_METHOD = 2;
- private static final short ROLE = 3;
- private static final short STATUS = 4;
- private static final short TITLE = 5;
- private static final short FIRST_NAME = 6;
- private static final short LAST_NAME = 7;
+ private static final short TITLE = 2;
+ private static final short FIRST_NAME = 3;
+ private static final short LAST_NAME = 4;
+ private static final short ORGANISATION = 5;
+ private static final short ROLES = 6;
+ private static final short AUTH_METHOD = 7;
private static final short EMAIL = 8;
- private static final short ADDRESS1 = 9;
- private static final short ADDRESS2 = 10;
- private static final short ADDRESS3 = 11;
- private static final short CITY = 12;
- private static final short STATE = 13;
- private static final short COUNTRY = 14;
- private static final short DAY_PHONE = 15;
- private static final short EVE_PHONE = 16;
- private static final short MOB_PHONE = 17;
- private static final short FAX = 18;
+ private static final short FLASH_THEME = 9;
+ private static final short HTML_THEME = 10;
+ private static final short LOCALE = 11;
+ private static final short ADDRESS1 = 12;
+ private static final short ADDRESS2 = 13;
+ private static final short ADDRESS3 = 14;
+ private static final short CITY = 15;
+ private static final short STATE = 16;
+ private static final short POSTCODE = 17;
+ private static final short COUNTRY = 18;
+ private static final short DAY_PHONE = 19;
+ private static final short EVE_PHONE = 20;
+ private static final short MOB_PHONE = 21;
+ private static final short FAX = 22;
-
- private static String[] errMsgArray =
- new String[]{LOGIN_REQUIRED,PASSWORD_REQUIRED,AUTH_METHOD_REQUIRED,ROLE_REQUIRED};
- //end of definition
-
+ ArrayList results = new ArrayList();
+ ArrayList rowResult = new ArrayList();
private boolean emptyRow;
private boolean hasError;
- private String errMsgForRow;
- private IUserManagementService service;
- public ExcelUserImportFileParser(IUserManagementService service){
+ public ExcelUserImportFileParser(IUserManagementService service, MessageService messageService){
this.service = service;
+ this.messageService = messageService;
}
- *//**
+ /**
* @see org.lamsfoundation.lams.admin.util.IUserImportFileParser#parseUsersInOrganisation(FileItem fileItem, Organisation org, String adminLogin, boolean existingUsersOnly)
- *//*
- public String parseUsersInOrganisation(FileItem fileItem, Organisation org, String adminLogin, boolean existingUsersOnly) throws IOException{
- String errorMessage = "";
+ */
+ public List parseSpreadsheet(FormFile fileItem) throws IOException{
POIFSFileSystem fs = new POIFSFileSystem(fileItem.getInputStream());
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
- int count = 0;
- Double dbl;
- Long l;
- HSSFCell cell = null;
- for (int i = startRow + 1; i < endRow + 1; i++)
- {
+
+ log.debug("sheet rows: "+startRow+".."+endRow);
+
+ HSSFRow row;
+ User user = null;
+ Organisation org;
+ List roles;
+ for (int i = startRow + 1; i < endRow + 1; i++) {
+ log.debug("starting row: "+i);
emptyRow = true;
hasError = false;
- errMsgForRow = "";
- HSSFRow row = sheet.getRow(i);
- User user = new User();
- Set roles = null;
-
- user.setLogin(parseStringCell(row.getCell(LOGIN),i,LOGIN));
- if(existingUsersOnly){//if existingUsersOnly, ignore all the other columns
- user = service.getUserByLogin(user.getLogin());
- if(user==null)
- {
- errMsgForRow = errMsgForRow + ROW + i + SKIP + parseStringCell(row.getCell(LOGIN),i,LOGIN) + USER_NOT_EXIST ;
- hasError = true;
- }
- else{//check if the admin is authorised
- List userOrgs = service.getUserOrganisationsForUser(user);
- Iterator iter = userOrgs.iterator();
- boolean userOrgExisted = false;
- boolean authorised = false;
- while(iter.hasNext()){
- UserOrganisation userOrg = (UserOrganisation)iter.next();
- if(userOrg.getOrganisation().getOrganisationId().equals(org.getOrganisationId())){
- userOrgExisted = true;
- break;
- }
- User admin = service.getUserByLogin(adminLogin);
- Iterator iter2 = service.getUserOrganisationsForUser(admin).iterator();
- while(iter2.hasNext()){
- UserOrganisation adminOrg = (UserOrganisation)iter2.next();
- if(adminOrg.getOrganisation().getOrganisationId().equals(userOrg.getOrganisation().getOrganisationId())){
- authorised = true;
- break;
- }
- }
- if(authorised)
- break;
- }
- if(!authorised)
- {
- errMsgForRow = errMsgForRow + ROW + i + SKIP + parseStringCell(row.getCell(LOGIN),i,LOGIN) + NO_AUTHORISATION;
- hasError = true;
- }
- if(userOrgExisted){
- errMsgForRow = errMsgForRow + ROW + i + SKIP + parseStringCell(row.getCell(LOGIN),i,LOGIN) + MEMBERSHIP_EXIST + org.getName();
- hasError = true;
- }
- roles = parseRoleCell(row.getCell(ROLE),i,ROLE);
- }
- }else{
- user.setPassword(parseStringCell(row.getCell(PASSWORD),i,PASSWORD));
- user.setAuthenticationMethod(parseAuthMethodCell(row.getCell(AUTH_METHOD),i,AUTH_METHOD));
- roles = parseRoleCell(row.getCell(ROLE),i,ROLE);
- user.setDisabledFlag(parseStatusCell(row.getCell(STATUS),i));
- user.setTitle(parseStringCell(row.getCell(TITLE),i,-1));
- user.setFirstName(parseStringCell(row.getCell(FIRST_NAME),i,-1));
- user.setLastName(parseStringCell(row.getCell(LAST_NAME),i,-1));
- user.setEmail(parseStringCell(row.getCell(EMAIL),i,-1));
- user.setAddressLine1(parseStringCell(row.getCell(ADDRESS1),i,-1));
- user.setAddressLine2(parseStringCell(row.getCell(ADDRESS2),i,-1));
- user.setAddressLine3(parseStringCell(row.getCell(ADDRESS3),i,-1));
- user.setCity(parseStringCell(row.getCell(CITY),i,-1));
- user.setState(parseStringCell(row.getCell(STATE),i,-1));
- user.setCountry(parseStringCell(row.getCell(COUNTRY),i,-1));
- user.setDayPhone(parseStringCell(row.getCell(DAY_PHONE),i,-1));
- user.setEveningPhone(parseStringCell(row.getCell(EVE_PHONE),i,-1));
- user.setMobilePhone(parseStringCell(row.getCell(MOB_PHONE),i,-1));
- user.setFax(parseStringCell(row.getCell(FAX),i,-1));
- }
-
- if (emptyRow)
- {
+ rowResult = new ArrayList();
+ org = null;
+ roles = null;
+ row = sheet.getRow(i);
+ user = parseUser(row, i);
+ String orgId = parseStringCell(row.getCell(ORGANISATION));
+ if (orgId!=null) org = (Organisation)service.findById(Organisation.class, new Integer(orgId));
+ roles = parseRolesCell(row.getCell(ROLES));
+
+ if (emptyRow) {
+ log.debug("emptyRow: "+emptyRow);
break;
}
- if (hasError)
- {
- errorMessage = errorMessage + errMsgForRow;
+ if (hasError) {
+ log.debug("hasError: "+hasError);
+ results.add(rowResult);
continue;
- }
- else
- {
- try
- {
- if(!existingUsersOnly){
- user.setCreateDate(new Date());
- service.createUser(user);
+ } else {
+ try {
+ user.setCreateDate(new Date());
+ if (org!=null || roles!=null) { // save user+roles if org or roles are set
+ log.debug("org: "+org+" roles: "+roles);
+ if (org!=null && roles!=null) {
+ service.save(user);
+ service.setRolesForUserOrganisation(user, org, roles);
+ //rowResult.add(org.getOrganisationId().toString()); // for stat summary in save action
+ log.debug("saved user: "+user.getUserId()+" with roles: "+roles);
+ } else {
+ String[] args = new String[1];
+ String error;
+ if (org!=null) {
+ args[0] = "("+parseStringCell(row.getCell(ROLES))+")";
+ error = messageService.getMessage("error.roles.invalid", args);
+ } else {
+ args[0] = "("+orgId+")";
+ error = messageService.getMessage("error.org.invalid", args);
+ }
+ rowResult.add(error);
+ }
+ } else {
+ service.save(user);
+ //rowResult.add(String.valueOf(0)); // for stat summary in save action
+ log.debug("saved user: "+user.getUserId());
}
- UserOrganisation userOrg = new UserOrganisation();
- userOrg.setUser(user);
- userOrg.setOrganisation(org);
- service.saveOrUpdateUserOrganisation(userOrg);
- Iterator iter = roles.iterator();
- while(iter.hasNext()){
- UserOrganisationRole userOrgRole = new UserOrganisationRole();
- userOrgRole.setUserOrganisation(userOrg);
- userOrgRole.setRole((Role)iter.next());
- service.saveOrUpdateUserOrganisationRole(userOrgRole);
- }
- count++;
+ } catch (Exception e) {
+ rowResult.add(messageService.getMessage("error.fail.add"));
}
- catch (Exception e)
- {
- errMsgForRow =
- errMsgForRow
- + ROW
- + i
- + FAIL_ADD
- + user.getLogin()
- + SKIP
- + e.getMessage();
- errorMessage = errorMessage + errMsgForRow;
- }
+ log.debug("rowResult size: "+rowResult.size());
+ results.add(rowResult);
}
}
- return (count + SUCCESS_ADD + errorMessage);
+ log.debug("found "+results.size()+" users in spreadsheet.");
+ return results;
}
- private String parseStringCell(HSSFCell cell, int row, int msgIndex){
- if ((msgIndex!=-1)&&(cell == null))
- {
- if (hasError)
- {
- errMsgForRow = errMsgForRow + errMsgArray[msgIndex];
- }
- else
- {
- errMsgForRow = errMsgForRow + ROW + row + SKIP + errMsgArray[msgIndex];
- hasError = true;
- }
+ /**
+ * gathers error messages for each cell as required, unless it's the login field in which case,
+ * flags whole row as empty.
+ */
+ private User parseUser(HSSFRow row, int rowIndex) {
+ User user = new User();
+ String[] args = new String[1];
+
+ String login = parseStringCell(row.getCell(LOGIN));
+ if (login==null || login=="") {
+ rowResult.add(messageService.getMessage("error.login.required"));
+ hasError = true;
return null;
+ } else if (service.getUserByLogin(login)!=null) {
+ args[0] = "("+login+")";
+ rowResult.add(messageService.getMessage("error.login.unique", args));
+ hasError = true;
+ return null;
}
- else if(cell!=null)
- {
- try{
+
+ user.setDisabledFlag(false);
+ user.setLogin(login);
+
+ String password = HashUtil.sha1(parseStringCell(row.getCell(PASSWORD)));
+ user.setPassword(password);
+
+ user.setTitle(parseStringCell(row.getCell(TITLE)));
+
+ String fname = parseStringCell(row.getCell(FIRST_NAME));
+ if (fname==null || fname=="") {
+ rowResult.add(messageService.getMessage("error.firstname.required"));
+ hasError = true;
+ }
+ user.setFirstName(fname);
+
+ String lname = parseStringCell(row.getCell(LAST_NAME));
+ if (lname==null || lname=="") {
+ rowResult.add(messageService.getMessage("error.lastname.required"));
+ hasError = true;
+ }
+ user.setLastName(lname);
+
+ String authMethodName = parseStringCell(row.getCell(AUTH_METHOD));
+ AuthenticationMethod authMethod = getAuthMethod(authMethodName);
+ if (authMethod==null) {
+ args[0] = "("+authMethodName+")";
+ rowResult.add(messageService.getMessage("error.authmethod.invalid", args));
+ hasError = true;
+ }
+ user.setAuthenticationMethod(authMethod);
+
+ user.setEmail(parseStringCell(row.getCell(EMAIL)));
+
+ String flashId = parseStringCell(row.getCell(FLASH_THEME));
+ CSSThemeVisualElement flashTheme = getFlashTheme(flashId);
+ if (flashTheme==null) {
+ args[0] = "("+flashId+")";
+ rowResult.add(messageService.getMessage("error.flash.theme.invalid", args));
+ hasError = true;
+ }
+ user.setFlashTheme(flashTheme);
+
+ String htmlId = parseStringCell(row.getCell(HTML_THEME));
+ CSSThemeVisualElement htmlTheme = getHtmlTheme(htmlId);
+ if (htmlTheme==null) {
+ args[0] = "("+htmlId+")";
+ rowResult.add(messageService.getMessage("error.html.theme.invalid", args));
+ hasError = true;
+ }
+ user.setHtmlTheme(htmlTheme);
+
+ String localeId = parseStringCell(row.getCell(LOCALE));
+ SupportedLocale locale = getLocale(localeId);
+ if (locale==null) {
+ args[0] = "("+localeId+")";
+ rowResult.add(messageService.getMessage("error.locale.invalid", args));
+ hasError = true;
+ }
+ user.setLocale(locale);
+
+ user.setAddressLine1(parseStringCell(row.getCell(ADDRESS1)));
+ user.setAddressLine2(parseStringCell(row.getCell(ADDRESS2)));
+ user.setAddressLine3(parseStringCell(row.getCell(ADDRESS3)));
+ user.setCity(parseStringCell(row.getCell(CITY)));
+ user.setState(parseStringCell(row.getCell(STATE)));
+ user.setPostcode(parseStringCell(row.getCell(POSTCODE)));
+ user.setCountry(parseStringCell(row.getCell(COUNTRY)));
+ user.setDayPhone(parseStringCell(row.getCell(DAY_PHONE)));
+ user.setEveningPhone(parseStringCell(row.getCell(EVE_PHONE)));
+ user.setMobilePhone(parseStringCell(row.getCell(MOB_PHONE)));
+ user.setFax(parseStringCell(row.getCell(FAX)));
+ return (hasError ? null : user);
+ }
+
+ /*
+ * the methods below return legible data from individual cells
+ * only specify msgIndex if you want to retrieve an error message, otherwise, use -1
+ */
+ private String parseStringCell(HSSFCell cell){
+ if (cell!=null) {
+ try {
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
- if(cell.getStringCellValue()!= null){
- if(cell.getStringCellValue().trim().length()!= 0){
+ if (cell.getStringCellValue()!= null) {
+ if (cell.getStringCellValue().trim().length()!= 0) {
emptyRow = false;
}
- }else{
+ } else {
return null;
}
+ log.debug("string cell value: "+cell.getStringCellValue().trim());
return cell.getStringCellValue().trim();
- }catch(Exception e)
- {
+ } catch(Exception e) {
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
double d = cell.getNumericCellValue();
emptyRow = false;
+ log.debug("numeric cell value: "+d);
return (new Long(new Double(d).longValue()).toString());
}
}
return null;
}
- private AuthenticationMethod parseAuthMethodCell(HSSFCell cell, int row, int msgIndex){
- String authMethodName = parseStringCell(cell,row,msgIndex);
- if(authMethodName==null){
- return null;
- }else{
- return service.getAuthenticationMethodByName(authMethodName);
+ private AuthenticationMethod getAuthMethod(String authMethodName){
+ List list;
+ if (authMethodName==null || authMethodName=="") {
+ return (AuthenticationMethod)service.findById(AuthenticationMethod.class, AuthenticationMethod.DB);
+ } else {
+ list = service.findByProperty(AuthenticationMethod.class, "authenticationMethodName", authMethodName);
+ return (list==null || list.isEmpty() ? null : (AuthenticationMethod)list.get(0));
}
}
- private Set parseRoleCell(HSSFCell cell, int row, int msgIndex)
+ private List parseRolesCell(HSSFCell cell)
{
String roleDescription = "";
- if ((msgIndex!=-1)&&(cell == null))
- {
- if (hasError)
- {
- errMsgForRow = errMsgForRow + errMsgArray[msgIndex];
- }
- else
- {
- errMsgForRow = errMsgForRow + ROW + row + SKIP + errMsgArray[msgIndex];
- hasError = true;
- }
- return null;
- }
- else if(cell!=null)
- {
- try{
+ if (cell!=null) {
+ try {
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
- if(cell.getStringCellValue()!= null){
- if(cell.getStringCellValue().trim().length()!= 0){
- emptyRow = false;
- }
- }else{
+ if (cell.getStringCellValue()!= null || cell.getStringCellValue().trim().length()!= 0) {
+ emptyRow = false;
+ } else {
+ log.debug("role cell is null");
return null;
}
roleDescription = cell.getStringCellValue().trim();
- }catch(Exception e)
- {
+ } catch(Exception e) {
+ log.debug("role cell exception");
return null;
}
-
+ List roles = new ArrayList();
+ int fromIndex = 0;
+ int index = roleDescription.indexOf(SEPARATOR, fromIndex);
+ while (index != -1) {
+ log.debug("using role name: "+roleDescription.substring(fromIndex, index));
+ List list = service.findByProperty(Role.class, "name", roleDescription.substring(fromIndex, index));
+ Role role = (list==null ? null : (Role)list.get(0));
+ if (role!=null) { //ignore wrong spelled role
+ roles.add(role.getRoleId().toString());
+ log.debug("role: "+role.getName());
+ }
+ fromIndex = index + 1;
+ index = roleDescription.indexOf(SEPARATOR, fromIndex);
+ }
+ log.debug("using rolee name: "+roleDescription.substring(fromIndex, roleDescription.length()));
+ List list = service.findByProperty(Role.class, "name", roleDescription.substring(fromIndex, roleDescription.length()));
+ Role role = (list==null ? null : (Role)list.get(0));
+ if (role!=null) {
+ roles.add(role.getRoleId().toString());
+ log.debug("rolee: "+role.getName());
+ }
+ return roles;
}
- Set roles = new HashSet();
- int fromIndex = 0;
- int index = roleDescription.indexOf(SEPERATOR, fromIndex);
- while (index != -1)
- {
- Role role = service.getRoleByName(roleDescription.substring(fromIndex, index));
- if(role!=null)//ignore wrong spelled role
- {
- roles.add(role);
+ return null;
+ }
+
+ // set CSSThemeVisualElement to default flash theme if cell is empty
+ private CSSThemeVisualElement getFlashTheme(String flashId){
+ if (flashId==null || flashId=="") {
+ String flashName = Configuration.get(ConfigurationKeys.DEFAULT_FLASH_THEME);
+ List list = service.findByProperty(CSSThemeVisualElement.class, "name", flashName);
+ return (list != null && list.size() > 0) ? (CSSThemeVisualElement) list.get(0) : null;
+ } else {
+ try {
+ return (CSSThemeVisualElement)service.findById(CSSThemeVisualElement.class, new Long(flashId));
+ } catch (Exception e) {
+ return null;
}
- fromIndex = index + 1;
- index = roleDescription.indexOf(SEPERATOR, fromIndex);
}
- Role role = service.getRoleByName(roleDescription.substring(fromIndex, roleDescription.length()));
- if(role!=null){
- roles.add(role);
+ }
+
+ // set CSSThemeVisualElement to default html theme if cell is empty
+ private CSSThemeVisualElement getHtmlTheme(String htmlId){
+ if (htmlId==null || htmlId=="") {
+ String htmlName = Configuration.get(ConfigurationKeys.DEFAULT_HTML_THEME);
+ List list = service.findByProperty(CSSThemeVisualElement.class, "name", htmlName);
+ return (list != null && list.size() > 0) ? (CSSThemeVisualElement) list.get(0) : null;
+ } else {
+ try {
+ return (CSSThemeVisualElement)service.findById(CSSThemeVisualElement.class, new Long(htmlId));
+ } catch (Exception e) {
+ return null;
+ }
}
- return roles;
}
-
- private Boolean parseStatusCell(HSSFCell cell, int row)
- {
- String status = parseStringCell(cell,row,-1);
- return new Boolean(STATUS_DISABLED.equals(status));
+
+ // set locale to default system locale if cell is empty
+ private SupportedLocale getLocale(String localeId){
+ if (localeId==null || localeId=="") {
+ String defaultLocale = Configuration.get(ConfigurationKeys.SERVER_LANGUAGE);
+ return service.getSupportedLocale(defaultLocale.substring(0, 2), defaultLocale.substring(3));
+ } else {
+ try {
+ return (SupportedLocale)service.findById(SupportedLocale.class, new Byte(localeId));
+ } catch (Exception e) {
+ return null;
+ }
+ }
}
-*/}
+
+}
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/util/IUserImportFileParser.java
===================================================================
diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r0892350e28ca67031ad97e624f167dccd6272871
--- lams_admin/src/java/org/lamsfoundation/lams/admin/util/IUserImportFileParser.java (.../IUserImportFileParser.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/util/IUserImportFileParser.java (.../IUserImportFileParser.java) (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -24,11 +24,10 @@
package org.lamsfoundation.lams.admin.util;
import java.io.IOException;
+import java.util.List;
-import org.apache.commons.fileupload.FileItem;
+import org.apache.struts.upload.FormFile;
-import org.lamsfoundation.lams.usermanagement.Organisation;
-
/**
* TODO Add description here
*
@@ -40,23 +39,8 @@
*/
public interface IUserImportFileParser {
- public static final String STATUS_DISABLED = "disabled";
- public static final String SEPERATOR = "|";
- public static final String NO_AUTHORISATION =
- "
You are not authorised to select the user!";
- public static final String ROW = "
Row ";
- public static final String FAIL_ADD = ": Failed to add ";
- public static final String SUCCESS_ADD =
- " user(s) have been added successfully!";
- public static final String SKIP = ": Skipped. Error was: ";
- public static final String USER_NOT_EXIST = " does not exist! ";
- public static final String MEMBERSHIP_EXIST = " is already a member of the current org: ";
-
- public static final String LOGIN_REQUIRED = "Login is required.";
- public static final String PASSWORD_REQUIRED = "Password is required.";
- public static final String AUTH_METHOD_REQUIRED = "Authentication method is required.";
- public static final String ROLE_REQUIRED = "Role is required.";
+ public static final String SEPARATOR = "|";
- public String parseUsersInOrganisation(FileItem fileItem, Organisation org, String adminLogin, boolean existingUsersOnly) throws IOException;
+ public List parseSpreadsheet(FormFile file) throws IOException;
}
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelAction.java
===================================================================
diff -u
--- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelAction.java (revision 0)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelAction.java (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -0,0 +1,61 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.admin.web;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.lamsfoundation.lams.util.WebUtil;
+
+/**
+ * @author jliew
+ *
+ * @struts:action path="/importexcel"
+ * name="ImportExcelForm"
+ * scope="request"
+ * validate="false"
+ *
+ * @struts:action-forward name="importexcel" path=".importexcel"
+ */
+public class ImportExcelAction extends Action {
+
+ public ActionForward execute(ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ Integer orgId = WebUtil.readIntParam(request,"orgId",true);
+ //if (orgId==null) orgId = (Integer)request.getAttribute("orgId");
+
+ ImportExcelForm importExcelForm = (ImportExcelForm)form;
+ importExcelForm.setOrgId(orgId);
+
+ return mapping.findForward("importexcel");
+ }
+
+}
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelForm.java
===================================================================
diff -u
--- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelForm.java (revision 0)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelForm.java (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -0,0 +1,55 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.admin.web;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.upload.FormFile;
+
+/**
+ * @author jliew
+ *
+ * @struts.form name="ImportExcelForm"
+ */
+public class ImportExcelForm extends ActionForm {
+
+ private Integer orgId;
+ private FormFile file;
+
+ public Integer getOrgId() {
+ return orgId;
+ }
+
+ public void setOrgId(Integer orgId) {
+ this.orgId = orgId;
+ }
+
+ public FormFile getFile() {
+ return file;
+ }
+
+ public void setFile(FormFile file) {
+ this.file = file;
+ }
+
+}
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelSaveAction.java
===================================================================
diff -u
--- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelSaveAction.java (revision 0)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelSaveAction.java (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -0,0 +1,90 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.admin.web;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.upload.FormFile;
+import org.lamsfoundation.lams.admin.service.AdminServiceProxy;
+import org.lamsfoundation.lams.admin.util.ExcelUserImportFileParser;
+import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
+import org.lamsfoundation.lams.util.MessageService;
+
+/**
+ * @author jliew
+ *
+ * @struts:action path="/importexcelsave"
+ * name="ImportExcelForm"
+ * input=".importexcel"
+ * scope="request"
+ * validate="false"
+ *
+ * @struts:action-forward name="importresult" path=".importresult"
+ * @struts:action-forward name="usersearch" path=".usersearchlist"
+ */
+public class ImportExcelSaveAction extends Action {
+
+ public ActionForward execute(ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ if (isCancelled(request)) {
+ //return mapping.getInputForward();
+ return mapping.findForward("usersearch");
+ }
+
+ ImportExcelForm importExcelForm = (ImportExcelForm)form;
+ FormFile file = importExcelForm.getFile();
+ //Integer orgId = importExcelForm.getOrgId();
+
+ IUserManagementService service = AdminServiceProxy.getService(getServlet().getServletContext());
+ MessageService messageService = AdminServiceProxy.getMessageService(getServlet().getServletContext());
+ //Organisation org = (Organisation)service.findById(Organisation.class, orgId);
+
+ ExcelUserImportFileParser parser = new ExcelUserImportFileParser(service, messageService);
+ List results = parser.parseSpreadsheet(file);
+
+ int successful = 0;
+ for(int i=0; i
+
+
+
+
+
+
+
+
+
+
Index: lams_admin/web/WEB-INF/web.xml
===================================================================
diff -u -rca73a51b45e6071a6a9edd5da8b0d61bf3a39929 -r0892350e28ca67031ad97e624f167dccd6272871
--- lams_admin/web/WEB-INF/web.xml (.../web.xml) (revision ca73a51b45e6071a6a9edd5da8b0d61bf3a39929)
+++ lams_admin/web/WEB-INF/web.xml (.../web.xml) (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -15,23 +15,23 @@
classpath:/org/lamsfoundation/lams/applicationContext.xml
classpath:/org/lamsfoundation/lams/toolApplicationContext.xml
+ classpath:/org/lamsfoundation/lams/integrationContext.xml
classpath:/org/lamsfoundation/lams/admin/adminApplicationContext.xml
+
+ xls
+ excel/ms-excel
+
+
SystemSessionFilter
org.lamsfoundation.lams.web.session.SystemSessionFilter
- LocaleFilter
-
- org.lamsfoundation.lams.web.filter.LocaleFilter
-
-
-
HibernateFilter
org.lamsfoundation.lams.util.CustomizedOpenSessionInViewFilter
@@ -43,7 +43,6 @@
true
-
LocaleFilter
Index: lams_admin/web/file/lams_users_template.xls
===================================================================
diff -u
Binary files differ
Index: lams_admin/web/import/importexcel.jsp
===================================================================
diff -u
--- lams_admin/web/import/importexcel.jsp (revision 0)
+++ lams_admin/web/import/importexcel.jsp (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -0,0 +1,30 @@
+<%@ page contentType="text/html; charset=utf-8" language="java" %>
+
+<%@ taglib uri="tags-html" prefix="html" %>
+<%@ taglib uri="tags-core" prefix="c" %>
+<%@ taglib uri="tags-bean" prefix="bean" %>
+<%@ taglib uri="tags-logic" prefix="logic" %>
+<%@ taglib uri="tags-fmt" prefix="fmt" %>
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ : |
+ |
+
+
+
+ |
+
+
+
+
\ No newline at end of file
Index: lams_admin/web/import/importresult.jsp
===================================================================
diff -u
--- lams_admin/web/import/importresult.jsp (revision 0)
+++ lams_admin/web/import/importresult.jsp (revision 0892350e28ca67031ad97e624f167dccd6272871)
@@ -0,0 +1,26 @@
+<%@ page contentType="text/html; charset=utf-8" language="java" %>
+
+<%@ taglib uri="tags-html" prefix="html" %>
+<%@ taglib uri="tags-core" prefix="c" %>
+<%@ taglib uri="tags-bean" prefix="bean" %>
+<%@ taglib uri="tags-logic" prefix="logic" %>
+<%@ taglib uri="tags-fmt" prefix="fmt" %>
+
+
+
+
+
+
+
+ Row :
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file