use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class DataValueCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
final Set<DataValue> dataValues = event.getDataValues();
final ImportSummary importSummary = new ImportSummary();
final User user = ctx.getImportOptions().getUser();
for (DataValue dataValue : dataValues) {
if (!checkHasValidDataElement(importSummary, ctx, dataValue) || !checkSerializeToJson(importSummary, ctx, dataValue)) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setReference(event.getUid());
importSummary.incrementIgnored();
return importSummary;
}
}
if (!importSummary.hasConflicts()) {
if (doValidationOfMandatoryAttributes(user) && isValidationRequired(event, ctx)) {
validateMandatoryAttributes(importSummary, ctx, event);
}
}
if (importSummary.hasConflicts()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setReference(event.getUid());
importSummary.incrementIgnored();
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class AttributeOptionComboCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
Program program = ctx.getProgramsMap().get(event.getProgram());
CategoryOptionCombo coc = ctx.getCategoryOptionComboMap().get(event.getUid());
if (coc != null && coc.isDefault() && program.getCategoryCombo() != null && !program.getCategoryCombo().isDefault()) {
ImportSummary importSummary = new ImportSummary(event.getEvent());
importSummary.addConflict("attributeOptionCombo", "Valid attribute option combo must be specified since program does not have the default category combo");
importSummary.setStatus(ImportStatus.ERROR);
return importSummary.incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class BaseEventAclCheck method check.
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
ImportOptions importOptions = ctx.getImportOptions();
ProgramStageInstance programStageInstance = prepareForAclValidation(ctx, event);
List<String> errors = checkAcl(ctx.getServiceDelegator().getTrackerAccessManager(), importOptions.getUser(), programStageInstance);
final ImportSummary importSummary = new ImportSummary();
if (!errors.isEmpty()) {
errors.forEach(error -> importSummary.addConflict(event.getUid(), error));
importSummary.incrementIgnored();
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setReference(event.getEvent());
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class EventBaseCheck method validateProgramInstance.
private void validateProgramInstance(ImmutableEvent event, WorkContext ctx, List<String> errors) {
ProgramInstance programInstance = ctx.getProgramInstanceMap().get(event.getUid());
ImportOptions importOptions = ctx.getImportOptions();
if (programInstance == null) {
errors.add("No program instance found for event: " + event.getEvent());
} else if (COMPLETED.equals(programInstance.getStatus())) {
if (importOptions == null || importOptions.getUser() == null || importOptions.getUser().isAuthorized(F_EDIT_EXPIRED.getAuthority())) {
return;
}
Date referenceDate = parseDate(event.getCreated());
if (referenceDate == null) {
referenceDate = new Date();
}
referenceDate = removeTimeStamp(referenceDate);
if (referenceDate.after(removeTimeStamp(programInstance.getEndDate()))) {
errors.add("Not possible to add event to a completed enrollment. Event created date ( " + referenceDate + " ) is after enrollment completed date ( " + removeTimeStamp(programInstance.getEndDate()) + " ).");
}
}
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class ProgramStageInstanceBasicCheck method check.
@Override
public ImportSummary check(final ImmutableEvent event, final WorkContext ctx) {
final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getEvent());
if (programStageInstance == null) {
final ImportSummary error = error("Event ID " + event.getEvent() + " doesn't point to valid event", event.getEvent());
error.addConflict("Invalid Event ID", event.getEvent());
return error;
} else if (programStageInstance.isDeleted() || ctx.getImportOptions().getImportStrategy().isCreate()) {
return error("Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.").setReference(event.getEvent());
}
return success();
}
Aggregations