I want to to intercept a method in Service Builder, for example: XXXLocalService.update(). But I don't know the correct way to do this. I have done some research but I haven't found a clear way to do this.
Any help will be greatly appreciated.
There are basically two ways to achieve this in Liferay, assuming you want to intercept Liferay's services:
Service Wrapper Hooks
What this does is gives you a wrapper around the desired service, for eg: UserLocalServiceWrapper would be a wrapper around UserLocalService and would have complete control over the methods defined in this interface. And this is a good approach if you know the exact method you want to modify/intercept in that particular service.
Also with this approach you have full control whether the original method should run or not.
The link provides the full detailed tutorial how to achieve this.
Model Listener Hooks
This hook should be used when you want to track any changes on the particular Model like in the above case User and this is helpful when you are not sure which method is going to update the model.
What this basically does is gives you a set of methods like onBeforeUpdate, onAfterUpdate, onAfterCreate etc to have control over the model.
Also this approach would work good enough for your custom services as well.
Related
I notice that JHipster microservices have their own Auditing viz. PersistentAuditEvent it seems easier to use than say AuditEventRepository which only has add and some limited find methods.
I want to save an Event of a task being run with a role of SYSTEM and identify it by something like type:executedLongQuery
Then in future I want to check the last run of this query and decide whether we need to run in again for report generation then log an event again if it is run. It seems to me PersistentAuditEvent offered by JHipster is the best way to go.
I don't see a PersistentAuditEventRepository or any suitable implementation within the microservice so if I can get a documentation with example that would be very helpful. Even a clue in the right direction could help me start.
I found the repository interface and a custom implementation in JHipster Gateway which is not present in microservice. It was easy to simply copy it over to microservice and use the repository. Ofcourse here I am using a database in the microservice, an empty one, which still adds the migrations as well as Audit tables.
Since I cannot modify builtin models (entities, intents..) as provided by the LUIS.ai, How can I import them into my own model in a way that I can modify them further specific to my scenario(s).
Some of the contextual information can be found here: https://github.com/Microsoft/BotBuilder/issues/1694#issuecomment-305531910
I am using Azure Bot Service with Node.js
If you are using the new prebuilt domains, once you add them to your model, you should be able to tweak them.
If you are using the Cortana prebuilt app, I don't think you will be able to update it; however, the documentation contains some information if you want to "mimic" it.
If you explain exactly what are your scenarios, we might be able to come up with other alternatives.
I can't think of a straight-forward way to go about doing this, but you could take the .csv logs from LUIS and incorporate it into your model; at the least the response column data is in json format.
There're a lot of parameters which I need to maintain while I perform developing/debugging in my JSF/EJB application:
scheduler running or not
can emails be sent or not
can sms be sent or not
WebFilter turned on or off, etc..
What is the best practice to maintain all these parameters? Make Java properties file as described here Java Properties file examples or there's better approach?
I need to define these parameters in a single place, and get access to them from JSF and EJB projects as well.
Thank you in advance.
There are a lot of things you need to consider before you can choose the best alternative.
A properties file would be a good practice if these parameters are very rarely changed and are also user independent.
You could also implement a singleton EJB that caches these values.
If these parameters you mention are user dependent or change often it would be better if you include them as user properties, or role properties. (Following an RBAC approach)
I need to call a webservice from my MVC5 project to populate a model. But I'm not sure if the call to the webservice should be made from the controller or from the model. Reading answers on Stackoverflow regarding this issue, seems to point in both directions. So where is the right place to put the call?
A bit shocked nobody has answered this after 20 hours. Umm lets see here :) At minimum the controller would be responsible for this. Don't dirty up your model with responsibilities it shouldn't have.
I would create a service layer to handle this, the service layer would hold the refrence instead of the UI / web project, and then call _myservice.ExecuteSomeWebserviceMethod(); This really is just a light wrapper around the web service call but allows you more freedom to do things before returning whatever value(s) back to the controller.
You can inject the service into the constructor of the controller, it would be testable as well.
Without getting into all of the gory details, I am trying to design a service-based solution that will be consumed by several client applications. The solution allows admins to create and modify document templates which are used by regular users to perform data entry. It is my intent to make the application a learning tool for best practices, techniques, etc.
And, at the same time, I have to accomodate a schizophrenic environment because the 'powers that be' cannot ever stick to their decisions regarding technologies and tools. For example, I am using Linq-to-SQL today because they aren't ready to go to EF4 but there is also discussion about switching over to NHibernate. So, I have to make the code as persistent ignorant as possible to minimize the work required should we change OR/M tools.
At this point, I am also limited to using the partial class approach to extend the Linq-to-SQL classes so they implement interfaces defined in my business layer. I cannot go with POCOs because management insists that we leverage all built-in tooling, etc. so I must support the Linq-to-SQL designer.
That said, my service interface has a StartSession method that accepts a template identifier in its signature. The operation flows like this:
If a session already exists in the database for the current user and specified template, update the record to show the current activity. If not, create a new session object.
The session is associated with an instance of the template, call it the "form". So if the session is new, I need to retrieve the template information to create the new "form", associate it with the session then save the session to the database. On the other hand, if the session already existed, then I need to also load the "form" with the data entered by the user and stored in the session previously.
Finally, the session (with form definition and data) is returned to the caller.
My first objective is to create clean separation between the logical layers of my application. The second is to maintain persistence ignorance (as mentioned above). Third, I have to be able to test everything so all dependencies must be externalized for easy mocking. I am using Unity as an IoC tool to help in this area.
To accomplish this, I have defined my service class and data contracts as needed to support the service interface. The service class will have a dependency injected from the business layer that actually performs the work. And here's where it has gotten messy for me.
I've been try to go the Unit of Work and Repository route to help with persistance ignorance. I have an ITemplateRepository and an ISessionRepository which I can access from my IUnitOfWork implementation. The service class gets an instance of my SessionManager class (in my BLL) injected. The SessionManager receives the IUnitOfWork implementation through constructor injection and will delegate all persistence to the UoW but I find myself playing a shell game with the various logic.
Should all of the logic described above be in the SessionManager class or perhaps the UoW implementation? I want as little logic as possible in the repository implementations because changing the data access platform could result in unwanted changes to the application logic. Since my repository is working against an interface, how do I best go about creating the new session (keeping in mind that a valid session has a reference to the template, er, form being used)? Would it be better to still use POCOs even though I have to support the designer and use a tool like AutoMapper inside the repository implementation to handle translating the objects?
Ugh!
I know I am just stuck in analysis paralysis so a little nudge is probably all I need. What would be ideal would be if someone could provide an example how you would you would solve the problem given the business rules and architectural constraints I've defined.
If you don't use POCOs then your not really going to be data store agnostic. And using POCOs will allow you to get your system up and running with memory based repositories which is what you'll likely want to use for your unit tests anyhow.
The AutoMapper sounds nice but I wouldn't consider it a deal breaker. Mapping POCOs to EF4, LinqToSql, nHibernate isn't that time consuming unless you have hundreds of tables. When/If your POCOs begin to diverge from your persistence layer then you might find that an AutoMapper wont really fit the bill.