use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AttributeOptionComboCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
Program program = ctx.getProgramsMap().get(event.getProgram());
CategoryOptionCombo coc = ctx.getCategoryOptionComboMap().get(event.getUid());
if (coc != null && coc.isDefault() && program.getCategoryCombo() != null && !program.getCategoryCombo().isDefault()) {
ImportSummary importSummary = new ImportSummary(event.getEvent());
importSummary.addConflict("attributeOptionCombo", "Valid attribute option combo must be specified since program does not have the default category combo");
importSummary.setStatus(ImportStatus.ERROR);
return importSummary.incrementIgnored();
}
return success();
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AttributeOptionComboAclCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
ImportSummary importSummary = new ImportSummary();
TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
ImportOptions importOptions = ctx.getImportOptions();
CategoryOptionCombo categoryOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), categoryOptionCombo);
if (!errors.isEmpty()) {
importSummary.setStatus(ImportStatus.ERROR);
errors.forEach(error -> importSummary.addConflict("CategoryOptionCombo", error));
importSummary.incrementIgnored();
}
return importSummary;
}
use of org.hisp.dhis.category.CategoryOptionCombo 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.CategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultAclService method canWrite.
private <T extends IdentifiableObject> boolean canWrite(User user, T object, Class<? extends T> objType) {
if (readWriteCommonCheck(user, objType)) {
return true;
}
Schema schema = schemaService.getSchema(objType);
List<String> anyAuthorities = new ArrayList<>(schema.getAuthorityByType(AuthorityType.CREATE));
if (anyAuthorities.isEmpty()) {
anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PRIVATE));
anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PUBLIC));
}
if (canAccess(user, anyAuthorities)) {
if (object instanceof CategoryOptionCombo) {
return checkOptionComboSharingPermission(user, object, Permission.WRITE);
}
return writeCommonCheck(schema, user, object, objType);
} else if (schema.isImplicitPrivateAuthority() && checkSharingAccess(user, object, objType)) {
return true;
}
return false;
}
use of org.hisp.dhis.category.CategoryOptionCombo 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);
}
Aggregations