本文整理汇总了Java中org.commcare.cases.util.CasePurgeFilter类的典型用法代码示例。如果您正苦于以下问题:Java CasePurgeFilter类的具体用法?Java CasePurgeFilter怎么用?Java CasePurgeFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CasePurgeFilter类属于org.commcare.cases.util包,在下文中一共展示了CasePurgeFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOwnerPurge
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
private void testOwnerPurge() {
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), c.getID(), b.getID(), d.getID()};
int[] toRemove = new int[] { };
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage, userOwned));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例2: testUnownedPurge
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
private void testUnownedPurge() {
b.setUserId(otherOwner);
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), c.getID(), d.getID()};
int[] toRemove = new int[] { b.getID()};
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage, userOwned));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例3: testOwnerLiveness
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
private void testOwnerLiveness() {
b.setUserId(otherOwner);
c.setUserId(otherOwner);
d.setIndex("b","b",b.getCaseId());
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), b.getID(), d.getID()};
int[] toRemove = new int[] { c.getID()};
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage, userOwned));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例4: testNoDependence
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
public void testNoDependence() {
b.setClosed(true);
d.setClosed(true);
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), c.getID()};
int[] toRemove = new int[] { b.getID(), d.getID() };
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例5: testLiveDependency
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
public void testLiveDependency() {
b.setClosed(true);
d.setIndex("b", "b", b.getCaseId());
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), b.getID(), c.getID(), d.getID()};
int[] toRemove = new int[] { };
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例6: testDependenceDirection
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
public void testDependenceDirection() {;
d.setIndex("b", "b", b.getCaseId());
d.setClosed(true);
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), b.getID(), c.getID()};
int[] toRemove = new int[] {d.getID()};
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例7: testDeadness
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
public void testDeadness() {
b.setClosed(true);
d.setIndex("b", "b", b.getCaseId());
d.setClosed(true);
try {
storage.write(a);
storage.write(b);
storage.write(c);
storage.write(d);
int[] present = new int[] {a.getID(), c.getID()};
int[] toRemove = new int[] {b.getID(), d.getID()};
Vector<Integer> removed = storage.removeAll(new CasePurgeFilter(storage));
testOutcome(storage, present, toRemove);
testRemovedClaim(removed, toRemove);
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e.getMessage());
}
}
示例8: testSimpleExtensions
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
@Test
public void testSimpleExtensions() throws Exception {
MockUserDataSandbox sandbox;
Vector<String> owners;
sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/simple_extension_test.xml"), sandbox);
owners = SandboxUtils.extractEntityOwners(sandbox);
CasePurgeFilter purger = new CasePurgeFilter(sandbox.getCaseStorage(), owners);
int removedCases = sandbox.getCaseStorage().removeAll(purger).size();
if (removedCases > 0) {
throw new RuntimeException("Incorrectly removed cases");
}
}
示例9: test
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
@Test
public void test() {
CasePurgeFilter purger = new CasePurgeFilter(sandbox.getCaseStorage(), owners);
int removedCases = sandbox.getCaseStorage().removeAll(purger).size();
if (removedCases == 0) {
throw new RuntimeException("Failed to remove purged case");
}
if (sandbox.getCaseStorage().getNumRecords() < 1) {
throw new RuntimeException("Incorrectly purged case");
}
if (sandbox.getCaseStorage().getNumRecords() > 1) {
throw new RuntimeException("Incorrectly retained case");
}
if(!"sync_token_a".equals(sandbox.getSyncToken())) {
throw new RuntimeException("Invalid Sync Token: " + sandbox.getSyncToken());
}
}
示例10: performCasePurge
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
public void performCasePurge(UserSandbox sandbox) {
printStream.println("Performing Case Purge");
CasePurgeFilter purger = new CasePurgeFilter(sandbox.getCaseStorage(),
SandboxUtils.extractEntityOwners(sandbox));
int removedCases = sandbox.getCaseStorage().removeAll(purger).size();
printStream.println("");
printStream.println("Purge Report");
printStream.println("=========================");
if (removedCases == 0) {
printStream.println("0 Cases Purged");
} else {
printStream.println("Cases Removed from device[" + removedCases + "]: " +
purger.getRemovedCasesString());
}
if (!("".equals(purger.getRemovedCasesString()))) {
printStream.println("[Error/Warning] Cases Missing from Device: " + purger.getMissingCasesString());
}
if (purger.invalidEdgesWereRemoved()) {
printStream.println("[Error/Warning] During Purge Invalid Edges were Detected");
}
}
示例11: executeTest
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
@Test
public void executeTest() {
DummyIndexedStorageUtility<Case> storage =
new DummyIndexedStorageUtility<>(Case.class, new LivePrototypeFactory());
String userId = "user";
initCaseStorage(storage, userId);
Vector<String> ownerIds = new Vector<>();
ownerIds.add(userId);
storage.removeAll(new CasePurgeFilter(storage, ownerIds));
HashSet<String> inStorage = new HashSet<>();
for (IStorageIterator<Case> iterator = storage.iterate(); iterator.hasMore(); ) {
Case c = iterator.nextRecord();
inStorage.add(c.getCaseId());
}
Assert.assertEquals(name, outcomeSet, inStorage);
}
示例12: caseFilter
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
private EntityFilter<Case> caseFilter() {
//We need to determine if we're using ownership for purging. For right now, only in sync mode
Vector<String> owners = null;
if(CommCareProperties.TETHER_SYNC.equals(PropertyManager._().getSingularProperty(CommCareProperties.TETHER_MODE))) {
owners = new Vector<String>();
Vector<String> users = new Vector<String>();
for(IStorageIterator<User> userIterator = StorageManager.getStorage(User.STORAGE_KEY).iterate(); userIterator.hasMore();) {
String id = userIterator.nextRecord().getUniqueId();
owners.addElement(id);
users.addElement(id);
}
//Now add all of the relevant groups
//TODO: Wow. This is.... kind of megasketch
for(String userId : users) {
DataInstance instance = CommCareUtil.loadFixtureForUser("user-groups", userId);
if(instance == null) { continue; }
EvaluationContext ec = new EvaluationContext(instance);
for(TreeReference ref : ec.expandReference(XPathReference.getPathExpr("/groups/group/@id").getReference())) {
AbstractTreeElement<AbstractTreeElement> idelement = ec.resolveReference(ref);
if(idelement.getValue() != null) {
owners.addElement(idelement.getValue().uncast().getString());
}
}
}
}
return new CasePurgeFilter((RMSStorageUtilityIndexed<Case>)StorageManager.getStorage(Case.STORAGE_KEY), owners);
}
示例13: testValidateCaseGraphBeforePurge_simple
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
/**
* Test correct validation of a graph where 1 case indexes a non-existent node
*/
@Test
public void testValidateCaseGraphBeforePurge_simple() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_simple.xml"), sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
HashMap<String, Integer> caseIdsToRecordIds = createCaseIdsMap(storage);
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_one");
nodesExpectedToBeLeft.add("case_two");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_two", "case_one"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
expectedToRemove.add(caseIdsToRecordIds.get("case_three"));
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}
示例14: testValidateCaseGraphBeforePurge_complex
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
/**
* Test correct validation of a graph where 2 different cases index the same non-existent node,
* and both of those cases have child nodes
*/
@Test
public void testValidateCaseGraphBeforePurge_complex() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_complex.xml"), sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
HashMap<String, Integer> caseIdsToRecordIds = createCaseIdsMap(storage);
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_one");
nodesExpectedToBeLeft.add("case_two");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_two", "case_one"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
expectedToRemove.add(caseIdsToRecordIds.get("case_three"));
expectedToRemove.add(caseIdsToRecordIds.get("case_four"));
expectedToRemove.add(caseIdsToRecordIds.get("case_five"));
expectedToRemove.add(caseIdsToRecordIds.get("case_six"));
expectedToRemove.add(caseIdsToRecordIds.get("case_seven"));
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}
示例15: testValidateCaseGraphBeforePurge_multipleParents
import org.commcare.cases.util.CasePurgeFilter; //导入依赖的package包/类
/**
* Test correct validation of a graph where 1 case indexes 2 other cases - 1 valid and 1 that
* does not exist
*/
@Test
public void testValidateCaseGraphBeforePurge_multipleParents() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_multiple_parents.xml"),
sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
HashMap<String, Integer> caseIdsToRecordIds = createCaseIdsMap(storage);
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_two");
nodesExpectedToBeLeft.add("case_three");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_three", "case_two"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
expectedToRemove.add(caseIdsToRecordIds.get("case_one"));
expectedToRemove.add(caseIdsToRecordIds.get("case_four"));
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}