use of org.eclipse.scout.rt.shared.data.model.EntityPath in project scout.rt by eclipse.
the class AbstractComposerField method execResolveEntityPath.
/**
* For {@link #exportFormFieldData(AbstractFormFieldData)}, {@link AbstractTree#exportTreeData(AbstractTreeFieldData)}
* and {@link #storeToXml(Element)} it is necessary to export {@link IDataModelEntity} and {@link IDataModelAttribute}
* as external strings. see {@link EntityPath}
* <p>
* This callback completes an entity path to its root. The parameter path contains the entity path represented in the
* composer tree of {@link EntityNode}s, the last element is the deepest tree node.
* <p>
* The default traverses the tree up to the root and collects all non-null {@link EntityNode#getEntity()}
* <p>
* This is prefixed with {@link #interceptResolveRootPathForTopLevelEntity(IDataModelEntity, List)}
*/
@ConfigOperation
@Order(99)
protected EntityPath execResolveEntityPath(EntityNode node) {
LinkedList<IDataModelEntity> list = new LinkedList<IDataModelEntity>();
EntityNode tmp = node;
while (tmp != null) {
if (tmp.getEntity() != null) {
list.add(0, tmp.getEntity());
}
// next
tmp = tmp.getAncestorNode(EntityNode.class);
}
if (list.size() > 0) {
interceptResolveRootPathForTopLevelEntity(list.get(0), list);
}
return new EntityPath(list);
}
use of org.eclipse.scout.rt.shared.data.model.EntityPath in project scout.rt by eclipse.
the class FormDataStatementBuilderWithComposerTest method prepareComposer.
private ComposerAttributeNodeData prepareComposer(int aggregationType) {
IDataModelEntity entity = m_dataModel.getEntity(TestDataModel.Entity.class);
IDataModelEntity subEntity = entity.getEntity(TestDataModel.Entity.SubEntity.class);
IDataModelAttribute subAttribute = subEntity.getAttribute(TestDataModel.Entity.SubEntity.SubAttribute.class);
ComposerAttributeNodeData subAttributeNode = new ComposerAttributeNodeData();
subAttributeNode.setAggregationType(aggregationType);
subAttributeNode.setOperator(DataModelConstants.OPERATOR_EQ);
String attributeExternalId = DataModelUtility.attributePathToExternalId(m_dataModel, new EntityPath().addToEnd(entity).addToEnd(subEntity).addToEnd(subAttribute));
subAttributeNode.setAttributeExternalId(attributeExternalId);
subAttributeNode.setValues(CollectionUtility.arrayList(10L));
ComposerEntityNodeData subEntityNode = new ComposerEntityNodeData();
subEntityNode.setEntityExternalId(DataModelUtility.entityPathToExternalId(m_dataModel, new EntityPath().addToEnd(entity).addToEnd(subEntity)));
subEntityNode.setChildNodes(Arrays.<TreeNodeData>asList(subAttributeNode));
ComposerEntityNodeData entityNode = new ComposerEntityNodeData();
entityNode.setEntityExternalId(DataModelUtility.entityPathToExternalId(m_dataModel, new EntityPath().addToEnd(entity)));
entityNode.setChildNodes(Arrays.<TreeNodeData>asList(subEntityNode));
return subAttributeNode;
}
use of org.eclipse.scout.rt.shared.data.model.EntityPath in project scout.rt by eclipse.
the class FormDataStatementBuilderCheck method checkDataModelEntity.
@SuppressWarnings("bsiRulesDefinition:htmlInString")
protected void checkDataModelEntity(EntityPath ePath) {
IDataModelEntity e = ePath.lastElement();
DataModelEntityPartDefinition part = builder.getDataModelEntityPartDefinitions().get(e.getClass());
if (part == null) {
String name = entityToName(ePath);
String sqlTableName = toSqlTable(name);
String sqlPKName = toSqlPrimaryKey(name);
String parentName = name;
String parentSqlPKName = sqlPKName;
EntityPath parentPath = ePath.parent();
if (!parentPath.isEmpty()) {
parentName = entityToName(parentPath);
parentSqlPKName = toSqlPrimaryKey(parentName);
}
String sqlTemplate = "\"EXISTS ( SELECT 1 \"+\n" + "\"FROM ${sqlTableName} @${name}@ \"+\n" + "\"WHERE @${name}@.${parentSqlPKName}=@parent.${parentName}@.${parentSqlPKName} \"+\n" + "\"<whereParts/> \"+\n" + "\"<groupBy> \"+\n" + "\" GROUP BY @${name}@.${parentSqlPKName} \"+\n" + "\" HAVING 1=1 \"+\n" + "\" <havingParts/> \"+\n" + "\"</groupBy> \"+\n" + "\")\"";
String sql = sqlTemplate.replace("${name}", name).replace("${parentName}", parentName).replace("${sqlTableName}", sqlTableName).replace("${parentSqlPKName}", parentSqlPKName);
addBodyLine("//entity " + e.getClass().getSimpleName());
addBodyLine("setComposerEntityDefinition(" + resolveImport(e.getClass()) + ".class," + sql + ");");
}
}
use of org.eclipse.scout.rt.shared.data.model.EntityPath in project scout.rt by eclipse.
the class FormDataStatementBuilder method buildComposerEntityNodeContribution.
public EntityContribution buildComposerEntityNodeContribution(ComposerEntityNodeData node, EntityStrategy entityStrategy) {
if (getDataModel() == null) {
throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
}
EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), node.getEntityExternalId());
IDataModelEntity entity = (entityPath != null ? entityPath.lastElement() : null);
if (entity == null) {
LOG.warn("no entity for external id: {}", node.getEntityExternalId());
return null;
}
DataModelEntityPartDefinition def = m_dataModelEntMap.get(entity.getClass());
if (def == null) {
LOG.warn("no PartDefinition for entity: {}", entity);
return null;
}
ComposerEntityNodeData parentEntityNode = getParentNodeOfType(node, ComposerEntityNodeData.class);
Map<String, String> parentAliasMap = (parentEntityNode != null ? m_aliasMapper.getNodeAliases(parentEntityNode) : m_aliasMapper.getRootAliases());
String baseStm;
switch(entityStrategy) {
case BuildQuery:
{
baseStm = def.getSelectClause();
break;
}
case BuildConstraints:
{
baseStm = def.getWhereClause();
break;
}
default:
{
baseStm = null;
}
}
String stm = null;
if (baseStm != null) {
stm = def.createInstance(this, node, entityStrategy, baseStm, parentAliasMap);
}
if (stm == null) {
return null;
}
m_aliasMapper.addAllNodeEntitiesFrom(node, stm);
stm = m_aliasMapper.replaceMarkersByAliases(stm, m_aliasMapper.getNodeAliases(node), parentAliasMap);
switch(entityStrategy) {
case BuildQuery:
{
EntityContribution resultContrib = buildComposerEntityUnitContribution(node, entityStrategy, stm, node.getChildNodes(), isConsumeChildContributions(entityPath));
return resultContrib;
}
case BuildConstraints:
{
String s = buildComposerEntityEitherOrSplit(entityStrategy, stm, node.isNegative(), node.getChildNodes());
EntityContribution resultContrib = (s != null ? EntityContribution.create(s) : new EntityContribution());
return resultContrib;
}
default:
{
return null;
}
}
}
use of org.eclipse.scout.rt.shared.data.model.EntityPath in project scout.rt by eclipse.
the class FormDataStatementBuilderCheck method checkDataModelAttribute.
protected void checkDataModelAttribute(AttributePath aPath) {
IDataModelAttribute a = aPath.getAttribute();
DataModelAttributePartDefinition part = builder.getDataModelAttributePartDefinitions().get(a.getClass());
if (part == null) {
if (a.getClass().getSimpleName().endsWith("CountAttribute")) {
// default aggregate count attribute
return;
}
String parentName = "";
EntityPath parentPath = aPath.getEntityPath();
if (!parentPath.isEmpty()) {
parentName = entityToName(parentPath);
}
String name = attributeToName(aPath);
String sqlColumnName = toSqlColumn(name);
//
String sqlTemplate;
if (!parentPath.isEmpty()) {
sqlTemplate = "\"@${parentName}@.${sqlColumnName}\"";
} else {
sqlTemplate = "\"${sqlColumnName}\"";
}
String sql = sqlTemplate.replace("${sqlColumnName}", sqlColumnName).replace("${parentName}", parentName);
addBodyLine("setComposerAttributeDefinition(" + resolveImport(a.getClass()) + ".class," + sql + ");");
}
}
Aggregations