use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeIsSetToUidForDataValueSet.
@Test
void testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeIsSetToUidForDataValueSet() {
// Given
final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
final OrganisationUnit orUnitStub = stubOrgUnit();
final Period periodStub = stubPeriod();
final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
theDataQueryParams.setOutputDataElementIdScheme(UID);
// When
final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
// Then
final String orgUnitUid = orUnitStub.getUid();
final String periodIsoDate = periodStub.getIsoDate();
final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
assertThat(responseMap.get(orgUnitUid), is(equalTo(orUnitStub.getUid())));
assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getUid())));
assertThat(responseMap.get(dataElementA.getUid()), is(emptyOrNullString()));
assertThat(responseMap.get(dataElementB.getUid()), is(emptyOrNullString()));
assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputDataElementAndOrgUnitIdSchemeOverrideOutputOrgUnitIdSchemeForDataValueSet.
@Test
void testGetSchemeIdResponseMapWhenOutputDataElementAndOrgUnitIdSchemeOverrideOutputOrgUnitIdSchemeForDataValueSet() {
// Given
final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
final OrganisationUnit orUnitStub = stubOrgUnit();
final Period periodStub = stubPeriod();
final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
theDataQueryParams.setOutputIdScheme(NAME);
// Overriding output id schema and setting CODE for Data
// Element/Operands
theDataQueryParams.setOutputDataElementIdScheme(CODE);
// Overriding output id schema and setting ID for Org Unit
theDataQueryParams.setOutputOrgUnitIdScheme(ID);
// When
final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
// Then
final String orgUnitUid = orUnitStub.getUid();
final String periodIsoDate = periodStub.getIsoDate();
final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
assertThat(responseMap.get(orgUnitUid), is(equalTo(valueOf(orUnitStub.getId()))));
assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getName())));
assertThat(responseMap.get(dataElementA.getUid()), is(equalTo(dataElementA.getCode())));
assertThat(responseMap.get(dataElementB.getUid()), is(equalTo(dataElementB.getCode())));
assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataSetDeletionHandler method deleteDataElement.
private void deleteDataElement(DataElement dataElement) {
Iterator<DataSetElement> elements = dataElement.getDataSetElements().iterator();
while (elements.hasNext()) {
DataSetElement element = elements.next();
elements.remove();
dataElement.removeDataSetElement(element);
idObjectManager.updateNoAcl(element.getDataSet());
}
List<DataSet> dataSets = idObjectManager.getAllNoAcl(DataSet.class);
for (DataSet dataSet : dataSets) {
boolean update = false;
Iterator<DataElementOperand> operands = dataSet.getCompulsoryDataElementOperands().iterator();
while (operands.hasNext()) {
DataElementOperand operand = operands.next();
if (operand.getDataElement().equals(dataElement)) {
operands.remove();
update = true;
}
}
if (update) {
idObjectManager.updateNoAcl(dataSet);
}
}
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationService method getMissingCompulsoryFields.
@Override
@Transactional(readOnly = true)
public List<DataElementOperand> getMissingCompulsoryFields(DataSet dataSet, Period period, OrganisationUnit organisationUnit, CategoryOptionCombo attributeOptionCombo) {
List<DataElementOperand> missingDataElementOperands = new ArrayList<>();
if (!dataSet.getCompulsoryDataElementOperands().isEmpty()) {
DataExportParams params = new DataExportParams();
params.setDataElementOperands(dataSet.getCompulsoryDataElementOperands());
params.setPeriods(Sets.newHashSet(period));
params.setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo));
params.setOrganisationUnits(Sets.newHashSet(organisationUnit));
List<DeflatedDataValue> deflatedDataValues = dataValueService.getDeflatedDataValues(params);
MapMapMap<Long, Long, Long, Boolean> dataPresent = new MapMapMap<>();
for (DeflatedDataValue dv : deflatedDataValues) {
dataPresent.putEntry(dv.getSourceId(), dv.getDataElementId(), dv.getCategoryOptionComboId(), true);
}
User currentUser = currentUserService.getCurrentUser();
for (DataElementOperand deo : dataSet.getCompulsoryDataElementOperands()) {
List<String> errors = accessManager.canWrite(currentUser, deo);
if (!errors.isEmpty()) {
continue;
}
MapMap<Long, Long, Boolean> ouDataPresent = dataPresent.get(organisationUnit.getId());
if (ouDataPresent != null) {
Map<Long, Boolean> deDataPresent = ouDataPresent.get(deo.getDataElement().getId());
if (deDataPresent != null && (deo.getCategoryOptionCombo() == null || deDataPresent.get(deo.getCategoryOptionCombo().getId()) != null)) {
continue;
}
}
missingDataElementOperands.add(deo);
}
}
return missingDataElementOperands;
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DefaultPreheatService method collectReferences.
@SuppressWarnings("unchecked")
private Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> collectReferences(Map<Class<?>, List<?>> objects) {
Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> map = new HashMap<>();
map.put(PreheatIdentifier.UID, new HashMap<>());
map.put(PreheatIdentifier.CODE, new HashMap<>());
Map<Class<? extends IdentifiableObject>, Set<String>> uidMap = map.get(PreheatIdentifier.UID);
Map<Class<? extends IdentifiableObject>, Set<String>> codeMap = map.get(PreheatIdentifier.CODE);
if (objects.isEmpty()) {
return map;
}
// Clone objects list, we don't want to modify it
Map<Class<?>, List<?>> targets = new HashMap<>(objects);
collectScanTargets(targets);
for (Class<?> klass : targets.keySet()) {
Schema schema = schemaService.getDynamicSchema(klass);
List<Property> referenceProperties = schema.getProperties().stream().filter(p -> p.isPersisted() && p.isOwner() && (PropertyType.REFERENCE == p.getPropertyType() || PropertyType.REFERENCE == p.getItemPropertyType())).collect(Collectors.toList());
for (Object object : targets.get(klass)) {
if (schema.isIdentifiableObject()) {
IdentifiableObject identifiableObject = (IdentifiableObject) object;
identifiableObject.getAttributeValues().forEach(av -> addIdentifiers(map, av.getAttribute()));
identifiableObject.getSharing().getUserGroups().values().forEach(uga -> addIdentifiers(map, uga.toDtoObject().getUserGroup()));
identifiableObject.getSharing().getUsers().values().forEach(ua -> addIdentifiers(map, ua.toDtoObject().getUser()));
if (identifiableObject.getCreatedBy() != null) {
addIdentifiers(map, identifiableObject.getCreatedBy());
}
addIdentifiers(map, identifiableObject);
}
referenceProperties.forEach(p -> {
if (!p.isCollection()) {
Class<? extends IdentifiableObject> itemKlass = (Class<? extends IdentifiableObject>) p.getKlass();
if (!uidMap.containsKey(itemKlass))
uidMap.put(itemKlass, new HashSet<>());
if (!codeMap.containsKey(itemKlass))
codeMap.put(itemKlass, new HashSet<>());
Object reference = ReflectionUtils.invokeMethod(object, p.getGetterMethod());
if (reference != null) {
IdentifiableObject identifiableObject = (IdentifiableObject) reference;
addIdentifiers(map, identifiableObject);
}
} else {
Collection<IdentifiableObject> reference = ReflectionUtils.invokeMethod(object, p.getGetterMethod());
reference.forEach(identifiableObject -> addIdentifiers(map, identifiableObject));
if (DataElementOperand.class.isAssignableFrom(p.getItemKlass())) {
CollectionUtils.nullSafeForEach(reference, identifiableObject -> {
DataElementOperand dataElementOperand = (DataElementOperand) identifiableObject;
addIdentifiers(map, dataElementOperand.getDataElement());
addIdentifiers(map, dataElementOperand.getCategoryOptionCombo());
});
}
}
});
collectAnalyticalObjectReferences(map, object);
}
}
cleanEmptyEntries(uidMap);
cleanEmptyEntries(codeMap);
return map;
}
Aggregations