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;
}
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));
}
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());
}
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());
}
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));
}
Aggregations