public OptionSet getOptionSet(org.hisp.dhis.dataelement.DataElement dataElement) { org.hisp.dhis.option.OptionSet dhisOptionSet = dataElement.getOptionSet(); OptionSet mobileOptionSet = new OptionSet(); if (dhisOptionSet != null) { mobileOptionSet.setId(dhisOptionSet.getId()); mobileOptionSet.setName(dhisOptionSet.getName()); mobileOptionSet.setOptions(dhisOptionSet.getOptions()); } else { return null; } return mobileOptionSet; }
@Override public String execute() throws Exception { OptionSet optionSet = optionService.getOptionSet(optionSetId); valueType = optionSet != null && optionSet.getValueType() != null ? optionSet.getValueType() : valueType; TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute(id); trackedEntityAttribute.setName(StringUtils.trimToNull(name)); trackedEntityAttribute.setShortName(StringUtils.trimToNull(shortName)); trackedEntityAttribute.setCode(StringUtils.trimToNull(code)); trackedEntityAttribute.setDescription(StringUtils.trimToNull(description)); trackedEntityAttribute.setValueType(valueType); trackedEntityAttribute.setAggregationType(AggregationType.fromValue(aggregationType)); trackedEntityAttribute.setExpression(expression); trackedEntityAttribute.setDisplayOnVisitSchedule(false); trackedEntityAttribute.setOptionSet(optionSet); unique = unique != null; trackedEntityAttribute.setUnique(unique); inherit = inherit != null; trackedEntityAttribute.setInherit(inherit); confidential = confidential != null; trackedEntityAttribute.setConfidential(confidential); if (unique) { boolean orgunitScope = false; boolean programScope = false; if (Objects.equals(scope, SCOPE_ORGUNIT) || Objects.equals(scope, SCOPE_PROGRAM_IN_ORGUNIT)) { orgunitScope = true; } if (Objects.equals(scope, SCOPE_PROGRAM) || Objects.equals(scope, SCOPE_PROGRAM_IN_ORGUNIT)) { programScope = true; } trackedEntityAttribute.setOrgunitScope(orgunitScope); trackedEntityAttribute.setProgramScope(programScope); } else if (ValueType.TRACKER_ASSOCIATE == valueType) { trackedEntityAttribute.setTrackedEntity( trackedEntityService.getTrackedEntity(trackedEntityId)); } if (legendSetId != null) { trackedEntityAttribute.setLegendSet(legendService.getLegendSet(legendSetId)); } if (jsonAttributeValues != null) { AttributeUtils.updateAttributeValuesFromJson( trackedEntityAttribute.getAttributeValues(), jsonAttributeValues, attributeService); } trackedEntityAttributeService.updateTrackedEntityAttribute(trackedEntityAttribute); return SUCCESS; }