In drools rule file how do I set the value of (or initialize) a global variable for optaplanner. My use case is following:
I want to declare a global java map that is constant and will not change during the execution. Every rule will access the map to check for a value, if value is in the map then rule will evaluate to false. The map is being generated before execution starts by accessing data in files/database.
This link https://issues.jboss.org/browse/PLANNER-94 is also requesting the access to global variable but this feature is rejected now.
How do i use the hack defined in this link: Setting global variables in working memory in Drools planner, from which object i should get CustomSolverPhaseCommand? [I am not able to comment on this post yet because i don't have enough reputation, sorry if it seems duplicate question].
I am creating SolverFactory from xml Resource and xml file contains the path to .drl file. Just like in .drl we can access object HardSoftScoreHolder scoreHolder, I want to access the map in the same way in 'then' part of rule.
can anyone please help?
Look at the examples that have a class that ends with Parameterization instead, such as ConferenceParametrization, this is probably a better alternative than globals.
Related
I have a function in my firebase rules file userRolesIncludesPermission, this function checks a property on the user to determine whether that user has a certain permission on their role, it does so by comparing references.
This works as expected in the firebase rules file when used for security rules for firestore. Unfortunately this does not work as expected with "storage".
After research I found out that the problem is the comparison between the references from the permissions list under user.data.roles[0] and my custom made path.
Is there any better way to produce a path that can be recognizable using a list function?
Is it an unknown limitation of storage security rules?
Note that the function getRootCollectionDocRef works perfectly when I try to build a queryable path even in the same request (for example when I try earlier in the code to query the user)
Another note is that in the rules playground (console debugger) it works. But in an actual request from the website (dev, for now) it doesn't.
function getRootCollectionDocRef(collection, docId) {
return /databases/(default)/documents/$(collection)/$(docId);
}
function userRolesIncludesPermission(user, permissionId) {
return firestore.get(user.data.roles[0]).data.permissions.hasAll([getRootCollectionDocRef("permissions", permissionId)]);
}
I tried to use every available list function such as "in", "hasAny" etc.
I tried to build the path while converting it with path() function.
I tried to convert to a set.
I tried to use a hard coded non-dynamic path. It failed as long as I use a custom-made path.
However when trying to query the path with a fixed index (i.e firebase.get(permissions[1]) it worked. But this is an invalid practice. I have to make it dynamic, but the problem is that I can't loop over the list and convert the paths to strings on the fly.
Thanks in advance!!
In short: I have a method name provided via a JSON configuration file. I'd like to call a method using this provided name. The method (with a matching name) will exist in the backend. What's the best way of going about this?
I am not quite sure what I should be searching for as an example.
To detail: I am working with a legacy application, hence the VB.NET. I am building a single PDF file from multiple PDF sources. Most of these are as is, I simply read the configuration and grab the relevant files and the job is done. However some require processing, I'd like the configuration file to pass in a method name to be called that will perform extra processing on the PDF, whatever that may be.
As there can be a lot of PDF files that can vary, I cannot simply use a property such as "PostProcessing: true".
Any ideas?
You could use reflection to reflect method names back and check them against the name passed from the property in the config file.
Like so
Type magicType = Type.GetType("MagicClass");
MethodInfo magicMethod = magicType.GetMethod("ItsMagic");
object magicValue = magicMethod.Invoke(magicClassObject, new object[]{100});
That would work.. but to be honest, I'd go with a case statement as you'll be hardcoding the method names anyway (because they are code), and it'll be strongly typed (less chance of typos and errors).
I have a transmogrifier pipeline to insert objects to my Zope database (importing zexp files from a directory structure). This works - the objects are created; but I don't get them added to the portal_catalog.
I added a section to add the objects to the catalog explicitly, inspired by plone.app.transmogrifier.reindexobject: I call portal_catalog.catalog_object(obj) for each item.
The objects exist, and getPhysicalPath yields the correct values, but the objects are not added. There is no error message or exception whatsoever.
I tried to specify the list of indexes (the idxs argument), but this didn't change anything. If not specified, all indexes should be filled anyway, right?
Since it looks like a transaction problem to me (no errors, but nothing stored in the catalog either), I tried transaction code (begin, savepoint, commit, and in case of exceptions abort), but it didn't help. When I call the catalog immediately after the catalog_object call (portal_catalog(path='/Plonesite/full/path/to/object')), nothing has happened, and an empty list is returned.
The catalog does contain objects; even objects of my custom datatypes (AT-based). Not even the Folder objects of my imports are indexed.
Without the objects in the catalog, my import is useless. What can I do?
Thank you!
Edit: Any hint about how to get my object trees in the catalog is appreciated! Even if it can't be integrated in my process. I need the contents cataloged ...
My custom content types are contained in the Plone Catalog Tool page selection field, but I don't know whether this is sufficient.
Edit 2:
Somehow my objects have been catalogued - the unrestrictedSearchResults method shows them! However, it can't be the desired solution to use this method all over; so I need to "un-restrict" the entries somehow.
It turned out that I have a monkey:patch (xmlns:monkey="http://namespaces.plone.org/monkey") for the Products.CMFPlone.CatalogTool.CatalogTool.searchResults method; this filters the catalog for my additional field subportal unless a special value for it is given - even in the management view ... Unfortunately, I had no way to specify this special value in that view.
Thus, the solution was to weed out all wrong values (for subportals which don't exist in the other Zope tree) to have the default value take effect.
Quite specific to my setup, I'm afraid ...
I would like to use collective.easytemplate to generate templated emails (for content rules). However, I am not sure if it can output an objects workflow state. Anybody know if it is possible and how it is done?
Thanks.
You can, it is possible, and one way is to use the portal_workflow tool e.g. from parts/omelette/plone/app/contentrules/tests/test_action_workflow.py:
self.assertEquals('published',
self.portal.portal_workflow.getInfoFor(self.folder.d1, 'review_state'))
More generally, something like:
context.portal_workflow.getInfoFor(context, 'review_state')
in a page template should work. Or use the portal_catalog as Spanky suggests e.g. if "obj" is a catalog "brain" (i.e. part of a result set from a catalog search) then:
obj.review_state
should work.
The portal_catalog also has an index of the workflow's Review State, so if you don't already have the object you're working on (e.g. context ≠ the object) you could use the catalog, look up the object and get the review state from the resulting "brains" object.
Apparently there are ALSO browser view methods available to you as well, and I notice that one of them is workflow_state. See:
http://plone.org/documentation/manual/theme-reference/page/otherinfo
The issue:
I'm trying to transform and route a message based on its input file name. The file name gives hints about how the data should be processed. Being a noob I'm reasonably sure I'm doing this the hard way...
I created an orchestration. I transform the message from the input schema to the output schema. I'd like to examine the file name and add a little logic to classify the input message. That works just fine.
What I tried:
I added an expression shape after the transformation. I added logic to classify the message and assign that to a property. It won't allow me to change the property (messages are immutable?)
I added a construct message shape. I can set properties in a new message within this shape but it doesn't allow "if" statements or conditional assignments in the expression. I need conditional logic to search the file name string and set the property to one of several choices.
Any suggestions?
You can either wrap your logic into a .net helper method and call this from the assignment shape, or you can use the conditional flow control shapes provided by biztalk, such as the decide shape, and have multiple contruct shapes in your branches.
Let me know if you need more detail about either approach via a comment and I will expand the answer to include.
Hope this helps.
You could use a helper class to take the file name and return the value to set in the property.
Alternatively, you could use the decide shape for your if..then..else.
Have I understood your question?
HTH...