use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class ModuleLoader2MergeModulesTest method setUp.
@Before
public void setUp() throws Exception {
Path tpmProjectPath = tmp.newFolder().toPath();
project = ProjectTestUtils.getProject("test");
// Entity entity = ProjectTestUtils.createEntity( project, "entity", "ID" );
// ProjectTestUtils.createScheme( entity );
// ProjectTestUtils.createScript( project, "delete from entity;\nINSERT INTO entity (name) VALUES ('foo')" );
ProjectTestUtils.createH2Profile(project, "profileTestMavenPlugin");
// Query query = ProjectTestUtils.createQuery(entity, "All records", Arrays.asList('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP, "-User"));
// query.getOperationNames().setValues( Collections.singleton( "op" ) );
// ProjectTestUtils.createOperation( entity );
Path modulePath = tmp.newFolder().toPath();
Project moduleProject1 = createModuleWithQueryRoles(project, null, "testModule1", "testQuery1", "testRole1", modulePath);
Path modulePath2 = tmp.newFolder().toPath();
Project moduleProject2 = createModuleWithQueryRoles(project, moduleProject1, "testModule2", "testQuery2", "testRole2", modulePath2);
project.setRoles(Arrays.asList("testRole1", "testRole2"));
Serialization.save(project, tpmProjectPath);
ArrayList<URL> urls = new ArrayList<>();
urls.add(modulePath.resolve("project.yaml").toUri().toURL());
urls.add(modulePath2.resolve("project.yaml").toUri().toURL());
urls.add(tpmProjectPath.resolve("project.yaml").toUri().toURL());
ModuleLoader2.loadAllProjects(urls);
LoadContext ctx = new LoadContext();
ModuleLoader2.mergeAllModules(project, Arrays.asList(moduleProject1, moduleProject2), ctx);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Project method getContext.
/**
* Creates and returns FreeMarker context for given element
* @param element to create context for (can be null)
* @return
*/
public Map<String, Object> getContext(TemplateElement element) {
Map<String, Object> context = new HashMap<>();
BeModelElement parent = element;
while (parent != null) {
if (parent instanceof PageCustomization) {
context.put("customization", parent);
} else if (parent instanceof Query) {
context.put("query", parent);
} else if (parent instanceof Operation) {
context.put("operation", parent);
} else if (parent instanceof Entity) {
context.put("entity", parent);
} else if (parent instanceof Module) {
context.put("module", parent);
}
parent = parent.getOrigin();
}
for (String name : getPropertyNames()) {
context.put(name, getProperty(name));
}
BeConnectionProfile profile = getConnectionProfile();
if (profile != null) {
for (String name : profile.getPropertyNames()) {
context.put(name, profile.getProperty(name));
}
}
return context;
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Query method getErrors.
@Override
public List<ProjectElementException> getErrors() {
List<ProjectElementException> result = super.getErrors();
try {
ModelValidationUtils.checkValueInSet(this, "type", getType().getName(), getQueryTypes());
} catch (ProjectElementException e) {
result.add(e);
}
String templateQueryName = getTemplateQueryName();
if (!templateQueryName.isEmpty()) {
int pos = templateQueryName.indexOf('.');
if (pos < 0) {
result.add(new ProjectElementException(getCompletePath(), "templateQueryName", new IllegalArgumentException("templateQueryName must have format <entity>:<query>")));
}
}
Set<String> missingEntries = getRoles().getMissingEntries();
if (!missingEntries.isEmpty()) {
result.add(new ProjectElementException(getCompletePath(), "roles", "Unknown role(s): " + missingEntries));
}
ProjectElementException error = getQueryCompiled().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 Document method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
String queryName = req.getNonEmpty(RestApiConstants.QUERY);
int sortColumn = req.getInt("order[0][column]", -1);
boolean sortDesc = "desc".equals(req.get("order[0][dir]"));
Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
HashUrl url = new HashUrl(TABLE_ACTION, entityName, queryName).named(parametersMap);
Query query;
try {
query = userAwareMeta.getQuery(entityName, queryName);
} catch (Be5Exception e) {
sendError(req, res, url, e);
return;
}
try {
switch(req.getRequestUri()) {
case "":
JsonApiModel document = documentGenerator.getDocument(query, parametersMap, sortColumn, sortDesc);
document.setMeta(req.getDefaultMeta());
res.sendAsJson(document);
return;
case "moreRows":
res.sendAsRawJson(new MoreRowsGenerator(injector).generate(req));
return;
default:
res.sendUnknownActionError();
}
} catch (Be5Exception e) {
sendError(req, res, url, e);
} catch (Throwable e) {
sendError(req, res, url, Be5Exception.internalInQuery(e, query));
}
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Menu method generateEntityQueries.
private List<QueryNode> generateEntityQueries(List<Query> permittedQueries, String language, Meta meta, boolean withIds) {
List<OrderedQuery> queries = new ArrayList<>();
for (Query permittedQuery : permittedQueries) {
queries.add(new OrderedQuery(permittedQuery, meta.getTitle(permittedQuery, language)));
}
Collections.sort(queries);
List<QueryNode> children = new ArrayList<>();
for (OrderedQuery query : queries) {
Query permittedQuery = query.query;
Id id = null;
if (withIds) {
id = new Id(permittedQuery.getEntity().getName(), permittedQuery.getName());
}
children.add(new QueryNode(id, query.title, ActionUtils.toAction(permittedQuery), permittedQuery.isDefaultView()));
}
return children;
}
Aggregations