use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentUserWithNoDataReadWriteOrgUnit.
/**
* program = orgUnit = Accessible status = ERROR
*/
@Test
void testGetEnrollmentUserWithNoDataReadWriteOrgUnit() {
ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
programA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
manager.updateNoAcl(programA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
injectSecurityContext(user);
assertThrows(IllegalQueryException.class, () -> enrollmentService.getEnrollment(importSummary.getReference()));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataReadNoOrgUnit.
/**
* program = DATA READ orgUnit = Not Accessible status = ERROR
*/
@Test
void testGetEnrollmentUserWithDataReadNoOrgUnit() {
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");
injectSecurityContext(user);
assertThrows(IllegalQueryException.class, () -> enrollmentService.getEnrollment(importSummary.getReference()));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataReadWrite.
/**
* program = DATA READ/WRITE orgUnit = Accessible status = SUCCESS
*/
@Test
void testGetEnrollmentUserWithDataReadWrite() {
ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
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.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataReadWriteNoOrgUnit.
/**
* program = DATA READ/WRITE orgUnit = Not Accessible status = ERROR
*/
@Test
void testGetEnrollmentUserWithDataReadWriteNoOrgUnit() {
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");
injectSecurityContext(user);
assertThrows(IllegalQueryException.class, () -> enrollmentService.getEnrollment(importSummary.getReference()));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class ObjectBundleServiceAttributesTest method testCreateSimpleMetadataAttributeValuesUID.
@Test
void testCreateSimpleMetadataAttributeValuesUID() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata_with_av.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
assertFalse(validationReport.hasErrorReports());
transactionTemplate.execute(status -> {
objectBundleService.commit(bundle);
return null;
});
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<Option> options = manager.getAll(Option.class);
List<OptionSet> optionSets = manager.getAll(OptionSet.class);
List<Attribute> attributes = manager.getAll(Attribute.class);
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(dataSets.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(2, attributes.size());
assertEquals(2, options.size());
assertEquals(1, optionSets.size());
Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = manager.getDefaults();
DataSet dataSet = dataSets.get(0);
User user = users.get(0);
OptionSet optionSet = optionSets.get(0);
for (DataElement dataElement : dataElements) {
assertNotNull(dataElement.getCategoryCombo());
assertEquals(defaults.get(CategoryCombo.class), dataElement.getCategoryCombo());
}
assertFalse(dataSet.getSources().isEmpty());
assertFalse(dataSet.getDataSetElements().isEmpty());
assertEquals(1, dataSet.getSources().size());
assertEquals(2, dataSet.getDataSetElements().size());
assertEquals(PeriodType.getPeriodTypeByName("Monthly"), dataSet.getPeriodType());
assertNotNull(user);
assertEquals("admin", user.getUsername());
assertFalse(user.getUserAuthorityGroups().isEmpty());
assertFalse(user.getOrganisationUnits().isEmpty());
assertEquals("PdWlltZnVZe", user.getOrganisationUnit().getUid());
assertEquals(2, optionSet.getOptions().size());
// attribute value check
DataElement dataElementA = manager.get(DataElement.class, "SG4HuKlNEFH");
DataElement dataElementB = manager.get(DataElement.class, "CCwk5Yx440o");
DataElement dataElementC = manager.get(DataElement.class, "j5PneRdU7WT");
DataElement dataElementD = manager.get(DataElement.class, "k90AVpBahO4");
assertNotNull(dataElementA);
assertNotNull(dataElementB);
assertNotNull(dataElementC);
assertNotNull(dataElementD);
assertTrue(dataElementA.getAttributeValues().isEmpty());
assertTrue(dataElementB.getAttributeValues().isEmpty());
assertFalse(dataElementC.getAttributeValues().isEmpty());
assertFalse(dataElementD.getAttributeValues().isEmpty());
}
Aggregations