Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 Västra Götalandsregionen This library is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package se.vgregion.userupdate.ldap;
import  org.springframework.ldap.core.ContextMapper;
import  org.springframework.ldap.core.DirContextAdapter;
import  org.springframework.ldap.core.simple.ParameterizedContextMapper;
Created by IntelliJ IDEA. Created: 2011-11-28 11:05

Author(s):
David Rosell
public class UserMapper implements ParameterizedContextMapper<UserLdapAttributes> {
    @Override
    public UserLdapAttributes mapFromContext(Object context) {
        DirContextAdapter ctx = (DirContextAdapter) context;
        UserLdapAttributes attrs = new UserLdapAttributes();
        attrs.setDn(ctx.getDn());
        attrs.setUid(ctx.getStringAttribute("uid"));
        attrs.setCn(ctx.getStringAttribute("cn"));
        attrs.setSn(ctx.getStringAttribute("sn"));
        attrs.setGivenName(ctx.getStringAttribute("givenName"));
        attrs.setDisplayName(ctx.getStringAttribute("displayName"));
        attrs.setFullName(ctx.getStringAttribute("fullName"));
        attrs.setMail(ctx.getStringAttribute("mail"));
        attrs.setHsaTitle(ctx.getStringAttribute("hsaTitle"));
        attrs.setTitle(ctx.getStringAttribute("title"));
        attrs.setHsaPersonIdentityNumber(ctx.getStringAttribute("hsaPersonIdentityNumber"));
        attrs.setHsaPersonPrescriptionCode(ctx.getStringAttribute("hsaPersonPrescriptionCode"));
        attrs.setVgrAdminType(ctx.getStringAttribute("vgrAdminType"));
        attrs.setVgrLabeledURI(ctx.getStringAttributes("labeledURI"));
        attrs.setVgrStrukturPerson(ctx.getStringAttributes("vgrStrukturPerson"));
        attrs.setVgrStrukturPersonDN(ctx.getStringAttributes("vgrStrukturPersonDN"));
        attrs.setStrukturGrupp(ctx.getStringAttributes("StrukturGrupp"));
        String type = ctx.getDn().toString();
        if (type.contains("ou=personal")) {
            attrs.setType(..);
        } else if (type.contains("ou=externa")) {
            attrs.setType(..);
        } else if (type.contains("ou=medborgare")) {
            attrs.setType(..);
        } else if (type.contains("ou=politiker")) {
            attrs.setType(..);
        } else if (type.contains("ou=admin")) {
            attrs.setType(..);
        } else {
            attrs.setType(..);
        }
        return attrs;
    }
New to GrepCode? Check out our FAQ X