use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.
the class FormDataStatementBuilder method buildComposerOrNodes.
/**
* do not use or override this method, it is protected for unit test purposes
*/
protected EntityContribution buildComposerOrNodes(List<ComposerEitherOrNodeData> nodes, EntityStrategy entityStrategy, AttributeStrategy attributeStrategy) {
EntityContribution contrib = new EntityContribution();
// check if only one condition
StringBuilder buf = new StringBuilder();
int count = 0;
for (ComposerEitherOrNodeData node : nodes) {
EntityContribution subContrib = buildTreeNodes(node.getChildNodes(), entityStrategy, attributeStrategy);
contrib.getFromParts().addAll(subContrib.getFromParts());
if (subContrib.getWhereParts().size() + subContrib.getHavingParts().size() > 0) {
if (count > 0) {
buf.append(" OR ");
if (node.isNegative()) {
buf.append(" NOT ");
}
}
buf.append("(");
// remove possible outer join signs (+) in where / having constraint
// this is necessary because outer joins are not allowed in OR clause
// the removal of outer joins does not influence the result set
buf.append(CollectionUtility.format(CollectionUtility.combine(subContrib.getWhereParts(), subContrib.getHavingParts()), " AND ").replaceAll("\\(\\+\\)", ""));
buf.append(")");
count++;
}
}
if (count > 0) {
if (count > 1) {
buf.insert(0, "(");
buf.append(")");
contrib.getWhereParts().add(buf.toString());
} else {
String s = buf.toString();
if (s.matches("\\(.*\\)")) {
s = s.substring(1, s.length() - 1).trim();
}
contrib.getWhereParts().add(s);
}
}
return contrib;
}
use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.
the class FormDataStatementBuilder method buildComposerEntityEitherOrSplit.
/**
* only used with strategy {@link EntityStrategy#BuildConstraints}
* <p>
* do not use or override this method, it is protected for unit test purposes
*/
protected String buildComposerEntityEitherOrSplit(EntityStrategy entityStrategy, String baseStm, boolean negative, List<TreeNodeData> childParts) {
if (entityStrategy != EntityStrategy.BuildConstraints) {
return null;
}
List<List<ComposerEitherOrNodeData>> orBlocks = new ArrayList<List<ComposerEitherOrNodeData>>();
List<TreeNodeData> otherParts = new ArrayList<TreeNodeData>();
List<ComposerEitherOrNodeData> currentOrBlock = new ArrayList<ComposerEitherOrNodeData>();
for (TreeNodeData ch : childParts) {
if (ch instanceof ComposerEitherOrNodeData) {
ComposerEitherOrNodeData orData = (ComposerEitherOrNodeData) ch;
if (orData.isBeginOfEitherOr()) {
if (currentOrBlock.size() > 0) {
orBlocks.add(new ArrayList<ComposerEitherOrNodeData>(currentOrBlock));
}
currentOrBlock.clear();
}
currentOrBlock.add(orData);
} else {
otherParts.add(ch);
}
}
if (currentOrBlock.size() > 0) {
orBlocks.add(new ArrayList<ComposerEitherOrNodeData>(currentOrBlock));
currentOrBlock.clear();
}
//
if (orBlocks.size() > 0) {
StringBuilder blockBuf = new StringBuilder();
int blockCount = 0;
for (List<ComposerEitherOrNodeData> list : orBlocks) {
int elemCount = 0;
StringBuilder elemBuf = new StringBuilder();
for (ComposerEitherOrNodeData orData : list) {
ArrayList<TreeNodeData> subList = new ArrayList<TreeNodeData>();
subList.addAll(otherParts);
subList.addAll(orData.getChildNodes());
String s = buildComposerEntityEitherOrSplit(entityStrategy, baseStm, negative ^ orData.isNegative(), subList);
if (s != null) {
if (elemCount > 0) {
elemBuf.append(" OR ");
}
elemBuf.append(" ( ");
elemBuf.append(s);
elemBuf.append(" ) ");
elemCount++;
}
}
if (elemCount > 0) {
if (blockCount > 0) {
blockBuf.append(" AND ");
}
blockBuf.append(" ( ");
blockBuf.append(elemBuf.toString());
blockBuf.append(" ) ");
blockCount++;
}
}
if (blockCount > 0) {
return blockBuf.toString();
}
return null;
}
return buildComposerEntityZeroTraversingSplit(entityStrategy, baseStm, negative, childParts);
}
use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.
the class ComposerFieldTest method testExportEitherOrNode.
@Test
public void testExportEitherOrNode() throws Exception {
// setup field
ITreeNode parentNode = m_composerField.getTree().getRootNode();
EitherOrNode eitherNode = m_composerField.addEitherNode(parentNode, false);
m_composerField.addAdditionalOrNode(eitherNode, false);
// export
m_composerField.exportFormFieldData(m_fieldData);
// verify export
assertEquals(2, m_fieldData.getRootCount());
//
TreeNodeData eitherNodeData = m_fieldData.getRoots().get(0);
assertTrue(eitherNodeData instanceof ComposerEitherOrNodeData);
assertTrue(((ComposerEitherOrNodeData) eitherNodeData).isBeginOfEitherOr());
assertFalse(((ComposerEitherOrNodeData) eitherNodeData).isNegative());
//
TreeNodeData orNodeData = m_fieldData.getRoots().get(1);
assertTrue(orNodeData instanceof ComposerEitherOrNodeData);
assertFalse(((ComposerEitherOrNodeData) orNodeData).isBeginOfEitherOr());
assertFalse(((ComposerEitherOrNodeData) orNodeData).isNegative());
}
use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.
the class ComposerFieldTest method testImportEitherOrOrNode.
@Test
public void testImportEitherOrOrNode() throws Exception {
// setup field data
ComposerEitherOrNodeData eitherNodeData = new ComposerEitherOrNodeData();
eitherNodeData.setBeginOfEitherOr(true);
ComposerEitherOrNodeData or1NodeData = new ComposerEitherOrNodeData();
ComposerEitherOrNodeData or2NodeData = new ComposerEitherOrNodeData();
List<TreeNodeData> rootList = Arrays.<TreeNodeData>asList(eitherNodeData, or1NodeData, or2NodeData);
m_fieldData.setRoots(rootList);
// import
m_composerField.importFormFieldData(m_fieldData, false);
// verify import
ITreeNode rootNode = m_composerField.getTree().getRootNode();
assertEquals(3, rootNode.getChildNodeCount());
//
ITreeNode eitherNode = rootNode.getChildNode(0);
assertTrue(eitherNode instanceof EitherOrNode);
assertTrue(((EitherOrNode) eitherNode).isBeginOfEitherOr());
assertFalse(((EitherOrNode) eitherNode).isNegative());
//
ITreeNode or1Node = rootNode.getChildNode(1);
assertTrue(or1Node instanceof EitherOrNode);
assertFalse(((EitherOrNode) or1Node).isBeginOfEitherOr());
assertFalse(((EitherOrNode) or1Node).isNegative());
//
ITreeNode or2Node = rootNode.getChildNode(2);
assertTrue(or2Node instanceof EitherOrNode);
assertFalse(((EitherOrNode) or2Node).isBeginOfEitherOr());
assertFalse(((EitherOrNode) or2Node).isNegative());
}
use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.
the class ComposerFieldTest method testImportEitherOrNode.
@Test
public void testImportEitherOrNode() throws Exception {
// setup field data
ComposerEitherOrNodeData eitherNodeData = new ComposerEitherOrNodeData();
eitherNodeData.setBeginOfEitherOr(true);
ComposerEitherOrNodeData orNodeData = new ComposerEitherOrNodeData();
List<TreeNodeData> rootList = Arrays.<TreeNodeData>asList(eitherNodeData, orNodeData);
m_fieldData.setRoots(rootList);
// import
m_composerField.importFormFieldData(m_fieldData, false);
// verify import
ITreeNode rootNode = m_composerField.getTree().getRootNode();
assertEquals(2, rootNode.getChildNodeCount());
//
ITreeNode eitherNode = rootNode.getChildNode(0);
assertTrue(eitherNode instanceof EitherOrNode);
assertTrue(((EitherOrNode) eitherNode).isBeginOfEitherOr());
assertFalse(((EitherOrNode) eitherNode).isNegative());
//
ITreeNode orNode = rootNode.getChildNode(1);
assertTrue(orNode instanceof EitherOrNode);
assertFalse(((EitherOrNode) orNode).isBeginOfEitherOr());
assertFalse(((EitherOrNode) orNode).isNegative());
}
Aggregations