修复了将端点附加到用户后KAA-1594:错误的错误

时间:2016-12-06 03:03:58

标签: kaa

kaa 0.10中的

The 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相比,它增加了一个判断条件,在上面的粗体代码中:(

  

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

  

else if(endpointIds                      != null                      &安培;&安培; endpointIds.contains(profile.getId()))。

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

1 个答案:

答案 0 :(得分:0)

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

用几句话来说:

  1. fork kaa repository here.
  2. 克里特新分支,包含您要修复的分支内容(release-0.10)
  3. commit(提交消息必须以“KAA-1594:”开头)并将更改推送到您的分支中。
  4. 在kaa页面上创建一个拉取请求(比较原始kaa分支发布-0.10和您新编辑的分支)
  5. 允许所有者进行更改
  6. 你完成了!
  7. UPD:如果您在github上描述问题并解决问题,那将会很棒。它将帮助我们更快地进行官方修复。