use of org.eclipse.scout.rt.shared.data.model.AttributePath in project scout.rt by eclipse.
the class FormDataStatementBuilder method buildComposerAttributeNode.
public EntityContribution buildComposerAttributeNode(final ComposerAttributeNodeData node, AttributeStrategy attributeStrategy) {
if (getDataModel() == null) {
throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
}
AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), node.getAttributeExternalId());
IDataModelAttribute attribute = (attPath != null ? attPath.getAttribute() : null);
if (attribute == null) {
LOG.warn("no attribute for external id: {}", node.getAttributeExternalId());
return new EntityContribution();
}
DataModelAttributePartDefinition def = m_dataModelAttMap.get(attribute.getClass());
if (def == null) {
Integer agg = node.getAggregationType();
if (agg != null && agg == AGGREGATION_COUNT) {
def = new DataModelAttributePartDefinition(null, "1", false);
}
}
if (def == null) {
LOG.warn("no PartDefinition for attribute: {}", attribute);
return new EntityContribution();
}
List<Object> bindValues = new ArrayList<Object>();
if (node.getValues() != null) {
bindValues.addAll(node.getValues());
}
List<String> bindNames = new ArrayList<String>(bindValues.size());
for (int i = 0; i < bindValues.size(); i++) {
bindNames.add("" + (char) (((int) 'a') + i));
}
AliasMapper aliasMap = getAliasMapper();
ComposerEntityNodeData parentEntityNode = FormDataStatementBuilder.getParentNodeOfType(node, ComposerEntityNodeData.class);
Map<String, String> parentAliasMap = parentEntityNode != null ? aliasMap.getNodeAliases(parentEntityNode) : aliasMap.getRootAliases();
String stm = null;
switch(attributeStrategy) {
case BuildConstraintOfAttribute:
case BuildConstraintOfContext:
case BuildConstraintOfAttributeWithContext:
{
stm = def.getWhereClause();
break;
}
case BuildQueryOfAttributeAndConstraintOfContext:
{
stm = def.getSelectClause();
break;
}
}
EntityContribution contrib = null;
if (stm != null) {
contrib = def.createInstance(this, node, attributeStrategy, stm, bindNames, bindValues, parentAliasMap);
}
if (contrib == null) {
contrib = new EntityContribution();
}
switch(attributeStrategy) {
case BuildQueryOfAttributeAndConstraintOfContext:
{
if (contrib.getSelectParts().isEmpty()) {
contrib.getSelectParts().add("NULL");
contrib.getGroupByParts().add("NULL");
}
break;
}
}
if (hasInjections()) {
injectPostBuildAttribute(node, attributeStrategy, contrib);
}
return contrib;
}
use of org.eclipse.scout.rt.shared.data.model.AttributePath in project scout.rt by eclipse.
the class AbstractComposerField method loadXMLRec.
private void loadXMLRec(Element x, ITreeNode parent) {
// build tree
for (Element xmlElem : XmlUtility.getChildElements(x)) {
if ("attribute".equals(xmlElem.getTagName())) {
String id = xmlElem.getAttribute("id");
IDataModelAttributeOp op;
Integer aggregationType = 0;
try {
int operator = DataModelConstants.OPERATOR_EQ;
String opAttribName = "op";
if (xmlElem.hasAttribute(opAttribName)) {
operator = Integer.parseInt(xmlElem.getAttribute(opAttribName));
}
op = DataModelAttributeOp.create(operator);
String aggregTypeName = "aggregationType";
if (xmlElem.hasAttribute(aggregTypeName)) {
aggregationType = Integer.parseInt(xmlElem.getAttribute(aggregTypeName));
}
if (aggregationType == 0) {
aggregationType = null;
}
} catch (Exception e) {
LOG.warn("read op", e);
continue;
}
ArrayList<Object> valueList = new ArrayList<Object>();
try {
for (int i = 1; i <= 5; i++) {
String valueName = (i == 1 ? "value" : "value" + i);
if (xmlElem.hasAttribute(valueName)) {
valueList.add(XmlUtility.getObjectAttribute(xmlElem, valueName));
}
}
} catch (Exception e) {
LOG.warn("read value for attribute {}", id, e);
continue;
}
ArrayList<String> displayValueList = new ArrayList<String>();
for (int i = 1; i <= 5; i++) {
String displayValueName = (i == 1 ? "displayValue" : "displayValue" + i);
if (xmlElem.hasAttribute(displayValueName)) {
String val = null;
if (xmlElem.hasAttribute(displayValueName)) {
val = xmlElem.getAttribute(displayValueName);
}
displayValueList.add(val);
}
}
// find definition
AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), id);
IDataModelAttribute foundAtt = (attPath != null ? attPath.getAttribute() : null);
if (foundAtt == null) {
LOG.warn("cannot find attribute with id={}", id);
continue;
}
ITreeNode node = addAttributeNode(parent, foundAtt, aggregationType, op, valueList, displayValueList);
if (node != null) {
// add children recursive
loadXMLRec(xmlElem, node);
}
} else if ("entity".equals(xmlElem.getTagName())) {
String id = xmlElem.getAttribute("id");
boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
String text = null;
if (xmlElem.hasAttribute("displayValues")) {
text = xmlElem.getAttribute("displayValues");
}
// find definition
EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), id);
IDataModelEntity foundEntity = (entityPath != null ? entityPath.lastElement() : null);
if (foundEntity == null) {
LOG.warn("cannot find entity with id={}", id);
continue;
}
ITreeNode node = addEntityNode(parent, foundEntity, negated, null, text != null ? Collections.singletonList(text) : null);
if (node != null) {
// add children recursive
loadXMLRec(xmlElem, node);
}
} else if ("or".equals(xmlElem.getTagName())) {
boolean beginning = Boolean.parseBoolean(xmlElem.getAttribute("begin"));
boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
ITreeNode node = null;
if (beginning) {
node = addEitherNode(parent, negated);
} else {
// find last EitherOrNode
EitherOrNode orNode = null;
for (ITreeNode n : parent.getChildNodes()) {
if (n instanceof EitherOrNode && ((EitherOrNode) n).isEndOfEitherOr()) {
orNode = (EitherOrNode) n;
}
}
if (orNode != null) {
node = addAdditionalOrNode(orNode, negated);
}
}
if (node != null) {
// add children recursive
loadXMLRec(xmlElem, node);
}
}
}
}
use of org.eclipse.scout.rt.shared.data.model.AttributePath in project scout.rt by eclipse.
the class AbstractComposerField method execResolveAttributePath.
/**
* see {@link #execResolveEntityPathForEntityExport(EntityNode)}, {@link AttributePath} for more details
* <p>
* The path in the composer tree is prefixed with
* {@link #interceptResolveRootPathForTopLevelAttribute(IDataModelAttribute, List)}
*/
@ConfigOperation
@Order(99)
protected AttributePath execResolveAttributePath(AttributeNode node) {
LinkedList<IDataModelEntity> list = new LinkedList<IDataModelEntity>();
if (node == null) {
return null;
}
EntityNode tmp = node.getAncestorNode(EntityNode.class);
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);
} else {
interceptResolveRootPathForTopLevelAttribute(node.getAttribute(), list);
}
return new AttributePath(list, node.getAttribute());
}
Aggregations