Skip to content

Commit

Permalink
issue #169
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Jul 14, 2016
1 parent a77c4a1 commit f6a08f6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ public ItemCollection getReport(String aReportName) {
public List<ItemCollection> getReportList() {
String sQuery = null;
sQuery = "SELECT";
sQuery += " wi FROM Entity as wi "
+ " JOIN wi.textItems t "
+ " WHERE wi.type = 'ReportEntity' "
+ " AND t.itemName='txtname' "
+ " ORDER BY t.itemValue ASC";
sQuery += " wi FROM Entity as wi " + " JOIN wi.textItems t " + " WHERE wi.type = 'ReportEntity' "
+ " AND t.itemName='txtname' " + " ORDER BY t.itemValue ASC";

List<ItemCollection> col = entityService.findAllEntities(sQuery, 0, -1);

Expand Down Expand Up @@ -265,35 +262,21 @@ public List<ItemCollection> executeReport(String reportName, int startPos, int m
// next we iterate over all entities from the result set and clone
// each entity with the given itemList
for (ItemCollection entity : result) {
ItemCollection clone = new ItemCollection();
Set<String> fieldNames = formatMap.keySet();
for (String field : fieldNames) {

// first look for converter
String converter = converterMap.get(field);
// did we have a format definition?
if (converter != null) {
entity = convertItemValue(entity, field, converter);
}

String format = formatMap.get(field);
// did we have a format definition?
if (!format.isEmpty()) {
String sLocale = XMLParser.findAttribute(format, "locale");
// create string array of formated values
ArrayList<String> vValues = new ArrayList<String>();
List<?> rawValues = entity.getItemValue(field);
for (Object rawValue : rawValues) {
vValues.add(formatObjectValue(rawValue, format, sLocale));
}
clone.replaceItemValue(field, vValues);

} else {
// not format definition - clone value as is
clone.replaceItemValue(field, entity.getItemValue(field));
// in case _ChildItems are requested the entity will be
// duplicated for each child attribute.
// a child item is identified by the '~' char in the item name
List<ItemCollection> embeddedChildItems = getEmbeddedChildItems(entity, formatMap.keySet());
if (!embeddedChildItems.isEmpty()){
for (ItemCollection child: embeddedChildItems) {
ItemCollection clone = cloneEntity(child, formatMap, converterMap);
clonedResult.add(clone);
}
} else {
// default - clone the entity
ItemCollection clone = cloneEntity(entity, formatMap, converterMap);
clonedResult.add(clone);
}
clonedResult.add(clone);
}
logger.fine("executed report '" + reportName + "' in " + (System.currentTimeMillis() - l) + "ms");
return clonedResult;
Expand All @@ -303,6 +286,91 @@ public List<ItemCollection> executeReport(String reportName, int startPos, int m
}
}

/**
* This method returns all embedded child items of a entity. The childItem
* are identified by a fieldname containing a '~'. The left part is the
* container item (List of Map), the right part is the attribute name in the
* child itemcollection.
*
* @param entity
* @param keySet
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<ItemCollection> getEmbeddedChildItems(ItemCollection entity, Set<String> fieldNames) {
List<String> embeddedItemNames = new ArrayList<String>();
List<ItemCollection> result = new ArrayList<ItemCollection>();
// first find all items containing a child element
for (String field : fieldNames) {
field=field.toLowerCase();
if (field.contains("~")) {
field = field.substring(0,field.indexOf('~'));
if (!embeddedItemNames.contains(field)) {
embeddedItemNames.add(field);
}
}
}
if (!embeddedItemNames.isEmpty()) {
for (String field : embeddedItemNames) {
List<Object> mapChildItems = entity.getItemValue(field);
// try to convert
for (Object mapOderItem : mapChildItems) {
if (mapOderItem instanceof Map) {
ItemCollection child=new ItemCollection((Map)mapOderItem);
// clone entity and add all map entries
ItemCollection clone=new ItemCollection(entity);
Set<String> childFieldNameList = child.getAllItems().keySet();
for(String childFieldName : childFieldNameList) {
clone.replaceItemValue(field+"~"+childFieldName, child.getItemValue(childFieldName));
}
result.add(clone);
}
}
}
}
return result;
}

/**
* This helper method clones a entity with a given format and converter map.
*
* @param formatMap
* @param converterMap
* @param entity
* @return
*/
private ItemCollection cloneEntity(ItemCollection entity, Map<String, String> formatMap,
Map<String, String> converterMap) {
ItemCollection clone = new ItemCollection();
Set<String> fieldNames = formatMap.keySet();
for (String field : fieldNames) {
// first look for converter
String converter = converterMap.get(field);
// did we have a format definition?
if (converter != null) {
entity = convertItemValue(entity, field, converter);
}

String format = formatMap.get(field);
// did we have a format definition?
if (!format.isEmpty()) {
String sLocale = XMLParser.findAttribute(format, "locale");
// create string array of formated values
ArrayList<String> vValues = new ArrayList<String>();
List<?> rawValues = entity.getItemValue(field);
for (Object rawValue : rawValues) {
vValues.add(formatObjectValue(rawValue, format, sLocale));
}
clone.replaceItemValue(field, vValues);

} else {
// not format definition - clone value as is
clone.replaceItemValue(field, entity.getItemValue(field));
}
}
return clone;
}

/**
* This method parses a <date /> xml tag and computes a dynamic date by
* parsing the attributes:
Expand Down
6 changes: 6 additions & 0 deletions src/site/markdown/modelling/report_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ To convert the item value the tag 'convert' can be appended behind the item nam

In case the value is not from the specified type (Double, Integer) the value will be converted into a double or integer object. In case the value can not be converted the value will be reset to 0.

### Embedded Child Items
A Workitem can optional contain embedded child items in a single item value. An embedded ChildItem can be named in the attribute list of a report by seperating the ChildItem name from the item name inside the child with a '~'. For example:

_childItems~amount

This attribute definition will extend the JPQL result with all embedded Child Items stored in the attribute '_childItems' and containing the item 'amount'.

## The XSL Transformation
To transform the result of a report definition into various output formats a XSL template can be added into each report.
Expand Down

0 comments on commit f6a08f6

Please sign in to comment.