use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity in project scout.rt by eclipse.
the class MoveDataModelEntitiyAndAttributeTest method testSetup.
@Test
public void testSetup() {
TestDataModel dataModel = new TestDataModel();
assertDataModelElements(dataModel.getEntities(), Top1Entity.class, Top2Entity.class, Top3Entity.class);
assertDataModelElements(dataModel.getAttributes(), Top1Attribute.class, Top2Attribute.class, Top3Attribute.class);
IDataModelEntity entity = dataModel.getEntities().get(0);
assertDataModelElements(entity.getEntities(), Sub1Top1Entity.class, Sub2Top1Entity.class, Sub3Top1Entity.class);
assertDataModelElements(entity.getAttributes(), Sub1Top1Attribute.class, Sub2Top1Attribute.class, Sub3Top1Attribute.class);
}
use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity 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.IDataModelEntity in project scout.rt by eclipse.
the class FormDataStatementBuilderCheck method entityToName.
protected String entityToName(EntityPath ePath) {
if (ePath.isEmpty()) {
return null;
}
IDataModelEntity e = ePath.lastElement();
String name = e.getClass().getSimpleName();
name = name.replaceAll("^Abstract(.*)$", "$1");
name = name.replaceAll("^(.*)Entity$", "$1");
String[] array = name.replaceAll("([a-z])([A-Z])", "$1 $2").split(" ");
return array[array.length - 1];
}
use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity 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.IDataModelEntity in project scout.rt by eclipse.
the class AbstractComposerField method execResolveRootPathForTopLevelAttribute.
/**
* see {@link #interceptResolveAttributePath(AttributeNode)}
*/
@ConfigOperation
@Order(98)
protected void execResolveRootPathForTopLevelAttribute(IDataModelAttribute a, List<IDataModelEntity> lifeList) {
IDataModelEntity tmp = (a != null ? a.getParentEntity() : null);
while (tmp != null) {
lifeList.add(0, tmp);
tmp = tmp.getParentEntity();
}
}
Aggregations