use of org.openforis.collect.model.NameValueEntry in project collect by openforis.
the class DatabaseLookupProvider method lookupSamplingPointColumnValue.
private Object lookupSamplingPointColumnValue(Survey survey, String valueColumnName, String... keys) {
int maxKeys = SamplingDesignDao.LEVEL_CODE_FIELDS.length;
if (keys == null || keys.length == 0 || keys.length > maxKeys) {
throw new IllegalArgumentException(String.format("Invalid number of keys. It should be between 1 and %d", maxKeys));
}
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
addSurveyFilter(filters, survey);
String[] paddedKeys = Arrays.copyOf(keys, maxKeys);
for (int i = 0; i < paddedKeys.length; i++) {
String key = paddedKeys[i];
TableField<?, ?> keyField = SamplingDesignDao.LEVEL_CODE_FIELDS[i];
NameValueEntry filter = new NameValueEntry(keyField.getName(), key);
filters.add(filter);
}
Object value = loadValue(OfcSamplingDesign.OFC_SAMPLING_DESIGN.getName(), valueColumnName, filters.toArray(new NameValueEntry[filters.size()]));
return value;
}
use of org.openforis.collect.model.NameValueEntry in project collect by openforis.
the class DatabaseExternalCodeListProvider method createChildItemsFilters.
protected List<NameValueEntry> createChildItemsFilters(ExternalCodeListItem item) {
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
CodeList list = item.getCodeList();
Collection<NameValueEntry> parentKeys = getParentKeys(item);
filters.addAll(parentKeys);
addSurveyFilter(list, filters);
int itemLevel = item.getLevel();
int childrenLevel = itemLevel + 1;
String itemKeyColName = getLevelKeyColumnName(list, itemLevel);
filters.add(new NameValueEntry(itemKeyColName, item.getCode()));
List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, childrenLevel);
filters.addAll(emptyNextLevelsFilters);
return filters;
}
use of org.openforis.collect.model.NameValueEntry in project collect by openforis.
the class DatabaseExternalCodeListProvider method createEmptyNextLevelFilters.
protected List<NameValueEntry> createEmptyNextLevelFilters(CodeList list, int level) {
List<NameValueEntry> result = new ArrayList<NameValueEntry>();
List<CodeListLevel> hierarchy = list.getHierarchy();
for (int i = level; i < hierarchy.size(); i++) {
CodeListLevel codeListLevel = hierarchy.get(i);
String name = codeListLevel.getName();
result.add(new NameValueEntry(name, ""));
}
return result;
}
use of org.openforis.collect.model.NameValueEntry in project collect by openforis.
the class DatabaseExternalCodeListProvider method getParentItem.
public ExternalCodeListItem getParentItem(ExternalCodeListItem item) {
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
CodeList list = item.getCodeList();
Collection<NameValueEntry> parentKeys = getParentKeys(item);
filters.addAll(parentKeys);
addSurveyFilter(list, filters);
int level = parentKeys.size() + 1;
int parentLevel = level - 1;
List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, parentLevel);
filters.addAll(emptyNextLevelsFilters);
Map<String, String> row = dynamicTableDao.loadRow(list.getLookupTable(), filters.toArray(new NameValueEntry[0]));
return parseRow(row, list, parentLevel);
}
use of org.openforis.collect.model.NameValueEntry in project collect by openforis.
the class DatabaseExternalCodeListProvider method createSurveyFilter.
protected NameValueEntry createSurveyFilter(CodeList list) {
CollectSurvey survey = (CollectSurvey) list.getSurvey();
Integer surveyId = survey.getId();
if (surveyId != null) {
return new NameValueEntry(SURVEY_ID_FIELD, surveyId.toString());
} else {
return null;
}
}
Aggregations