Search in sources :

Example 11 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class SurveyViewGenerator method createCodeListItemView.

private CodeListItemView createCodeListItemView(CodeListItem item) {
    CodeListService service = item.getSurvey().getContext().getCodeListService();
    CodeListItemView itemView = new CodeListItemView();
    itemView.id = item.getId();
    itemView.code = item.getCode();
    itemView.label = item.getLabel(languageCode);
    itemView.color = item.getColor();
    List<CodeListItemView> childItemsView = new ArrayList<CodeListItemView>();
    List<CodeListItem> childItems = service.loadChildItems(item);
    for (CodeListItem childItem : childItems) {
        childItemsView.add(createCodeListItemView(childItem));
    }
    itemView.items.addAll(childItemsView);
    return itemView;
}
Also used : ArrayList(java.util.ArrayList) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 12 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class CSVValueFormatter method format.

public String format(AttributeDefinition defn, Value value) {
    if (value == null) {
        return "";
    } else if (value instanceof BooleanValue) {
        return ((BooleanValue) value).getValue().toString();
    } else if (value instanceof Code) {
        CodeListService codeListService = defn.getSurvey().getContext().getCodeListService();
        CodeList list = ((CodeAttributeDefinition) defn).getList();
        if (codeListService.hasQualifiableItems(list)) {
            return String.format("%s: %s", ((Code) value).getCode(), ((Code) value).getQualifier());
        } else {
            return ((Code) value).getCode();
        }
    } else if (value instanceof Coordinate) {
        return value.toString();
    } else if (value instanceof Date) {
        Date date = (Date) value;
        return String.format("%d/%d/%d", ((Date) value).getDay(), ((Date) value).getMonth(), date.getYear());
    } else if (value instanceof File) {
        return ((File) value).getFilename();
    } else if (value instanceof NumberValue) {
        Number val = ((NumberValue<?>) value).getValue();
        NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
        String formattedVal = numberFormat.format(val);
        return formattedVal;
    } else if (value instanceof NumericRange) {
        Number from = ((NumericRange<?>) value).getFrom();
        Number to = ((NumericRange<?>) value).getFrom();
        String format;
        if (value instanceof IntegerRange) {
            format = "%d-%d";
        } else {
            format = "%f-%f";
        }
        String formattedValue = String.format(Locale.ENGLISH, format, from, to);
        return formattedValue;
    } else if (value instanceof TextValue) {
        return ((TextValue) value).getValue();
    } else if (value instanceof Time) {
        Time time = (Time) value;
        return String.format("%d:%d", time.getHour(), time.getMinute());
    } else
        throw new IllegalArgumentException("Unsupported attribute value type: " + value.getClass().getName());
}
Also used : IntegerRange(org.openforis.idm.model.IntegerRange) CodeListService(org.openforis.idm.metamodel.CodeListService) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date) NumericRange(org.openforis.idm.model.NumericRange) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Coordinate(org.openforis.idm.model.Coordinate) NumberValue(org.openforis.idm.model.NumberValue) TextValue(org.openforis.idm.model.TextValue) BooleanValue(org.openforis.idm.model.BooleanValue) File(org.openforis.idm.model.File) NumberFormat(java.text.NumberFormat)

Example 13 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class CodeColumnProvider method getCodeListService.

private CodeListService getCodeListService() {
    SurveyContext context = attributeDefinition.getSurvey().getContext();
    CodeListService codeListService = context.getCodeListService();
    return codeListService;
}
Also used : CodeListService(org.openforis.idm.metamodel.CodeListService) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 14 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class EnumerableEntityColumnProvider method createProviders.

private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition defn) {
    List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
    List<AttributeDefinition> keyDefs = defn.getKeyAttributeDefinitions();
    CodeAttributeDefinition keyDef = (CodeAttributeDefinition) keyDefs.get(0);
    CodeList codeList = keyDef.getList();
    SurveyContext context = defn.getSurvey().getContext();
    CodeListService codeListService = context.getCodeListService();
    List<CodeListItem> items = codeListService.loadRootItems(codeList);
    for (CodeListItem item : items) {
        String code = item.getCode();
        String keyName = keyDef.getName();
        EnumeratedCodeItemColumnProvider p = new EnumeratedCodeItemColumnProvider(config, defn, keyName, code);
        providers.add(p);
    }
    return providers;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) SurveyContext(org.openforis.idm.metamodel.SurveyContext) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 15 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class CodeAttributeProxy method getCodeListItem.

@ExternalizedProperty
public CodeListItemProxy getCodeListItem() {
    if (isEnumerator()) {
        CodeListService codeListManager = getCodeListService();
        CodeListItem codeListItem = codeListManager.loadItem(codeAttribute);
        return codeListItem == null ? null : new CodeListItemProxy(codeListItem);
    } else {
        return null;
    }
}
Also used : CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Aggregations

CodeListService (org.openforis.idm.metamodel.CodeListService)19 CodeListItem (org.openforis.idm.metamodel.CodeListItem)13 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)8 CodeList (org.openforis.idm.metamodel.CodeList)8 SurveyContext (org.openforis.idm.metamodel.SurveyContext)6 ArrayList (java.util.ArrayList)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 HashMap (java.util.HashMap)2 List (java.util.List)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 Survey (org.openforis.idm.metamodel.Survey)2 Code (org.openforis.idm.model.Code)2 NumberValue (org.openforis.idm.model.NumberValue)2 IOException (java.io.IOException)1 NumberFormat (java.text.NumberFormat)1 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)1 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1