With custom type/providers how can i restrict refreshonly? - puppet

I have two custom type/providers. The first creates a resource, and manages a few properties on said resource. The second is a refreshonly (exec style) type/provider that needs to import some data into the resource. I need the import to only execute on the initial creation, not when the properties are changed.
Simple example:
nifi_processgroup{'processgroup':
ensure =>present,
location =>'0,100',
}
nifi_templateimport{'atemplate':
processgroup=>'processgroup',
template =>'standard-template',
refreshonly =>true,
subscribe =>Nifi_processgroup['processgroup'],
}
so if location updates, it refreshes the import. Is there any way to limit/scope the refresh?

I need the import to only execute on the initial creation, not when the properties are changed.
Then you need something other than refreshing. A resource broadcasts an event whenever Puppet changes its state in any way. This causes resources receiving the event to refresh. No information is conveyed about the nature or extent of the changes that caused the event to be broadcast, so there is no distinguishing between creation and other kinds of changes.
If indeed you have work that you want performed only upon creation of an instance of your custom resource, then the best thing to do would probably be to integrate that into the resource instead of trying to define it via a separate one.

Related

Is it possible to create a button factory with buttons these emit signal by pressed?

I want to create a button factory that creates buttons by a specific configuration as parameters. The button have to emit a signal if there is pressed. I can't find any method to add that functionality programatically.
I know, that i can add buttons by the editor and add that function to it by a script. But with a factory, i don't need to add every button by my self.
Big thanks!
Buttons emit a signal when they are pressed, it is called "pressed". That is not a functionality you need to add.
Perhaps what you need is something else? The Godot editor is built on the same API as your game, so you can do from code virtually anything the editor can do… such as…
You can add a script from code
If you need to add a signal, the usual way is to attach a script that has the signal declared and the logic to emit it.
If you have such script created, you can load or preload it in your code, and then attach the script to the Object you want (with set_script). There is also a get_script method to retrieve it. And a "script_changed".
And yes, you can create scripts from code too. Create a GDScript object, set its source_code, and reload it. Then you can attach it to an Object just as if you had loaded it.
By the way, the script is a Resource which is why you can load it or preload it. See also ResourceLoader. It also means that you can save it with ResourceSaver. However, I remind that resource paths aren't always writable.
You can add signals from code
Yes, you can add dynamically signals from code. I mean custom signals that are not declared in a script, and that could be added at any moment. To do that you call add_user_signal on the Object. You can check with has_user_signal (use has_signal if you don't care if it was added with add_user_signal or not). And no, there is no remove method for these. So use these sparingly and with intent.
By the way, you can get an Array of all signals on an object with get_signal_list.
You can emit signals from code
You do that you can call emit_signal.
And you can call it on other objects too (I mean, you don't have to call emit_signal from an script attached to the Object that has the signal, it can be from a different one).
You can manage connections from code
I also remind you that you can connect a signal with the connect method. See also disconnect and is_connected.
Oh, and you can query the connections with get_incoming_connections and get_signal_connection_list (Here is an example, it also demonstrates get_signal_list). No, you don't need to worry about disconnecting the signals when freeing the object. Godot takes care of that.
And you can block signals too
You can have an object block its signals with set_block_signals, and check with is_blocking_signals. I - personally - haven't used this, never had the necessity. I just mentioning it for completeness sake.

NetSuite: Calling an API in real time as field values get updated

I'm looking for a way (using SuiteScript 2.0) to handle real-time persistent (stored) field updates, where a field might have changed in NetSuite (for example a lead time was just updated), and it doesn't matter if a user saved the change, or some other automated process changed that field. I just want to be able to pick up on that change:
The moment that it's done, and
Without regard for who or what kicked it off (e.g. it could be a person, but it could also be an automated change from a workflow, or a formula on the field itself which pulls values from another field)
Doing some research I found some options that looked somewhat promising at first. One being the afterSubmit event in a client script, and the other being the fieldChanged event. My issue however is, from what I understood those only really seem to be triggered by a user manually going in and making those changes, but this is only one part of the puzzle and doesn't seem to cover changes made outside of the scope of the user making those changes. Is that correct however? Or would one of those events still be able to capture changes done to that field regardless of who (or what) initiated or triggered the change, and right at the moment the change was saved/ persisted to the database?
UserEvents are basically triggers. In their deployment records you can set the context in which they fire so you can get them to fire in all circumstances (called contexts in Netsuite) but one.
That circumstance is User Events are not fired for record saves made in User Event scripts. i.e., if an AfterSubmit UserEvent script loads, changes and saves your record a fresh user event will not be fired.

How to log last changes in hybris when the new feed/ feeds updates come through

I'm aware that Hybris have savedvaluesmodel and savedvalueentrymodel to capture last changes of the data model and its attribute value whatever has changed recently, and it also maintains the history.
And this works only if we are modifying the data after login into Backoffice and this doesn't seem to work in case of feeds which comes via HotFolder. I'd like to know, is there any provision which comes with Hybris out of the box to capture the same information or changes that was done for a given data model through feed?
What I have observed based on OOTB code is ,this class DefaultItemModificationHistoryService is responsible for logging the changes (populate the values and saved the last changes into the saved values model table) that was done at the model level, and this is located inside the OOTB Backoffice extension and this extension is already extended by myprojectbakcoffice extension which further extends myprojectcore extension.
In order to capture the last changes done via feed we thought of handling that logic in an interceptor, however the above class isn't accessible in our myprojectcore extension as it's declared in Backoffice.
What are the other possible solutions that I can think of in order to implement this?
Found some article related to this in here.
Please advise.
You can use the hybris commerce audit framework to log all of the changes happening in the system.
The documentation here says, "Generic audit tracks every persistence action, including creation, modification, and deletion for specified types. The audit is stored as a change log that allows you to see how an item changed over time."
But this comes with a DB overhead. There are specific tables that gets heavily logged with the details of the changes.
These tables have a naming convention as <item_type>_sn.
E.g.: For Order item type, the audit table would be auto created as orders_sn
This is why it is always advisable to turn off the audit as applicable.

does NSManagedObjectContextDidSaveNotification get called for transient property updates?

I can't seem to get a clear answer for this: when you change a transient property, and then call save, should the NSManagedObjectContextDidSaveNotification be triggered? In my notification listener, how can I filter out these notifications that are coming from changes in transient properties?
Here's what I'm trying to do: I want to load up a list of contacts in the main thread, and when it's done, I want to read the images in a background thread from the address book and attach them to the contacts. This works fine on the face of it: after loading from the Contacts entity, I use a dispatch queue to loop through all the contacts, find their image in the Address Book, and save them in Contact's "contactImage" property (which is transient). The dispatch queue then successfully reloads the tableview (on the main thread) and the images show up next to the contacts.
The problem is that if I do anything to the contact that invokes a "save" on even ONE of the managed objects (for e.g. I delete one of the contacts), the NSManagedObjectContextDidSaveNotification is invoked for ALL the contacts. I've found that this is because the contactImage property was changed before ... commenting that the "self.contactImage = img;" line makes the issue go away. This is surprising to me, since I would have thought that the save notification would only be called for non-transient properties.
Can anyone confirm if this is expected behavior? Or am I doing something wrong? If it's expected, how do you filter out the updates to transient properties in the NSManagedObjectContextDidSaveNotification listener? I need to do some post-processing in the listener, and I don' want to do it needlessly for transient property updates. I've checked the changedValues dictionary on the NSManagedObject, but it seems to show empty inside the listener (since only transient properties changed, I'm guessing).
Thanks.
Yesterday,
Transient properties have one key characteristic -- they are managed. You can easily add ivars that are not managed to any NSManagedObject. If you do so, they are not subject to -save: notifications.
A related question: Why are you using a transient ivar? They have some specialized uses; primarily, they are used to trigger property updates throughout the model; i.e. the behavior you are seeing.
A second related question: why are you background fetching all of the images instead of lazy loading them from the Address Book? This looks like a case of premature optimization to me.
Andrew

How to handle entity creation/editing in a master-detail

I'm wondering what strategies people are using to handle the creation and editing of an entity in a master-detail setup. (Our app is an internet-enabled desktop app.)
Here's how we currently handle this: a form is created in a popup for the entity that needs to be edited, which we give a copy of the object. When the user clicks the "Cancel" button, we close the window and ignore the object completely. When the user clicks the "OK" button, the master view is notified and receives the edited entity. It then copies the properties of the modified entity into the original entity using originalEntity.copyFrom(modifiedEntity). In case we want to create a new entity, we pass an empty entity to the popup which the user can then edit as if it was an existing entity. The master view needs to decide whether to "insert" or "update" the entities it receives into the collection it manages.
I have some questions and observations on the above workflow:
who should handle the creation of the copy of the entity? (master or detail)
we use copyFrom() to prevent having to replace entities in a collection which could cause references to break. Is there a better way to do this? (implementing copyFrom() can be tricky)
new entities receive an id of -1 (which the server tier/hibernate uses to differentiate between an insert or an update). This could potentially cause problems when looking up (cached) entities by id before they are saved. Should we use a temporary unique id for each new entity instead?
Can anyone share tips & tricks or experiences? Thanks!
Edit: I know there is no absolute wrong or right answer to this question, so I'm just looking for people to share thoughts and pros/cons on the way they handle master/details situations.
There are a number of ways you could alter this approach. Keep in mind that no solution can really be "wrong" per se. It all depends on the details of your situation. Here's one way to skin the cat.
who should handle the creation of the copy of the entity? (master or detail)
I see the master as an in-memory list representation of a subset of persisted entities. I would allow the master to handle any changes to its list. The list itself could be a custom collection. Use an ItemChanged event to fire a notification to the master that an item has been updated and needs to be persisted. Fire a NewItem event to notify the master of an insert.
we use copyFrom() to prevent having to replace entities in a collection which could cause references to break. Is there a better way to do this? (implementing copyFrom() can be tricky)
Instead of using copyFrom(), I would pass the existing reference to the details popup. If you're using an enumerable collection to store the master list, you can pass the object returned from list[index] to the details window. The reference itself will be altered so there's no need to use any kind of Replace method on the list. When OK is pressed, fire that ItemChanged event. You can even pass the index so it knows which object to update.
new entities receive an id of -1 (which the server tier/hibernate uses to differentiate between an insert or an update). This could potentially cause problems when looking up (cached) entities by id before they are saved. Should we use a temporary unique id for each new entity instead?
Are changes not immediately persisted? Use a Hibernate Session with the Unit of Work pattern to determine what's being inserted and what's being updated. There are more examples of Unit of Work out there. You might have to check out some blog posts by the .NET community if there's not much on the Java end. The concept is the same animal either way.
Hope this helps!
The CSLA library can help with this situation a lot.
However, if you want to self implement :
You have a master object, the master object contains a list of child objects.
The detail form can edit a child object directly. Since everything is reference types, the master object is automatically updated.
The issue is knowing that the master object is dirty, and therefore should be persisted to your database or whatnot.
CSLA handles this with an IsDirty() property. In the master object you would query each child object to see if it is dirty, and if so persist everything (as well as tracking if the master object itself is dirty)
You can also handle this is the INotifyPropertyChanged interface.
As for some of your other questions :
You want to separate your logic. The entity can handle storage of its own properties, and integrity rules for itself, but logic for how different object interact with each other should be separate. Look into patterns such as MVC or MVP.
In this case, creation of a new child object should either be in the master object, or should be in a separate business logic object that creates the child and then adds it to the parent.
For IDs, using GUIDs as the ID can save you quite a bit of problems, because then you don't have to talk to the database to determine a correct ID. You can keep a flag on the object for if it is new or not (and therefore should be inserted or updated).
Again, CSLA handles all of this for you, but does have quite a bit of overhead.
regarding undo on cancel : CSLA has n-level undo implemented, but if you are trying to do it by hand, I would either use your CopyFrom function, or refresh the object's data from the persistance layer on cancel (re-fetch).
i just implemented such a model.but not using NH, i am using my own code to persist objects in Oracle Db.
i have used the master detail concept in the same web form.
like i have master entity grid and on detail action command i open a penal just below the clicked master record row.
On Detail Add mode, i just populate an empty entity whose id were generated in negative numbers by a static field.and on Save Detail button i saved that entity in the details list of the Master Record in Asp.NET Session.
On Detail Edit,View i populated the Detail Panel with selected Detail through ajax calls using Jquery and appended that penal just below the clicked row.
On Save Button i persisted the Master Session (containing list of Details) in database.
and i worked good for me as if multiple details a master need to fill.
also if you like you can use Jquery Modal to Popup that Panel instead of appending below the row.
Hope it helps :)
Thanks,

Resources