Search in sources :

Example 6 with NameValueEntry

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;
}
Also used : ArrayList(java.util.ArrayList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 7 with NameValueEntry

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ArrayList(java.util.ArrayList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 8 with NameValueEntry

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;
}
Also used : CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) ArrayList(java.util.ArrayList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 9 with NameValueEntry

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);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ArrayList(java.util.ArrayList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 10 with NameValueEntry

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;
    }
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Aggregations

NameValueEntry (org.openforis.collect.model.NameValueEntry)16 ArrayList (java.util.ArrayList)8 CodeList (org.openforis.idm.metamodel.CodeList)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Condition (org.jooq.Condition)1 TableField (org.jooq.TableField)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 LookupRecord (org.openforis.collect.persistence.jooq.tables.records.LookupRecord)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CodeListLevel (org.openforis.idm.metamodel.CodeListLevel)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1