Search in sources :

Example 1 with DefaultContext

use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.

the class DataXOssReader method getSelectedTabs.

@Override
public List<ParseColsResult.DataXReaderTabMeta> getSelectedTabs() {
    DefaultContext context = new DefaultContext();
    ParseColsResult parseOSSColsResult = ParseColsResult.parseColsCfg(new MockFieldErrorHandler(), context, StringUtils.EMPTY, this.column);
    if (!parseOSSColsResult.success) {
        throw new IllegalStateException("parseOSSColsResult must be success");
    }
    return Collections.singletonList(parseOSSColsResult.tabMeta);
}
Also used : DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext)

Example 2 with DefaultContext

use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.

the class DataXHdfsReader method getSelectedTabs.

@Override
public List<ParseColsResult.DataXReaderTabMeta> getSelectedTabs() {
    DefaultContext context = new DefaultContext();
    ParseColsResult parseOSSColsResult = ParseColsResult.parseColsCfg(new MockFieldErrorHandler(), context, StringUtils.EMPTY, this.column);
    if (!parseOSSColsResult.success) {
        throw new IllegalStateException("parseOSSColsResult must be success");
    }
    return Collections.singletonList(parseOSSColsResult.tabMeta);
}
Also used : DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext)

Example 3 with DefaultContext

use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.

the class DataXFtpReader method getSelectedTabs.

@Override
public List<ParseColsResult.DataXReaderTabMeta> getSelectedTabs() {
    DefaultContext context = new DefaultContext();
    ParseColsResult parseColsResult = ParseColsResult.parseColsCfg(new DefaultFieldErrorHandler(), context, StringUtils.EMPTY, this.column);
    if (!parseColsResult.success) {
        throw new IllegalStateException("parseColsResult must be success");
    }
    return Collections.singletonList(parseColsResult.tabMeta);
}
Also used : DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) DefaultFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler)

Example 4 with DefaultContext

use of com.alibaba.citrus.turbine.impl.DefaultContext in project plugins by qlangtech.

the class TestRockMqPluginValidate method testDigital_Alpha_CharacterValidate.

public void testDigital_Alpha_CharacterValidate() throws Exception {
    final DefaultContext context = new DefaultContext();
    final Map<String, Object> fieldErrors = context.getContextMap();
    validatePluginPostForm("rockmq_plugin_from_invalid.json", context);
    List<List<DefaultFieldErrorHandler.FieldError>> /**
     * item
     */
    itemsErrorList = (List<List<DefaultFieldErrorHandler.FieldError>>) fieldErrors.get(IFieldErrorHandler.ACTION_ERROR_FIELDS);
    assertNotNull(itemsErrorList);
    assertEquals(1, itemsErrorList.size());
    List<DefaultFieldErrorHandler.FieldError> fieldErrors1 = itemsErrorList.get(0);
    assertEquals(2, fieldErrors1.size());
    Optional<DefaultFieldErrorHandler.FieldError> mqTopicErr = fieldErrors1.stream().filter((r) -> mqTopic.equals(r.getFieldName())).findFirst();
    assertTrue(mqTopicErr.isPresent());
    assertEquals(ValidatorCommons.MSG_IDENTITY_ERROR, mqTopicErr.get().getMsg());
    assertNull(mqTopicErr.get().itemsErrorList);
    assertEquals(mqTopic, mqTopicErr.get().getFieldName());
    Optional<DefaultFieldErrorHandler.FieldError> deserializeErr = fieldErrors1.stream().filter((r) -> deserialize.equals(r.getFieldName())).findFirst();
    assertTrue(deserializeErr.isPresent());
    DefaultFieldErrorHandler.FieldError dErr = deserializeErr.get();
    assertEquals(deserialize, dErr.getFieldName());
    assertNull(dErr.getMsg());
    assertNotNull(dErr.itemsErrorList);
    assertEquals(1, dErr.itemsErrorList.size());
    List<DefaultFieldErrorHandler.FieldError> /**
     * item
     */
    dValsItem = dErr.itemsErrorList.get(0);
    assertEquals(1, dValsItem.size());
    DefaultFieldErrorHandler.FieldError testName = dValsItem.get(0);
    assertEquals(testProp, testName.getFieldName());
    assertEquals("ddd", testName.getMsg());
    assertNull(testName.itemsErrorList);
}
Also used : DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) Descriptor(com.qlangtech.tis.extension.Descriptor) AttrValMap(com.qlangtech.tis.util.AttrValMap) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) JSONArray(com.alibaba.fastjson.JSONArray) IOUtils(org.apache.commons.io.IOUtils) ValidatorCommons(com.qlangtech.tis.plugin.ValidatorCommons) List(java.util.List) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) Map(java.util.Map) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) Optional(java.util.Optional) DefaultFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler) InputStream(java.io.InputStream) List(java.util.List) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) DefaultFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler)

Example 5 with DefaultContext

use of com.alibaba.citrus.turbine.impl.DefaultContext in project tis by qlangtech.

the class TestValidator method testValidateFieldByMultiRules.

public void testValidateFieldByMultiRules() {
    final String numbericValidateFaild = "必须是数字";
    // 
    // 
    Map<String, Validator.FieldValidators> validatorsRules = // 
    Validator.fieldsValidator(// 
    field1Name, new Validator.FieldValidators(Validator.require) {
    }, (Validator.IFieldValidator) ((msgHandler, context, fieldKey, fieldData) -> {
        if (!StringUtils.isNumeric(fieldData)) {
            msgHandler.addFieldError(context, field1Name, numbericValidateFaild);
            // 校验是否是数字
            return false;
        }
        return true;
    }));
    assertEquals("validatorsRules size", 1, validatorsRules.size());
    Validator.FieldValidators fieldValidators = validatorsRules.get(field1Name);
    assertNotNull(fieldValidators);
    assertEquals(2, fieldValidators.validators.size());
    Context context = new DefaultContext();
    IControlMsgHandler msgHandler = EasyMock.createMock("msgHandler", IControlMsgHandler.class);
    EasyMock.expect(msgHandler.getString(field1Name)).andReturn("123");
    msgHandler.errorsPageShow(context);
    EasyMock.expectLastCall().andVoid().times(2);
    EasyMock.expect(msgHandler.getString(field1Name)).andReturn("123aaa");
    msgHandler.addFieldError(context, field1Name, numbericValidateFaild);
    msgHandler.addErrorMessage(context, Validator.FORM_ERROR_SUMMARY);
    // EasyMock.expect().andReturn("123aaa");
    EasyMock.replay(msgHandler);
    assertTrue(Validator.validate(msgHandler, context, validatorsRules));
    // 第二次应该校验失败了
    assertFalse(Validator.validate(msgHandler, context, validatorsRules));
    EasyMock.verify(msgHandler);
}
Also used : DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) Context(com.alibaba.citrus.turbine.Context) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)

Aggregations

DefaultContext (com.alibaba.citrus.turbine.impl.DefaultContext)9 Context (com.alibaba.citrus.turbine.Context)4 DefaultFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.impl.DefaultFieldErrorHandler)4 IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)3 List (java.util.List)3 JSONArray (com.alibaba.fastjson.JSONArray)2 Descriptor (com.qlangtech.tis.extension.Descriptor)2 TisUTF8 (com.qlangtech.tis.manage.common.TisUTF8)2 ValidatorCommons (com.qlangtech.tis.plugin.ValidatorCommons)2 IFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)2 DelegateControl4JsonPostMsgHandler (com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler)2 AttrValMap (com.qlangtech.tis.util.AttrValMap)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 IOUtils (org.apache.commons.io.IOUtils)2 IndexIncrStatus (com.qlangtech.tis.coredefine.module.action.IndexIncrStatus)1