We can create SAP NetWeaver Portal users from various sources. One is through LDAP. Unfortunately, the details from LDAP are never comprehensive. Next, is through user inputs. Users register and provide details like country and language. This post shows how to update user country and language in SAP NetWeaver Portal using Java. This is useful when creating users from LDAP that do not provide country and language information.
SAP NetWeaver Portal Requirements
We used the following items for this post.
- Windows 7 Professional SP1
- SAP NetWeaver Developer Studio Version 7.0.09 for Java
- SAP NetWeaver Application Server
- sap.com/SAP-JEECOR – 7.00 SP26 (1000.7.00.26.1.20120307143343)
- sap.com/SAP-JEE – 7.00 SP26 (1000.7.00.26.0.20120109175405)
Java Codes To Update User country and language
Consider the following Java codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // Using email address as user id if(!externaluser) { try { IUserFactory userFactory = UMFactory.getUserFactory(); IUserSearchFilter userFilter = userFactory.getUserSearchFilter(); userFilter.setUniqueName(mail, ISearchAttribute.EQUALS_OPERATOR, false); ISearchResult userResult = userFactory.searchUsers(userFilter); while(userResult.hasNext()) { String rs=userResult.next().toString(); IUser user = UMFactory.getUserFactory().getUser(rs); IUserMaint User = UMFactory.getUserFactory().getMutableUser(user.getUniqueID()); User.setCountry(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getCountry()); if(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages().equalsIgnoreCase("Traditional Chinese")) { Locale TRADITIONAL_CHINESE = new Locale("zh", "TW", ""); User.setLocale(TRADITIONAL_CHINESE); } else if(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages().equalsIgnoreCase("Simplified Chinese")) { Locale SIMPLIFIED_CHINESE = new Locale("zh", "CN", ""); User.setLocale(SIMPLIFIED_CHINESE); } else if(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages().equalsIgnoreCase("Japanese")) { Locale JAPAN = new Locale("ja", "JP", ""); User.setLocale(JAPAN); } else if(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages().equalsIgnoreCase("English")) { Locale ENGLISH = new Locale("en", "", ""); User.setLocale(ENGLISH); } else if(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages().equalsIgnoreCase("Korean")) { Locale KOREAN= new Locale("ko", "SK", ""); User.setLocale(KOREAN); } else if(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages().equalsIgnoreCase("Spanish")) { Locale SPANISH= new Locale("es", "ES", ""); User.setLocale(SPANISH); } else { User.setLocale(new Locale(wdContext.nodeVn_UserDetailsBean().currentVn_UserDetailsBeanElement().getLanguages())); } User.commit(); break; } } catch(Exception e) { logger.debugT("Excepion: " + e.toString()); } |