Search in sources :

Example 1 with TrackerAccessManager

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;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Set(java.util.Set) User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 2 with TrackerAccessManager

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;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 TrackerAccessManager (org.hisp.dhis.trackedentity.TrackerAccessManager)2 Set (java.util.Set)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)1 User (org.hisp.dhis.user.User)1