use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class AclServiceTest method testCanDataOrMetadataRead.
@Test
void testCanDataOrMetadataRead() {
User user1 = createUser("user1A8", "F_CATEGORY_OPTION_GROUP_SET_PUBLIC_ADD");
manager.save(user1);
// non data shareable object //
CategoryOptionGroupSet categoryOptionGroupSet = new CategoryOptionGroupSet();
categoryOptionGroupSet.setAutoFields();
categoryOptionGroupSet.setName("cogA");
manager.save(categoryOptionGroupSet);
assertTrue(aclService.canDataOrMetadataRead(user1, categoryOptionGroupSet));
// data shareable object //
CategoryOption categoryOption = new CategoryOption();
categoryOption.setAutoFields();
categoryOption.setName("coA");
categoryOption.setPublicAccess(AccessStringHelper.DATA_READ);
categoryOption.setCreatedBy(user1);
categoryOption.getSharing().setOwner(user1);
categoryOption.setPublicAccess("rwrw----");
manager.save(categoryOption, false);
assertTrue(aclService.canDataOrMetadataRead(user1, categoryOption));
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class AclServiceTest method testCategoryOptionSharingPrivateRW.
@Test
void testCategoryOptionSharingPrivateRW() {
User user1 = createUser("user11", "F_CATEGORY_OPTION_PRIVATE_ADD");
User user2 = createUser("user22", "F_CATEGORY_OPTION_PRIVATE_ADD");
CategoryOption categoryOption = createCategoryOption('A');
categoryOption.setCreatedBy(user1);
categoryOption.getSharing().setOwner(user1);
manager.save(categoryOption);
assertFalse(aclService.canUpdate(user2, categoryOption));
assertEquals(AccessStringHelper.DEFAULT, categoryOption.getPublicAccess());
UserGroup userGroup = createUserGroup('A', new HashSet<>());
userGroup.getMembers().add(user1);
userGroup.getMembers().add(user2);
manager.save(userGroup);
user2.getGroups().add(userGroup);
user1.getGroups().add(userGroup);
categoryOption.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
manager.update(categoryOption);
assertTrue(aclService.canUpdate(user2, categoryOption));
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultFieldFilterServiceTest method baseIdentifiable.
@Test
void baseIdentifiable() {
final OrganisationUnit ou1 = new OrganisationUnit();
ou1.setUid("abc1");
ou1.setName("Test 1");
final OrganisationUnit ou2 = new OrganisationUnit();
ou2.setUid("abc2");
ou2.setName("Test 2");
final CategoryOption option = new CategoryOption();
option.setUid("def1");
option.getOrganisationUnits().add(ou1);
option.getOrganisationUnits().add(ou2);
final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(option), Arrays.asList("id", "organisationUnits[id,name]"));
final ComplexNode node = service.toComplexNode(params);
Assertions.assertEquals("categoryOption", node.getName());
Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "organisationUnits") instanceof CollectionNode);
final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "organisationUnits");
Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
final List<String> ouIds = new ArrayList<>();
final List<String> ouNames = new ArrayList<>();
Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof ComplexNode);
ComplexNode complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(0);
Assertions.assertEquals("organisationUnit", complexNode.getName());
Assertions.assertEquals(2, complexNode.getUnorderedChildren().size());
Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "id") instanceof SimpleNode);
SimpleNode simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "id");
Assertions.assertEquals("id", simpleNode.getName());
ouIds.add(String.valueOf(simpleNode.getValue()));
Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "name") instanceof SimpleNode);
simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "name");
Assertions.assertEquals("name", simpleNode.getName());
ouNames.add(String.valueOf(simpleNode.getValue()));
Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof ComplexNode);
complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(1);
Assertions.assertEquals("organisationUnit", complexNode.getName());
Assertions.assertEquals(2, complexNode.getUnorderedChildren().size());
Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "id") instanceof SimpleNode);
simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "id");
Assertions.assertEquals("id", simpleNode.getName());
ouIds.add(String.valueOf(simpleNode.getValue()));
Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "name") instanceof SimpleNode);
simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "name");
Assertions.assertEquals("name", simpleNode.getName());
ouNames.add(String.valueOf(simpleNode.getValue()));
assertThat(ouIds, Matchers.containsInAnyOrder("abc1", "abc2"));
assertThat(ouNames, Matchers.containsInAnyOrder("Test 1", "Test 2"));
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultFieldFilterServiceTest method baseIdentifiableIdOnly.
@Test
void baseIdentifiableIdOnly() {
final OrganisationUnit ou1 = new OrganisationUnit();
ou1.setUid("abc1");
final OrganisationUnit ou2 = new OrganisationUnit();
ou2.setUid("abc2");
final CategoryOption option = new CategoryOption();
option.setUid("def1");
option.getOrganisationUnits().add(ou1);
option.getOrganisationUnits().add(ou2);
final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(option), Arrays.asList("id", "organisationUnits"));
final ComplexNode node = service.toComplexNode(params);
Assertions.assertEquals("categoryOption", node.getName());
Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "organisationUnits") instanceof CollectionNode);
final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "organisationUnits");
Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
final List<String> ouIds = new ArrayList<>();
Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof ComplexNode);
ComplexNode complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(0);
Assertions.assertEquals("organisationUnit", complexNode.getName());
Assertions.assertEquals(1, complexNode.getUnorderedChildren().size());
Assertions.assertTrue(complexNode.getUnorderedChildren().get(0) instanceof SimpleNode);
SimpleNode simpleNode = (SimpleNode) complexNode.getUnorderedChildren().get(0);
Assertions.assertEquals("id", simpleNode.getName());
ouIds.add(String.valueOf(simpleNode.getValue()));
Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof ComplexNode);
complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(1);
Assertions.assertEquals("organisationUnit", complexNode.getName());
Assertions.assertEquals(1, complexNode.getUnorderedChildren().size());
Assertions.assertTrue(complexNode.getUnorderedChildren().get(0) instanceof SimpleNode);
simpleNode = (SimpleNode) complexNode.getUnorderedChildren().get(0);
Assertions.assertEquals("id", simpleNode.getName());
ouIds.add(String.valueOf(simpleNode.getValue()));
assertThat(ouIds, Matchers.containsInAnyOrder("abc1", "abc2"));
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategoryOption.
public static CategoryOption createCategoryOption(char uniqueIdentifier) {
CategoryOption categoryOption = new CategoryOption("CategoryOption" + uniqueIdentifier);
categoryOption.setAutoFields();
return categoryOption;
}
Aggregations