0

kaa 0.10 中的 bug影响了我的应用程序开发。所以我尝试修复它。然后我比较了 kaa 0.9 和 kaa 0.10 的代码。我发现Kaa DAO接口模块化类EndpointServiceImpl的区别:里面有两个attachEndpointToUser方法

1、

public EndpointProfileDto attachEndpointToUser(String endpointUserId, String
          endpointAccessToken) throws KaaOptimisticLockingFailureException {
    LOG.info("Try to attach endpoint with access token {} to user with {}", endpointAccessToken,
            endpointUserId);
    validateString(endpointUserId, "Incorrect endpointUserId "
                                   + endpointUserId);
    EndpointUser endpointUser = endpointUserDao.findById(endpointUserId);
    LOG.trace("[{}] Found endpoint user with id {} ", endpointUserId, endpointUser);
    if (endpointUser
        != null) {
      EndpointProfile endpoint = endpointProfileDao.findByAccessToken(endpointAccessToken);
      LOG.trace("[{}] Found endpoint profile by with access token {} ", endpointAccessToken,
              endpoint);
      if (endpoint
          != null) {
        if (endpoint.getEndpointUserId()
            == null
            || endpointUserId.equals(endpoint.getEndpointUserId())) {
          LOG.debug("Attach endpoint profile with id {} to endpoint user with id {} ", endpoint
                  .getId(), endpointUser.getId());
          List<String> endpointIds = endpointUser.getEndpointIds(); 

          **/*if (endpointIds
                  != null
                  && endpointIds.contains(endpoint.getId())) {
                LOG.warn("Endpoint is already assigned to current user {}.", endpoint
                        .getEndpointUserId());
                return getDto(endpoint);
          }*/**

          if (endpointIds
              == null) {
            endpointIds = new ArrayList<>();
            endpointUser.setEndpointIds(endpointIds);
          }
          endpointIds.add(endpoint.getId());
          endpointUser = endpointUserDao.save(endpointUser);
          while (true) {
            try {
              endpoint.setEndpointUserId(endpointUser.getId());
              LOG.trace("Save endpoint user {} and endpoint profile {}", endpointUser, endpoint);
              endpoint = endpointProfileDao.save(endpoint);
              break;
            } catch (KaaOptimisticLockingFailureException ex) {
              LOG.warn("Optimistic lock detected in endpoint profile ", Arrays.toString(endpoint
                      .getEndpointKey()), ex);
              endpoint = endpointProfileDao.findByKeyHash(Sha1HashUtils.hashToBytes(endpoint
                      .getEndpointKey()));
            }
          }
          return getDto(endpoint);
        } else {
          LOG.warn("Endpoint is already assigned to different user {}. Unassign it first!.",
                  endpoint.getEndpointUserId());
          throw new DatabaseProcessingException("Endpoint is already assigned to different user.");
        }
      } else {
        LOG.warn("Endpoint with accessToken {} is not present in db.", endpointAccessToken);
        throw new DatabaseProcessingException("No endpoint found for specified accessToken.");
      }
    } else {
      LOG.warn("Endpoint user with id {} is not present in db.", endpointUserId);
      throw new DatabaseProcessingException("Endpoint user is not present in db.");
    }
  }

2、

public EndpointProfileDto attachEndpointToUser(String userExternalId, String tenantId,
                                                 EndpointProfileDto profile) {
    validateString(userExternalId, "Incorrect userExternalId "
                                   + userExternalId);
    EndpointUser endpointUser = endpointUserDao.findByExternalIdAndTenantId(userExternalId,
            tenantId);
    if (endpointUser
        == null) {
      LOG.info("Creating new endpoint user with external id: [{}] in context of [{}] tenant",
              userExternalId, tenantId);
      EndpointUserDto endpointUserDto = new EndpointUserDto();
      endpointUserDto.setTenantId(tenantId);
      endpointUserDto.setExternalId(userExternalId);
      endpointUserDto.setUsername(userExternalId);
      endpointUser = endpointUserDao.save(endpointUserDto);
    }
    List<String> endpointIds = endpointUser.getEndpointIds();
    if (endpointIds
        == null) {
      endpointIds = new ArrayList<>();
      endpointUser.setEndpointIds(endpointIds);
    } **/*else if (endpointIds
               != null
               && endpointIds.contains(profile.getId())) {
      LOG.warn("Endpoint is already assigned to current user {}.", profile.getEndpointUserId());
      return profile;
    }*/**
    endpointIds.add(profile.getId());
    endpointUser = endpointUserDao.save(endpointUser);
    profile.setEndpointUserId(endpointUser.getId());
    while (true) {
      try {
        LOG.trace("Save endpoint user {} and endpoint profile {}", endpointUser, profile);
        return saveEndpointProfile(profile);
      } catch (KaaOptimisticLockingFailureException ex) {
        LOG.warn("Optimistic lock detected in endpoint profile ", Arrays.toString(profile
                .getEndpointKey()), ex);
        profile = findEndpointProfileByKeyHash(profile.getEndpointKeyHash());
        profile.setEndpointUserId(endpointUser.getId());
      }
    }
  }

上面的代码是在kaa 0.10 中。与Kaa 0.9 相比,它在上面的Bold 代码中增加了一个判断条件:(

if(endpointIds!=null&&endpointIds.contains(endpoint.getId())) )

否则 if (endpointIds != null && endpointIds.contains(profile.getId()))。

我做了一个评论判断条件代码的测试。结果没问题。我想知道修复方法是否可用。

4

1 回答 1

0

您可以为 kaa 做出贡献。您可以在此处找到有关此过程的说明。

简单地说:

  1. 在这里fork kaa 存储库
  2. 使用您要修复的分支内容创建新分支(release-0.10)
  3. 提交(提交消息必须以“KAA-1594:”开头)并将更改推送到您的分叉中。
  4. 在 kaa 页面上创建拉取请求(比较原始 kaa 分支 release-0.10 和您新编辑的分支)
  5. 允许所有者进行更改
  6. 你完成了!

UPD:如果您在 github 上描述问题和您的问题解决方案会很棒,它将帮助我们更快地进行官方修复。

于 2016-12-06T12:00:20.060 回答