0

kaa 0.10のバグが私のアプリケーション開発に影響を与えました。そこで、修正を試みます。それから、kaa 0.9 と kaa 0.10 のコードを比較しました。Kaa DAO インターフェイス モジュラーのクラス EndpointServiceImpl の違いを発見しました。そこには、attachEndpointToUser の 2 つのメソッドがあります。

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&&endpointIds.contains(endpoint.getId())) )

それ以外の場合 (endpointIds != null && endpointIds.contains(profile.getId()))。

判定条件コードをコメントしたテストを作成しました。結果はOKです。修正方法があることを知りたい。

4

1 に答える 1

0

kaaに寄付できます。この手順の説明は、こちらにあります。

それについて一言で言えば:

  1. fork kaa リポジトリはこちら。
  2. 修正したいブランチの内容で新しいブランチを作成する(リリース-0.10)
  3. commit (commit メッセージは "KAA-1594:" で始まる必要があります) し、変更をフォークにプッシュします。
  4. kaa ページでプル リクエストを作成します (元の kaa ブランチ リリース 0.10 と新しく編集したブランチを比較してください)。
  5. 所有者からの変更を許可する
  6. あなたは終わった!

UPD: 問題と解決策を github で説明していただければ、正式な修正をより迅速に行うのに役立ちます。

于 2016-12-06T12:00:20.060 に答える