14 |
14 |
import org.apache.commons.lang3.StringUtils;
|
15 |
15 |
import org.gvsig.expressionevaluator.Expression;
|
16 |
16 |
import org.gvsig.expressionevaluator.ExpressionUtils;
|
17 |
|
import org.gvsig.expressionevaluator.MutableSymbolTable;
|
18 |
|
import org.gvsig.fmap.dal.DALLocator;
|
19 |
17 |
import org.gvsig.fmap.dal.StoresRepository;
|
20 |
|
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
|
|
18 |
import org.gvsig.fmap.dal.feature.EditableForeingKey;
|
21 |
19 |
import org.gvsig.fmap.dal.feature.Feature;
|
22 |
20 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
|
23 |
21 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
... | ... | |
29 |
27 |
import org.gvsig.tools.dataTypes.DataTypesManager;
|
30 |
28 |
import org.gvsig.tools.dataTypes.Coercion;
|
31 |
29 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
30 |
import org.gvsig.tools.dynobject.DynObjectValueItem;
|
32 |
31 |
import org.gvsig.tools.util.GetItem;
|
33 |
32 |
import org.gvsig.tools.util.GetItem64;
|
34 |
33 |
import org.gvsig.tools.util.Size;
|
... | ... | |
53 |
52 |
private final JasperReportsContext context;
|
54 |
53 |
protected String name;
|
55 |
54 |
private Map<String, Coercion> coercions;
|
|
55 |
private final FeatureType featureType;
|
|
56 |
private final Map<String, DynObjectValueItem[]> availableValues;
|
56 |
57 |
|
57 |
|
public JRFeatureStoreDataSource(JasperReportsContext context, UnmodifiableBasicList64<Feature> features, StoresRepository storesRepository) {
|
|
58 |
public JRFeatureStoreDataSource(JasperReportsContext context, UnmodifiableBasicList64<Feature> features, StoresRepository storesRepository, FeatureType featureType) {
|
58 |
59 |
this.context = context;
|
59 |
60 |
this.features = features;
|
60 |
61 |
this.storesRepository = storesRepository;
|
61 |
62 |
this.index = -1;
|
62 |
63 |
this.name = "<unknown>";
|
63 |
64 |
this.coercions = new HashMap<>();
|
|
65 |
this.featureType = featureType;
|
|
66 |
this.availableValues = new HashMap<>();
|
64 |
67 |
|
65 |
68 |
LOGGER.info("DataSource(" + this.name + ")");
|
|
69 |
calculateAvailableValues();
|
66 |
70 |
}
|
67 |
71 |
|
68 |
72 |
public JRFeatureStoreDataSource(JasperReportsContext context, FeatureStore store, Expression filter) {
|
69 |
73 |
this(
|
70 |
74 |
context,
|
71 |
75 |
(UnmodifiableBasicList64<Feature>) store.getFeatures(filter),
|
72 |
|
store.getStoresRepository()
|
|
76 |
store.getStoresRepository(),
|
|
77 |
store.getDefaultFeatureTypeQuietly()
|
73 |
78 |
);
|
74 |
79 |
this.name = store.getName();
|
75 |
80 |
// System.out.println("DataSurce("+this.name+")");
|
76 |
81 |
}
|
|
82 |
|
|
83 |
private void calculateAvailableValues() {
|
|
84 |
for (FeatureAttributeDescriptor attr : featureType) {
|
77 |
85 |
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
78 |
89 |
@Override
|
79 |
90 |
public boolean next() throws JRException {
|
80 |
91 |
this.index++;
|
... | ... | |
85 |
96 |
|
86 |
97 |
public String getLabel(Feature feature, String fieldName) {
|
87 |
98 |
|
88 |
|
FeatureType ft = feature.getType();
|
89 |
|
FeatureAttributeDescriptor attr = ft.getAttributeDescriptor(fieldName);
|
90 |
|
String labelPhrase = attr.getTags().getString(TAG_REPORT_ATTR_LABEL, null);
|
91 |
|
if (labelPhrase == null) {
|
92 |
|
return feature.getLabelOfValue(fieldName);
|
|
99 |
DynObjectValueItem[] theAvailableValues = this.availableValues.get(fieldName);
|
|
100 |
Object value = feature.get(fieldName);
|
|
101 |
if (theAvailableValues==null) {
|
|
102 |
FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(fieldName);
|
|
103 |
if (attr.hasAvailableValues()) {
|
|
104 |
this.availableValues.put(attr.getName(), attr.getAvailableValues(null));
|
|
105 |
}
|
|
106 |
String labelPhrase = attr.getTags().getString(TAG_REPORT_ATTR_LABEL, null);
|
|
107 |
if (StringUtils.isNotBlank(labelPhrase)) {
|
|
108 |
if (attr.isForeingKey()) {
|
|
109 |
EditableForeingKey fk;
|
|
110 |
try {
|
|
111 |
fk = (EditableForeingKey) attr.getForeingKey().clone();
|
|
112 |
fk.unbind();
|
|
113 |
fk.setLabelFormula(labelPhrase);
|
|
114 |
|
|
115 |
// ForeingKey.ContextForeingKey myContext = fk.createContext();
|
|
116 |
this.availableValues.put(attr.getName(), fk.getAvailableValues(null));
|
|
117 |
} catch (CloneNotSupportedException ex) {
|
|
118 |
LOGGER.warn("Not able to clone foreing key. "+ex.toString());
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
}
|
|
123 |
theAvailableValues = this.availableValues.get(fieldName);
|
93 |
124 |
}
|
94 |
|
|
95 |
|
FeatureSymbolTable fst = DALLocator.getDataManager().createFeatureSymbolTable();
|
96 |
|
MutableSymbolTable symbolTable = fst.createParent();
|
97 |
|
fst.setFeature(feature);
|
98 |
125 |
|
99 |
|
Object label = ExpressionUtils.evaluate(symbolTable, labelPhrase);
|
100 |
|
String finalLabel = Objects.toString(label);
|
101 |
|
return finalLabel;
|
102 |
|
|
|
126 |
if (theAvailableValues!=null) {
|
|
127 |
for (DynObjectValueItem theAvailableValue : theAvailableValues) {
|
|
128 |
if (Objects.equals(value, theAvailableValue.getValue())) {
|
|
129 |
return theAvailableValue.getLabel();
|
|
130 |
}
|
|
131 |
}
|
|
132 |
}
|
|
133 |
return Objects.toString(value);
|
103 |
134 |
}
|
104 |
135 |
|
105 |
136 |
@Override
|
... | ... | |
179 |
210 |
|
180 |
211 |
@Override
|
181 |
212 |
public JsonData subDataSource() throws JRException {
|
182 |
|
return new JRFeatureStoreDataSource(this.context, this.features, this.storesRepository);
|
|
213 |
return new JRFeatureStoreDataSource(this.context, this.features, this.storesRepository, this.featureType);
|
183 |
214 |
}
|
184 |
215 |
|
185 |
216 |
@Override
|