use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class AttributeOptionComboDateCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
CategoryOptionCombo attributeOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
Date executionDate = null;
if (event.getEventDate() != null) {
executionDate = DateUtils.parseDate(event.getEventDate());
}
Date dueDate = new Date();
if (event.getDueDate() != null) {
dueDate = DateUtils.parseDate(event.getDueDate());
}
Date eventDate = executionDate != null ? executionDate : dueDate;
if (eventDate == null) {
return error("Event date can not be empty", event.getEvent());
}
Program program = ctx.getProgramsMap().get(event.getProgram());
for (CategoryOption categoryOption : attributeOptionCombo.getCategoryOptions()) {
if (categoryOption.getStartDate() != null && eventDate.compareTo(categoryOption.getStartDate()) < 0) {
return error("Event date " + getMediumDateString(eventDate) + " is before start date " + getMediumDateString(categoryOption.getStartDate()) + " for attributeOption '" + categoryOption.getName() + "'", event.getEvent());
}
if (categoryOption.getEndDate() != null && eventDate.compareTo(categoryOption.getAdjustedEndDate(program)) > 0) {
return error("Event date " + getMediumDateString(eventDate) + " is after end date " + getMediumDateString(categoryOption.getAdjustedEndDate(program)) + " for attributeOption '" + categoryOption.getName() + "' in program '" + program.getName() + "'", event.getEvent());
}
}
return success();
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultAclService method checkOptionComboSharingPermission.
private boolean checkOptionComboSharingPermission(User user, IdentifiableObject object, Permission permission) {
CategoryOptionCombo optionCombo = (CategoryOptionCombo) object;
if (optionCombo.isDefault() || optionCombo.getCategoryOptions().isEmpty()) {
return true;
}
List<Long> accessibleOptions = new ArrayList<>();
for (CategoryOption option : optionCombo.getCategoryOptions()) {
if (checkSharingPermission(user, option, permission)) {
accessibleOptions.add(option.getId());
}
}
return accessibleOptions.size() == optionCombo.getCategoryOptions().size();
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DataSetOrganisationUnitCategoryResourceTable method getPopulateTempTableContent.
/**
* Iterate over data sets and associated organisation units. If data set has
* a category combination and the organisation unit has category options,
* find the intersection of the category option combinations linked to the
* organisation unit through its category options, and the category option
* combinations linked to the data set through its category combination. If
* not, use the default category option combo.
*/
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
List<Object[]> batchArgs = new ArrayList<>();
for (DataSet dataSet : objects) {
CategoryCombo categoryCombo = dataSet.getCategoryCombo();
for (OrganisationUnit orgUnit : dataSet.getSources()) {
if (!categoryCombo.isDefault()) {
if (orgUnit.hasCategoryOptions()) {
Set<CategoryOption> orgUnitOptions = orgUnit.getCategoryOptions();
for (CategoryOptionCombo optionCombo : categoryCombo.getOptionCombos()) {
Set<CategoryOption> optionComboOptions = optionCombo.getCategoryOptions();
if (orgUnitOptions.containsAll(optionComboOptions)) {
Date startDate = DateUtils.min(optionComboOptions.stream().map(co -> co.getStartDate()).collect(Collectors.toSet()));
Date endDate = DateUtils.max(optionComboOptions.stream().map(co -> co.getAdjustedEndDate(dataSet)).collect(Collectors.toSet()));
List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), optionCombo.getId(), startDate, endDate);
batchArgs.add(values.toArray());
}
}
}
} else {
List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), defaultOptionCombo.getId(), null, null);
batchArgs.add(values.toArray());
}
}
}
return Optional.of(batchArgs);
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultDataApprovalLevelService method getLowestDataApprovalLevel.
@Override
@Transactional(readOnly = true)
public DataApprovalLevel getLowestDataApprovalLevel(OrganisationUnit orgUnit, CategoryOptionCombo attributeOptionCombo) {
Set<CategoryOptionGroupSet> cogSets = null;
if (attributeOptionCombo != null && attributeOptionCombo != categoryService.getDefaultCategoryOptionCombo()) {
cogSets = new HashSet<>();
for (CategoryOption option : attributeOptionCombo.getCategoryOptions()) {
if (option.getGroupSets() != null) {
cogSets.addAll(option.getGroupSets());
}
}
}
int orgUnitLevel = orgUnit.getLevel();
List<DataApprovalLevel> approvalLevels = getDataApprovalLevelsByOrgUnitLevel(orgUnitLevel);
for (DataApprovalLevel level : Lists.reverse(approvalLevels)) {
if (level.getCategoryOptionGroupSet() == null) {
if (cogSets == null) {
return level;
}
} else if (cogSets != null && cogSets.contains(level.getCategoryOptionGroupSet())) {
return level;
}
}
return null;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultCategoryService method getCoDimensionConstraints.
@Override
@Transactional(readOnly = true)
public Set<CategoryOption> getCoDimensionConstraints(User user) {
Set<CategoryOption> options = null;
Set<Category> catConstraints = user.getCatDimensionConstraints();
if (catConstraints != null && !catConstraints.isEmpty()) {
options = new HashSet<>();
for (Category category : catConstraints) {
options.addAll(getCategoryOptions(category));
}
}
return options;
}
Aggregations