Search in sources :

Example 21 with CategoryOption

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));
}
Also used : User(org.hisp.dhis.user.User) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOption(org.hisp.dhis.category.CategoryOption) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with 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));
}
Also used : User(org.hisp.dhis.user.User) CategoryOption(org.hisp.dhis.category.CategoryOption) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with 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"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

Example 24 with CategoryOption

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"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

Example 25 with CategoryOption

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;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption)

Aggregations

CategoryOption (org.hisp.dhis.category.CategoryOption)87 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)47 CategoryCombo (org.hisp.dhis.category.CategoryCombo)38 Category (org.hisp.dhis.category.Category)34 Test (org.junit.jupiter.api.Test)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)26 Program (org.hisp.dhis.program.Program)19 ArrayList (java.util.ArrayList)18 Event (org.hisp.dhis.tracker.domain.Event)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 DataElement (org.hisp.dhis.dataelement.DataElement)13 Collections (java.util.Collections)12 DataSet (org.hisp.dhis.dataset.DataSet)12 CodeGenerator (org.hisp.dhis.common.CodeGenerator)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)11 CategoryService (org.hisp.dhis.category.CategoryService)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10