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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations