0

im working on a little java-program that synchronizes active directory users with users in my db. therefor, i am using modelmapper. seems to be working fine and is also pretty fast.

anyway i added a converter to my mapping configuration. shows no markers, and i checked the syntax, so it should be fine. but when i fire the syncer to see if hes mapping everything correctly, nothing happens. i mean, the objects get mapped correctly but not the property i set the converter for.

i already went into debug-mode, the convert method is not even entered, not once

so heres my modelmapper-propertymapconfiguration

private PropertyMap<ActiveDirectoryUser, User> createUserMap = new PropertyMap<ActiveDirectoryUser, User>() {
    protected void configure() {
        map(source.getCn(), destination.getFullName());
        map(source.getsAMAccountName(), destination.getLoginName());
        map(source.getMail(), destination.getEmail());
        map(source.isEnabled(), destination.isActive());
        using(new ModelmapperMemberOfToIsAdminConverter(Arrays.asList(ConfigApp.get(ConfigKeys.AD_DISTINGUISHEDNAME_ADMINS).split(";")))
                ).map(source.getGroupMembership(), destination.isAdmin());
    };
};

and theres my converter:

package ch.itp.absencemanagersync.synchronize;

import java.util.ArrayList;
import java.util.List;

import org.modelmapper.AbstractConverter;

public class ModelmapperMemberOfToIsAdminConverter extends AbstractConverter<ArrayList<String>, Boolean>{

    private List<String> comparisonList;

    protected ModelmapperMemberOfToIsAdminConverter(List<String> blablablist){
        comparisonList = blablablist;
    }

    @Override
    protected Boolean convert(ArrayList<String> source) {
        //empty for now, will do some logic here later
        //for testing, always return true
        return true;
    }

}

so if i run the syncer, in theory, every user in my db should turn admin, but that doesnt happen i dont know what im doing wrong here, any help is appreciated^^

ps: dont worry about the Arrays.asList shit in the config, thats working just fine

greetings,

mike

4

1 回答 1

0

工作代码:

映射配置:

private PropertyMap<ActiveDirectoryUser, User> createUserMap = new PropertyMap<ActiveDirectoryUser, User>() {
    protected void configure() {
        using(myConverter).map(source.getGroupMembership()).setAdmin(false);
        map(source.getCn(), destination.getFullName());
        map(source.getsAMAccountName(), destination.getLoginName());
        map(source.getMail(), destination.getEmail());
        map(source.isEnabled(), destination.isActive());
    };
};

和转换器:

package ch.itp.absencemanagersync.synchronize;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.modelmapper.AbstractConverter;

import ch.itp.absencemanagersync.util.ConfigApp;
import ch.itp.absencemanagersync.util.ConfigKeys;

public class ModelmapperMemberOfToIsAdminConverter extends AbstractConverter<List<String>, Boolean>{

    private List<String> comparisonList = Arrays.asList(ConfigApp.get(ConfigKeys.AD_DISTINGUISHEDNAME_ADMINS).split(";"));

    protected ModelmapperMemberOfToIsAdminConverter(){  
    }
    @Override
    protected Boolean convert(List<String> source) {
        if (!Collections.disjoint(source, comparisonList)){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}

现在正在将所需用户映射为管理员,正常工作

于 2015-11-19T12:02:43.700 回答