DefaultCompleteDataSetRegistrationExchangeService implements CompleteDataSetRegistrationExchangeService { @Override public ImportSummary saveCompleteDataSetRegistrationsJson( InputStream in, ImportOptions importOptions ) { return saveCompleteDataSetRegistrationsJson( in, ImportOptions.getDefaultImportOptions(), null ); } DefaultCompleteDataSetRegistrationExchangeService(
        CompleteDataSetRegistrationExchangeStore cdsrStore,
        IdentifiableObjectManager idObjManager,
        OrganisationUnitService orgUnitService,
        Notifier notifier,
        I18nManager i18nManager,
        BatchHandlerFactory batchHandlerFactory,
        SystemSettingManager systemSettingManager,
        CategoryService categoryService,
        PeriodService periodService,
        CurrentUserService currentUserService,
        CompleteDataSetRegistrationService registrationService,
        InputUtils inputUtils,
        AggregateAccessManager accessManager,
        DataSetNotificationEventPublisher notificationPublisher,
        MessageService messageService,
        ObjectMapper jsonMapper ); @Override ExportParams paramsFromUrl( Set<String> dataSets, Set<String> orgUnits, Set<String> orgUnitGroups,
        Set<String> periods, Date startDate, Date endDate, boolean includeChildren, Date created,
        String createdDuration, Integer limit, IdSchemes idSchemes ); @Override void writeCompleteDataSetRegistrationsXml( ExportParams params, OutputStream out ); @Override void writeCompleteDataSetRegistrationsJson( ExportParams params, OutputStream out ); @Override void writeCompleteDataSetRegistrationsJson( Date lastUpdated, OutputStream outputStream,
        IdSchemes idSchemes ); @Override ImportSummary saveCompleteDataSetRegistrationsXml( InputStream in, ImportOptions importOptions ); @Override ImportSummary saveCompleteDataSetRegistrationsXml( InputStream in, ImportOptions importOptions, JobConfiguration jobId ); @Override ImportSummary saveCompleteDataSetRegistrationsJson( InputStream in, ImportOptions importOptions ); @Override ImportSummary saveCompleteDataSetRegistrationsJson( InputStream in, ImportOptions importOptions, JobConfiguration jobId ); void validate( ExportParams params );  }
@Test public void verifyUserHasNoWritePermissionOnCategoryOption() throws Exception { OrganisationUnit organisationUnit = createOrganisationUnit( 'A' ); DataSet dataSetA = createDataSet( 'A', new MonthlyPeriodType() ); CategoryCombo categoryCombo = createCategoryCombo( 'A' ); CategoryOption categoryOptionA = createCategoryOption( 'A' ); CategoryOption categoryOptionB = createCategoryOption( 'B' ); CategoryOptionCombo categoryOptionCombo = createCategoryOptionCombo( categoryCombo, categoryOptionA, categoryOptionB ); Period period = createPeriod( "201907" ); String payload = createPayload( period, organisationUnit, dataSetA, categoryCombo, categoryOptionA, categoryOptionB ); whenNew( MetadataCaches.class ).withNoArguments().thenReturn( metaDataCaches ); when( idObjManager.get( CategoryCombo.class, categoryCombo.getUid() ) ).thenReturn( categoryCombo ); when( idObjManager.getObject( CategoryOption.class, IdScheme.UID, categoryOptionA.getUid() ) ) .thenReturn( categoryOptionA ); when( idObjManager.getObject( CategoryOption.class, IdScheme.UID, categoryOptionB.getUid() ) ) .thenReturn( categoryOptionB ); when( categoryService.getCategoryOptionCombo( categoryCombo, Sets.newHashSet( categoryOptionA, categoryOptionB ) ) ).thenReturn( categoryOptionCombo ); when( datasetCache.get( eq( dataSetA.getUid() ), any() ) ).thenReturn( dataSetA ); when( periodCache.get( eq( period.getIsoDate() ), any() ) ).thenReturn( period ); when( orgUnitCache.get( eq( organisationUnit.getUid() ), any() ) ).thenReturn( createOrganisationUnit( 'A' ) ); when( orgUnitInHierarchyCache.get( eq( organisationUnit.getUid() ), any() ) ).thenReturn( Boolean.TRUE ); when( attrOptComboOrgUnitCache.get( eq( categoryOptionCombo.getUid() + organisationUnit.getUid() ), any() ) ) .thenReturn( Boolean.TRUE ); when( categoryService.getCategoryOptionCombo( categoryOptionCombo.getUid() ) ) .thenReturn( categoryOptionCombo ); when( aclService.canDataWrite( user, dataSetA ) ).thenReturn( true ); when( aclService.canDataWrite( user, categoryOptionA ) ).thenReturn( false ); when( aclService.canDataWrite( user, categoryOptionB ) ).thenReturn( true ); ImportSummary summary = subject.saveCompleteDataSetRegistrationsJson( new ByteArrayInputStream( payload.getBytes() ), new ImportOptions() ); assertThat( summary.getStatus(), is( ImportStatus.ERROR ) ); assertThat( summary.getImportCount().getIgnored(), is( 1 ) ); assertThat( summary.getConflicts(), hasSize( 1 ) ); assertThat( summary.getConflicts().iterator().next().getValue(), is( "User has no data write access for CategoryOption: " + categoryOptionA.getUid() ) ); }