Index: lams_admin/conf/language/ApplicationResources.properties =================================================================== diff -u -r4d7c3f5641fd7081af1ed74a2d265242ad69551c -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4d7c3f5641fd7081af1ed74a2d265242ad69551c) +++ lams_admin/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -216,11 +216,12 @@ sysadmin.library.createtim =Create time sysadmin.function =Function admin.importv1.title = Import LAMS 1 Users -msg.importv1.1 = Download +msg.importv1.1 = Download the LAMS 1 export script. msg.importv1.2 = On the command line of your LAMS 1 database server, run the following command msg.importv1.3a = Submit msg.importv1.3b = using the form below. msg.importv1.4 = You will be presented with a list of organisations and session classes to import. +msg.importv1.5 = Note that the passwords of the imported users will be reset, since LAMS 2 does not accept md5 passwords. They will be reset to the user's login. label.importv1.integrated = Include integration users and organisations label.continue = Continue msg.importv1.found.users = Found {0} LAMS 1 users. Index: lams_admin/conf/language/ApplicationResources_en_AU.properties =================================================================== diff -u -r4d7c3f5641fd7081af1ed74a2d265242ad69551c -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/conf/language/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 4d7c3f5641fd7081af1ed74a2d265242ad69551c) +++ lams_admin/conf/language/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -216,11 +216,12 @@ sysadmin.library.createtim =Create time sysadmin.function =Function admin.importv1.title = Import LAMS 1 Users -msg.importv1.1 = Download +msg.importv1.1 = Download the LAMS 1 export script. msg.importv1.2 = On the command line of your LAMS 1 database server, run the following command msg.importv1.3a = Submit msg.importv1.3b = using the form below. msg.importv1.4 = You will be presented with a list of organisations and session classes to import. +msg.importv1.5 = Note that the passwords of the imported users will be reset, since LAMS 2 does not accept md5 passwords. They will be reset to the user's login. label.importv1.integrated = Include integration users and organisations label.continue = Continue msg.importv1.found.users = Found {0} LAMS 1 users. Index: lams_admin/src/java/org/lamsfoundation/lams/admin/adminApplicationContext.xml =================================================================== diff -u -r35da7c79459d1e4ecc8a599e72abef1f5f8a69bf -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/src/java/org/lamsfoundation/lams/admin/adminApplicationContext.xml (.../adminApplicationContext.xml) (revision 35da7c79459d1e4ecc8a599e72abef1f5f8a69bf) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/adminApplicationContext.xml (.../adminApplicationContext.xml) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -8,7 +8,7 @@ - + Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java =================================================================== diff -u -r35da7c79459d1e4ecc8a599e72abef1f5f8a69bf -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java (.../AdminServiceProxy.java) (revision 35da7c79459d1e4ecc8a599e72abef1f5f8a69bf) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java (.../AdminServiceProxy.java) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -43,7 +43,7 @@ private static MessageService messageService; private static IIntegrationService integrationService; private static IAuditService auditService; - private static ISpreadsheetService spreadsheetService; + private static IImportService importService; public static final IUserManagementService getService(ServletContext servletContext){ if (manageService == null) { @@ -79,11 +79,11 @@ return auditService; } - public static final ISpreadsheetService getSpreadsheetService(ServletContext servletContext){ - if(spreadsheetService==null){ + public static final IImportService getImportService(ServletContext servletContext){ + if(importService==null){ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); - spreadsheetService = (ISpreadsheetService)ctx.getBean("spreadsheetService"); + importService = (IImportService)ctx.getBean("importService"); } - return spreadsheetService; + return importService; } } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/IImportService.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/IImportService.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/IImportService.java (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -0,0 +1,93 @@ +/**************************************************************** + * 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.service; + +import java.io.IOException; +import java.util.List; + +import org.apache.struts.upload.FormFile; + +/** + *

+ * View Source + *

+ * + * @author Fei Yang + * @author Jun-Dir Liew + */ +public interface IImportService { + + public static final String SEPARATOR = "|"; + public static final String IMPORT_HELP_PAGE = "Import+Users"; + public static final String IMPORTV1_HELP_PAGE = "Import+LAMS+1+Users"; + + /** + * Returns true if spreadsheet contains user data. + * @param fileItem + * @return + * @throws IOException + */ + public boolean isUserSpreadsheet(FormFile fileItem) throws IOException; + + /** + * Returns true if spreadsheet contains userorgrole data. + * @param fileItem + * @return + * @throws IOException + */ + public boolean isRolesSpreadsheet(FormFile fileItem) throws IOException; + + /** + * Checks first row of spreadsheet and determines whether to parse as + * a user or orgrole spreadsheet. + * @param fileItem + * @throws IOException + */ + public List parseSpreadsheet(FormFile fileItem) throws IOException; + + /** + * Returns list of V1 users and orgs after parsing the output of a mysql dump. + * @param fileItem + * @return + * @throws IOException + */ + public List parseV1UsersFile(FormFile fileItem, boolean includeIntegrated) throws IOException; + + /** + * Returns message results from parsing list of users in spreadsheet. + * @param file + * @return + * @throws IOException + */ + public List parseUserSpreadsheet(FormFile file) throws IOException; + + /** + * Returns message results from parsing list of organisation memberships + * in spreadsheet. + * @param file + * @return + * @throws IOException + */ + public List parseRolesSpreadsheet(FormFile file) throws IOException; +} Fisheye: Tag f8ae5239ffcb6ac62937458e9750b3780528dc9f refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/service/ISpreadsheetService.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/ImportService.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/ImportService.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/ImportService.java (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -0,0 +1,699 @@ +/**************************************************************** + * 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.service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang.StringUtils; +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.apache.struts.upload.FormFile; +import org.lamsfoundation.lams.admin.AdminConstants; +import org.lamsfoundation.lams.admin.web.dto.V1OrgRightDTO; +import org.lamsfoundation.lams.admin.web.dto.V1OrganisationDTO; +import org.lamsfoundation.lams.admin.web.dto.V1UserDTO; +import org.lamsfoundation.lams.themes.CSSThemeVisualElement; +import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +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; +import org.lamsfoundation.lams.util.audit.IAuditService; + +/** + *

+ * View Source + *

+ * + * @author Fei Yang + * @author Jun-Dir Liew + */ +public class ImportService implements IImportService { + + private static Logger log = Logger.getLogger(ImportService.class); + public IUserManagementService service; + public MessageService messageService; + public IAuditService auditService; + + public IUserManagementService getService() { + return service; + } + + public void setService(IUserManagementService service) { + this.service = service; + } + + public MessageService getMessageService() { + return messageService; + } + + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } + + public IAuditService getAuditService() { + return auditService; + } + + public void setAuditService(IAuditService auditService) { + this.auditService = auditService; + } + + // spreadsheet column indexes for user spreadsheet + private static final short LOGIN = 0; + private static final short PASSWORD = 1; + private static final short TITLE = 2; + private static final short FIRST_NAME = 3; + private static final short LAST_NAME = 4; + private static final short AUTH_METHOD = 5; + private static final short EMAIL = 6; + private static final short FLASH_THEME = 7; + private static final short HTML_THEME = 8; + private static final short LOCALE = 9; + private static final short ADDRESS1 = 10; + private static final short ADDRESS2 = 11; + private static final short ADDRESS3 = 12; + private static final short CITY = 13; + private static final short STATE = 14; + private static final short POSTCODE = 15; + private static final short COUNTRY = 16; + private static final short DAY_PHONE = 17; + private static final short EVE_PHONE = 18; + private static final short MOB_PHONE = 19; + private static final short FAX = 20; + + // spreadsheet column indexes for userorgrole spreadsheet + private static final short ORGANISATION = 1; + private static final short ROLES = 2; + + ArrayList results = new ArrayList(); + ArrayList rowResult = new ArrayList(); + private boolean emptyRow; + private boolean hasError; + + private HSSFSheet getSheet(FormFile fileItem) throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(fileItem.getInputStream()); + HSSFWorkbook wb = new HSSFWorkbook(fs); + return wb.getSheetAt(0); + } + + public boolean isUserSpreadsheet(FormFile fileItem) throws IOException { + HSSFSheet sheet = getSheet(fileItem); + HSSFRow row = sheet.getRow(sheet.getFirstRowNum()); + String string = parseStringCell(row.getCell(PASSWORD)); + return (StringUtils.equals(string, "* password")) ? true : false; + } + + public boolean isRolesSpreadsheet(FormFile fileItem) throws IOException { + HSSFSheet sheet = getSheet(fileItem); + HSSFRow row = sheet.getRow(sheet.getFirstRowNum()); + String string = parseStringCell(row.getCell(ORGANISATION)); + return (StringUtils.equals(string, "* organisation")) ? true : false; + } + + public List parseSpreadsheet(FormFile fileItem) throws IOException { + if (isUserSpreadsheet(fileItem)) { + return parseUserSpreadsheet(fileItem); + } else if (isRolesSpreadsheet(fileItem)) { + return parseRolesSpreadsheet(fileItem); + } + return new ArrayList(); + } + + public List parseV1UsersFile(FormFile fileItem, boolean includeIntegrated) throws IOException { + ArrayList users = new ArrayList(); + ArrayList orgs = new ArrayList(); + ArrayList results = new ArrayList(); + ArrayList integPrefixes = new ArrayList(); + ArrayList integOrgid = new ArrayList(); + BufferedReader reader = new BufferedReader(new InputStreamReader(fileItem.getInputStream())); + + // get username prefixes, for integrations on the lams 1 server + String line = reader.readLine(); + while (!line.startsWith("login\tpassword")) { + if (!line.startsWith("prefix")) { + String[] lineArray = line.split("\t"); + if (lineArray.length > 0) { + integPrefixes.add(lineArray[0]); + } + if (lineArray.length > 1) { + integOrgid.add(lineArray[1]); + } + } + line = reader.readLine(); + } + + // get user details + // login, password, fname, lname, email + line = reader.readLine(); // skip line containing column headings + while (!line.startsWith("sid\tname")) { + String[] userDetails = line.split("\t"); + line = reader.readLine(); + if (!includeIntegrated && isIntegratedUser(integPrefixes, userDetails[0])) { + continue; + } + V1UserDTO userDTO = new V1UserDTO( + userDetails[0], userDetails[1], userDetails[2], userDetails[3]); + if (userDetails.length > 4 && !StringUtils.equals(userDetails[4], "NULL")) { + userDTO.setEmail(userDetails[4]); + } + users.add(userDTO); + } + + // get organisations + // sid, name, description, account_organisation + line = reader.readLine(); + while (!line.startsWith("login\tg")) { + String[] orgDetails = line.split("\t"); + line = reader.readLine(); + if (orgDetails.length != 4) { + log.debug("LAMS 1 text file has troublesome organisation: "); + for (int i=0; i currentRoles = new ArrayList(); + String currentLogin = ""; + while (!line.startsWith("login\tsid")) { + String[] userRole = line.split("\t"); + line = reader.readLine(); + if (!includeIntegrated && isIntegratedUser(integPrefixes, userRole[0])) { + continue; + } + if (!StringUtils.equals(userRole[0], currentLogin)) { + if (!currentRoles.isEmpty()) { + int index = users.indexOf(new V1UserDTO(currentLogin)); + V1UserDTO userDTO = users.get(index); + userDTO.setRoleIds(new ArrayList(currentRoles)); + users.set(index, userDTO); + } + currentLogin = userRole[0]; + currentRoles.clear(); + } + currentRoles.add(userRole[1]); + } + int index = users.indexOf(new V1UserDTO(currentLogin)); + V1UserDTO userDTO = users.get(index); + userDTO.setRoleIds(new ArrayList(currentRoles)); + users.set(index, userDTO); + + // get user rights + // login, org id, right id + line = reader.readLine(); + while (line!=null) { + String[] userRight = line.split("\t"); + line = reader.readLine(); + if (!includeIntegrated && isIntegratedUser(integPrefixes, userRight[0])) { + continue; + } + V1OrgRightDTO orgRightDTO = new V1OrgRightDTO(userRight[1], userRight[2]); + index = users.indexOf(new V1UserDTO(userRight[0])); + userDTO = users.get(index); + List orgRights = userDTO.getOrgRights(); + if (orgRights==null) { + orgRights = new ArrayList(); + } + orgRights.add(orgRightDTO); + userDTO.setOrgRights(orgRights); + users.set(index, userDTO); + } + + results.add(users); + results.add(orgs); + + return results; + } + + private boolean isIntegratedUser(List integPrefixes, String login) { + int underscore = login.indexOf('_'); + if (underscore >= 0) { + if (integPrefixes.contains(login.substring(0, underscore))) { + return true; + } + } + return false; + } + + public List parseUserSpreadsheet(FormFile fileItem) throws IOException { + results = new ArrayList(); + HSSFSheet sheet = getSheet(fileItem); + int startRow = sheet.getFirstRowNum(); + int endRow = sheet.getLastRowNum(); + + log.debug("sheet rows: "+startRow+".."+endRow); + + HSSFRow row; + User user = null; + for (int i = startRow + 1; i < endRow + 1; i++) { + log.debug("starting row: "+i); + emptyRow = true; + hasError = false; + rowResult = new ArrayList(); + row = sheet.getRow(i); + user = parseUser(row, i); + + if (emptyRow) { + log.debug("emptyRow: "+emptyRow); + break; + } + if (hasError) { + log.debug("hasError: "+hasError); + results.add(rowResult); + continue; + } else { + try { + service.save(user); + writeAuditLog(user); + log.debug("saved user: "+user.getUserId()); + } catch (Exception e) { + log.debug(e); + rowResult.add(messageService.getMessage("error.fail.add")); + } + log.debug("rowResult size: "+rowResult.size()); + results.add(rowResult); + } + } + log.debug("found "+results.size()+" users in spreadsheet."); + return results; + } + + public List parseRolesSpreadsheet(FormFile fileItem) throws IOException { + results = new ArrayList(); + HSSFSheet sheet = getSheet(fileItem); + int startRow = sheet.getFirstRowNum(); + int endRow = sheet.getLastRowNum(); + + log.debug("sheet rows: "+startRow+".."+endRow); + + HSSFRow row; + List roles; + for (int i = startRow + 1; i < endRow + 1; i++) { + log.debug("starting row: "+i); + emptyRow = true; + hasError = false; + rowResult = new ArrayList(); + row = sheet.getRow(i); + + String login = parseStringCell(row.getCell(LOGIN)); + String orgId = parseStringCell(row.getCell(ORGANISATION)); + roles = parseRolesCell(row.getCell(ROLES)); + + if (emptyRow) { + log.debug("emptyRow: "+emptyRow); + break; + } + if (hasError) { + log.debug("hasError: "+hasError); + results.add(rowResult); + continue; + } else { + try { + saveUserRoles(login, orgId, roles, row); + } catch (Exception e) { + log.debug(e); + rowResult.add(messageService.getMessage("error.fail.add")); + } + log.debug("rowResult size: "+rowResult.size()); + results.add(rowResult); + } + } + log.debug("found "+results.size()+" users in spreadsheet."); + return results; + } + + private void setError(String message, String arg) { + if (StringUtils.isBlank(arg)) { + rowResult.add(messageService.getMessage(message)); + } else { + String[] args = new String[1]; + args[0] = arg; + rowResult.add(messageService.getMessage(message, args)); + } + hasError = true; + } + + /* + * user must already exist + */ + private void saveUserRoles(String login, String orgId, List roles, HSSFRow row) { + User user = null; + if (StringUtils.isNotBlank(login)) { + user = service.getUserByLogin(login); + } else if (StringUtils.isBlank(login)) { + setError("error.login.required", ""); + } + if (user==null) { + setError("user.does.not.exist", login); + } + + Organisation org = null; + if (StringUtils.isNotBlank(orgId)) { + org = (Organisation)service.findById(Organisation.class, new Integer(orgId)); + } + if (StringUtils.isBlank(orgId) || org==null){ + setError("error.org.invalid", "("+orgId+")"); + } else { + if (roles==null || !checkValidRoles(roles, service.isUserSysAdmin(), org.getOrganisationType())) { + setError("error.roles.invalid", "("+parseStringCell(row.getCell(ROLES))+")"); + } + } + + if (!hasError) { + service.setRolesForUserOrganisation(user, org, roles); + log.debug("added: "+login+" to: "+org.getName()+" with roles: "+roles); + } + } + + /* + * 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; + } + + 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; + } else { + user.setFirstName(fname); + } + + String lname = parseStringCell(row.getCell(LAST_NAME)); + if (lname==null || lname=="") { + rowResult.add(messageService.getMessage("error.lastname.required")); + hasError = true; + } else { + 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; + } else { + user.setAuthenticationMethod(authMethod); + } + + String email = parseStringCell(row.getCell(EMAIL)); + if (email==null || email=="") { + rowResult.add(messageService.getMessage("error.email.required")); + hasError = true; + } else { + Pattern p = Pattern.compile(".+@.+\\.[a-z]+"); + Matcher m = p.matcher(email); + if (!m.matches()) { + rowResult.add(messageService.getMessage("error.valid.email.required")); + hasError = true; + } + user.setEmail(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; + } else { + 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; + } else { + 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; + } else { + 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))); + user.setDisabledFlag(false); + user.setCreateDate(new Date()); + + return (hasError ? null : user); + } + + /* + * the methods below return legible data from individual cells + */ + 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) { + emptyRow = false; + } + } else { + return null; + } + //log.debug("string cell value: "+cell.getStringCellValue().trim()); + return cell.getStringCellValue().trim(); + } 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 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 List parseRolesCell(HSSFCell cell) + { + String roleDescription = ""; + if (cell!=null) { + try { + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + 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) { + 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)); + String role = addRoleId(roleDescription, fromIndex, index); + if (role==null) { + return null; + } else { + roles.add(role); + } + fromIndex = index + 1; + index = roleDescription.indexOf(SEPARATOR, fromIndex); + } + log.debug("using rolee name: "+roleDescription.substring(fromIndex, roleDescription.length())); + String role = addRoleId(roleDescription, fromIndex, roleDescription.length()); + if (role==null) { + return null; + } else { + roles.add(role); + } + return roles; + } + return null; + } + + // return id of role name in given role description + private String addRoleId(String roleDescription, int fromIndex, int index) { + List list = service.findByProperty(Role.class, "name", roleDescription.substring(fromIndex, index)); + Role role = (list==null || list.isEmpty() ? null : (Role)list.get(0)); + if (role!=null) { + log.debug("role: "+role.getName()); + return role.getRoleId().toString(); + } else { + return null; // if we can't translate the name to a role, return null + } + } + + // return false if a role shouldn't be assigned in given org type + private boolean checkValidRoles(List idList, boolean isSysadmin, OrganisationType orgType) { + // convert list of id's into list of Roles + List roleList = new ArrayList(); + for (String id : idList) { + Role role = (Role)service.findById(Role.class, Integer.parseInt(id)); + if (role!=null) { + roleList.add(role); + } else { + return false; + } + } + + // check they are valid + List validRoles = service.filterRoles(roleList, isSysadmin, orgType); + for (Role r : roleList) { + if (!validRoles.contains(r)) { + return false; + } + } + return true; + } + + // 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; + } + } + } + + // 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; + } + } + } + + // 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 Integer(localeId)); + } catch (Exception e) { + return null; + } + } + } + + private void writeAuditLog(User user) { + String[] args = new String[2]; + args[0] = user.getLogin()+"("+user.getUserId()+")"; + args[1] = user.getFullName(); + String message = messageService.getMessage("audit.user.create", args); + auditService.log(AdminConstants.MODULE_NAME, message); + } +} Fisheye: Tag f8ae5239ffcb6ac62937458e9750b3780528dc9f refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/service/SpreadsheetService.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelSaveAction.java =================================================================== diff -u -r35da7c79459d1e4ecc8a599e72abef1f5f8a69bf -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelSaveAction.java (.../ImportExcelSaveAction.java) (revision 35da7c79459d1e4ecc8a599e72abef1f5f8a69bf) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ImportExcelSaveAction.java (.../ImportExcelSaveAction.java) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -35,7 +35,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.admin.service.AdminServiceProxy; -import org.lamsfoundation.lams.admin.service.ISpreadsheetService; +import org.lamsfoundation.lams.admin.service.IImportService; import org.lamsfoundation.lams.util.MessageService; /** @@ -63,12 +63,12 @@ } MessageService messageService = AdminServiceProxy.getMessageService(getServlet().getServletContext()); - ISpreadsheetService spreadsheetService = AdminServiceProxy.getSpreadsheetService(getServlet().getServletContext()); + IImportService importService = AdminServiceProxy.getImportService(getServlet().getServletContext()); ImportExcelForm importExcelForm = (ImportExcelForm)form; FormFile file = importExcelForm.getFile(); - List results = spreadsheetService.parseSpreadsheet(file); - String successMessageKey = (spreadsheetService.isUserSpreadsheet(file) ? "msg.users.created" : "msg.users.added"); + List results = importService.parseSpreadsheet(file); + String successMessageKey = (importService.isUserSpreadsheet(file) ? "msg.users.created" : "msg.users.added"); int successful = 0; for(int i=0; i results = spreadsheetService.parseV1UsersFile(file, includeIntegrated); + List results = importService.parseV1UsersFile(file, includeIntegrated); List users = results.get(0); List orgs = results.get(1); Index: lams_admin/web/import/importexcel.jsp =================================================================== diff -u -r9f160f1d7a3047779dd5b80b39f10f84b71f3f75 -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/web/import/importexcel.jsp (.../importexcel.jsp) (revision 9f160f1d7a3047779dd5b80b39f10f84b71f3f75) +++ lams_admin/web/import/importexcel.jsp (.../importexcel.jsp) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -1,12 +1,12 @@ <%@ include file="/taglibs.jsp"%> -<%@ page import="org.lamsfoundation.lams.admin.service.ISpreadsheetService" %> +<%@ page import="org.lamsfoundation.lams.admin.service.IImportService" %>

:

- +

 

@@ -18,11 +18,11 @@
  • - +
  • - +
  • Index: lams_admin/web/import/importv1.jsp =================================================================== diff -u -r4d7c3f5641fd7081af1ed74a2d265242ad69551c -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/web/import/importv1.jsp (.../importv1.jsp) (revision 4d7c3f5641fd7081af1ed74a2d265242ad69551c) +++ lams_admin/web/import/importv1.jsp (.../importv1.jsp) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -1,24 +1,26 @@ <%@ include file="/taglibs.jsp"%> -<%@ page import="org.lamsfoundation.lams.admin.service.ISpreadsheetService" %> +<%@ page import="org.lamsfoundation.lams.admin.service.IImportService" %>

    :

    - +

     

    -

      -
    1. lams1_user_org_export.sql.
    2. +
        +
      • +
      • : -

        shell> mysql lamsone < lams1_user_org_export.sql -u root -p > lams1_users_orgs.txt

        +
        • shell> mysql lamsone < lams1_user_org_export.sql -u root -p > lams1_users_orgs.txt

      • lams1_users_orgs.txt   
      • -
    +
  • +

     

    Index: lams_admin/web/import/importv1contents.jsp =================================================================== diff -u -r4d7c3f5641fd7081af1ed74a2d265242ad69551c -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/web/import/importv1contents.jsp (.../importv1contents.jsp) (revision 4d7c3f5641fd7081af1ed74a2d265242ad69551c) +++ lams_admin/web/import/importv1contents.jsp (.../importv1contents.jsp) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -1,10 +1,13 @@ <%@ include file="/taglibs.jsp"%> +<%@ page import="org.lamsfoundation.lams.admin.service.IImportService" %>

    :

    + +

     

    @@ -72,7 +75,7 @@ - +

    Index: lams_admin/web/import/importv1result.jsp =================================================================== diff -u -r4d7c3f5641fd7081af1ed74a2d265242ad69551c -rf8ae5239ffcb6ac62937458e9750b3780528dc9f --- lams_admin/web/import/importv1result.jsp (.../importv1result.jsp) (revision 4d7c3f5641fd7081af1ed74a2d265242ad69551c) +++ lams_admin/web/import/importv1result.jsp (.../importv1result.jsp) (revision f8ae5239ffcb6ac62937458e9750b3780528dc9f) @@ -32,3 +32,10 @@ + +

     

    + +

    + +

    \ No newline at end of file