Get Cron Expression from Trigger - quartz.net

How can I get the CronExpression (string) from a trigger?
I see the expression in the DB but I am not sure how to retrieve it via the provided API.

You can simply try to cast the ITrigger instance to an ICronTrigger and call the CronExpressionString property.
if(trigger is ICronTrigger cronTrigger)
{
return cronTrigger.CronExpressionString;
}

Related

Language-ext: chain Either<L, R> with Option?

I am just starting with language-ext, trying to use it in my Azure Function.
In this function, I first parse/validate the POSTed data from the HTTP request using some validator.
This validator returns an Either<ValidationErrors, RequestModel>.
Then I would like to chain onto the either result a service call that should use the request model to grab some data from an API an return an Option.
At the end of the chain I would then like to return an IActionResult BadRequest if there were ValidationErrors in the first step, or otherwise perform a Match on the result of the service call Option to either return a NotFoundResult or ObjectResult.
The issue I run into is that if I want to chain my service call (using Bind, or BiBind) after the Either<ValidationErrors, GetRequestModel>, then the signature of my service method must be some Either<ValidationErrors, ...>, which is incorrect, since my service method has nothing to do with ValidationErrors. It should just return an Option.
So I guess my question is how can preserve any ValidationErrors until the end of the chain, and be able to chain my service call with a Option signature onto an Either?
You have to decide what the result of your chained expression is.
Option:
var maybeResult = from validated in GetValidationResult(...).ToOption()
from apiResult in ApiCall(...)
select apiResult;
Either:
var resultOrError = from validated in GetValidationResult(...)
from apiResult in ApiCall(...).ToEither(*LEFT*)
select apiResult;
You have to replace *LEFT* by some error value or error generating function returning same type like left type of GetValidationResult.
Replace above pseudo code with your own code and look at the return types of the functions used above to see what's going on.
The reason why you need a common left type is that the bind operation can return some left (error) of first (GetValidationResult) or second (ApiCall) function call -- or right of your last (ApiCall) function if your reach successful end of your chain.
Recommendation: If you mix different left (error) return types you might want to use some thing like LanguageExt's built-in Error type or maybe just a plain string (or Exception).
Either with string as error type:
var resultOrError = from validated in GetValidationResult(...).MapLeft(Prelude.toString)
from apiResult in ApiCall(...).ToEither("api call failed")
select apiResult;
Additional note: I use LINQ style here, you can use method style:
var resultOrError = GetValidationResult(...)
.MapLeft(Prelude.toString)
.Bind(validated => ApiCall(...)
.ToEither("api call failed"));

Dart Flutter: Why use getter instead of setter for Stream Sink?

To my basic understanding of Stream and sink we add data to sink in order to pass it through the stream but to add it we use a getter instead of setter, which I find counter-intuitive (see example below), could you please explain in simple words why is it how it is and not the other way around?
Example:
class BlogPostViewModel {
StreamController<List<BlogPost>> _blogPostListController = StreamController.broadcast();
Stream<List<BlogPost>> get outBlogPostList => _blogPostListController.stream;
Sink<List<BlogPost>> get _inBlogPostList => _blogPostListController.sink; // Here why use get and not a setter?
}
In advance, thank you.
The getter and setter concept is a way to simulate access to a field in a class but control the behavior of this. So behind the scene there can even not be any variable if we want to e.g. have a getter which fetch some data from somewhere each time (please don't do that).
get and set are therefore methods called when we try to get and set the value of this field:
class MyClass {
void get test => print('You called get');
set test(void input) => print('You called set');
}
void main() {
final obj = MyClass();
obj.test; // You called get
obj.test = null; // You called set
}
So in your case, you want to make so when you try to get the "variable" named _inBlogPostList you will instead get the result of _blogPostListController.sink.
The advantage of this is you get a Sink instance which you can call add and close on. If you don't need to close the sink you can instead use a set method to add stuff into the sink like Rémi Rousselet proposes.

Matching a method signature with a unknown parameter in a mocked class

I have this method:
Future<Either<Failure, WorkEntity>> updateWorkEntity({int id, String title, TimeType timeType, int times, DateTime executed})
that is being called like this:
repository.updateWorkEntity(id: workEntity.id, executed: DateTime.now())
the id I can control in a test, but the "DateTime.now()" I ofcourse can not. What I tried was this in my test:
when(repository.updateWorkEntity(id: expected.id, executed: any)).thenAnswer((_) async => Right(expected));
to be able to make my mock return a object for my test, by using "any" in the place of the "DateTime.now()", but I get this error:
Invalid argument(s): The "any" argument matcher is used outside of
method stubbing (via when) or verification (via verify or
untilCalled). This is invalid, and results in bad behavior during
the next stubbing or verification.
So I guess I can not use any here, but then how do I get my mock to return an object when I do not control one of the input parameters?
Thank you
Søren
Use executed: anyNamed('executed') instead of executed: any

Can I write a Neo4j Plugin to intercept and modify CYPHER queries

In my system, I would like to intercept and change Cypher queries as they come in, one alternative is to modify them before sending them from my middle layer to the graph - but is there a way to have a plugin do the conversion for me in the graph itself?
I'd like to do some of the following:
If someone identifying themselves as members of group A, imagine I'd like to change their request from:
MATCH(f:Film)-[r:REVIEWED_BY]-(u:User {id:"1337"})
to:
MATCH(p:Product)-[p:PURCHASED_BY]-(u:User {id:"1337"})
Is something like this possible? Or do I have to write the traversals in Java directly to achieve this?
Of course you can. You can do ANYTHING in Neo4j. Just grab the cypher string in an unmanaged extension that receives a post request, alter it any way you want, execute it with the graphdb.execute method and return the result as normal.
#POST
#Path("/batch")
public Response alterCypher(String body, #Context GraphDatabaseService db) throws IOException, InterruptedException {
ArrayList<Result> results = new ArrayList<>();
// Validate our input or exit right away
HashMap input = Validators.getValidCypherStatements(body);
ArrayList<HashMap> statements = (ArrayList<HashMap>)input.get("statements");
for (HashMap statement : statements) {
// write the alterQuery method to change the queries.
String alteredQuery = alterQuery((String)statement.get("statement"));
Result result = db.execute(alteredQuery, (Map)statement.getOrDefault("parameters", new HashMap<>()));
results.add(result);
}
// or go the results and return them however you want
// see https://github.com/dmontag/neo4j-unmanaged-extension-template/blob/master/src/main/java/org/neo4j/example/unmanagedextension/MyService.java#L36
return Response.ok().build();
}
At this time it's not possible to extend or modify Cypher queries.
If you need that I recommend you to use Transaction Event API - http://graphaware.com/neo4j/transactions/2014/07/11/neo4j-transaction-event-api.html
With that you should be able to change what query returns.

Verifying that a save was called in a Service Test

I'm using Grails 2.4 and I have a helper service that creates a specific domain class, sets up the dependencies surrounding it and then finally saves the object to the database, within a promise.
How would I test this service?
An example of the service is:
def persist(name, objectId, depTwoId) {
Person p = Person.findByName(name)
Object o = Object.findById(objectId)
RepObject rob = RepObject(p, o) //Ok you get the idea here
def task = Promises.task {
rob.save()
}
}
I don't care, within the context of the unit test, if there was a save to the database. I just want to know that it was called.
You'll have to do something to wait for the async call to finish, but that's a separate issue.
I'd do it with the metaclass if all you want to verify is that save is called, but not that the object is actually persisted:
Before you call the persist method in your integration test, add this:
boolean saveCalled = false
RepObject.metaClass.save = { -> saveCalled = true }
and in your Spock then block or wherever you do verification calls, add
assert saveCalled
Note that the signature of the metaclass save closure has to match what's actually called. You show it being called with no args, but if you call save(flush:true) then you're passing a Map arg and the signature would have to be
RepObject.metaClass.save = { Map m -> saveCalled = true }
otherwise Groovy won't choose yours, it will call the real method.

Resources