Hi All,

I have few of questions regarding, How the View will index and which is 
nice approach to write view.

First, let me explain some of test cases

> I have three role like(employee,student,clark), i want make index as per 
login user, if login user has a employee than i have to show only employee 
documents, else if login user has a student than i have to show only 
student documents, else if login user has a clark than i have to show only 
the clark document. some of the documents both will contains 
employee+student than if employee login i have to show all documents to 
him(employee+student).

> And also there is filter replication as per login user(But i am not 
removing any document because i need all documents in local)

> Here is my view. lets now login user is student
> Note: Once i found the my login user in any role, where i need to stop 
that why i wrote return a value, i am not emitting next level(reason is it 
may take time)

 com.couchbase.lite.View viewPerAuditTemplateStatus = 
database.getView(String.format("%s/%s", D_DOCNAME, EMPLOYEE_VIEW));
viewPerAuditTemplateStatus.setMap(new Mapper() {
    @Override
    public void map(Map<String, Object> document, Emitter emitter) {

        Object type = document.get(TYPE);
        String archivedState;
        if (document.containsKey(ARCHIVED))
            archivedState = (String) document.get(ARCHIVED) != null ? 
ARCHIVED : UNARCHIVED;
        else
            archivedState = UNARCHIVED;
        if (type != null && DOCTYPE_AUDIT.equals(type)) {
            emitter.emit(new 
Object[]{*getTicketFilteredEmailID*(*document*),document.get(PROJECT), 
archivedState, document.get(TEMPLATE), document.get(STATUS), 
document.get(NAME)}, document);
        }
    }
}, "1.1");

//Here is my role selecting method
private String getTicketFilteredEmailID(Map<String, Object> document){
        if(document.containsKey(PARTICIPANTS)) {
            HashMap<Object, Object> participantsObjectHashMap = 
(HashMap<Object, Object>) document.get(PARTICIPANTS);
            // check responsible
            if (participantsObjectHashMap != null) {
                try {
                    if (participantsObjectHashMap.containsKey(EMPLOYEE)) {
                        HashMap<String, String> employee = (HashMap<String, 
String>) participantsObjectHashMap.get(EMPLOYEE);
                        if (employee.containsKey(EMAIL) && 
employee.get(EMAIL).equalsIgnoreCase(AppConstants.roleEmailId)) {
                            return employee.get(EMAIL);
                        }
                    }
                }catch (Exception ex){
                    Alert.getInstance().callLog("Exception in view 
"+ex.getMessage()+"/"+document.get(ID));
                }
                if (participantsObjectHashMap.containsKey(STUDENT)) {
                    ArrayList<HashMap<String, String>> studentHashMap = 
(ArrayList<HashMap<String, String>>) participantsObjectHashMap.get(STUDENT);
                    for (HashMap<String, String> support : studentHashMap) {
                        if (studentHashMap.containsKey(EMAIL) && 
studentHashMap.get(EMAIL).equalsIgnoreCase(AppConstants.roleEmailId)) {
                            return studentHashMap.get(EMAIL);
                        }
                    }
                }
                if (participantsObjectHashMap.containsKey(CLARK)) {
                    HashMap<String, String> clark = (HashMap<String, 
String>) participantsObjectHashMap.get(CLARK);
                    if (clark.containsKey(EMAIL) && 
clark.get(EMAIL).equalsIgnoreCase(AppConstants.roleEmailId)) {
                        return clark.get(EMAIL);
                    }
                }
        }
        return null;
    }


> Where i can get all student document.

> If again login user is a employee where some of the documents are missing, 
> the reason is some of the document index is not happen to employee because 
> index is done in at the time student login so those documents i am not 
> getting.


So i would like to get documents according to this test cases.


What are the possible i think?

1) we can do emitting for all the roles while remove the return statement in 
that method, so that index will remember that.

2) Or else we can change the index version,so that it will reindex the all the 
documents

3) Or else while user logout, we have to delete all the exiting index in 
database and reindex.


There is a lot of confusion for me as per performance and which approach will 
take more time and all.


Please if any body explain me how we can achieve this and how the indexing will 
work and what is the best approach as per performance and also time taking 
process


please let me know if need any clarification. 


Thank you

prasanna

 
 

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/d0876a24-fe49-461d-bcae-a64922d2eb6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to