Revision 44300 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttributes.java
DefaultExportAttributes.java | ||
---|---|---|
19 | 19 |
import org.gvsig.fmap.dal.feature.FeatureType; |
20 | 20 |
import org.gvsig.tools.dataTypes.DataType; |
21 | 21 |
import org.gvsig.tools.util.UnmodifiableBasicListAdapter; |
22 |
import org.slf4j.Logger; |
|
23 |
import org.slf4j.LoggerFactory; |
|
22 | 24 |
|
23 |
public class DefaultExportAttributes implements ExportAttributes { |
|
25 |
public final class DefaultExportAttributes implements ExportAttributes {
|
|
24 | 26 |
|
25 | 27 |
private List<ExportAttribute> exportAttributes; |
26 |
private AttributeNamesTranslator namesTranslator; |
|
28 |
private AttributeNamesTranslator namesTranslator = null;
|
|
27 | 29 |
private FeatureType sourceFeatureType; |
30 |
static final Logger LOGGER = LoggerFactory.getLogger(DefaultExportAttributes.class); |
|
28 | 31 |
|
32 |
|
|
29 | 33 |
public DefaultExportAttributes(FeatureType ftype) { |
30 |
//TODO |
|
31 |
//rellenar pirmero sin el suggest name |
|
32 |
//rellamar al algorito de suggest |
|
33 |
this.fillExportAttributes(ftype); |
|
34 | 34 |
this.setSourceFeatureType(ftype); |
35 |
|
|
36 | 35 |
} |
37 | 36 |
|
38 | 37 |
public void fillExportAttributes(FeatureType ftype) { |
39 | 38 |
ArrayList attrs = new ArrayList(); |
40 |
for (FeatureAttributeDescriptor fad : ftype) { |
|
41 |
DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad); |
|
42 |
exportAttribute.setNewName(fad.getName()); |
|
43 |
exportAttribute.setNewType(fad.getDataType().getType()); |
|
44 |
exportAttribute.setSize(fad.getSize()); |
|
45 |
exportAttribute.setExported(true); |
|
46 |
attrs.add(exportAttribute); |
|
39 |
if (ftype != null) { |
|
40 |
for (FeatureAttributeDescriptor fad : ftype) { |
|
41 |
DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad); |
|
42 |
exportAttribute.setNewName(fad.getName()); |
|
43 |
exportAttribute.setNewType(fad.getDataType().getType()); |
|
44 |
exportAttribute.setSize(fad.getSize()); |
|
45 |
exportAttribute.setExported(true); |
|
46 |
attrs.add(exportAttribute); |
|
47 |
} |
|
47 | 48 |
} |
48 | 49 |
this.exportAttributes = attrs; |
49 | 50 |
|
... | ... | |
51 | 52 |
|
52 | 53 |
@Override |
53 | 54 |
public void setNamesTranslator(AttributeNamesTranslator namesTranslator) { |
54 |
//TODO tb hay que rehacer todos los suggestname. |
|
55 | 55 |
this.namesTranslator = namesTranslator; |
56 |
//this.fixAttributeNames(); |
|
56 | 57 |
} |
57 | 58 |
|
58 | 59 |
@Override |
... | ... | |
97 | 98 |
|
98 | 99 |
@Override |
99 | 100 |
public FeatureType getTargetFeatureType() { |
101 |
if (!this.isAttributeNamesValid()) { |
|
102 |
this.fixAttributeNames(); |
|
103 |
} |
|
100 | 104 |
EditableFeatureType targetFeatureType = this.getSourceFeatureType().getCopy().getEditable(); |
101 | 105 |
for (FeatureAttributeDescriptor attrSource : this.getSourceFeatureType()) { |
102 | 106 |
FeatureAttributeDescriptor attr = targetFeatureType.getAttributeDescriptor(attrSource.getName()); |
... | ... | |
106 | 110 |
targetFeatureType.remove(name); |
107 | 111 |
continue; |
108 | 112 |
} |
109 |
|
|
113 |
|
|
110 | 114 |
EditableFeatureAttributeDescriptor eAttr = targetFeatureType.getEditableAttributeDescriptor(name); |
111 | 115 |
if (this.getTargetName(name) == null ? name != null : !this.getTargetName(name).equals(name)) { |
112 | 116 |
eAttr.setName(this.getTargetName(name)); |
... | ... | |
125 | 129 |
@Override |
126 | 130 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
127 | 131 |
this.sourceFeatureType = sourceFeatureType; |
132 |
this.fillExportAttributes(sourceFeatureType); |
|
128 | 133 |
} |
129 | 134 |
|
130 | 135 |
@Override |
... | ... | |
134 | 139 |
|
135 | 140 |
@Override |
136 | 141 |
public String getTargetName(String name) { |
137 |
for (ExportAttribute exportAttribute : this.exportAttributes) { |
|
142 |
for (int i = 0; i < exportAttributes.size(); i++) { |
|
143 |
ExportAttribute exportAttribute = exportAttributes.get(i); |
|
138 | 144 |
if (StringUtils.equals(exportAttribute.getName(), name)) { |
139 |
return exportAttribute.getNewName(); |
|
145 |
String newName = exportAttribute.getNewName(); |
|
146 |
//TODO return value or fixed value? |
|
147 |
// if (!this.namesTranslator.isValidName(this, i, newName)) { |
|
148 |
// newName = this.namesTranslator.getNameSuggestion(this, i, newName); |
|
149 |
// //exportAttribute.setNewName(newName); //Change the name in the exportAttribute after chacking |
|
150 |
// } |
|
151 |
return newName; |
|
140 | 152 |
} |
141 | 153 |
} |
142 | 154 |
return null; |
... | ... | |
172 | 184 |
return 0; |
173 | 185 |
} |
174 | 186 |
|
187 |
@Override |
|
188 |
public boolean isAttributeNamesValid() { |
|
189 |
if (this.namesTranslator==null) { |
|
190 |
return true; |
|
191 |
} |
|
192 |
for (int i = 0; i < exportAttributes.size(); i++) { |
|
193 |
ExportAttribute attr = exportAttributes.get(i); |
|
194 |
if (!this.namesTranslator.isValidName(this, i, attr.getNewName())) { |
|
195 |
return false; |
|
196 |
} |
|
197 |
} |
|
198 |
return true; |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public void fixAttributeNames() { |
|
203 |
if (this.isAttributeNamesValid() == true) { |
|
204 |
return; |
|
205 |
} |
|
206 |
if (this.namesTranslator==null) { |
|
207 |
return; |
|
208 |
} |
|
209 |
int n = 0; |
|
210 |
while (!this.isAttributeNamesValid()) { |
|
211 |
for (int i = 0; i < exportAttributes.size(); i++) { |
|
212 |
ExportAttribute attr = exportAttributes.get(i); |
|
213 |
String newName = attr.getNewName(); |
|
214 |
if (!this.namesTranslator.isValidName(this, i, newName)) { |
|
215 |
String sug = this.namesTranslator.getNameSuggestion(this, i, newName); |
|
216 |
attr.setNewName(sug); |
|
217 |
} |
|
218 |
} |
|
219 |
if (n>5000) { |
|
220 |
LOGGER.warn("Not been able to fix attribute field names, it will require a manual operation"); |
|
221 |
break; |
|
222 |
} |
|
223 |
n += 1; |
|
224 |
} |
|
225 |
|
|
226 |
} |
|
227 |
|
|
175 | 228 |
} |
Also available in: Unified diff