use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueOptionsExist.
@Test
void testValidateDataValueOptionsExist() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
valueContext.getDataElement().setOptionSet(new OptionSet());
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7621, "Data value is not a valid option of the data element option set: `<object1>`", context, dataValue.getDataElement());
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class TrackedEntityAttributeServiceTest method successWhenTeaOptionValueIsValid.
@Test
void successWhenTeaOptionValueIsValid() {
tea.setUid("uid");
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(null, option, option1));
tea.setOptionSet(optionSet);
assertNull(trackedEntityAttributeService.validateValueType(tea, "CODE"));
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class DefaultCsvImportService method setOptionSetsFromCsv.
/**
* Option set format:
* <p>
* <ul>
* <li>option set name</li>
* <li>option set uid</li>
* <li>option set code</li>
* <li>option name</li>
* <li>option uid</li>
* <li>option code</li>
* </ul>
*/
private void setOptionSetsFromCsv(CsvReader reader, Metadata metadata) throws IOException {
ListMap<String, Option> nameOptionMap = new ListMap<>();
Map<String, OptionSet> nameOptionSetMap = new HashMap<>();
List<Option> options = new ArrayList<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
OptionSet optionSet = new OptionSet();
setIdentifiableObject(optionSet, values);
optionSet.setAutoFields();
optionSet.setValueType(ValueType.TEXT);
Option option = new Option();
option.setName(getSafe(values, 3, 230));
option.setUid(getSafe(values, 4, CodeGenerator.generateUid(), 11));
option.setCode(getSafe(values, 5, 50));
option.setAutoFields();
if (optionSet.getName() == null || option.getCode() == null) {
continue;
}
nameOptionSetMap.put(optionSet.getName(), optionSet);
nameOptionMap.putValue(optionSet.getName(), option);
options.add(option);
}
}
for (Entry<String, OptionSet> optionSetEntry : nameOptionSetMap.entrySet()) {
optionSetEntry.getValue().setOptions(new ArrayList<>(nameOptionMap.get(optionSetEntry.getKey())));
}
metadata.setOptions(options);
metadata.setOptionSets(new ArrayList<>(nameOptionSetMap.values()));
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class DefaultCsvImportService method setOptionGroupSetFromCsv.
/**
* Option group set format:
* <p>
* <ul>
* <li>option group set name</li>
* <li>option group set uid</li>
* <li>option group set code</li>
* <li>option group set description</li>
* <li>data dimension</li>
* <li>option set uid</li>
* <li>option set code</li>
* </ul>
*/
private List<OptionGroupSet> setOptionGroupSetFromCsv(CsvReader reader) throws IOException {
List<OptionGroupSet> optionGroupSets = new ArrayList<>();
Map<String, OptionSet> mapOptionSet = new HashMap<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
OptionGroupSet optionGroupSet = new OptionGroupSet();
optionGroupSet.setAutoFields();
setIdentifiableObject(optionGroupSet, values);
optionGroupSet.setDescription(getSafe(values, 4));
optionGroupSet.setDataDimension(// boolean
Boolean.parseBoolean(getSafe(values, 3, Boolean.FALSE.toString(), 40)));
OptionSet optionSet = new OptionSet();
optionSet.setUid(getSafe(values, 5, 11));
optionSet.setCode(getSafe(values, 6, 50));
if (optionSet.getUid() == null && optionSet.getCode() == null) {
continue;
}
OptionSet persistedOptionSet = optionSet.getUid() != null ? mapOptionSet.computeIfAbsent(optionSet.getUid(), key -> optionService.getOptionSet(optionSet.getUid())) : mapOptionSet.computeIfAbsent(optionSet.getCode(), key -> optionService.getOptionSetByCode(optionSet.getCode()));
if (persistedOptionSet == null) {
continue;
}
optionGroupSet.setOptionSet(optionSet);
optionGroupSets.add(optionGroupSet);
}
}
return optionGroupSets;
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class OptionObjectBundleHook method validate.
@Override
public void validate(Option option, ObjectBundle bundle, Consumer<ErrorReport> addReports) {
if (option.getOptionSet() != null) {
OptionSet optionSet = bundle.getPreheat().get(bundle.getPreheatIdentifier(), OptionSet.class, option.getOptionSet());
checkDuplicateOption(optionSet, option, addReports);
}
}
Aggregations