Is it advisable to use the build-test-data plugin to load the bootstrap (seed/initial) data for an application. The plugin tutorial is excellent at http://bitbucket.org/tednaleid/grails-test-data/wiki/Home , but only mention about loading test data. There is a section about TestDataConfig , which allows to set default data. But is it a viable option if the data needs to persist in a larger scale, with complex relations.\
thanks.
Testing data is the primary focus of the plugin, but I use it for all kinds of data loading situations, including bootstrapping data into a new system.
The only thing you need to be aware of is that the plugin, by design, will fill in any holes in required data that you don't supply. This means that you should specify everything that you actually want specific values on (or putting it in the TestDataConfig that you mention). If you don't give build-test-data a value, it'll make something up and that might be something that you don't want.
The newly added functionality around buildLazy makes it even easier to hook into an existing graph of objects that you might have in a BootStrap configuration.
It depends on your data. If you only need a few things like administrator account info, list of categories, etc it should work fine. I'd use it if you’re testing your app with the initial seed data and everything works fine. For large or complex data imports I'd use a gant script to create and save for all the domain objects. For example I'm working on a project that requires me to move data out of a legacy database into a grails application. For this I run a script that uses JDBC calls to get all the old data out of the legacy database. I then create and save new domain objects based off this data. For an example of how to run a script that has access to the entire Grails context including Gorm see this
Related
I am having trouble getting started on my first attempt with EF and Code First mostly due to trying to find an efficent way to organize the project in Visual Studio. I wanted to try Code First so I pictured a set of class files in a separate project to describe the entites, like MyApp.Models. To build on that I imagine I need something like Fluent API to make sure the database is created the way I expect which is where I hit the first snag. I think the only way to do this is to define the context where EF generates the database. So where should that code creating the context be defined? In a separate project like MyApp.DAL? I'd also like to include Asp.Net Identity 2.0 which I believe is part of defining the context so that is included in that step. Next I assume I need to actually call the code so EF can generate the DB which requires at least a configuration setting for the connection string. Eventually I want an MVC app but maybe next is a console EXE like MyApp.ConsoleTest? Also I'd also like a Web API project which would serve the MVC app. I think those can be covered with something like MyApp.WebAPI and MyApp.ClientWebMVC. Perhaps later I could also create MyApp.ClientWPF which would leverage the work done with the Web API. Along the way I should also probably have something like MyApp.Common or Shared.Common to hold things like logging and error catching.
I think the first few steps around the entities and context are what trip me up the most. I want to try and organize the data part of the code so changes can be isolated from ruining too much in the client apps. Is there a good tutorial on project organization that addresses EF Code First that isn't overly complicated (ie Unity of Work)?
I have an existing application that is a front end application which retrieves all of its information from external Web Services. I want to re-create this application using the Grails framework, however the use case is a bit odd. Grails is Model driven. In this case I really have no Database tables. My data is received real time through a web service call. My question to the community is how would you go about implementing the following use case:
Employee Search:
All employee data will come from a web service call. I need to allow the user to enter for example an "EmployeeID" and select a "Customer".
The Grails application then makes a web service query to the appropriate web service and pulls back the results.
HERE IS THE UNKOWN PART: What is the best way to take these results and fit them into the Grails model? In other words, I need to display a Data Grid of the results (Search Results). The grid should work like the Grails list action, allowing the user to sort on particular columns, pagination etc.
I would have to think that this use case is a common? What is the best way to lay a project like this down? Should I use external javaScript libraries like Dojo or JQuery to provide the grid functionality?
Performance is also a concern to an approach
There is no one single way to create Grails applications. Often applications do make use of domain classes that provide easy access to data in relational database tables, but you can easily switch to a NoSQL datastore or even use no direct persistence like in your application.
The simple answer to your question is that you should just create non-persistent data classes in src/groovy and src/java that represent the data you're working with from your web service calls. You can still use Grails for its controllers and GSPs, taglibs, services (non-transactional of course since there won't be database access), and also take advantage of the many available plugins.
You shouldn't have to do much to use the standard generated controllers and GSPs to display data with sorting and pagination. The generation scripts do expect domain classes, but you can cheat a bit to get those generated (and of course you can always code stuff by hand). For example if you have a Person class in src/groovy/com/yourcompany, move it to grails-app/domain:
package com.yourcompany
class Person {
String firstName
String lastName
}
Then run grails generate-all com.yourcompany.Person and it will create the controller and its unit test, and the GSPs. Now move it back to src/groovy and use it as you want. The GSPs don't expect domain classes, they just expect individual class instances or lists of instances.
You'll need to convert controller calls to stuff like person.save() to use your web services instead, but much of the code should be reusable.
One thing you can take advantage of is validation. You can annotate your classes with #Validateable and define constraints to take advantage of Grails validation for non-persistent classes - see the documentation for more details.
I got an online website written in ASP.MVC. Now, i need to periodically check one table, and if it changes, i need to take further actions related with modifying data in other tables. I could of course write a stand-alone application that would do that for me, but what other options do i have? I am asking, because maybe there is something better which i don't know about.
Assuming that you're using SQL Server, one option would be to add an item to the ASP.NET Cache, and then register a SqlCacheDependency on that item for the table or row that is to be monitored. There is a bit of configuration required to get this up and running, some instructions are here (with the code samples being in VB). When you add the item to the cache that has a SqlCacheDependency, you can specify a callback method that is fired when the data changes, which is how you would update related tables. If you are running SQL Server, want a pre-defined solution provided by Microsoft, and don't mind the setup process and additional database tables and configuration that this includes, this would be a great option.
I got an answer that is satysfying my requirements. There is something called Quartz.net that works just as i wanted it to. :)
Im building a Grails app that will have multiple similar websites (each it's own domain name) with the same code but different design and configuration. (think of blogger)
What is the best method for using different view and even some different logic on a single app without too much hacking?
I'm new to Grails and the method I have in mind is to check all the time to see what the domain name is and to serve the right controller/view. Is there a better way?
I would have a go with the MultiTenant plugin. You mention that views and logic differ, but I'm guessing what will differ most is the data? Use MultiTenant to cleanly separate the data for each site without too much hazzle, and if you store the configuration of views and logic in the DB you get that unique per site as well.
I think MultiTenant is being updated to the latest Grails release, at least I've seen that mentioned in the Grails mail list. I think you need to use an 1.2 release until then.
I'm doing something similar to separate data using the Hibernate Filter plugin. My views are the same but I have per-site texts and messages by looking up message "SITE-A.hello.world" first and if not found the default message "hello.world" is retrieved. Just to give you an idea how views may be customized, though you probably need to take it further than that for your system...
I'm getting started on a new MVC project where there are some peculiar rules and a little bit of strangeness, and it has me puzzled. Specifically, I have access to a database containing all of my data, but it has to be handled entirely through an external web service. Don't ask me why, I don't understand the reasons. That's just how it is.
So the CRUD will be handled via this API. I'm planning on creating a service layer that will wrap up all the calls, but I'm having trouble wrapping my head around the model... To create my model-based domain objects (customers, orders, so on..) should I:
Create them all manually
Create a dummy database and point an ORM at it
Point an ORM at the existing database but ignore the ORM's persistence in lieu of the API.
I feel like I've got all the information I need to build this out, but I'm getting caught up with the API. Any pointers or advice would be greatly appreciated.
Depending on the scale of what you're doing option 3 is dangerous as you're assuming the database model is the same as that exposed by the external service. Options 1 and 2 aren't IMHO much different from each other - in either case you'll have to decide what your objects, properties and behaviours are going to be - it just boils down to whether you're more comfortable doing it in classes or database tables.
The key thing is to make sure that the external service calls are hidden behind some sort of wrapper. Personally I'd then put a repository on top of that to handle querying the external service wrapper and return domain objects.
In general, ORMs are not known for their ability to generate clean domain model classes. ORMs are known for creating data layers, which you don't appear to need in this case.
You could probably use a code generation tool like T4 to code generate a first pass at your domain model classes, based on either the web service or the database, if that would save you time. Otherwise, you probably would just manually create the domain objects. Even if you code generate a first pass at your domain objects, it's unlikely there is a clean 1-1 mapping to your domain objects from either the database or web service, so you will likely need to spend significant time manually editing your code generated domain classes anyway.