use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class MoreRowsGenerator method generate.
/**
* Generates more rows for a table.
* @throws IllegalArgumentException
*/
public MoreRows generate(Request req) {
String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
String queryName = req.getNonEmpty(RestApiConstants.QUERY);
Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
String startStr = req.getNonEmpty(RestApiConstants.START);
String lengthStr = req.getNonEmpty(RestApiConstants.LENGTH);
String drawStr = req.getNonEmpty(RestApiConstants.DRAW);
String selectableStr = req.getNonEmpty(RestApiConstants.SELECTABLE);
String totalNumberOfRowsStr = req.getNonEmpty(RestApiConstants.TOTAL_NUMBER_OF_ROWS);
int draw;
int start;
int totalNumberOfRows;
int length;
try {
draw = Integer.parseInt(drawStr);
start = Integer.parseInt(startStr);
length = Integer.parseInt(lengthStr);
totalNumberOfRows = Integer.parseInt(totalNumberOfRowsStr);
} catch (NumberFormatException e) {
throw new IllegalArgumentException();
}
boolean selectable = Boolean.parseBoolean(selectableStr);
Query query = injector.get(UserAwareMeta.class).getQuery(entityName, queryName);
return generateMoreRows(query, req, parametersMap, selectable, draw, start, length, totalNumberOfRows);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class QueryBuilder method select.
private void select(String sql, Request req, Injector injector) {
DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
String userQBuilderQueryName = UserInfoHolder.getUserName() + "Query";
Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
Entity entity = new Entity(entityName, injector.getProject().getApplication(), EntityType.TABLE);
DataElementUtils.save(entity);
Query query = new Query(userQBuilderQueryName, entity);
query.setType(QueryType.D1_UNKNOWN);
if (sql != null) {
query.setQuery(sql);
}
DataElementUtils.save(query);
try {
resourceDataList.add(new ResourceData("finalSql", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Final sql", new Be5QueryExecutor(query, parametersMap, injector).getFinalSql()), null));
} catch (Be5Exception e) {
errorModelList.add(new ErrorModel(e));
}
try {
JsonApiModel document = documentGenerator.getDocument(query, parametersMap);
// todo refactor documentGenerator
document.getData().setId("result");
resourceDataList.add(document.getData());
resourceDataList.addAll(Arrays.asList(document.getIncluded()));
} catch (Be5Exception e) {
errorModelList.add(new ErrorModel(e));
}
entity.getOrigin().remove(entityName);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class PageCustomization method getErrors.
@Override
public List<ProjectElementException> getErrors() {
List<ProjectElementException> result = new ArrayList<>();
try {
ModelValidationUtils.checkValueInSet(this, "domain", domain, getDomains());
} catch (ProjectElementException e) {
result.add(e);
}
try {
ModelValidationUtils.checkValueInSet(this, "type", type, TYPES);
} catch (ProjectElementException e) {
result.add(e);
}
ProjectElementException error = getResult().getError();
if (error != null && !error.isNoError()) {
DataElementPath path = getCompletePath();
if (error.getPath().equals(path.toString()))
result.add(error);
else
result.add(new ProjectElementException(path, "query", error));
}
return result;
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadCustomizedModule.
@Test
public void testWriteReadCustomizedModule() throws Exception {
final Project project = new Project("TestProject");
final Module module = new Module("testmodule", project.getModules());
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("customizedtable", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Operation op1 = Operation.createOperation("normop", Operation.OPERATION_TYPE_JAVA, table);
assertFalse(module.isCustomized());
DataElementUtils.saveQuiet(op1);
final Operation op2 = Operation.createOperation("custop", Operation.OPERATION_TYPE_JAVA, table);
op2.setOriginModuleName(Project.APPLICATION);
DataElementUtils.saveQuiet(op2);
final Query q1 = new Query("normq", table);
DataElementUtils.saveQuiet(q1);
final Query q2 = new Query("custq", table);
q2.setOriginModuleName(Project.APPLICATION);
DataElementUtils.saveQuiet(q2);
assertTrue(module.isCustomized());
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project project2 = Serialization.load(tempFolder);
final Module readModule = project2.getModule("testmodule");
assertNotNull(readModule);
assertTrue(readModule.isCustomized());
final Entity readTable = readModule.getEntity("customizedtable");
assertNotNull(readTable);
assertTrue(readTable.isCustomized());
assertEquals(1, readTable.getOperations().getSize());
assertNotNull(readTable.getOperations().get("custop"));
assertEquals(1, readTable.getQueries().getSize());
assertNotNull(readTable.getQueries().get("custq"));
FileUtils.deleteRecursively(tempFolder);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadQueryFilters.
@Test
public void testWriteReadQueryFilters() throws Exception {
final Project project = new Project("TestProject");
final Module module = project.getApplication();
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("table", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Query query = new Query("q", table);
DataElementUtils.saveQuiet(query);
final Query query2 = new Query("q2", table);
DataElementUtils.saveQuiet(query2);
final Query filterQuery = new Query("filter query", table);
DataElementUtils.saveQuiet(filterQuery);
final QuickFilter qf1 = new QuickFilter("filter1", query);
qf1.setTargetQueryName(filterQuery.getName());
qf1.setQueryParam("param");
qf1.setFilteringClass("test.class");
DataElementUtils.saveQuiet(qf1);
final QuickFilter qf2 = new QuickFilter("filter2", query2);
qf2.setTargetQueryName(filterQuery.getName());
qf2.setQueryParam("param2");
DataElementUtils.saveQuiet(qf2);
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project readProject = Serialization.load(tempFolder);
final Entity readEntity = readProject.getApplication().getEntity("table");
assertEquals("filter1", readEntity.getQueries().get("q").getQuickFilters()[0].getName());
assertEquals("param", readEntity.getQueries().get("q").getQuickFilters()[0].getQueryParam());
assertEquals("test.class", readEntity.getQueries().get("q").getQuickFilters()[0].getFilteringClass());
assertSame(readEntity.getQueries().get("filter query"), readEntity.getQueries().get("q").getQuickFilters()[0].getTargetQuery());
assertEquals("filter2", readEntity.getQueries().get("q2").getQuickFilters()[0].getName());
assertEquals("param2", readEntity.getQueries().get("q2").getQuickFilters()[0].getQueryParam());
assertNull(readEntity.getQueries().get("q2").getQuickFilters()[0].getFilteringClass());
assertSame(readEntity.getQueries().get("filter query"), readEntity.getQueries().get("q2").getQuickFilters()[0].getTargetQuery());
FileUtils.deleteRecursively(tempFolder);
}
Aggregations