コード例 #1
0
 @Override
 public Account getAccountByKeys(String access, String secretKey) {
   try {
     Credential credential =
         create()
             .selectFrom(CREDENTIAL)
             .where(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE))
             .and(CREDENTIAL.PUBLIC_VALUE.eq(access))
             .and(CREDENTIAL.KIND.in(SUPPORTED_TYPES.get()))
             .fetchOne();
     if (credential == null) {
       return null;
     }
     boolean secretIsCorrect =
         ApiContext.getContext()
             .getTransformationService()
             .compare(secretKey, credential.getSecretValue());
     if (secretIsCorrect) {
       return create()
           .selectFrom(ACCOUNT)
           .where(
               ACCOUNT
                   .ID
                   .eq(credential.getAccountId())
                   .and(ACCOUNT.STATE.eq(CommonStatesConstants.ACTIVE)))
           .fetchOneInto(AccountRecord.class);
     } else {
       return null;
     }
   } catch (InvalidResultException e) {
     throw new ClientVisibleException(ResponseCodes.CONFLICT, "MultipleKeys");
   }
 }
コード例 #2
0
 @Override
 public Account getAccountByLogin(String publicValue, String secretValue) {
   Credential credential =
       create()
           .selectFrom(CREDENTIAL)
           .where(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE))
           .and(
               CREDENTIAL
                   .PUBLIC_VALUE
                   .eq(publicValue)
                   .and(CREDENTIAL.KIND.equalIgnoreCase(CredentialConstants.KIND_PASSWORD)))
           .fetchOne();
   if (credential == null) {
     return null;
   }
   boolean secretIsCorrect =
       ApiContext.getContext()
           .getTransformationService()
           .compare(secretValue, credential.getSecretValue());
   if (secretIsCorrect) {
     return create()
         .selectFrom(ACCOUNT)
         .where(
             ACCOUNT
                 .ID
                 .eq(credential.getAccountId())
                 .and(ACCOUNT.STATE.eq(CommonStatesConstants.ACTIVE)))
         .fetchOneInto(AccountRecord.class);
   } else {
     return null;
   }
 }
コード例 #3
0
 @Override
 public Account getAccountById(Long id) {
   return create()
       .selectFrom(ACCOUNT)
       .where(
           ACCOUNT
               .ID
               .eq(id)
               .and(ACCOUNT.STATE.ne(CommonStatesConstants.PURGED))
               .and(ACCOUNT.REMOVED.isNull()))
       .fetchOne();
 }
コード例 #4
0
  @Override
  public void updateAccount(
      Account account, String name, String kind, String externalId, String externalType) {
    Map<TableField<AccountRecord, String>, String> properties = new HashMap<>();
    if (StringUtils.isNotEmpty(name)) {
      properties.put(ACCOUNT.NAME, name);
    }
    if (StringUtils.isNotEmpty(kind)) {
      properties.put(ACCOUNT.KIND, kind);
    }
    if (StringUtils.isNotEmpty(externalId)) {
      properties.put(ACCOUNT.EXTERNAL_ID, externalId);
    }
    if (StringUtils.isNotEmpty(externalType)) {
      properties.put(ACCOUNT.EXTERNAL_ID_TYPE, externalType);
    }
    int updateCount =
        create().update(ACCOUNT).set(properties).where(ACCOUNT.ID.eq(account.getId())).execute();

    if (1 != updateCount) {
      throw new RuntimeException("UpdateAccount failed.");
    }
  }