use of org.opentransactions.otapi.StringMap in project otapij by FellowTraveler.
the class Basket method getRegisteredAssets.
public static List getRegisteredAssets(String serverID, String nymID) {
System.out.println("getRegisteredAssets - serverID:" + serverID + " nymID:" + nymID);
List registeredAssetsList = null;
// output will go here.
String strEncodedObj = null;
// we are about to create this object
StringMap stringMap = null;
Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_STRING_MAP);
if (storable != null) {
stringMap = StringMap.ot_dynamic_cast(storable);
if (stringMap != null) {
// ADD ALL THE ASSET IDs HERE (To the string map, so you
// can ask the server about them...)
//
int count = otapiJNI.OTAPI_Basic_GetAssetTypeCount();
System.out.println(" count:" + count);
for (int i = 0; i < count; i++) {
String key = otapiJNI.OTAPI_Basic_GetAssetType_ID(i);
System.out.println("key:" + key);
stringMap.SetValue(key, "exists");
}
System.out.println(" BEFORE ENCODE,stringMap:" + stringMap);
strEncodedObj = otapi.EncodeObject(stringMap);
}
}
System.out.println(" fter ENCODE,strEncodedObj:" + strEncodedObj);
if (!Utility.VerifyStringVal(strEncodedObj)) {
System.out.println("strEncodedObj is null");
return null;
//Error;
}
// Then send the server message
OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.QUERY_ASSET_TYPES, serverID, nymID, strEncodedObj);
System.out.println(" theRequest :" + theRequest);
String strResponse = theRequest.SendRequest(theRequest, "QUERY_ASSET_TYPES");
System.out.println(" strResponse:" + strResponse);
String strReplyMap = null;
if (Utility.VerifyStringVal(strResponse)) {
strReplyMap = otapiJNI.OTAPI_Basic_Message_GetPayload(strResponse);
}
System.out.println("strResponse is " + strResponse);
if (Utility.VerifyStringVal(strReplyMap)) {
StringMap stringMapOutput = null;
storable = otapi.DecodeObject(StoredObjectType.STORED_OBJ_STRING_MAP, strReplyMap);
if (storable != null) {
stringMapOutput = StringMap.ot_dynamic_cast(storable);
if (stringMapOutput != null) {
// Loop through string map. For each asset ID key, the value will
// say either "true" or "false".
int count = otapiJNI.OTAPI_Basic_GetAssetTypeCount();
for (int i = 0; i < count; i++) {
String key = otapiJNI.OTAPI_Basic_GetAssetType_ID(i);
System.out.println("key in output:" + key);
String isRegistered = stringMapOutput.GetValue(key);
System.out.println("isRegistered in output:" + isRegistered);
if ("true".equalsIgnoreCase(isRegistered)) {
if (registeredAssetsList == null) {
registeredAssetsList = new ArrayList();
}
registeredAssetsList.add(key);
}
}
}
}
}
System.out.println("registeredAssetsList is " + registeredAssetsList);
return registeredAssetsList;
}
use of org.opentransactions.otapi.StringMap in project otapij by FellowTraveler.
the class Load method SetupPasswordImage.
public boolean SetupPasswordImage(IPasswordImage passwordImage) throws LoadingOpenTransactionsFailure {
if (!isInitialized) {
throw new LoadingOpenTransactionsFailure(LoadErrorType.OTAPI_NOT_INSTIGATED, "Is Not Initialized");
}
if (isPasswordImageSet) {
throw new LoadingOpenTransactionsFailure(LoadErrorType.PASSWORD_IMAGE_ALREADY_SET, "Password Image Already Set!");
}
String imagePath = "";
boolean bHaveImage = false;
// First Lets Check if we already have a password image. (we don't need annother one)
if (otapi.Exists("moneychanger", "settings.dat")) {
Storable storable = null;
StringMap stringMap = null;
storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_STRING_MAP, "moneychanger", "settings.dat");
if (null != storable) {
stringMap = StringMap.ot_dynamic_cast(storable);
imagePath = stringMap.GetValue("ImagePath");
File f = new File(imagePath);
if (f.exists()) {
// Good we have a password Image
bHaveImage = true;
}
}
}
// We don't have an image... lets get it from the user, then save it.
if (!bHaveImage) {
for (; ; ) {
imagePath = passwordImage.GetPasswordImageFromUser("passwordImage");
if (passwordImage.GetIfUserCancelled()) {
bHaveImage = false;
break;
}
File f = new File(imagePath);
if (f.exists()) {
bHaveImage = true;
// Good we have a password Image
break;
}
}
if (!bHaveImage) {
return false;
}
// we are about to create this object
StringMap stringMap = null;
Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_STRING_MAP);
if (storable != null) {
stringMap = StringMap.ot_dynamic_cast(storable);
System.out.println("stringMap:" + stringMap);
if (stringMap != null) {
//stringMap.SetValue("ImagePath", "~/.ot/default.gif");
stringMap.SetValue("ImagePath", imagePath);
bHaveImage = otapi.StoreObject(stringMap, "moneychanger", "settings.dat");
}
}
}
if (bHaveImage) {
passwordImage.SetPasswordImage(imagePath);
} else {
throw new LoadingOpenTransactionsFailure(LoadErrorType.PASSWORD_IMAGE_FAILED_TO_SET, "Password image not Set!");
}
isPasswordImageSet = true;
return true;
}