554325746@qq.com
2019-08-07 2539f53391765abb74b6fe63f46e5a2c701e950f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.basic.security.manager.impl.cblite;
 
import android.text.TextUtils;
 
import com.basic.security.manager.impl.sqlite.SlIdentityManager;
import com.basic.security.utils.Constants;
import com.couchbase.lite.Expression;
import com.basic.security.model.ModelAdapter;
 
import java.util.ArrayList;
import java.util.List;
 
public class IdentityManager extends BaseManager {
 
    public static List<ModelAdapter> findIdentityList() {
        if (Constants.useCouchbase) {
            Expression expression = Expression.property("table").equalTo(Expression.string("identity"));
 
            return findList(expression);
        } else {
            return SlIdentityManager.findIdentityList();
        }
    }
 
    public static List<String> findIdentityNameListByPersonId(String personId) {
        if (Constants.useCouchbase) {
            List<String> identityNameList = new ArrayList();
            List<ModelAdapter> personPersonIdentity = PersonIdentityManager.findPersonIdentityListByPersonId(personId);
            for (ModelAdapter personIdentity : personPersonIdentity) {
                String identityId = personIdentity.getString("identity_id");
                ModelAdapter identityDocument = findById(identityId);
                if (identityDocument != null) {
                    String identityName = identityDocument.getString("name");
                    if (!TextUtils.isEmpty(identityName)) {
                        identityNameList.add(identityName);
                    }
                }
            }
            return identityNameList;
        } else {
            return SlIdentityManager.findIdentityNameListByPersonId(personId);
        }
    }
 
    public static ModelAdapter findIdentityById(String id) {
        if (Constants.useCouchbase) {
            return BaseManager.findById(id);
        } else {
            return SlIdentityManager.findIdentityById(id);
        }
    }
}