Import class from an inplacePlugin to another inplacePlugin Grails - grails

I need use a domain class define in one inplacePlugin to a controller class in another inplacePlugin inside my app, but when I try to define the class IDE "cannot resolve the symbol". AutorDef domain class I define public in my app. What i need to do for reselve this issue?
def autor = AutorDef.findAll()

I already know how can do it that, it is very simple, (of course after a few day of deep thinking and search). Here is the solution.
In BuildConfig.groovy inside the inplace plugin where we need import the domain class from other inplace plugin we add next code,
grails.plugin.location.'common'="../sdl-common"
We add this code directly below
grails.project.test.reports.dir = "target/test-reports"
The import code before equals
grails.plugin.location.'common'
is the name use for import the plugin data(domain class, etc) and
"../sdl-common"
is the route to inplace plugin, and when we need to import the data in our classes, or controllers, we only need add
import common.*
in the part where we import hte packages.

Related

Vaadin 23 cannot handle #Viewport annotation

I have upgraded a Vaadin 14 app to Vaadin 23.1.3 and now it refuses to start with this error message:
Found app shell configuration annotations in non `AppShellConfigurator` classes.
Please create a custom class implementing `AppShellConfigurator` and move the following annotations to it:
- #Viewport from my.custom.class
However, my class does not have this annotation, it only extends an abstract class with this annoation. But I cannot change the abstract class, because it is a third party lib. So is there a way to tell Vaadin to just ignore this annotation and use the one I provided in the AppShellConfigurator class? Or any other way to get this app to start short of ditching the 3rd party library?
If the problematic class is just an abstract one, You can try creating a custom class with exactly the same structure and name but without the Viewport annotation. Then just import your custom class instead of the one from external package.
For example while using the AppLayoutRouterLayout class from com.github.appreciated:app-layout-addon package You could replace its usage with following class:
import com.github.appreciated.app.layout.component.applayout.AppLayout;
import com.github.appreciated.app.layout.component.router.AppLayoutRouterLayoutBase;
public abstract class AppLayoutRouterLayout<T extends AppLayout> extends AppLayoutRouterLayoutBase<T> {
}

How to avoid writing an import for every single file in dart/flutter?

I am making a flutter application and I created a file/class for each custom widget I am using. Then, I imported all of these files into the main screen but I don't like how it looks. Especially because if I want to add another widget or delete the one I would need to fiddle with the imports.
Is there something like C# namespaces where I can just make one import for all files in folder/namespace?
I already tried using library/part with success but then in https://www.dartlang.org/guides/libraries/create-library-packages says that I should avoid using part/part of. So, are we expected to import each and every file?
Instead of having:
import 'package:custom_widgets/custom_multiplechoice.dart';
import 'package:custom_widgets/custom_singlechoice.dart';
import 'package:custom_widgets/custom_time.dart';
import 'package:custom_widgets/custom_yesnochoice.dart';
import 'package:custom_widgets/custom_date.dart';
I would like to have:
import 'package:custom_widgets';
Yes there is, you can use export to achieve what you want.
You can place all your widgets in a folder, for example libs/src/ and then create file custom_widgets.dart in libs/ and use export like this inside custom_widgets.dart:
export 'src/custom_multiplechoice.dart';
export 'src/custom_singlechoice.dart';
export 'src/custom_time.dart';
export 'src/custom_widgets/src/custom_yesnochoice.dart';
export 'src/custom_date.dart';
Once you import custom_widgets.dart, all those widgets will be available to you.
Check this out, its all explained here: Dart: Organizing a library package
Update:
In Dart there are no namespaces like in most other languages.
Dart uses libraries for encapsulation, data hiding.
Only way to import a class into your code is to use import in the beginning of your file, which should also be a library.
I have an issue with this too. Imagine a situation where you want to import library dynamically. Let's say you would like to implement MVC pattern in your application, if you are doing this on the server, you would have a Router class that would analyze URL and decide what Controller class to instantiate and what Method from that Controller to invoke. Now every URL would trigger different Controller, and you don't know it in advance, its up to your Router to detect a Class to instantiate. What you need to do in this situation is import every Controller that could get instantiated at the beginning of your file. And I have issues with that. What if your application gets big and you have to import lets say 20 Controller classes, just so Router / Dispatcher can invoke one of them, and in reality you will invoke only one Controller, as there is only Controller per URL.
Don't have issues with manual loading of Libraries, if they are going to be used, but for situation like described above, Dart fails as there is no "auto loading" of classes like in for example PHP, where you can use auto loaders that use namespaces to find out about location of your class and instantiate a class in the middle of the code dynamically.
There is this extension for VSCode which can help to create this.
Dart Barrel File Generator

Class name conflict with class in Framework

In main project, I have a class named: Result.
And I import a third framework through Cocoapods which is also named Result. The Result framework has a class named Result.
In project, how can I use the Result class in Result framework?
You need to put the package name in front of the class name.
ThirdPartyFrameworkName.Result
and
YourTargetName.Result

grails 2.5+ Duplicate class definition error when implementing serializable on a controller

Upgrading a legacy system of grails. One of the controllers implements Serializable. This is throwing the following error in newer versions of grails:
Invalid duplicate class definition of class com.regional.ScheduleController :
The source contains at least two definitions of the class.
One of the classes is an explicit generated class using the class statement,
the other is a class generated from the script body based on the file name.
Solutions are to change the file name or to change the class name.
The solution mentioned would break (previous) grails convention. Anyone know how to handle this in grails 2.5+?
EDIT
Serializable is not the issue. I tried removing it and got the same error.
I found this explanation from another question:
IN groovy.. class B{} is a class structure and defines a class B.
Scripts are classes too.
Now you may create a B.groovy, with the content "class B{}; def b = new B()".
There would be one class named B, and a script with the very same name.
This is a conflict.
However this does not explain why it runs fine below grails 2.5 and not above it. And I can't find a def conflict like the one mentioned above in that controller.
ANSWER:
One of the imports was what was actually failing- in a way that caused groovy to generate a class definition based on the current file name. When it hit the class definition, there was already an auto generated class name to collide with.

ConversionNotSupportedException with similarly named classes

UPDATED: made some wrong assumptions about classes etc. The following occurs now when I have a 'demo' project:
I have two classes, both named 'Company'.
One is placed in grails-app/domain/my.classes.domain.Company
the other is in src/groovy/my.clazz.Company
The last one has a #Validateable annotation, and the Config.groovy contains grails.validateable.packages = ['my.clazz']
I also have an Account class, in grails-app/domain/my.classes.domain.Account:
package my.classes.domain
import java.io.Serializable;
class Account implements Serializable { Company company }
Then I use the following code (in the bootstrap.groovy):
import my.classes.domain.Company
import my.classes.domain.Account
...
Company company = new Company
Account acccount = new Account(company: company)
When running this app, the following error is shown:
Caused by: org.springframework.beans.ConversionNotSupportedException: Cannot convert value of type [my.clazz.Company] to required type [my.classes.domain.Company] for property 'company': no matching editors or conversion strategy found
... 33 more
Caused by: java.lang.IllegalStateException:
Cannot convert value of type [my.clazz.Company] to required type [my.classes.domain.Company] for property 'company': no matching editors or conversion strategy found
This is a very strange exception, as everything seems to be fine.
Some testing proved the following 'hints':
This error does NOT occur when I modify the config.groovy to explicitly name the classes (i.e. use grails.validateable.classes = ['my.classes.domain.Company']),
This error does NOT occur when I modify the Account's company property to be named differently (and modify the bootstrap accordingly), i.e.:
class Account extends Serializable {
Company cmp
}
However, these are workarounds. I'm really interested in WHY this is happening. Anybody got a clue?
Just to be on the safe side, I did the following to create this problem:
create domain class: my.classes.domain.Company
create domain class: my.classes.domain.Account
modify the domain class as above
create a groovy class: my.clazz.Company
give this groovy class the Validatable annotation.
add the my.clazz package to the validateable packages
in the bootstrap, create a new Account with new Account(company:company)
Aside from the various typos in your code which makes the problem hard to determine, the problem would seem to be that you are trying to set the Account.company property which is of type my.class.Company with the my.class.domain.Company type. Your bootstrap would need to be changed to:
import my.class.Company
import my.class.Account
Company company = new Company
Account acccount = new Account(company: company)
Note, the correct import statement for Company.
According to the error you describe, I think that Grails have determined wrong: the company you transfer into Account was determined as a my.clazz.Company, not my.classes.domain.Company.
You can put a simple check to know for sure what's the type of company in bootstrap:
import java.lang.Class;
...
println company.getClass().getName()

Resources