Search in sources :

Example 1 with ObjectSimpleField

use of net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField in project n2o-framework by i-novus-llc.

the class DomainProcessor method doDomainConversation.

public DataSet doDomainConversation(DataSet inDataSet, Collection<AbstractParameter> values) {
    for (AbstractParameter param : values) {
        if (param instanceof ObjectSimpleField) {
            String paramName = param.getId();
            Object value = inDataSet.get(paramName);
            if (value == null)
                continue;
            String domain = ((ObjectSimpleField) param).getDomain();
            inDataSet.put(paramName, deserialize(value, domain));
        }
    }
    return inDataSet;
}
Also used : ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter)

Example 2 with ObjectSimpleField

use of net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField in project n2o-framework by i-novus-llc.

the class ValidationDialog method validate.

@Override
public void validate(DataSet dataSet, InvocationProcessor serviceProvider, ValidationFailureCallback callback) {
    dataSet = DomainProcessor.getInstance().doDomainConversation(dataSet, getInParametersList());
    DataSet result;
    if (getInvocation() != null)
        result = serviceProvider.invoke(getInvocation(), dataSet, getInParametersList(), getOutParametersList());
    else {
        Map<String, String> outMapping = new LinkedHashMap<>();
        if (getOutParametersList() != null)
            for (ObjectSimpleField parameter : getOutParametersList()) outMapping.put(parameter.getId(), parameter.getMapping());
        result = DataSetUtil.extract(dataSet, outMapping);
    }
    if (result.get(CompiledObject.VALIDATION_RESULT_PARAM) == null || !(boolean) result.get(CompiledObject.VALIDATION_RESULT_PARAM))
        callback.onFail(StringUtils.resolveLinks(getMessage(), result));
}
Also used : ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) DataSet(net.n2oapp.criteria.dataset.DataSet) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ObjectSimpleField

use of net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField in project n2o-framework by i-novus-llc.

the class ValidationDialogCompileTest method testValidationDialog.

@Test
public void testValidationDialog() {
    CompiledObject object = compile("net/n2oapp/framework/config/metadata/compile/object/validation/testValidationDialog.object.xml").get(new ObjectContext("testValidationDialog"));
    List<Validation> validations = object.getValidations();
    assertThat(validations.size(), is(2));
    assertThat(validations.get(0).getId(), is("dialog1"));
    assertThat(validations.get(0).getMoment(), is(N2oValidation.ServerMoment.afterFailOperation));
    assertThat(validations.get(0).getMessage(), is("message"));
    N2oTestDataProvider invocation = (N2oTestDataProvider) ((ValidationDialog) validations.get(0)).getInvocation();
    assertThat(invocation.getOperation(), is(N2oTestDataProvider.Operation.create));
    assertThat(invocation.getFile(), is("test.json"));
    List<AbstractParameter> inParametersList = ((ValidationDialog) validations.get(0)).getInParametersList();
    assertThat(inParametersList.size(), is(3));
    List<ObjectSimpleField> outParametersList = ((ValidationDialog) validations.get(0)).getOutParametersList();
    assertThat(outParametersList.size(), is(2));
    assertThat(outParametersList.get(0).getId(), is("name"));
    assertThat(outParametersList.get(1).getId(), is("validation"));
    assertThat(outParametersList.get(1).getMapping(), is("name=='test'"));
    N2oDialog dialog = ((ValidationDialog) validations.get(0)).getDialog();
    assertThat(dialog.getId(), is("dialog1"));
    assertThat(dialog.getTitle(), is("title"));
    assertThat(dialog.getDescription(), is("message"));
    assertThat(dialog.getSize(), is("sm"));
    N2oToolbar toolbar = dialog.getToolbar();
    assertThat(toolbar.getItems().length, is(2));
    assertThat(((N2oButton) toolbar.getItems()[0]).getLabel(), is("Yes"));
    assertThat(((N2oButton) toolbar.getItems()[0]).getAction(), instanceOf(N2oInvokeAction.class));
    assertThat(((N2oButton) toolbar.getItems()[1]).getAction(), instanceOf(N2oCloseAction.class));
    assertThat(validations.get(1).getId(), is("dialog2"));
    assertThat(validations.get(1).getSeverity(), is(SeverityType.danger));
    assertThat(validations.get(1).getMoment(), is(N2oValidation.ServerMoment.afterSuccessOperation));
    outParametersList = ((ValidationDialog) validations.get(1)).getOutParametersList();
    assertThat(outParametersList.size(), is(1));
    assertThat(outParametersList.get(0).getId(), is("validation"));
    assertThat(outParametersList.get(0).getMapping(), nullValue());
}
Also used : N2oValidation(net.n2oapp.framework.api.metadata.global.dao.validation.N2oValidation) Validation(net.n2oapp.framework.api.data.validation.Validation) CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) ValidationDialog(net.n2oapp.framework.api.data.validation.ValidationDialog) N2oCloseAction(net.n2oapp.framework.api.metadata.event.action.N2oCloseAction) N2oInvokeAction(net.n2oapp.framework.api.metadata.event.action.N2oInvokeAction) N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) N2oDialog(net.n2oapp.framework.api.metadata.global.view.page.N2oDialog) N2oToolbar(net.n2oapp.framework.api.metadata.global.view.widget.toolbar.N2oToolbar) ObjectContext(net.n2oapp.framework.config.metadata.compile.context.ObjectContext) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) Test(org.junit.Test)

Example 4 with ObjectSimpleField

use of net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField in project n2o-framework by i-novus-llc.

the class InvocationValidationCompiler method compileInvocationValidation.

protected void compileInvocationValidation(D compiled, S source, CompileProcessor p) {
    compileValidation(compiled, source, p);
    compiled.setId(source.getId());
    // in
    List<AbstractParameter> inParams = new ArrayList<>();
    if (source.getInFields() != null)
        for (AbstractParameter parameter : source.getInFields()) inParams.add(parameter instanceof ObjectSimpleField ? new ObjectSimpleField((ObjectSimpleField) parameter) : new ObjectReferenceField((ObjectReferenceField) parameter));
    compiled.setInParametersList(inParams);
    // out
    List<ObjectSimpleField> outParams = new ArrayList<>();
    if (source.getOutFields() != null)
        for (ObjectSimpleField parameter : source.getOutFields()) outParams.add(new ObjectSimpleField(parameter));
    ObjectSimpleField resultParam = new ObjectSimpleField();
    resultParam.setId(CompiledObject.VALIDATION_RESULT_PARAM);
    resultParam.setMapping(source.getResult());
    outParams.add(resultParam);
    compiled.setOutParametersList(outParams);
    compiled.setInvocation(source.getN2oInvocation());
}
Also used : ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) ObjectReferenceField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField) ArrayList(java.util.ArrayList) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter)

Example 5 with ObjectSimpleField

use of net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField in project n2o-framework by i-novus-llc.

the class InvocationProcessorTest method testAdvancedNestingWithMapInvocationProvider.

@Test
public void testAdvancedNestingWithMapInvocationProvider() {
    N2oTestDataProvider invocation = new N2oTestDataProvider();
    invocation.setOperation(N2oTestDataProvider.Operation.echo);
    // STRUCTURE
    // Reference
    ObjectReferenceField refParam = new ObjectReferenceField();
    refParam.setId("entity");
    refParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity");
    refParam.setMapping("['refEntity']");
    // Simple
    ObjectSimpleField simpleParam = new ObjectSimpleField();
    simpleParam.setId("valueStr");
    // List
    ObjectListField listParam = new ObjectListField();
    listParam.setId("entities");
    listParam.setMapping("['innerObjList']");
    listParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity$InnerEntity");
    ObjectSimpleField childParam1 = new ObjectSimpleField();
    childParam1.setId("id");
    childParam1.setMapping("['valueInt']");
    ObjectSimpleField childParam2 = new ObjectSimpleField();
    childParam2.setId("name");
    childParam2.setMapping("['valueStr']");
    // List Set
    ObjectSetField setParam = new ObjectSetField();
    setParam.setId("set");
    setParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity$InnerEntity$InnerInnerEntity");
    setParam.setMapping("['innerInnerObjSet']");
    ObjectSimpleField setChildParam = new ObjectSimpleField();
    setChildParam.setId("name");
    setChildParam.setMapping("['innerName']");
    setParam.setFields(new AbstractParameter[] { setChildParam });
    listParam.setFields(new AbstractParameter[] { childParam1, childParam2, setParam });
    refParam.setFields(new AbstractParameter[] { simpleParam, listParam });
    // DATASET
    DataSet innerDataSet1 = new DataSet();
    innerDataSet1.put("id", 666);
    innerDataSet1.put("name", "testStr1");
    HashSet innerInnerDataSet = new HashSet();
    innerDataSet1.put("set", innerInnerDataSet);
    innerInnerDataSet.add(new DataSet("name", "code1"));
    innerInnerDataSet.add(new DataSet("name", "code2"));
    DataSet innerDataSet2 = new DataSet();
    innerDataSet2.put("id", 777);
    innerDataSet2.put("name", "testStr2");
    innerInnerDataSet = new HashSet();
    innerDataSet2.put("set", innerInnerDataSet);
    innerInnerDataSet.add(new DataSet("name", "code3"));
    List list = Arrays.asList(innerDataSet1, innerDataSet2);
    DataSet refParamFields = new DataSet();
    refParamFields.put("entities", list);
    refParamFields.put("valueStr", "test");
    DataSet dataSet = new DataSet();
    dataSet.put("entity", refParamFields);
    List<AbstractParameter> inParameters = Arrays.asList(refParam);
    List<ObjectSimpleField> outParameters = new ArrayList<>();
    // Result
    DataSet result = invocationProcessor.invoke(invocation, dataSet, inParameters, outParameters);
    TestEntity entity = (TestEntity) result.get("entity");
    assertThat(entity.getValueInt(), nullValue());
    assertThat(entity.getInnerObj(), nullValue());
    assertThat(entity.getValueStr(), is("test"));
    List<TestEntity.InnerEntity> innerObjList = entity.getInnerObjList();
    assertThat(innerObjList.size(), is(2));
    assertThat(innerObjList.get(0).getValueInt(), is(666));
    assertThat(innerObjList.get(0).getValueStr(), is("testStr1"));
    Set<TestEntity.InnerEntity.InnerInnerEntity> innerInnerObjSet = innerObjList.get(0).getInnerInnerObjSet();
    assertThat(innerInnerObjSet.size(), is(2));
    assertThat(innerInnerObjSet.contains(new TestEntity.InnerEntity.InnerInnerEntity("code1")), is(true));
    assertThat(innerInnerObjSet.contains(new TestEntity.InnerEntity.InnerInnerEntity("code2")), is(true));
    assertThat(innerObjList.get(1).getValueInt(), is(777));
    assertThat(innerObjList.get(1).getValueStr(), is("testStr2"));
    innerInnerObjSet = innerObjList.get(1).getInnerInnerObjSet();
    assertThat(innerInnerObjSet.size(), is(1));
    assertThat(innerInnerObjSet.contains(new TestEntity.InnerEntity.InnerInnerEntity("code3")), is(true));
}
Also used : TestEntity(net.n2oapp.framework.engine.util.TestEntity) ObjectReferenceField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField) DataSet(net.n2oapp.criteria.dataset.DataSet) N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) ObjectSetField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSetField) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) ObjectListField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectListField) Test(org.junit.Test)

Aggregations

ObjectSimpleField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField)26 AbstractParameter (net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter)19 Test (org.junit.Test)17 DataSet (net.n2oapp.criteria.dataset.DataSet)15 N2oJavaDataProvider (net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider)8 Argument (net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument)8 ObjectReferenceField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField)8 ObjectListField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectListField)6 CompiledObject (net.n2oapp.framework.api.metadata.local.CompiledObject)6 ObjectSetField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSetField)5 TestEntity (net.n2oapp.framework.engine.util.TestEntity)5 ConstraintValidation (net.n2oapp.framework.api.data.validation.ConstraintValidation)4 Validation (net.n2oapp.framework.api.data.validation.Validation)4 N2oValidation (net.n2oapp.framework.api.metadata.global.dao.validation.N2oValidation)4 N2oTestDataProvider (net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider)3 ConditionValidation (net.n2oapp.framework.api.data.validation.ConditionValidation)2 MandatoryValidation (net.n2oapp.framework.api.data.validation.MandatoryValidation)2 N2oSqlDataProvider (net.n2oapp.framework.api.metadata.dataprovider.N2oSqlDataProvider)2 ObjectContext (net.n2oapp.framework.config.metadata.compile.context.ObjectContext)2 java.util (java.util)1