drools - Unable to Analyse Expression - drools

I have defined some rules in DRL file, and its my first program of creating a drl file. I am getting the error "unable to analyse expression".Here is my code:
package rules
import com.sample.Applicant.appli;
rule "Is of valid age"
when
$a : appli ( age < 18 ) // appli is my class name
// age is a variable in that class
then
$a.setValid( false ); // setValid is a method of appli
end
and getting the error:
Unable to Analyse Expression age < 18:
[Error: unable to resolve method using strict-mode: com.sample.Applicant$appli.age()]
[Near : {... age < 18 ....}]
^
[Line: 16, Column: 4] : [Rule name='Is of valid age']

Make sure in the class appli, age is either public or has a public getAge() method.

Even I was getting similar error 'Unable to Analyse Expression....' while validating a DRL file in Drools Workbench 6.4.0 Final. I checked Data Object, its fields, access specifier of the setters and getters. All seemed OK. Then I saved my data object and came back to DRL file and did validating. Suddenly the above error was gone and I saw message 'Successfully Validated'. My mistake was though I had created the Data Object in Drools Workbench, I had forgotten to save it by clicking 'Save' button.
So I would suggest you, if you are 100% sure that your Data Object and DRL files are correct, save these first and then validate DRL file again.

Related

ArangoDB "Spring Data Demo" Tutorial outdated?

Like the title says, is it possible the tutorial at https://www.arangodb.com/tutorials/spring-data/ is outdated? I'm having several problems, but don't know how to workaround the last one:
Part 2, "Save and read an entity"
I get an error: method getId() is undefined.
Workaround: I added a getter in class Character.
Also in "Save and read an entity"
final Character foundNed = repository.findOne(nedStark.getId());
The method findOne(Example) in the type QueryByExampleExecutor is not applicable for the arguments (String)
Workaround: I used find by example:
final Optional<Person> foundNed = repository.findOne(Example.of(nedStark));
Part 1, "Create a Configuration class"
public class DemoConfiguration extends AbstractArangoConfiguration {
Gives me an error:
"No constructor with 1 argument defined in class 'com.arangodb.springframework.repository.ArangoRepositoryFactoryBean'"
Workaround: ?
Can anyone point me in the right direction?
I found the demo project on github: https://github.com/arangodb/spring-data-demo
Number 1: They use a getter too.
Number 2: Was my fault, I did try ArangoRepository (of Character, Integer) but forgot that Id is a string.
Number 3: They don't seem use any Configuration (AbstractArangoConfiguration) class in the source at all although it is still mentioned in that tutorial. I think now the config and connection is handled by spring autoconfigure. Though I would like to know how the Arango driver is set, all I could find that may point further is ArangoOperations.
Anyway it works now, maybe this helps somebody else who is having the same problems.

Data driven unit test breaking entity framework connection

I have an application that uses entity framework. I am writing a unit test in which I would like to use data driven testing from a CSV file.
However, when I run the test, I get an error that the sqlserver provider cannot be loaded:
Initialization method UnitTest.CalculationTest.MyTestInitialize threw
exception. System.InvalidOperationException:
System.InvalidOperationException: The Entity Framework provider type
'System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer' registered in the application config file
for the ADO.NET provider with invariant name 'System.Data.SqlClient'
could not be loaded. Make sure that the assembly-qualified name is
used and that the assembly is available to the running application.
If I remove the data driven aspects and just test a single value, then the test works.
If I just use the data driven aspects and remove the Entity Framework stuff, then the test works.
So, its only when I try to use data driven test with entity framework active at the same time do I get the error. So, where am I going wrong here?
Here's my test method:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}
So I managed to work it out in the end. For future reference, here's the solution:
Rob Lang's post, Entity Framework upgrade to 6 configuration and nuget magic, reminded me of the issue here:
When a type cannot be loaded for a DLL that is referenced in a
project, it usually means that it has not been copied to the output
bin/ directory. When you're not using a type from a referenced
library, it will not be copied.
And this will raise its ugly head the moment you use deployment items in your tests. If you use a deployment item in your test, then all of the required binaries are copied to the deployment directory. Problem is, if you are using dynamically loaded items, then the test suite does not know it has to copy those items.
With Entity Framework, this means that your providers will not be copied to the deployment location and you will receive the error as per my question.
To resolve the issue, simply ensure that your entity framework provider is also marked as a deployment item.
So, note the inclusion of DeploymentItem(#"EntityFramework.SqlServer.dll") in my test attributes. All works perfectly from here:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")
, DeploymentItem(#"EntityFramework.SqlServer.dll")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}

F#. How to pass SQLite connection string to EF

I am trying to make SQLite work with EF6 and F3 using System.Data.Sqlite.
I am following walkthrough described here and got edmx file and C# program to compile (I've done that before).
Walkthrough: Generating F# Types from an EDMX Schema File (F#)
Default code shown no errors during the design time and table structure is picked up by VS. Basically, edmx file is ok.
type internal edmx = EdmxFile<"ModelK.edmx">
[<EntryPoint>]
let main argv =
let context = new edmx.MyBaseModel.MyBaseEntities(strBulder)
query { for course in context.T1 do
select course.r1 }
|> Seq.iter (fun course -> printfn "%s" course)
printfn "%A" argv
0 // return an integer exit code
I am using NuGet package System.Data.SQLite EF6 1.0.94.0, deps EntityFramework 6.1.1, System.Data.SQLite Core 1.0.94.0 and have bundle installed from SQLite side (one with VS2013 support).
My problem is sql connecion string. EF requires connection string with meta and the regular sting doesn't work.
This is my original connection string from designer.
#"metadata=res://*/ModelK.csdl|res://*/ModelK.ssdl|res://*/ModelK.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=D:\VS2013\FSharp940\FSharp940MyBase.db"" providerName="System.Data.EntityClient""
What I've tried so far:
Passing escaped (" to make a valid string and some other escape seqs) to MyBaseEntities(strBulder).
System.ArgumentException was unhandled Message: An unhandled exception
of type 'System.ArgumentException' occurred in System.Data.Entity.dll
Additional information: keyword not supported: data source.
Followed some SO advice and replaced " with '.
Got Error reading schema, must start with / and be divided by :.
The type provider
'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'
reported an error: Error reading schema. fel 7005: Parametern
source=D:\VS2013\FSharp940\FSharp940\MyBase.db har angetts p† ett
felaktigt s„tt. Alla v„xlar m†ste b”rja med tecknet / och namnet m†ste
avgr„nsas fr†n v„rdet med kolon ':'.
Taken my C# App.Config entity connection strings and other things to my F# App.Config and reading from there.
type internal FooDb =
SqlEntityConnection<ConnectionStringName="MyBaseEntities",
ConfigFile="App.config">
Nope.
The type provider
'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'
reported an error: Error reading schema. fel 7005: Parametern
source=D:\VS2013\FSharp940\FSharp940\MyBase.db
I do understand that it is complaining about filepath and done some experiments with it without any results
The type provider
'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'
reported an error: Error reading schema. fel 7001: keywork st”ds not:
metadata.
Finally I tried EntityConnectionStringBuilder.
let strBulder =
let conn = new EntityConnectionStringBuilder()
conn.Metadata <- #"res://*/ModelK.csdl|res://*/ModelK.ssdl|res://*/ModelK.msl;"
conn.Provider <- #"System.Data.EntityClient"
conn.ConnectionString <- #"D:\VS2013\FSharp940\FSharp940\MyBase.db"
let ec = new EntityConnection(conn.ToString())
ec
New one...
An unhandled exception of type 'System.TypeInitializationException'
occurred in Unknown Module.
Everything I write to conn.ConnectionString throws an exception, including MyBase.db without any path.
I see that the problem is in connection string and probably my filepath, but at the moment have no idea what the correct format is. I mean... EF must understand it's own config file, right?
Any ideas? :)

Enterprise Library 5.0 Exception Handler: How to remove sections from error message

I wrote up a custom MongoDB Listener with Entlib 5.0 as my Exception Handler in my web app. It works great except for the fact that it creates a document entry for every "line" below, including the empty lines:
----------------------------------------
Timestamp: 4/17/2012 4:13:50 PM
Message: HandlingInstanceID: c3c5f58a-89b3-4b64-b05d-3f72f998bab4
An exception of type 'System.NullReferenceException' occurred and was caught.
-----------------------------------------------------------------------------
04/17/2012 16:13:50
Type : System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : MyCo.Webservices.TheCoolService
Data : System.Collections.ListDictionaryInternal
TargetSite : System.String TestExceptionHandling()
Stack Trace : at Logging.TestExceptionHandling() in C:\tfs\Development\Source\MyCo.Webservices.TheCoolService\Logging\Logging.cs:line 55
----------------------------------------
What I'd like to do is throw most of this information into one document so as to not have 10 different documents for the same error. Even writing my own Exception formattter (http://msdn.microsoft.com/en-us/library/ff664587(v=pandp.50).aspx) I still can't seem to get around the multiple calls to the customlistener.Write() method, each of which creates a new document in my mongodb collection.
My Entlib experience is limited, but I don't see how to get around it unless I write the whole ExceptionFormatter from scratch. Anybody have any ideas how to get around this?
Found my problem. Turns out that I was missing the TraceData() method implementation on my listener. Once I told it what to do there, it handled the error message like a single WriteLine() call.

Trouble with upload component - Cakephp 2.0

I was trying to incorporate file upload to my project but whenever I access the a function in the controller it gives me these warnings:
Warning (2): call_user_func_array(): First argument is expected to be a valid callback, 'UploadComponent::initialize' was given [CORE/Cake/Utility/ObjectCollection.php, line 110]
Warning (2): call_user_func_array() [http://php.net/function.call-user-func-array]: First argument is expected to be a valid callback, 'UploadComponent::beforeRender' was given [CORE/Cake/Utility/ObjectCollection.php, line 110]
Warning (2): call_user_func_array() [http://php.net/function.call-user-func-array]: First argument is expected to be a valid callback, 'UploadComponent::shutdown' was given [CORE/Cake/Utility/ObjectCollection.php, line 110]
The upload component that I added works fine for my cake 1.3 version.
please help
Solved it, by modifying the Component.
In cake php 2.0 all components must extend Component; failing to do this will trigger an exception.
For example:
class UploadComponent extends Component {
}