Podio API - updating contact reference - java

I have an an Podio app that handles customer accounts where each customer has a manager (podio contact). All of this data resides in another system, and we are in the progress off writing software to synch the two. The software is written in java and using the podio api
I'm currently able to read and set all types of fields, except for the manager field (contact).
This is what is received from the API when a customer is loaded:
But how do you go about updating the manager reference to something else?
I've tried something like:
List<Map<String, Object>> list = new ArrayList<>();
HashMap<String, Object> values = new HashMap<>();
list.add(values);
HashMap<String, Object> value = new HashMap<>();
values.put("value", value);
value.put("mail", "employee#email.com");
//also tried user_id and profile_id
and then using the
ItemAPI.updateItemFieldValues(int itemId, int fieldId,
List<Map<String, Object>> values, boolean silent, boolean hook)
to update the field. Where am I going wrong?

Setup:
Podio app with 'Contact' field, configured to 'Workspace members / share when new address added' (like this screnshot)
Working example in Ruby
item_id = <some_item_id>
field_id = <contact_field_numeric_id>
field_external_id = <contact_field_external_id>
# set to empty value by field_id
empty_value = []
Podio::ItemField.update(item_id, field_id, single_value)
# set to single value by field_id
single_value = [{'value' => {'type' => 'user', 'id' => <Podio user id>}}]
Podio::ItemField.update(item_id, field_id, single_value)
# set to multiple values by external field id
multi_values = [{'value' => {'type' => 'user', 'id' => <Podio user id>}},
{'value' => {'type' => 'user', 'id' => <another Podio user id>}}]
Podio::ItemField.update(item_id, field_external_id, multi_values)
Will set this contact field to new value single_value or to list of new values multiple_value. Also, I'd strongly recommend to think again about your data architecture. It might be much more scalable to work with Podio Contact app type and use Reference field instead of using Contact field.
Java example:
HashMap<String, Object> pair = new HashMap<>();
HashMap<String, Object> value = new HashMap<>();
List<Map<String, Object>> list = new ArrayList<>();
// set to empty value
list = new ArrayList<>();
ItemAPI.updateItemFieldValues(<itemId>, <fieldId>, list, <silent>, <hook>)
// set to real value
value = new HashMap<>();
list = new ArrayList<>();
pair.put("id", <user_id>);
pair.put("type", "user");
value.put("value", pair);
list.add(value);
ItemAPI.updateItemFieldValues(<itemId>, <fieldId>, list, <silent>, <hook>)

Related

Adding card source works in 19.45.0, fails in 20.0.0 and above

I am playing with Stripe-Java and I'm trying to add a card to a customer.
My code looks like this:
Customer stripeCustomer = Customer.retrieve("cus_xxxxxxx");
Map<String, Object> cardParam = new HashMap<String, Object>();
cardParam.put("number", "4242424242424242");
cardParam.put("exp_month", "11");
cardParam.put("exp_year", "2022");
cardParam.put("cvc", "123");
//token
Map<String, Object> tokenParam = new HashMap<String, Object>();
tokenParam.put("card", cardParam);
Token token = Token.create(tokenParam);
//user token
Map<String, Object> sourceParam = new HashMap<String, Object>();
sourceParam.put("source", token.getId());
//add to customer
stripeCustomer.getSources().create(sourceParam);
This works successfully on Stripe-Java version 19.45.0 but not on 20.0.0 or any versions above. Has the method to add a card changed?
A nullpointer exception is thrown
Thanks
This : stripeCustomer.getSources() will be null in v20.0.0 and above of the library because it pins to API version 2020-08-27 where customer.sources was removed by default. [0] [1]
The sources property on Customers is no longer included by default.
You can expand the list but for performance reasons we recommended
against doing so unless needed.
You would need to explicitly expand [2] "sources" when retrieving the Customer in order to populate customer.getSources()
CustomerRetrieveParams params = CustomerRetrieveParams.builder()
.addExpand("sources").build();
Customer stripeCustomer = Customer.retrieve("cus_xxxxxxx", params, null);
Also, your code uses the legacy Token API, and is passing raw card details from your server that puts you in PCI scope, you should look into the recommended integration paths : https://stripe.com/docs/payments/accept-a-payment
[0] https://github.com/stripe/stripe-java/blob/master/CHANGELOG.md#2000---2020-08-31
[1] https://stripe.com/docs/upgrades#2020-08-27
[2] https://stripe.com/docs/expand

Query Json Objects using Hazelcast SqlPredicate

I'm using hazelcast in memory in my application.
Can anyone please explain how to query JSON objects using hazelcast..
map(String, new(HazelcastJsonValue());
In the value i'm storing entire JSON.
Storing JSON one by one in value:-
{"id":"01","name":"abc"}
{"id":"02","name":" data"}
{"id":"03","name":"abc"}
query:- name='abc'
Selecting based on the name
query:- name='abc'
Expecting output:-
{"id":"01","name":"abc"}
{"id":"03","name":"abc"}
how to do this using hazelcast?
Thank you.
This link (sent by #Neil) is good. In your case, it will look like this:
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
String item1 = "{\"id\":\"01\",\"name\":\"abc\"}";
String item2 = "{\"id\":\"02\",\"name\":\" data\"}";
String item3 = "{\"id\":\"03\",\"name\":\"abc\"}";
IMap<String, HazelcastJsonValue> map = instance.getMap("jsonValues");
map.put("1", new HazelcastJsonValue(item1));
map.put("2", new HazelcastJsonValue(item2));
map.put("3", new HazelcastJsonValue(item3));
Collection<HazelcastJsonValue> selected = map.values(Predicates.equal("name", "abc"));
System.out.println(selected);

How do I process a List of Maps in a subtemplate in JMustache?

I've been teaching myself JMustache and I'm attempting to send a List of Maps to a sub-template. I have the following Java test:
#Test
public void testWithNestedPartial() {
final WeakHashMap<String, Object> parameters = new WeakHashMap<>();
parameters.put("start", "hello");
final List<Map<String, String>> subParameterList = new ArrayList<>();
WeakHashMap<String, String> subParameters = new WeakHashMap<>();
subParameters.put("greek", "alpha");
subParameters.put("numeric", "1");
subParameterList.add(subParameters);
subParameters = new WeakHashMap<>();
subParameters.put("greek", "beta");
subParameters.put("numeric", "2");
subParameterList.add(subParameters);
parameters.put("sub", subParameters);
final Compiler subTemplateLoadingCompiler = Mustache.compiler()
.withLoader(templateName -> Files.newBufferedReader(Paths.get(TEST_TEMPLATE_PATH + templateName + ".htmm")));
final Template template = subTemplateLoadingCompiler.compile("{{start}}\r\n{{> complex-partial}}");
final String result = template.execute(parameters);
Assert.assertEquals(result, "hello\r\n• alpha\r\n• 1\r\n• beta\r\n• 2\r\n");
}
...with complex-partial.htmm:
{{# sub.this}}
• {{greek}}
• {{numeric}}
{{/ sub.this}}
...with the following result:
java.lang.AssertionError: expected [hello
• alpha
• 1
• beta
• 2
] but found [hello
• beta
• 2
]
If I switch it and put "alpha" and 1 last, it shows "alpha" and 1.
I know I don't have the sub-template written correctly, and I've tried different ways of setting up the parameters therein, but the solution escapes me. How do I write this partial to pass this test?
OP had a typo.
He meant to use
parameters.put("sub", subParameterList)
instead of
parameters.put("sub", subParameters)

Rendering a filled form in the template

I'm using Play! framework 20 on a java project and I have a problem with passing a form to the view.
In the controller I have the following code:
Filter filter = new Filter();
//add some state to the filter object
Form<Filter> filterForm = form(Filter.class).fill(filter);
Logger.info("FilterForm: " + filterForm.get().toString()); // So far so good
return ok(filterView.render(filterForm));
And in the template:
#filterForm.hasErrors() // renders false
#filterForm.data().isEmpty() // renders true!!
#* #filterForm.get().toString() *# throws an Exception: No Value
I also get the same error if in the controller I fill the filter state via a Map:
filterForm = filterForm.bind(aMapWithTheState);
This behaviour is only when filling the filter in code. when I do filterForm.bindFromRequest() in other methods all works fine.
Thanks!!
Solved.
I had to use the form's bind method using a map with the state as I did before. But the correct way is to also pass the properties name:
Map<String, String> formState = new HashMap<String, String>();
formState.put("name", name);
formState.put("birthDate", birthDate);
formState.put("address", address);
filterForm = filterForm.bind(formState, "name", "birthDate", "address");
Despite that the documentation says that the property names are not mandatory.

Google datastore - querying on key values

I have a EntityKind SuggestedInterest.
When I populate that with a key "GrpId" and property "suggestedint".
Now, I need the "suggestedint" value for a requested "GrpId"
So, I write the query as:
String findSuggestedInterest(String grpId)
{
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Filter filter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,FilterOperator.EQUAL,grpId);
Query q0 = new Query("SuggestedInterest").setFilter(filter);
PreparedQuery pq0 = datastore.prepare(q0);
Entity result = pq0.asSingleEntity();
return result.getProperty("suggestedint").toString();
}
When I execute this code I get
java.lang.IllegalArgumentException: __key__ filter value must be a Key
The developer docs told to use Entity.KEY_RESERVED_PROPERTY to query on keys, but I guess I misunderstood. What is the correct way to query on key ?
You should pass it a Key instead of String:
Key grpKey = KeyFactory.createKey("SuggestedInterest", grpId)
then use it:
Filter filter =
new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,FilterOperator.EQUAL,grpKey);

Categories