use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DataDimensionExtractor method getBaseDimensionalItemObject.
private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
BaseDimensionalItemObject dimensionalItemObject = null;
switch(id.getDimensionItemType()) {
case DATA_ELEMENT:
DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
if (dataElement != null) {
dimensionalItemObject = cloneIfNeeded(dataElement, id);
}
break;
case INDICATOR:
final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
if (indicator != null) {
dimensionalItemObject = cloneIfNeeded(indicator, id);
}
break;
case DATA_ELEMENT_OPERAND:
dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
}
break;
case REPORTING_RATE:
final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
if (dataSet != null) {
dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
}
break;
case PROGRAM_DATA_ELEMENT:
Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
if (program != null && dataElement != null) {
dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
}
break;
case PROGRAM_ATTRIBUTE:
program = (Program) atomicObjects.getValue(Program.class, id.getId0());
final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
if (program != null && attribute != null) {
dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
}
break;
case PROGRAM_INDICATOR:
final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
if (programIndicator != null) {
dimensionalItemObject = cloneIfNeeded(programIndicator, id);
}
break;
default:
log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
break;
}
return dimensionalItemObject;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultDimensionService method getDataElementOperand.
/**
* Returns a {@link DataElementOperand}. For identifier wild cards
* {@link ExpressionService#SYMBOL_WILDCARD}, the relevant property will be
* null.
*
* @param idScheme the identifier scheme.
* @param dataElementId the data element identifier.
* @param categoryOptionComboId the category option combo identifier.
*/
private DataElementOperand getDataElementOperand(IdScheme idScheme, String dataElementId, String categoryOptionComboId, String attributeOptionComboId) {
DataElement dataElement = idObjectManager.getObject(DataElement.class, idScheme, dataElementId);
CategoryOptionCombo categoryOptionCombo = idObjectManager.getObject(CategoryOptionCombo.class, idScheme, categoryOptionComboId);
CategoryOptionCombo attributeOptionCombo = idObjectManager.getObject(CategoryOptionCombo.class, idScheme, attributeOptionComboId);
if (dataElement == null || (categoryOptionCombo == null && !SYMBOL_WILDCARD.equals(categoryOptionComboId))) {
return null;
}
return new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class HibernateDataValueAuditStore method getDataValueAudits.
@Override
public List<DataValueAudit> getDataValueAudits(List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, CategoryOptionCombo categoryOptionCombo, CategoryOptionCombo attributeOptionCombo, AuditType auditType) {
CriteriaBuilder builder = getSession().getCriteriaBuilder();
List<Function<Root<DataValueAudit>, Predicate>> predicates = getDataValueAuditPredicates(builder, dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
if (!predicates.isEmpty()) {
return getList(builder, newJpaParameters().addPredicate(root -> builder.and(predicates.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[predicates.size()]))).addOrder(root -> builder.desc(root.get("created"))));
} else {
return new ArrayList<>();
}
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultAggregateAccessManager method canRead.
// ---------------------------------------------------------------------
// AggregateAccessManager implementation
// ---------------------------------------------------------------------
@Override
public List<String> canRead(User user, DataValue dataValue) {
List<String> errors = new ArrayList<>();
if (user == null || user.isSuper()) {
return errors;
}
Set<CategoryOption> options = new HashSet<>();
CategoryOptionCombo categoryOptionCombo = dataValue.getCategoryOptionCombo();
if (categoryOptionCombo != null) {
options.addAll(categoryOptionCombo.getCategoryOptions());
}
CategoryOptionCombo attributeOptionCombo = dataValue.getAttributeOptionCombo();
if (attributeOptionCombo != null) {
options.addAll(attributeOptionCombo.getCategoryOptions());
}
options.forEach(option -> {
if (!aclService.canDataRead(user, option)) {
errors.add("User has no data read access for CategoryOption: " + option.getUid());
}
});
return errors;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class HibernateCompleteDataSetRegistrationStore method getCompleteDataSetRegistration.
@Override
public CompleteDataSetRegistration getCompleteDataSetRegistration(DataSet dataSet, Period period, OrganisationUnit source, CategoryOptionCombo attributeOptionCombo) {
Period storedPeriod = periodStore.reloadPeriod(period);
if (storedPeriod == null) {
return null;
}
CriteriaBuilder builder = getCriteriaBuilder();
return getSingleResult(builder, newJpaParameters().addPredicate(root -> builder.equal(root, new CompleteDataSetRegistration(dataSet, storedPeriod, source, attributeOptionCombo))));
}
Aggregations