use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class HideOptionProgramRuleActionValidator method validate.
@Override
public ProgramRuleActionValidationResult validate(ProgramRuleAction programRuleAction, ProgramRuleActionValidationContext validationContext) {
// First checking the validity of DataElement and TEA
ProgramRuleActionValidationResult result = super.validate(programRuleAction, validationContext);
ProgramRule rule = validationContext.getProgramRule();
if (!result.isValid()) {
return result;
}
if (!programRuleAction.hasOption()) {
log.debug(String.format("Option cannot be null for program rule: %s ", rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4040, rule.getName())).build();
}
Option option = validationContext.getOption();
if (option == null) {
log.debug(String.format("Option %s associated with program rule %s does not exist", programRuleAction.getOption().getUid(), rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4041, programRuleAction.getOption().getUid(), rule.getName())).build();
}
return ProgramRuleActionValidationResult.builder().valid(true).build();
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class OptionObjectBundleHookTest method validate.
@Test
void validate() {
OptionSet optionSet = new OptionSet();
optionSet.setUid("optionSet1");
Option option = new Option();
option.setName("optionName");
option.setCode("optionCode");
optionSet.addOption(option);
OptionSet persistedOptionSet = new OptionSet();
persistedOptionSet.setUid("optionSet1");
Option persistedOption = new Option();
persistedOption.setName("optionName");
persistedOption.setCode("optionCode");
persistedOptionSet.addOption(persistedOption);
preheat.put(PreheatIdentifier.UID, persistedOptionSet);
ObjectBundleParams objectBundleParams = new ObjectBundleParams();
objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.singletonMap(OptionSet.class, Collections.singletonList(persistedOptionSet)));
List<ErrorReport> errors = hook.validate(option, bundle);
Assertions.assertNotNull(errors);
Assertions.assertEquals(1, errors.size());
Assertions.assertEquals(ErrorCode.E4028, errors.get(0).getErrorCode());
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class CsvMetadataImportTest method testOptionSetMergeDuplicate.
@Test
void testOptionSetMergeDuplicate() throws IOException {
// Import 1 OptionSet with 3 Options
ImportReport importReport = runImport("metadata/optionSet_add.csv", CsvImportClass.OPTION_SET);
assertEquals(4, importReport.getStats().getCreated());
// Send payload with 5 Options, 2 new and 3 old from above
importReport = runImport("metadata/optionSet_update_duplicate.csv", CsvImportClass.OPTION_SET, null, params -> {
params.setIdentifier(PreheatIdentifier.CODE);
params.setMergeMode(MergeMode.MERGE);
});
// Only 2 new Options are added
assertEquals(2, importReport.getStats().getCreated());
OptionSet optionSet = optionService.getOptionSetByCode("COLOR");
// Total 5 Options added
List<Option> options = optionSet.getOptions();
assertEquals(5, options.size());
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DefaultMetadataExportServiceTest method getParamsFromMapNoSecondary.
@Test
void getParamsFromMapNoSecondary() {
Mockito.when(schemaService.getSchemaByPluralName(Mockito.eq("options"))).thenReturn(new Schema(Option.class, "option", "options"));
final Map<String, List<String>> params = new HashMap<>();
params.put("options", Collections.singletonList("true"));
MetadataExportParams exportParams = service.getParamsFromMap(params);
Assertions.assertFalse(exportParams.getClasses().contains(JobConfiguration.class));
Assertions.assertTrue(exportParams.getClasses().contains(Option.class));
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class VersionedObjectObjectBundleHook method postCreate.
@Override
public <T extends IdentifiableObject> void postCreate(T persistedObject, ObjectBundle bundle) {
VersionedObject versionedObject = null;
if (Section.class.isInstance(persistedObject)) {
versionedObject = ((Section) persistedObject).getDataSet();
} else if (Option.class.isInstance(persistedObject)) {
versionedObject = ((Option) persistedObject).getOptionSet();
}
if (versionedObject != null) {
versionedObject.increaseVersion();
sessionFactory.getCurrentSession().save(versionedObject);
}
}
Aggregations