Hybris : How to create addons for acceleratorservices extension? - ant

I am new to Hybris environment. i'm working on add-ons concept in Hybris. I can able to create addons for storefront but my question is how to create addons for acceleratorservices extension. I have tried the usual method but that is not working.
(ant addoninstall -Daddonnames="{addonName}" -DaddonStorefront.yacceleratorstorefront="acceleratorservices"). When i compile my system it is throwing cyclic reference error. So can anyone tell me like how to create addons for acceleratorservices extension.
Any sort answer is welcome from Hybris expert. Thanks in advance.

Addon is used to extends the functionnality of templates (extensions starting with y). In your case acceleratorservices is just a dependency of storefront. So you should just use spring to override/extends the features of acceleratorservices you need.
To do it well, you class must extends the one from acceleratorservices that you want to modify. Then depending on your needs, add or override methods.
Finally update your sping configuration with "aliases" to replace the bean reference by your new implementation.

Related

Grails Plugin Development - override domain class

Plugins in Grails are great method to modularise an application.The documentation suggest to override the artifacts from the plugin in the application, which uses this plugin.
Is it realy the best approach?
Let's describe it by example: There is a domain class "org.User" defined in the plugin. The application overrides this domain class. If I use "grails run-app" then there are no warnings and it works. But Eclipse (GGTS) complains about "Invalid duplicate class definition of class org.User". For some developers it wouldn't matter, but I like the IDE helping on coding by stuf like "autocomplete".
At the end both classes are compiled an put on the java class loader. The application version of the class is loaded before the version of the plugin. The class resolver finds it first and that's why it works. Please correct me if I'm wrong at this point. Is it realy a good idea to have two versions of a class in one class loader?
What are the alternatives?
You can do like Spring Security Core plugin does, provide the User class as a template, so your application that use this plugin can choose between creating his own class or installing your default User class.
The plugin user template is here, and the script responsible to create this in the application is here.
You will need also a config value to know the class to use, and use it dynamic.
P.S: there are good security plugins like Shiro and Spring Security, maybe it's easier to check them instead of create your own.

How to create user account in grails using netbeans?

I have problem in creating user account in grails using netbeans. Show me the coding of how to create the new user account in grails using the netbeans IDE.
Don't expect this to be quick and easy. You have to create User class yourself before creating new Users, and set it up to work as a User.
Start with learning some security plugin - spring-security, I suggest.
If you need to manage users, start with creating required domain classes and spring-security-ui.
And this has nothing to do with Netbeans or whatever IDE, it's just the code you create with it.
Check out this screencast-series, which explains everything. It is done with SpringSource Toolsuite, but you can do it in whatever editor you use (e.g. Netbeans)
http://blog.springsource.com/2010/08/11/simplified-spring-security-with-grails/
Greetings,
Jan

How does Grails resolve Controller name conflicts?

What is the recommended approach when an application Controller name conflicts with the name of a plugin's Controller?
I've seen these Grails JIRAs:
GRAILS-4240
GRAILS-1243
...and Burt Beckwith's replies to these two threads imply that the only recourse is to rename one of the Controllers (presumably the application Controller since hacking plugin code is not desirable)
How to use the package name to differentiate between classes in grails?
How to extend/override controller actions of plugins?
However, Burt's own spring-security-ui plugin advocates the exact approach of naming an application Controller the same as a plugin Controller - see spring-security-ui docs.
This approach actually seems to work in both development mode (grails run-app) and when the app is deployed as a WAR. So can this functionality be depended on? If so, what is the Controller conflict resolution rule? The grails docs do not make any mention of it. Perhasps Burt can share his insight?
Having a "plugin" architecture like grails' without even a basic namespacing facility to handle conflicts like this seems pretty broken to me...
The problem is that while you can use packages for any artifact, the convention for controllers is to remove the package and "Controller" to create URLs, e.g. PersonController -> /appname/person/action_name. So in effect everything gets flattened.
In 1.2 and more so in 1.3 things were changed so plugins are compiled separately from application code (and are compiled first) and this gives you the opportunity to replace a plugin artifact with the application's version. Since you shouldn't edit plugin code, this gives you the flexibility to extend or replace a plugin artifact just by using the same name.
I tend to use UrlMappings to get around stuff like this when there are two similarly named controllers. For example say you have an admin UserController that allows low-level CRUD actions and a regular UserController that users work with. I'd name the admin controller AdminUserController and map it to /admin/user/* and leave UserController as is. The admin GSPs will be in views/adminUser and the others will be in views/user so there's no conflict there. This has the added benefit of being able to easily secure - map /admin/** -> ROLE_ADMIN. The conventions are convenient, but this is a simple configuration step that solves this issue for me.
The good news is that GRAILS-1243 will definitely be implemented in 2.0 and possibly in 1.4. And the plugin that Kim Betti references in the comments of GRAILS-1243 looks interesting.

What is the best way to work with services in grails

I've just started a project on grails and didn't find how to work with services using dependency injection and interfaces.
As I've seen so far in the documentation when you create a service - it's just a groovy class which can be auto wired wherever I want.
But what if I want to have an interface for a service and to inject one of its implementation like I did in Java using spring?
eg I want to have a service interface. let it be MyService.groovy
it will have 1 method doSmth()
and I'll have 2 implementations - MyServiceImpl1.groovy and MyServiceImpl2.groovy
I have a quartz job doing something like this
def myService
myService.doSmth()
Where should I put groovy interface (folder)? Shall I create a package for that in src/groovy?
How to configure resources.groovy to wire "myService" with 1 of the service implementation?
Any thoughts are appreciated
Thanks in advance!
Running grails create-service [name] is a convenient way of get a service deployed, but it doesn't create an interface with implementation, as you're looking for.
I'd suggest putting your interface and implementations into src/groovy and using resources.groovy to wire them up (you can access the environment, if you want to deploy a different implementation by environment).
Take a look at the 'Using the Spring DSL' section in chapter 14.2 of the user guide for how to wire up your service in resources.groovy. You also have the option of using resources.xml if you want to wire with XML, but I'd definitely recommend the Groovy DSL.
Just run grails create-service [name]

Is it possible to add Grails MVC classes at deployment time?

I'm writing a Grails app which I'd like 3rd parties to augment at runtime. Ideally they would be able to add a JAR/WAR to the webapp directory which contains new domain, controller and service classes, new views, and other content.
Is there a simple way to do this within grails? Would it be simplest to create a startup script which copies the new classes etc. into the relevant directories and then updates grails.xml and web.xml?
You will be able to do this in version 2 of grails in which plugins will be also OSGI plugins http://jira.codehaus.org/browse/GRAILS/fixforversion/15421
It seems that the Grails plugins will actually fit quite well for this: http://www.grails.org/Understanding+Plugins
A plugin can do just about anything... One thing a plugin cannot do though is modify the web-app/WEB-INF/web.xml or web-app/WEB-INF/applicationContext.xml files. A plugin can participate in web.xml generation, but not modify the file or provide a replacement. A plugin can NEVER change the applicationContext.xml file, but can provide runtime bean definitions

Resources