First off: If I am totally wrong with my request, please close this and point me into the right direction.
I use Drools (with Guvnor-created rules) in a JSF application for the verification of a created object. Basically, the workflow is:
user creates an object
rules are fired to check this object
rules for which the check fails insert a new fact into the working memory with some message, explaining why the verification failed
the facts are extracted from the working memory and displayed in the JSF application
My question: What is the best way to translate these messages? Are there any "best practices" for such scenarios?
What do you mean? Translate to different languages? You can use a different properties file and resolve the right text based on those files, right? as in every application that you want to use internationalization (I18N).
Cheers
You can have a "user message" object with message ids and insert this as a fact. In the rule, set an appropriate message id. In the presentation layer, map the id to a message string in locale-specific string table.
Related
While trying to save a new customer i get this error in my dev.log
Uncaught PHP Exception RuntimeException: "Provided language 2fbb5fe2e29a4d70aa5854ce7ce3e20b is not in list of available languages: " at /home/schcmjkg/staging/vendor/shopware/core/System/SalesChannel/Context/BaseContextFactory.php line 329 {"exception":"[object] (RuntimeException(code: 0): Provided language 2fbb5fe2e29a4d70aa5854ce7ce3e20b is not in list of available languages: at /home/schcmjkg/staging/vendor/shopware/core/System/SalesChannel/Context/BaseContextFactory.php:329)"} []
But the issue is that i have not changed the language at all and i cannot even change it because there are no translatable fields ->
While trying to save the admin panel tells me that it was unable to save the customer but the customer actually get saved. The event "customer.written" is never triggered, it is only triggered after editing the customer.
So what is the cause and how can i solve it? thank you very much.
I was able to reproduce this error. Seemingly "Deutsch" is your default language, which it reverts to since there are no translatable fields, as the tooltip states. I assume you're trying to save a customer assigned to a sales channel that doesn't include "Deutsch" in its languages. That's how I was able to reproduce it. You can get around that for now by additionally assigning "Deutsch" to the languages of the sales channel. There shouldn't be a language switch in the storefront as long as you don't define a domain using the language, so it shouldn't come with undesired side effects. At least then you should be able to save customer assigned to that sales channel without that exception being thrown. Eventually this undesirable behavior will be fixed though.
Is there any adequate design pattern that should be used in order to do number of validations?
For example, let's say that I have an application containing a toolbar with icons, each representing a picture on my file system. I am dragging an icon on a document. Validations during the drag and drop operation could be:
check if the file exists in file system
check if the user has access rights to drag the icon
check that the document is open in order to drop the picture on it
and so on...
I thought of using the Chain of Responsibility or Decorator patterns.
Thanks!
Actually, what you're after, or rather what I'd suggest, is Continuation Passing Style. It's not so much a design pattern as a way of writing code where validation would be defined as a pipeline of methods that an object would go through. This pipeline would use an accumulator to collect all the validation problems encountered by the code.
My waveform initializes well on startup, but after a few seconds into processing, it pops up a red flag on the symbol on the right in the IDE's SCA Explorer tab. The tool tip says "Failed to query property values".
I believe the issue is caused by the "process" method in the component taking too long, but I need to be able to obtain a certain element of a rather long list of chunks of data, so I can process each chunk. Therefore, I need to have a property of the component be a reference to this long list of data. Is there a better way of doing this? I had created a child process to do all of this, but that sort of defeats the purpose of using REDHAWK to manage the execution.
Thanks for your time!
Ben,
The first step will be to understand exactly what error occurred. This can be done by following the steps listed here. Basically:
Window > Show View > Other ...
Select General > Properties. The properties view should now be visible
In the SCA Explorer view, select the application with the red flag symbol
Now in the Properties view, you should see two tabs "Properties", and "Advanced". In the "Advanced" tab where will be a Status field that says "Failed to query property values...". When you select this field it will show a "Details..." button. Click that to receive the stack trace for the error.
Another alternative is to use the Python Sandbox (or unittest) capabilities to start your component and attempt a query. The equivalent error will be thrown as a Python exception. You can learn about the sandbox here.
As for the second part of your question, the REDHAWK process() method is already executing as a sub-thread, so it won't block query() operations unless you have created a thread lock (or used the propertySetAccess lock within your serviceFunction). If you are using a lock, then it is possible that the query() will block until the CORBA timeout is reached. You will know if this has occurred because the stack trace will be a CORBA Timeout error.
However, you said "I need to have a property of the component be a reference to this long list of data" so I think you may be getting an error related to the maximum CORBA transfer size. You can adjust the CORBA maximum transfer size by editing /etc/omniORB.cfg so the problem goes away, but your component will cause problems for others who use it. A better option is to reconsider the design of the component. You will probably want to use BULKIO ports to transfer the data in-to and out-of your component.
If you could provide more details about the algorithm you are using or source code examples, that could provide additional information that would help isolate the root problem.
Our Orchard application displays two of all notifications that are added to the notification service. So far we have traced the problem and know what is causing it, but are looking for a solution other than the obvious, for reasons I shall now elaborate.
So we are using a number of themes to render our Orchard based application. Within our layout, we have a Razor call to draw a header bar that displays a set of information about the user that is logged in.
#Html.Action("OutOfGameHeader", "Options", new { area = "Area.area.Location.Common" })
This action calls the OnResultExecuting() method in Orchard.UI.Notify.NotifyFilter which (among other things) populates the Messages Zone with the current set of notifications. When we make the call the render the Messages Zone, this same method runs again and the notifications are added to the Zone's shape again resulting in duplicate notification being displayed when the Zone is actually drawn.
Can anyone think of a solution that meets the following criteria:
Drawing the header without calling #Html.Action() to avoid OnResultExecuting() being triggered the first time.
Without creating a new Widget in a new Zone as this would involve us changing the manifest for dozens of existing themes to include it.
We also found this just below the point in the code where the notifications are added to the Zone, so if anyone knows anything more about it, that would be helpful too.
//todo: (heskew) probably need to keep duplicate messages from being pushed into the zone like the previous behavior
//baseViewModel.Messages = baseViewModel.Messages == null ? messageEntries .Messages.Union(messageEntries).ToList();
//baseViewModel.Zones.AddRenderPartial("content:before", "Messages", baseViewModel.Messages);
Any thoughts greatly appreciated.
Avoid Html.Action. This runs through the whole lifecycle as if this was a new request. That you think you need it is often a sign that you need to refactor and extract that logic that you want to re-use out of your controller. In Orchard, it's also better to use dynamic shapes.
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,