-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRDelete.java
More file actions
52 lines (46 loc) · 2.3 KB
/
CRDelete.java
File metadata and controls
52 lines (46 loc) · 2.3 KB
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
/*
Created by Ashok for Grievance system on 11/10/2019
*/
/*
The below function is implemented inside a manual action button , which will be inside authority app to
delete all CR students after a semester or any duration.
The task is deleted into two parts i.e to delete all student tag from database and
then delete the CR root node.
*/
public void deleteCR() {
final DatabaseReference mRootDatabase, mDatabase, mCrReference;
mRootDatabase = FirebaseDatabase.getInstance().getReference().child("app");
mDatabase = mRootDatabase.child("cr");
mCrReference = mRootDatabase.child("users").child("students");
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot crdata : dataSnapshot.getChildren()) {
String uid = crdata.getKey();
if (uid != null) {
mCrReference.child(uid).child("tag").setValue("default").addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.v("Cr_removal_Error", e.getMessage());
}
});
}
}
// The code to delete main CR node
mDatabase.removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Snackbar snackbar = Snackbar.make(rootlayout, "All CR are removed", Snackbar.LENGTH_LONG); // rootlayout need to be provided
snackbar.show();
} else
Log.v("CR_Node_Error", task.getException().getMessage());
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.v("Error_in_students_node", databaseError.getMessage());
}
});
}