use of org.openforis.collect.persistence.DataInconsistencyException in project collect by openforis.
the class UIOptionsBinder method unmarshal.
@Override
public UIOptions unmarshal(Survey survey, String type, String body) {
XmlPullParser parser = null;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
Reader reader = new StringReader(body);
parser.setInput(reader);
UIOptions uiOptions = new UIOptions((CollectSurvey) survey);
UITabSet tabSet = unmarshalTabSet(parser, uiOptions);
while (tabSet != null) {
uiOptions.addTabSet(tabSet);
tabSet = unmarshalTabSet(parser, uiOptions);
}
return uiOptions;
} catch (Exception e) {
throw new DataInconsistencyException(e.getMessage(), e);
}
}
use of org.openforis.collect.persistence.DataInconsistencyException in project collect by openforis.
the class DataLoader method processRow.
private void processRow(CollectRecord record, Record row) throws DataInconsistencyException {
Integer id = row.getValueAsInteger(DATA.ID);
Integer parentId = row.getValueAsInteger(DATA.PARENT_ID);
Integer defnId = row.getValueAsInteger(DATA.DEFINITION_ID);
Node<?> o;
if (parentId == null) {
// Process root entity
o = record.getRootEntity();
Integer rootEntityDefnId = o.getDefinition().getId();
if (!rootEntityDefnId.equals(defnId)) {
throw new DataInconsistencyException(DATA.DEFINITION_ID + " " + defnId + " does not match " + RECORD.ROOT_ENTITY_ID + " " + rootEntityDefnId);
}
} else {
// Process other objects
Node<? extends NodeDefinition> parent = objectsById.get(parentId);
if (parent == null) {
throw new DataInconsistencyException("Parent " + parentId + " not yet loaded");
}
if (!(parent instanceof Entity)) {
throw new DataInconsistencyException("Parent " + parentId + " not an entity");
}
NodeDefinition defn = record.getSurvey().getSchema().getById(defnId);
if (defn == null) {
throw new DataInconsistencyException("Unknown schema definition " + DATA.DEFINITION_ID);
}
NodeMapper mapper = NodeMapper.getInstance(defn.getClass());
Node<?> o1 = mapper.addNode(defn, row, (Entity) parent);
if (defn instanceof AttributeDefinition) {
String remarks = row.getValue(DATA.REMARKS);
String s = row.getValueAsString(DATA.SYMBOL);
Character symbol = null;
if (s != null && s.length() == 1) {
symbol = s.charAt(0);
}
Attribute<?, ?> attribute = (Attribute<?, ?>) o1;
attribute.setRemarks(remarks);
attribute.setSymbol(symbol);
}
o = o1;
}
objectsById.put(id, o);
}
Aggregations