use of org.openforis.idm.model.Value in project collect by openforis.
the class AttributeAddRequestProxy method toAttributeUpdateRequest.
@Override
public AttributeAddRequest<?> toAttributeUpdateRequest(CodeListManager codeListManager, RecordSessionManager sessionManager, CollectRecord record) {
Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
AttributeAddRequest<Value> result = new NodeUpdateRequest.AttributeAddRequest<Value>();
result.setParentEntity(parentEntity);
result.setNodeName(nodeName);
result.setRemarks(remarks);
result.setSymbol(symbol);
if (value != null) {
Value parsedValue = parseCompositeAttributeValue(codeListManager, parentEntity, nodeName, value);
result.setValue(parsedValue);
}
return result;
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class CSVDataImportProcess method validateRecordKey.
private boolean validateRecordKey(DataLine line) {
long currentRowNumber = line.getLineNumber();
EntityDefinition parentEntityDefn = getParentEntityDefinition();
EntityDefinition rootEntityDefn = parentEntityDefn.getRootEntity();
Value[] recordKeyValues = line.getRecordKeyValues(rootEntityDefn);
String[] recordKeyStringValues = Values.toStringValues(recordKeyValues);
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefn.getId());
filter.setKeyValues(recordKeyStringValues);
List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
String[] recordKeyColumnNames = DataCSVReader.getKeyAttributeColumnNames(parentEntityDefn, rootEntityDefn.getKeyAttributeDefinitions());
String errorMessageKey = null;
if (settings.isInsertNewRecords()) {
if (!recordSummaries.isEmpty()) {
errorMessageKey = ONLY_NEW_RECORDS_ALLOWED_MESSAGE_KEY;
}
} else if (recordSummaries.isEmpty() && settings.isReportNoRecordFoundErrors()) {
errorMessageKey = NO_RECORD_FOUND_ERROR_MESSAGE_KEY;
} else if (recordSummaries.size() > 1) {
errorMessageKey = MULTIPLE_RECORDS_FOUND_ERROR_MESSAGE_KEY;
}
if (errorMessageKey == null) {
return true;
} else {
ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, currentRowNumber, recordKeyColumnNames, errorMessageKey);
parsingError.setMessageArgs(new String[] { StringUtils.join(recordKeyStringValues) });
status.addParsingError(currentRowNumber, parsingError);
return false;
}
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class CSVDataImportProcess method createChildEntity.
private Entity createChildEntity(Entity currentParent, String childName, EntityIdentifier<?> identifier, Map<FieldValueKey, String> colNamesByField, long row) {
if (identifier instanceof EntityPositionIdentifier) {
int position = ((EntityPositionIdentifier) identifier).getPosition();
if (position == currentParent.getCount(childName) + 1) {
Entity entity = (Entity) performNodeAdd(currentParent, childName);
return entity;
} else {
throw new IllegalArgumentException(String.format("Trying to create child in a invalid position: row=%d path=%s[%d]", row, currentParent.getPath() + "/" + childName, position));
}
} else {
Entity entity = (Entity) performNodeAdd(currentParent, childName);
Value[] keyValues = ((EntityKeysIdentifier) identifier).getKeyValues();
setKeyValues(entity, keyValues, colNamesByField, row);
return entity;
}
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class CSVDataImportProcess method loadRecordSummaryIfAny.
private CollectRecordSummary loadRecordSummaryIfAny(DataLine line) {
EntityDefinition parentEntityDefn = getParentEntityDefinition();
EntityDefinition rootEntityDefn = parentEntityDefn.getRootEntity();
Value[] recordKeyValues = line.getRecordKeyValues(rootEntityDefn);
CollectRecordSummary recordSummary = recordManager.loadUniqueRecordSummaryByKeys(survey, rootEntityDefn.getName(), Values.toStringValues(recordKeyValues));
return recordSummary;
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class CSVDataImportProcess method findChildEntities.
private List<Entity> findChildEntities(Entity currentParent, String childName, EntityIdentifier<?> identifier) {
if (identifier instanceof EntityPositionIdentifier) {
int position = ((EntityPositionIdentifier) identifier).getPosition();
if (currentParent.getCount(childName) >= position) {
ArrayList<Entity> result = new ArrayList<Entity>();
Entity child = (Entity) currentParent.getChild(childName, position - 1);
result.add(child);
return result;
} else {
return Collections.emptyList();
}
} else {
EntityDefinition parentDefn = currentParent.getDefinition();
EntityDefinition childDefn = parentDefn.getChildDefinition(childName, EntityDefinition.class);
Value[] keyValues = ((EntityKeysIdentifier) identifier).getKeyValues();
return currentParent.findChildEntitiesByKeys(childDefn, keyValues);
}
}
Aggregations