Update to replace all fields in Spring Data MongoDB - spring-data-mongodb

MongoDB has the capability to update a document by replacing all of the fields. This is done by not passing any modifier operators.
I would like to do the same operation in Spring Data MongoOperations update* methods. In the JavaDoc, it seems that this is supported out of the box:
update - the update document that contains the updated object or $ operators to manipulate the existing object
From all of the examples I found, the update parameter is created with the $ operators.
How can I create an Update object directly from my POJO?

I just found a method Update.fromDBObject. I think this is what the javadoc meant.
Code example:
DBObject dbObject = new BasicDBObject();
mongoOps.getConverter().write(object, dbObject);
Update.fromDBObject(dbObject, "_id");

Related

SolrJ AddBean problems with UpdateProcessorFactory

I'm trying to get TimestampUpdateProcessorFactory and UUIDUpdateProcessorFactory to work with SolrJ's AddBean method but it's just not working, the fields are not automatically filled on update. For example I have a UUIDUpdateProcessorFactory on the id field of my schema and in order to get the UUIDUpdateProcessorFactory to automatically generate the id on document update, I have to set the id in the Bean to an empty string, because it doesn't work to just set the value to null.
Is there some kind of configuration like omit empty fields for the ObjectBinder or so, to make this work? When I add Documents the classical way via add(new SolrInputDocument()) method it works fine, but not with AddBean. That Object to SolrInputDocument Mapper seems to be doing strange stuff here.

Custom Activity Data Binding with Salesforce Objects

We can't extract data from the incoming Salesforce Object in the Journey Builder to the Custom Activity we made. We have already followed the syntax that was instructed in your documentation -> https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/how-data-binding-works.htm (under Event Context section).
We are primarily using Postmonger for our Custom Activity, and in our config.json under the inArguments, we input something like below to fetch the data from the Salesforce Object:
"fieldKey": "{{Event." + [ eventDefinitionKey ] + ".Task:Field_Name__c}}"
The eventDefinitionKey we get from the data loaded by triggering the requestedTriggerEventDefinition exposed by the Postmonger.
The resulting inArguments from above would be something like this:
"fieldKey": "{{Event.SalesforceObjacf28b016bf83c75b4926e0ec292eda5.Task:SMS_Content__c}}"
And based from the documentation mentioned previously, that syntax should be enough, yet we cannot retrieve it on our Custom Activity.
Another thing to note is that we can fetch information using the same syntax if the entry object is a Data Extension like below:
"fieldKey": "Event.DEAudience-e56d43c3-e2cf-60f1-fecd-ecf4d358d7b4.Field_Name"
The syntax above work which uses Data Extension is okay, but the one with the Salesforce Object does not.
What are we doing incorrectly here or is not possible entirely?
NOTE: the journey gets triggered by creating a task in Service Cloud
We put " around the eventDefinitionKey and the field name as well, and it works from Salesforce Data sources.
Something like:
"fieldKey": '{{Event."SalesforceObjacf28b016bf83c75b4926e0ec292eda5"."Task:SMS_Content__c"}}'
Note the switch to single quotes and how we're explicitly wrapping those inner attributes with double quotes
Update Oct 2020
Please see this post here which allows you to see the full merge fields of the entire Data Extension (no matter what type it is)

Spring Data MongoDB default type for inheritance

My model consisted of the following example:
class Aggregate {
private SomeClassWithFields property;
}
Now I decided to introduce inheritance to SomeClassWithFields. This results in:
class Aggregate {
private AbstractBaseClass property;
}
The collection already contains a lot of documents. These documents do not contain a _class property inside the DB since they were stored before the inheritance was present.
Is there a way to tell Spring Data MongoDB to use SomeClassWithFields as the default implementation of AbstractBaseClass if no _class property is present?
The other solution would be to add the _class to all the existing documents with a script but this would take some time since we have a lot of documents.
I solved it by using an AbstractMongoEventListener
The AbstractMongoEventListener has an onAfterLoad method which I used to set the default _class value if none was present :) This method is called before any mapping from the DBObject to my domain model by spring so it works then.
Do note that I also needed to let spring data mongodb know the mappingBasePackage in order for it to be able to read an Aggregate before writing one. This can be done implementing the getMappingBasePackage method of the PreconfiguredAbstractMongoConfiguration class.

How can I add a post insert hook to Solr?

I am using Solr 5.3.1 and would like to run some code whenever a new document is inserted into Solr.
I am aware of the <listener> element in solrconfig.xml, however this does not provide a mechanism (as far as I can tell) to pass the new document, or its ID, to the listener code.
Do I need to create my own UpdateRequestHandler?
You can hook the insertion of documents both before and after they're added through the StatelessScriptUpdateProcessor which allows you to write a JavaScript that has access to all the fields of the document. There's an example at the Script Update Processor wiki page:
function processAdd(cmd) {
doc = cmd.solrDoc; // org.apache.solr.common.SolrInputDocument
id = doc.getFieldValue("id");
This example should also be included as one of the example cores in the current bundle.

How to get $settings data out of CakePHP 2.0 FormAuthenticate object

I am building a RememberMe Component using the AuthComponent and would like to get the BaseAuthenticate::$settings data (userModel and fields) data out of the XxxxAuthenticate object so I can know what model and fields I should be dealing with, but I can't seem to figure out how to get that data back out.
Any suggestions?
Basically I need something with the same functionality as Auth::getModel( ) or Auth::$userModel from Cake 1.X.
Cake- 2.0.3
Auth::$userModel still exists in 2.0. However, you probably have to access it via the instantied object rather than statically:
$modelData = $this->Auth->userModel;
If this isn't set, then it defaults to User.
You can then get the model by looking at the first array key that is returned:
$modelName = key($modelData[0]);

Resources