Search in sources :

Example 1 with EntityPath

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);
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) LinkedList(java.util.LinkedList) EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 2 with EntityPath

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;
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) AbstractDataModelEntity(org.eclipse.scout.rt.shared.data.model.AbstractDataModelEntity) EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ComposerAttributeNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Example 3 with EntityPath

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 + ");");
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity)

Example 4 with EntityPath

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;
            }
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 5 with EntityPath

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 + ");");
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Aggregations

EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)6 IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)5 IDataModelAttribute (org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)3 ComposerEntityNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)1 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)1 EntityNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)1 Order (org.eclipse.scout.rt.platform.Order)1 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 ComposerAttributeNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData)1 AbstractDataModelEntity (org.eclipse.scout.rt.shared.data.model.AbstractDataModelEntity)1 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)1 IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)1 Element (org.w3c.dom.Element)1