All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.eamon.open.mapping.mapper.support.strategy.ExtraEnableStrategy Maven / Gradle / Ivy

There is a newer version: 1.0.5-ALPHA
Show newest version
package cc.eamon.open.mapping.mapper.support.strategy;

import cc.eamon.open.mapping.mapper.util.StringUtils;
import cc.eamon.open.mapping.mapper.structure.item.MapperField;
import cc.eamon.open.mapping.mapper.structure.strategy.MapperBaseStrategy;
import cc.eamon.open.mapping.mapper.structure.strategy.MapperStrategy;
import cc.eamon.open.mapping.mapper.support.MapperEnum;
import cc.eamon.open.mapping.mapper.support.detail.ExtraDetail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author: eamon
 * Email: [email protected]
 * Time: 2019-09-14 16:53:17
 */
public class ExtraEnableStrategy extends MapperBaseStrategy implements ExtraStrategy {

    private List details;

    public List getDetails() {
        return details;
    }

    public void setDetails(List details) {
        this.details = details;
    }

    @Override
    public boolean open() {
        return true;
    }

    @Override
    public List getMapperFields() {
        List fields = new ArrayList<>();
        details.forEach((detail) -> {
            MapperField field = new MapperField();
            field.setMapperName(detail.getMapper());
            field.setSimpleName(StringUtils.classNameFromQualifiedName(detail.getName()));
            field.setQualifiedTypeName(detail.getType());
            field.setList(detail.getList());

            Map strategies = new HashMap<>();
            field.setStrategies(strategies);
            MapperBaseStrategy ignoreStrategy = new IgnoreNormalStrategy();
            MapperBaseStrategy modifyStrategy = new ModifyNormalStrategy();
            MapperBaseStrategy renameStrategy = new RenameNormalStrategy();
            ignoreStrategy.setElementName(field.getSimpleName());
            modifyStrategy.setElementName(field.getSimpleName());
            renameStrategy.setElementName(field.getSimpleName());
            ignoreStrategy.setMapper(detail.getMapper());
            modifyStrategy.setMapper(detail.getMapper());
            renameStrategy.setMapper(detail.getMapper());
            ignoreStrategy.setQualifiedTypeName(field.getQualifiedTypeName());
            modifyStrategy.setQualifiedTypeName(field.getQualifiedTypeName());
            renameStrategy.setQualifiedTypeName(field.getQualifiedTypeName());
            strategies.put(MapperEnum.IGNORE.getName(), ignoreStrategy);
            strategies.put(MapperEnum.MODIFY.getName(), modifyStrategy);
            strategies.put(MapperEnum.RENAME.getName(), renameStrategy);
            fields.add(field);
        });
        return fields;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy