Search in sources :

Example 1 with OAuth2UsersRecord

use of com.infiniteautomation.mango.db.tables.records.OAuth2UsersRecord in project ma-core-public by infiniteautomation.

the class UserDao method updateLinkedAccounts.

public void updateLinkedAccounts(int userId, Iterable<? extends LinkedAccount> accounts) {
    this.doInTransaction(txStatus -> {
        create.deleteFrom(oauth).where(oauth.userId.equal(userId)).execute();
        InsertValuesStep3<OAuth2UsersRecord, Integer, String, String> insert = create.insertInto(oauth, oauth.userId, oauth.issuer, oauth.subject);
        for (LinkedAccount account : accounts) {
            if (account instanceof OAuth2LinkedAccount) {
                OAuth2LinkedAccount oAuth2Account = (OAuth2LinkedAccount) account;
                insert = insert.values(userId, oAuth2Account.getIssuer(), oAuth2Account.getSubject());
            } else {
                throw new UnsupportedOperationException();
            }
        }
        insert.execute();
    });
}
Also used : OAuth2LinkedAccount(com.serotonin.m2m2.vo.OAuth2LinkedAccount) OAuth2UsersRecord(com.infiniteautomation.mango.db.tables.records.OAuth2UsersRecord) OAuth2LinkedAccount(com.serotonin.m2m2.vo.OAuth2LinkedAccount) LinkedAccount(com.serotonin.m2m2.vo.LinkedAccount)

Aggregations

OAuth2UsersRecord (com.infiniteautomation.mango.db.tables.records.OAuth2UsersRecord)1 LinkedAccount (com.serotonin.m2m2.vo.LinkedAccount)1 OAuth2LinkedAccount (com.serotonin.m2m2.vo.OAuth2LinkedAccount)1