コード例 #1
0
  private Role createRole(String namespaceCode, String name, String kimTypeId) {
    Role.Builder bldr = Role.Builder.create();
    bldr.setNamespaceCode(namespaceCode);
    bldr.setName(name);
    bldr.setKimTypeId(kimTypeId);
    bldr.setActive(true);

    Role fromCreate = this.roleService.createRole(bldr.build());
    assertEquals(namespaceCode, fromCreate.getNamespaceCode());
    assertEquals(name, fromCreate.getName());
    assertEquals(kimTypeId, fromCreate.getKimTypeId());
    assertNotNull(fromCreate.getId());
    assertNotNull(fromCreate.getVersionNumber());
    assertTrue(fromCreate.isActive());
    assertNull(fromCreate.getDescription());

    bldr = Role.Builder.create(fromCreate);
    bldr.setDescription(namespaceCode + " " + name);
    Role fromUpdate = this.roleService.updateRole(bldr.build());
    assertEquals(fromCreate.getNamespaceCode(), fromUpdate.getNamespaceCode());
    assertEquals(fromCreate.getName(), fromUpdate.getName());
    assertEquals(fromCreate.getId(), fromUpdate.getId());
    assertNotSame(fromCreate.getVersionNumber(), fromUpdate.getVersionNumber());
    assertEquals(fromCreate.isActive(), fromUpdate.isActive());
    assertEquals(bldr.getDescription(), fromUpdate.getDescription());

    Role fromGet = this.roleService.getRole(fromUpdate.getId());
    assertEquals(fromUpdate.getNamespaceCode(), fromGet.getNamespaceCode());
    assertEquals(fromUpdate.getName(), fromGet.getName());
    assertEquals(fromUpdate.getKimTypeId(), fromGet.getKimTypeId());
    assertEquals(fromUpdate.getId(), fromGet.getId());
    assertEquals(fromUpdate.getVersionNumber(), fromGet.getVersionNumber());
    assertEquals(fromUpdate.isActive(), fromGet.isActive());
    assertEquals(fromUpdate.getDescription(), fromGet.getDescription());

    Role fromFind = this.roleService.getRoleByNamespaceCodeAndName(namespaceCode, name);
    assertEquals(fromUpdate.getNamespaceCode(), fromFind.getNamespaceCode());
    assertEquals(fromUpdate.getName(), fromFind.getName());
    assertEquals(fromUpdate.getKimTypeId(), fromFind.getKimTypeId());
    assertEquals(fromUpdate.getId(), fromFind.getId());
    assertEquals(fromUpdate.getVersionNumber(), fromFind.getVersionNumber());
    assertEquals(fromUpdate.isActive(), fromFind.isActive());
    assertEquals(fromUpdate.getDescription(), fromFind.getDescription());

    // TODO: test update

    return fromFind;
  }
コード例 #2
0
  /**
   * Gets the derived role service for {@code role}.
   *
   * @param role the role
   * @return the derived role service name for {@code role}.
   */
  protected RoleTypeService getRoleTypeService(Role role) {
    RoleTypeService roleTypeService = null;

    if (role != null) {
      String serviceName = getDerivedRoleServiceName(role.getKimTypeId());

      if (serviceName != null) {
        try {
          KimTypeService service =
              (KimTypeService) GlobalResourceLoader.getService(QName.valueOf(serviceName));
          if (service != null && service instanceof RoleTypeService) {
            return (RoleTypeService) service;
          }
        } catch (Exception ex) {
          LOG.error("Unable to find role type service with name: " + serviceName, ex);
        }
      }
    }

    return roleTypeService;
  }