Search in sources :

Example 11 with SUCCESS

use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess6.

/**
 * program = DATA WRITE programStage = DATA WRITE orgUnit = Accessible
 * status = SUCCESS
 */
@Test
void testAddEventSimpleUserFullAccess6() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(event.getEvent(), importSummary.getReference());
    programA.setPublicAccess(AccessStringHelper.DATA_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
    assertNotNull(programStageInstance);
    Event eventFromPsi = eventService.getEvent(programStageInstance);
    assertNotNull(eventFromPsi);
    assertEquals(event.getUid(), eventFromPsi.getEvent());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with SUCCESS

use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.

the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataRead.

/**
 * program = DATA READ orgUnit = Accessible status = SUCCESS
 */
@Test
void testGetEnrollmentUserWithDataRead() {
    ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ);
    manager.updateNoAcl(programA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    Enrollment enrollment = enrollmentService.getEnrollment(importSummary.getReference());
    assertNotNull(enrollment);
    assertEquals(enrollment.getEnrollment(), importSummary.getReference());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with SUCCESS

use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.

the class ImportDataValueAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    strategy = strategy != null ? strategy : ImportStrategy.NEW_AND_UPDATES;
    TaskId taskId = new TaskId(TaskCategory.DATAVALUE_IMPORT, currentUserService.getCurrentUser());
    notifier.clear(taskId);
    InputStream in = new FileInputStream(upload);
    in = StreamUtils.wrapAndCheckCompressionFormat(in);
    ImportOptions options = new ImportOptions().setDryRun(dryRun).setStrategy(strategy).setPreheatCache(preheatCache).setSkipExistingCheck(skipExistingCheck).setIdScheme(StringUtils.trimToNull(idScheme)).setDataElementIdScheme(StringUtils.trimToNull(dataElementIdScheme)).setOrgUnitIdScheme(StringUtils.trimToNull(orgUnitIdScheme)).setFilename(uploadFileName);
    log.info(options);
    scheduler.executeTask(new ImportDataValueTask(dataValueSetService, adxDataService, sessionFactory, in, options, taskId, importFormat));
    return SUCCESS;
}
Also used : TaskId(org.hisp.dhis.scheduling.TaskId) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportDataValueTask(org.hisp.dhis.dxf2.datavalueset.tasks.ImportDataValueTask)

Example 14 with SUCCESS

use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.

the class ImportEventAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
    notifier.clear(taskId);
    InputStream in = new FileInputStream(upload);
    in = StreamUtils.wrapAndCheckCompressionFormat(in);
    ImportOptions importOptions = new ImportOptions().setDryRun(dryRun).setOrgUnitIdScheme(orgUnitIdScheme.toString()).setEventIdScheme(eventIdScheme.toString()).setFilename(uploadFileName);
    if (FORMAT_CSV.equals(payloadFormat)) {
        Events events = csvEventService.readEvents(in, skipFirst);
        scheduler.executeTask(new ImportEventsTask(events.getEvents(), eventService, importOptions, taskId));
    } else {
        List<Event> events;
        if (FORMAT_JSON.equals(payloadFormat)) {
            events = eventService.getEventsJson(in);
        } else {
            events = eventService.getEventsXml(in);
        }
        scheduler.executeTask(new ImportEventTask(events, eventService, importOptions, taskId));
    }
    return SUCCESS;
}
Also used : ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) TaskId(org.hisp.dhis.scheduling.TaskId) ImportEventTask(org.hisp.dhis.dxf2.events.event.ImportEventTask) Events(org.hisp.dhis.dxf2.events.event.Events) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) FileInputStream(java.io.FileInputStream) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 15 with SUCCESS

use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.

the class GetHistoryAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    DataElement dataElement = dataElementService.getDataElement(dataElementId);
    CategoryOptionCombo categoryOptionCombo = categoryService.getCategoryOptionCombo(optionComboId);
    if (categoryOptionCombo == null) {
        categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    }
    if (dataElement == null) {
        throw new IllegalArgumentException("DataElement doesn't exist: " + dataElementId);
    }
    Period period = PeriodType.getPeriodFromIsoString(periodId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
    dataElementHistory = historyRetriever.getHistory(dataElement, categoryOptionCombo, attributeOptionCombo, organisationUnit, period, HISTORY_LENGTH);
    dataValueAudits = dataValueAuditService.getDataValueAudits(Lists.newArrayList(dataElement), Lists.newArrayList(period), Lists.newArrayList(organisationUnit), categoryOptionCombo, attributeOptionCombo, null);
    dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
    if (dataValue != null) {
        User credentials = userService.getUserByUsername(dataValue.getStoredBy());
        storedBy = credentials != null ? credentials.getName() : dataValue.getStoredBy();
    }
    if (dataElement.isFileType()) {
        fileNames = new HashMap<String, String>();
        dataValueAudits.removeIf(audit -> fileResourceService.getFileResource(audit.getValue()) == null);
        dataValueAudits.stream().filter(audit -> audit != null).map(audit -> fileResourceService.getFileResource(audit.getValue())).forEach(fr -> fileNames.put(fr.getUid(), fr.getName()));
    }
    historyInvalid = dataElementHistory == null;
    minMaxInvalid = !dataElement.getValueType().isNumeric();
    commentOptionSet = dataElement.getCommentOptionSet();
    attributeOptionComboId = attributeOptionCombo.getUid();
    return SUCCESS;
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) DataValueAuditService(org.hisp.dhis.datavalue.DataValueAuditService) DataElementService(org.hisp.dhis.dataelement.DataElementService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataElement(org.hisp.dhis.dataelement.DataElement) DataValueService(org.hisp.dhis.datavalue.DataValueService) Lists(com.google.common.collect.Lists) DataElementHistory(org.hisp.dhis.dataelementhistory.DataElementHistory) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) User(org.hisp.dhis.user.User) InputUtils(org.hisp.dhis.dxf2.util.InputUtils) Period(org.hisp.dhis.period.Period) UserService(org.hisp.dhis.user.UserService) Collection(java.util.Collection) HistoryRetriever(org.hisp.dhis.dataelementhistory.HistoryRetriever) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OptionSet(org.hisp.dhis.option.OptionSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValue(org.hisp.dhis.datavalue.DataValue) PeriodType(org.hisp.dhis.period.PeriodType) Action(com.opensymphony.xwork2.Action) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)20 User (org.hisp.dhis.user.User)10 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)9 Test (org.junit.jupiter.api.Test)9 Event (org.hisp.dhis.dxf2.events.event.Event)6 Date (java.util.Date)4 Program (org.hisp.dhis.program.Program)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 DataValueService (org.hisp.dhis.datavalue.DataValueService)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)3 Events (org.hisp.dhis.dxf2.events.event.Events)3 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)3 IOException (java.io.IOException)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 IdScheme (org.hisp.dhis.common.IdScheme)2 IdSchemes (org.hisp.dhis.common.IdSchemes)2 ImportSummariesResponseExtractor (org.hisp.dhis.dxf2.common.ImportSummariesResponseExtractor)2 DataValueSetService (org.hisp.dhis.dxf2.datavalueset.DataValueSetService)2