public MappingRule createV2()

in gdbwriter/src/main/java/com/alibaba/datax/plugin/writer/gdbwriter/mapping/MappingRuleFactory.java [102:219]


    public MappingRule createV2(final Configuration config, final ImportType type) {
        final MappingRule rule = new MappingRule();
        boolean patternChecked = false;

        ConfigHelper.assertHasContent(config, Key.LABEL);
        rule.setLabel(config.getString(Key.LABEL));
        rule.setImportType(type);
        patternChecked = isPattern(rule.getLabel(), rule, patternChecked);

        IdTransRule srcTransRule = IdTransRule.none;
        IdTransRule dstTransRule = IdTransRule.none;
        if (type == ImportType.EDGE) {
            ConfigHelper.assertHasContent(config, Key.SRC_ID_TRANS_RULE);
            ConfigHelper.assertHasContent(config, Key.DST_ID_TRANS_RULE);

            srcTransRule = IdTransRule.valueOf(config.getString(Key.SRC_ID_TRANS_RULE));
            dstTransRule = IdTransRule.valueOf(config.getString(Key.DST_ID_TRANS_RULE));

            if (srcTransRule == IdTransRule.labelPrefix) {
                ConfigHelper.assertHasContent(config, Key.SRC_LABEL);
            }

            if (dstTransRule == IdTransRule.labelPrefix) {
                ConfigHelper.assertHasContent(config, Key.DST_LABEL);
            }
        }
        ConfigHelper.assertHasContent(config, Key.ID_TRANS_RULE);
        final IdTransRule transRule = IdTransRule.valueOf(config.getString(Key.ID_TRANS_RULE));

        final List<Configuration> configurationList = config.getListConfiguration(Key.COLUMN);
        ConfigHelper.assertConfig(Key.COLUMN, () -> (configurationList != null && !configurationList.isEmpty()));
        for (final Configuration column : configurationList) {
            ConfigHelper.assertHasContent(column, Key.COLUMN_NAME);
            ConfigHelper.assertHasContent(column, Key.COLUMN_VALUE);
            ConfigHelper.assertHasContent(column, Key.COLUMN_TYPE);
            ConfigHelper.assertHasContent(column, Key.COLUMN_NODE_TYPE);

            final String columnValue = column.getString(Key.COLUMN_VALUE);
            final ColumnType columnType = ColumnType.valueOf(column.getString(Key.COLUMN_NODE_TYPE));
            if (columnValue == null || columnValue.isEmpty()) {
                // only allow edge empty id
                ConfigHelper.assertConfig("empty column value",
                    () -> (type == ImportType.EDGE && columnType == ColumnType.primaryKey));
            }
            patternChecked = isPattern(columnValue, rule, patternChecked);

            if (columnType == ColumnType.primaryKey) {
                final ValueType propType = ValueType.fromShortName(column.getString(Key.COLUMN_TYPE));
                ConfigHelper.assertConfig("only string is allowed in primary key",
                    () -> (propType == ValueType.STRING));

                if (transRule == IdTransRule.labelPrefix) {
                    rule.setId(config.getString(Key.LABEL) + columnValue);
                } else {
                    rule.setId(columnValue);
                }
            } else if (columnType == ColumnType.edgeJsonProperty || columnType == ColumnType.vertexJsonProperty) {
                // only support one json property in column
                ConfigHelper.assertConfig("multi JsonProperty", () -> (rule.getPropertiesJsonStr() == null));

                rule.setPropertiesJsonStr(columnValue);
            } else if (columnType == ColumnType.vertexProperty || columnType == ColumnType.edgeProperty
                || columnType == ColumnType.vertexSetProperty) {
                final PropertyMappingRule propertyMappingRule = new PropertyMappingRule();

                propertyMappingRule.setKey(column.getString(Key.COLUMN_NAME));
                propertyMappingRule.setValue(columnValue);
                final ValueType propType = ValueType.fromShortName(column.getString(Key.COLUMN_TYPE));
                ConfigHelper.assertConfig("unsupported property type", () -> propType != null);

                if (columnType == ColumnType.vertexSetProperty) {
                    propertyMappingRule.setPType(Key.PropertyType.set);
                }
                propertyMappingRule.setValueType(propType);
                rule.getProperties().add(propertyMappingRule);
            } else if (columnType == ColumnType.srcPrimaryKey) {
                if (type != ImportType.EDGE) {
                    continue;
                }

                final ValueType propType = ValueType.fromShortName(column.getString(Key.COLUMN_TYPE));
                ConfigHelper.assertConfig("only string is allowed in primary key",
                    () -> (propType == ValueType.STRING));

                if (srcTransRule == IdTransRule.labelPrefix) {
                    rule.setFrom(config.getString(Key.SRC_LABEL) + columnValue);
                } else {
                    rule.setFrom(columnValue);
                }
            } else if (columnType == ColumnType.dstPrimaryKey) {
                if (type != ImportType.EDGE) {
                    continue;
                }

                final ValueType propType = ValueType.fromShortName(column.getString(Key.COLUMN_TYPE));
                ConfigHelper.assertConfig("only string is allowed in primary key",
                    () -> (propType == ValueType.STRING));

                if (dstTransRule == IdTransRule.labelPrefix) {
                    rule.setTo(config.getString(Key.DST_LABEL) + columnValue);
                } else {
                    rule.setTo(columnValue);
                }
            }
        }

        if (rule.getImportType() == ImportType.EDGE) {
            if (rule.getId() == null) {
                rule.setId("");
                log.info("edge id is missed, uuid be default");
            }
            ConfigHelper.assertConfig("to needed in edge", () -> (rule.getTo() != null));
            ConfigHelper.assertConfig("from needed in edge", () -> (rule.getFrom() != null));
        }
        ConfigHelper.assertConfig("id needed", () -> (rule.getId() != null));

        return rule;
    }