use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class EventSecurityImportValidationTest method setupMetadata.
private void setupMetadata() {
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitA);
manager.save(organisationUnitB);
organisationUnitA.setPublicAccess(AccessStringHelper.FULL);
manager.update(organisationUnitA);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementA.setValueType(ValueType.INTEGER);
dataElementB.setValueType(ValueType.INTEGER);
manager.save(dataElementA);
manager.save(dataElementB);
programStageA = createProgramStage('A', 0);
programStageB = createProgramStage('B', 0);
programStageB.setRepeatable(true);
manager.save(programStageA);
manager.save(programStageB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
TrackedEntityType trackedEntityTypeFromProgram = createTrackedEntityType('C');
trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeFromProgram);
manager.save(programA);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA.setProgram(programA);
programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementB);
programStageDataElement.setProgramStage(programStageB);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageB.getProgramStageDataElements().add(programStageDataElement);
programStageB.setProgram(programA);
programStageB.setMinDaysFromStart(2);
programA.getProgramStages().add(programStageA);
programA.getProgramStages().add(programStageB);
programA.setTrackedEntityType(trackedEntityType);
trackedEntityType.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
manager.update(programStageA);
manager.update(programStageB);
manager.update(programA);
maleA = createTrackedEntityInstance('A', organisationUnitA);
maleB = createTrackedEntityInstance(organisationUnitB);
femaleA = createTrackedEntityInstance(organisationUnitA);
femaleB = createTrackedEntityInstance(organisationUnitB);
maleA.setTrackedEntityType(trackedEntityType);
maleB.setTrackedEntityType(trackedEntityType);
femaleA.setTrackedEntityType(trackedEntityType);
femaleB.setTrackedEntityType(trackedEntityType);
manager.save(maleA);
manager.save(maleB);
manager.save(femaleA);
manager.save(femaleB);
int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
Date dateMar20 = getDate(testYear, 3, 20);
Date dateApr10 = getDate(testYear, 4, 10);
ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(maleA, programA, dateMar20, dateApr10, organisationUnitA, "MNWZ6hnuhSX");
programInstanceService.addProgramInstance(programInstance);
trackedEntityProgramOwnerService.updateTrackedEntityProgramOwner(maleA.getUid(), programA.getUid(), organisationUnitA.getUid());
manager.update(programA);
User user = userService.getUser(USER_5);
OrganisationUnit qfUVllTs6cS = organisationUnitService.getOrganisationUnit("QfUVllTs6cS");
user.addOrganisationUnit(qfUVllTs6cS);
user.addOrganisationUnit(organisationUnitA);
User adminUser = userService.getUser(ADMIN_USER_UID);
adminUser.addOrganisationUnit(organisationUnitA);
Program p = programService.getProgram("prabcdefghA");
p.addOrganisationUnit(qfUVllTs6cS);
programService.updateProgram(p);
manager.update(user);
manager.update(adminUser);
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatchAndTEIIsInPayload.
@Test
void verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatchAndTEIIsInPayload() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, trackedEntityType(TEI_TYPE_ID)));
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(null);
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).trackedEntityType(ANOTHER_TEI_TYPE_ID).build();
bundle.setTrackedEntities(Collections.singletonList(trackedEntity));
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).build();
hook.validateEnrollment(reporter, enrollment);
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1022));
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatch.
@Test
void verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatch() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, trackedEntityType(TEI_TYPE_ID)));
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
TrackedEntityType anotherTrackedEntityType = trackedEntityType(TEI_ID, 'B');
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(trackedEntityInstance(TEI_ID, anotherTrackedEntityType, orgUnit));
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).build();
hook.validateEnrollment(reporter, enrollment);
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1022));
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class PreCheckUpdatableFieldsValidationHookTest method trackedEntityInstance.
private TrackedEntityInstance trackedEntityInstance() {
TrackedEntityType trackedEntityType = new TrackedEntityType();
trackedEntityType.setUid(TRACKED_ENTITY_TYPE_ID);
TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
trackedEntityInstance.setUid(TRACKED_ENTITY_ID);
trackedEntityInstance.setTrackedEntityType(trackedEntityType);
return trackedEntityInstance;
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class TrackedEntityAttributeValidationHookTest method shouldPassValidation.
@Test
void shouldPassValidation() {
TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
trackedEntityAttribute.setUid("uid");
trackedEntityAttribute.setValueType(ValueType.TEXT);
when(validationContext.getTrackedEntityAttribute(anyString())).thenReturn(trackedEntityAttribute);
when(validationContext.getTrackedEntityType(anyString())).thenReturn(new TrackedEntityType());
TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("uid").value("value").build())).trackedEntityType("trackedEntityType").build();
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
assertFalse(reporter.hasErrors());
assertEquals(0, reporter.getReportList().size());
}
Aggregations