本文整理汇总了Java中org.commcare.core.interfaces.UserSandbox类的典型用法代码示例。如果您正苦于以下问题:Java UserSandbox类的具体用法?Java UserSandbox怎么用?Java UserSandbox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserSandbox类属于org.commcare.core.interfaces包,在下文中一共展示了UserSandbox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWrappedDisplaytitle
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
/**
* Get the title of the current screen, wrapped with the relevant app metadata.
*/
public String getWrappedDisplaytitle(UserSandbox sandbox, CommCarePlatform platform) {
String title = getScreenTitle();
if (title == null) {
try {
title = Localization.get("app.display.name");
} catch (NoLocalizedTextException e) {
//swallow. Unimportant
title = "CommCare";
}
}
String userSuffix = sandbox.getLoggedInUser() != null ? " | " + sandbox.getLoggedInUser().getUsername() : "";
String version = (" [" + platform.getCurrentProfile().getVersion() + "]");
return title + userSuffix + version;
}
示例2: process
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
public static void process(final UserSandbox sandbox, InputStream stream)
throws InvalidStructureException, IOException, XmlPullParserException,
UnfullfilledRequirementsException {
process(stream, new TransactionParserFactory() {
@Override
public TransactionParser getParser(KXmlParser parser) {
if (LedgerXmlParsers.STOCK_XML_NAMESPACE.equals(parser.getNamespace())) {
return new LedgerXmlParsers(parser, sandbox.getLedgerStorage());
} else if ("case".equalsIgnoreCase(parser.getName())) {
return new CaseXmlParser(parser, sandbox.getCaseStorage());
}
return null;
}
});
}
示例3: loadFixture
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
/**
* Load the referenced fixture out of storage for the provided user
*
* @param sandbox The current user's sandbox
* @param refId The jr:// reference
* @param userId The user's ID
* @return The form instance matching the refId in the sandbox
*/
public static FormInstance loadFixture(UserSandbox sandbox,
String refId, String userId) {
IStorageUtilityIndexed<FormInstance> userFixtureStorage =
sandbox.getUserFixtureStorage();
Vector<Integer> userFixtures =
userFixtureStorage.getIDsForValue(FormInstance.META_ID, refId);
if (userFixtures.size() == 1) {
return userFixtureStorage.read(userFixtures.elementAt(0));
// TODO: Userid check anyway?
} else if (userFixtures.size() > 1) {
FormInstance result = intersectFixtureSets(userFixtureStorage, userId, userFixtures);
if (result != null) {
return result;
}
}
return loadAppFixture(sandbox, refId, userId);
}
示例4: loadAppFixture
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
private static FormInstance loadAppFixture(UserSandbox sandbox, String refId, String userId) {
IStorageUtilityIndexed<FormInstance> appFixtureStorage =
sandbox.getAppFixtureStorage();
Vector<Integer> appFixtures = appFixtureStorage.getIDsForValue(FormInstance.META_ID, refId);
Integer globalFixture =
ArrayUtilities.intersectSingle(appFixtureStorage.getIDsForValue(FormInstance.META_XMLNS, ""), appFixtures);
if (globalFixture != null) {
return appFixtureStorage.read(globalFixture);
} else {
// See if we have one manually placed in the suite
Integer userFixture =
ArrayUtilities.intersectSingle(appFixtureStorage.getIDsForValue(FormInstance.META_XMLNS, userId), appFixtures);
if (userFixture != null) {
return appFixtureStorage.read(userFixture);
}
// Otherwise, nothing
return null;
}
}
示例5: performCasePurge
import org.commcare.core.interfaces.UserSandbox; //导入依赖的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");
}
}
示例6: testGoBackAfterEndOfFormNavigation
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
/**
* This is the stack state we would be in after end of form navigation
* - this test ensures that we correctly resolve the unknown state (a
* case selection)
*/
@Test
public void testGoBackAfterEndOfFormNavigation() throws Exception {
MockApp mockApp = new MockApp("/nav_back/");
SessionWrapper session = mockApp.getSession();
UserSandbox sandbox = session.getSandbox();
SessionWrapper blankSession = new SessionWrapper(session.getPlatform(), sandbox);
String descriptor = "COMMAND_ID m1 " +
"STATE_UNKNOWN case_id test_id";
SessionDescriptorUtil.loadSessionFromDescriptor(descriptor, blankSession);
assertEquals(SessionFrame.STATE_COMMAND_ID, blankSession.getNeededData());
blankSession.stepBack();
assertEquals(SessionFrame.STATE_DATUM_VAL, blankSession.getNeededData());
blankSession.stepBack();
assertEquals(SessionFrame.STATE_COMMAND_ID, blankSession.getNeededData());
}
示例7: loadRegistrationFormTitleFromSessionTest
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
/**
* Load form title from session where the case id is computed, not
* selected, and the case name is loaded from detail referenced by m0-f0,
* which is implicitly referenced
*/
@Test
public void loadRegistrationFormTitleFromSessionTest() throws Exception {
MockApp mockApp = new MockApp("/case_title_form_loading/");
SessionWrapper session = mockApp.getSession();
UserSandbox sandbox = session.getSandbox();
SessionWrapper blankSession = new SessionWrapper(session.getPlatform(), sandbox);
String descriptor = "COMMAND_ID m0 "
+ "COMMAND_ID m3-f0 "
+ "CASE_ID case_id_new_adult_0 case_one "
+ "CASE_ID usercase_id 05c0fb7a77a54eed9872fc1b72a21826 "
+ "CASE_ID return_to m0";
SessionDescriptorUtil.loadSessionFromDescriptor(descriptor, blankSession);
String title = FormDataUtil.getTitleFromSession(sandbox,
blankSession, blankSession.getEvaluationContext());
assertEquals("Saul", title);
}
示例8: process
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
public static void process(final UserSandbox sandbox, InputStream stream) throws InvalidStructureException, IOException, XmlPullParserException, UnfullfilledRequirementsException, StorageFullException {
process(stream, new TransactionParserFactory() {
public TransactionParser getParser(KXmlParser parser) {
if (LedgerXmlParsers.STOCK_XML_NAMESPACE.equals(parser.getNamespace())) {
return new LedgerXmlParsers(parser, sandbox.getLedgerStorage());
} else if ("case".equalsIgnoreCase(parser.getName())) {
return new CaseXmlParser(parser, sandbox.getCaseStorage());
}
return null;
}
});
}
示例9: extractEntityOwners
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
/**
* For the users and groups in the provided sandbox, extracts out the list
* of valid "owners" for entities (cases, ledgers, etc) in the universe.
*
*/
public static Vector<String> extractEntityOwners(UserSandbox sandbox) {
Vector<String> owners = new Vector<String>();
Vector<String> users = new Vector<String>();
for (IStorageIterator<User> userIterator = sandbox.getUserStorage().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 = loadFixture(sandbox, "user-groups", userId);
if (instance == null) {
continue;
}
EvaluationContext ec = new EvaluationContext(instance);
for (TreeReference ref : ec.expandReference(XPathReference.getPathExpr("/groups/group/@id").getReference())) {
AbstractTreeElement idElement = ec.resolveReference(ref);
if (idElement.getValue() != null) {
owners.addElement(idElement.getValue().uncast().getString());
}
}
}
return owners;
}
示例10: getInstanceContexts
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
/**
* A quick way to request an evaluation context with an abstract instance available.
*
* Used in Touchforms
*/
@SuppressWarnings("unused")
public static EvaluationContext getInstanceContexts(UserSandbox sandbox, String instanceId, String instanceRef){
InstanceInitializationFactory iif = new CommCareInstanceInitializer(sandbox);
Hashtable<String, DataInstance> instances = new Hashtable<String, DataInstance>();
ExternalDataInstance edi = new ExternalDataInstance(instanceRef, instanceId);
edi.initialize(iif, instanceId);
instances.put(instanceId, edi);
return new EvaluationContext(null, instances);
}
示例11: CommCareTransactionParserFactory
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
public CommCareTransactionParserFactory(UserSandbox sandbox) {
this.sandbox = sandbox;
this.initFixtureParser();
this.initUserParser();
this.initCaseParser();
this.initStockParser();
}
示例12: IndexedFixtureXmlParser
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
public IndexedFixtureXmlParser(KXmlParser parser, String fixtureId,
FixtureIndexSchema schema, UserSandbox sandbox) {
super(parser);
this.sandbox = sandbox;
this.fixtureName = fixtureId;
if (schema == null) {
// don't create any table indices if there was no fixture index schema
this.indices = new HashSet<>();
this.columnIndices = new HashSet<>();
} else {
this.indices = schema.getSingleIndices();
this.columnIndices = schema.getColumnIndices();
}
}
示例13: getTitleFromSession
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
public static String getTitleFromSession(UserSandbox userSandbox,
CommCareSession session,
EvaluationContext evalContext) {
CommCareSession sessionCopy = new CommCareSession(session);
String datumValue = null;
while (sessionCopy.getFrame().getSteps().size() > 0) {
SessionDatum datum = sessionCopy.getNeededDatum();
if (isCaseIdComputedDatum(datum, datumValue, sessionCopy.getPoppedStep())) {
// Loads case id for forms that create cases, since case id was
// a computed datum injected into the form. Assumes that it was
// the 1st computed datum... another good heuristic would be
// session.getPoppedStep().getId().startsWith("case_id")
datumValue = sessionCopy.getPoppedStep().getValue();
} else if (datum instanceof EntityDatum) {
String tmpDatumValue = sessionCopy.getPoppedStep().getValue();
if (tmpDatumValue != null) {
datumValue = tmpDatumValue;
}
if (((EntityDatum)datum).getLongDetail() == null) {
// In the absence of a case detail, use the plain case name as the title
break;
} else {
return loadTitleFromEntity((EntityDatum)datum, datumValue, evalContext, sessionCopy, userSandbox);
}
}
sessionCopy.popStep(evalContext);
}
if (datumValue == null) {
return null;
} else {
return getCaseName(userSandbox, datumValue);
}
}
示例14: loadTitleFromEntity
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
private static String loadTitleFromEntity(EntityDatum entityDatum, String value,
EvaluationContext evalContext,
CommCareSession sessionCopy,
UserSandbox userSandbox) {
TreeReference elem = entityDatum.getEntityFromID(evalContext, value);
if (elem == null) {
return null;
}
Text detailText = sessionCopy.getDetail(entityDatum.getLongDetail()).getTitle().getText();
boolean isPrettyPrint = true;
//CTS: this is... not awesome.
//But we're going to use this to test whether we _need_ an evaluation context
//for this. (If not, the title doesn't have prettyprint for us)
try {
String outcome = detailText.evaluate();
if (outcome != null) {
isPrettyPrint = false;
}
} catch (Exception e) {
//Cool. Got us a fancy string.
}
if (isPrettyPrint) {
// Get the detail title for that element
EvaluationContext elementContext = new EvaluationContext(evalContext, elem);
return detailText.evaluate(elementContext);
} else {
return getCaseName(userSandbox, value);
}
}
示例15: getCaseName
import org.commcare.core.interfaces.UserSandbox; //导入依赖的package包/类
private static String getCaseName(UserSandbox userSandbox, String caseId) {
try {
Case ourCase = userSandbox.getCaseStorage().getRecordForValue(Case.INDEX_CASE_ID, caseId);
if (ourCase != null) {
return ourCase.getName();
} else {
return null;
}
} catch (Exception e) {
return null;
}
}