use of org.hisp.dhis.trackedentity.TrackerAccessManager in project dhis2-core by dhis2.
the class DataValueAclCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
final TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getUid());
Map<String, Set<EventDataValue>> eventDataValueMap = ctx.getEventDataValueMap();
final User user = ctx.getImportOptions().getUser();
final ImportSummary importSummary = new ImportSummary();
// Note that here we are passing a ProgramStageInstance, which during a
// INSERT
// operation
// is going to be null, so the ACL method will not be able to check that
final Set<EventDataValue> dataValues = eventDataValueMap.get(event.getUid());
for (EventDataValue dataValue : dataValues) {
DataElement dataElement = ctx.getDataElementMap().get(dataValue.getDataElement());
List<String> errors = trackerAccessManager.canWrite(user, programStageInstance, dataElement, true);
if (!errors.isEmpty()) {
errors.forEach(error -> importSummary.addConflict(dataElement.getUid(), error));
}
}
return importSummary;
}
use of org.hisp.dhis.trackedentity.TrackerAccessManager 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;
}
Aggregations