use of net.n2oapp.framework.api.metadata.dataprovider.N2oSqlDataProvider in project n2o-framework by i-novus-llc.
the class SqlDataProviderEngine method invoke.
@Override
public Object invoke(N2oSqlDataProvider invocation, Map<String, Object> data) {
Map<String, Object> args = new HashMap<>(data);
String query = loadQuery(invocation);
query = replaceListPlaceholder(query, ":select", args.remove("select"), "*", QueryUtil::reduceComma);
query = replaceListPlaceholder(query, ":join", args.remove("join"), "", QueryUtil::reduceSpace);
query = replaceListPlaceholder(query, ":filters", args.remove("filters"), "1=1", QueryUtil::reduceAnd);
query = replaceListPlaceholder(query, ":sorting", args.remove("sorting"), "1", s -> replaceSortDirection(s, data), QueryUtil::reduceComma);
query = replacePlaceholder(query, ":limit", args.remove("limit"), "10");
query = replacePlaceholder(query, ":offset", args.remove("offset"), "0");
query = replacePlaceholder(query, ":count", args.remove("count"), "-1");
if (invocation.getConnectionUrl() == null)
return executeQuery(args, query, rowMapperFactory.produce(castDefault(invocation.getRowMapper(), "map")), namedParameterJdbcTemplate);
NamedParameterJdbcTemplate jdbcTemplate = createJdbcTemplate(invocation);
return executeQuery(args, query, rowMapperFactory.produce(castDefault(invocation.getRowMapper(), "map")), jdbcTemplate);
}
use of net.n2oapp.framework.api.metadata.dataprovider.N2oSqlDataProvider in project n2o-framework by i-novus-llc.
the class InvocationProcessorTest method testMapsInvocation.
@Test
public void testMapsInvocation() {
DataSet dataSet = new DataSet();
dataSet.put("id", 1);
List<AbstractParameter> inMapping = new ArrayList<>();
ObjectSimpleField param1 = new ObjectSimpleField();
param1.setId("id");
param1.setMapping("['id']");
inMapping.add(param1);
List<ObjectSimpleField> outMapping = new ArrayList<>();
ObjectSimpleField outParam = new ObjectSimpleField();
outParam.setId("id");
outParam.setMapping("[0][0][0]");
outMapping.add(outParam);
N2oSqlDataProvider invocation = new N2oSqlDataProvider();
invocation.setQuery("select 1");
DataSet result = invocationProcessor.invoke(invocation, dataSet, inMapping, outMapping);
assert result.size() == 1;
assert result.get("id").equals(1);
}
use of net.n2oapp.framework.api.metadata.dataprovider.N2oSqlDataProvider in project n2o-framework by i-novus-llc.
the class TestDynamicProvider method read.
@Override
public List<? extends SourceMetadata> read(String context) {
N2oSimplePage page = new N2oSimplePage();
N2oForm form = new N2oForm();
form.setName(context);
form.setRefId("formForTestDynamic");
form.setQueryId("testDynamic?Dummy");
form.adapterV4();
page.setWidget(form);
N2oObject n2oObject = new N2oObject();
n2oObject.setName(TEST_DYNAMIC + "Object");
N2oQuery query = new N2oQuery();
query.setId(TEST_DYNAMIC + "?" + context);
N2oQuery.Selection selection = new N2oQuery.Selection(N2oQuery.Selection.Type.list);
N2oSqlDataProvider invocation = new N2oSqlDataProvider();
invocation.setQuery("test select");
selection.setInvocation(invocation);
query.setLists(new N2oQuery.Selection[] { selection });
query.setFields(new N2oQuery.Field[] { new N2oQuery.Field("id") });
query.setObjectId("testDynamic?Dummy");
N2oTable table = new N2oTable();
table.setQueryId("testDynamic?Dummy");
N2oSimpleColumn idColumn = new N2oSimpleColumn();
idColumn.setId("id");
idColumn.setTextFieldId("id");
table.setColumns(new AbstractColumn[] { idColumn });
table.setId("testDynamic?Dummy");
N2oToolbar toolbar = new N2oToolbar();
toolbar.setPlace("topLeft");
N2oButton create = new N2oButton();
create.setId("create");
N2oShowModal showModal = new N2oShowModal();
showModal.setPageId("testDynamic?Dummy");
create.setModel(ReduxModel.filter);
create.setAction(showModal);
N2oButton update = new N2oButton();
update.setId("update");
N2oShowModal updShowModal = new N2oShowModal();
updShowModal.setPageId("testDynamic?Dummy");
update.setModel(ReduxModel.resolve);
update.setAction(updShowModal);
toolbar.setItems(new ToolbarItem[] { create, update });
table.setToolbars(new N2oToolbar[] { toolbar });
table.adapterV4();
return Arrays.asList(n2oObject, query, table, page);
}
use of net.n2oapp.framework.api.metadata.dataprovider.N2oSqlDataProvider in project n2o-framework by i-novus-llc.
the class StandardFieldCompileTest method testValidations.
@Test
public void testValidations() {
PageContext pageContext = new PageContext("testStandardField");
pageContext.setSubmitOperationId("update");
SimplePage page = (SimplePage) compile("net/n2oapp/framework/config/mapping/testStandardField.page.xml", "net/n2oapp/framework/config/mapping/testCell.object.xml").get(pageContext);
List<Validation> clientValidations = page.getDatasources().get("testStandardField_form").getValidations().get("test3");
assertThat(clientValidations.size(), is(2));
ConstraintValidation validation = (ConstraintValidation) clientValidations.get(0);
assertThat(validation.getId(), is("val1"));
assertThat(validation.getMessage(), is("Message"));
assertThat(validation.getSeverity(), is(SeverityType.danger));
assertThat(validation.getMoment(), is(N2oValidation.ServerMoment.beforeOperation));
assertThat(validation.getRequiredFields().size(), is(1));
assertThat(validation.getRequiredFields().contains("param"), is(true));
assertThat(validation.getInvocation(), instanceOf(N2oSqlDataProvider.class));
assertThat(((N2oSqlDataProvider) validation.getInvocation()).getQuery(), is("select * from table"));
assertThat(validation.getInParametersList().size(), is(1));
ObjectSimpleField parameter = ((ObjectSimpleField) validation.getInParametersList().get(0));
assertThat(parameter.getDomain(), is("boolean"));
assertThat(parameter.getRequired(), is(true));
assertThat(parameter.getMapping(), is("mapping"));
assertThat(parameter.getNormalize(), is("normalize"));
ConditionValidation validation2 = (ConditionValidation) clientValidations.get(1);
assertThat(validation2.getId(), is("val2"));
assertThat(validation2.getMessage(), is("Message"));
assertThat(validation2.getSeverity(), is(SeverityType.warning));
assertThat(validation2.getSide(), is("client,server"));
ActionContext actionContext = (ActionContext) route("/testStandardField/submit", CompiledObject.class);
List<Validation> serverValidations = actionContext.getValidations();
assertThat(serverValidations.size(), is(4));
assertThat(serverValidations.get(0).getFieldId(), is("test1"));
assertThat(serverValidations.get(1), is(validation));
assertThat(serverValidations.get(2), is(validation2));
MandatoryValidation validation3 = (MandatoryValidation) serverValidations.get(3);
assertThat(validation3.getId(), is("val3"));
assertThat(validation3.getMessage(), is("Message"));
assertThat(validation3.getSeverity(), is(SeverityType.danger));
assertThat(validation3.getEnabled(), is(false));
assertThat(validation3.getSide(), is("server"));
}
Aggregations