The SoftSlate Extender Code Generation Tool

We spend a lot of time here working for clients helping them to customize their SoftSlate Commerce stores. That often means extending the built-in SoftSlate domain model (ie, adding new fields to the database and the programming code) to keep track of or support some special business logic.

This is why we are very excited by the SoftSlate Extender tool. The SoftSlate Extender automatically generates the necessary code to add new fields to existing SoftSlate Commerce entities, or even new entities altogether. This includes all the code required to view and manipulate the fields and entities in the SoftSlate Administrator. (If you’re familiar with Grails think “grails generate-all”.) In just a couple of steps, you can add your new field to the existing application, and view and update it within the Administrator application alongside all the core fields. Where before this process could take a few hours of manually creating or updating files, with the SoftSlate Extender it can take just minutes. Joy!

The SoftSlate Extender is available starting with version 3.3.0. We’re calling it “beta” for now because it currently only supports generating SQL for the new database objects in MySQL format, and also there are a couple minor limitations when it comes to extending an existing entity (though it is certainly still worth using for that purpose).

The Extender tool lives entirely within the following package: com.softslate.commerce.administrator.extender, or, on the file system, in the /WEB-INF/src/com/softslate/commerce/administrator/extender directory. Inside there, you’ll find a lot of .vm files, which are Velocity templates. The Extender uses Velocity templates to represent the boilerplate Java classes, JSP templates, and other files it needs to generate. You’ll also find a README file, but I’ll go over everything the README discusses here as well.

Operating the extender boils down to this:

  1. Modify extender-custom.properties with the fields/entities you want to add to the system, and with the settings you want to use for the Extender.
  2. Run the ExtenderCommandLine class as a Java application. (Eg, in Eclipse, right-click on ExtenderCommandLine.java, and Select Run As … Java Application). If you’re using Eclipse, refresh the project to view the new/modified files.
  3. Make any tweaks you need to to the output (eg, adding a database index for the field).
  4. Run the CREATE TABLE or ALTER TABLE statements outputted by the Extender, which will be placed in .sql files for you under the businessobjects package.
  5. Test the new entity or fields in the Administrator.
  6. Take an early lunch!

Here’s what a typical configuration might look like in the configuration file, extender-custom.properties:

entity=com.mydomainname.commerce.businessobjects.product.ExtraProductThingy
foreignKeys=com.softslate.commerce.businessobjects.product.ProductBean
fields=name|String,code|String,price|Double,numberOfPoints|Integer,isActive|Boolean
createAdminInterface=true
updateExistingEntity=false
overwriteExistingFiles=true
webinfDirectoryPath=

Let’s dive into each of these properties a little bit more:

  • entity=The fully-qualified class name of the Bean you wish to create or extend.
  • foreignKeys=A comma-separated list of the fully-qualified class names of other Beans the entity needs to reference as foreign keys. ID fields referencing each foreign key will be generated in the new entity (or added to the existing entity).
  • fields=A comma-separated list of all the fields for the new entity, or the new fields being added to an existing entity. Each field is composed of the name of the field, followed by a pipe character (|), followed by the data type for the field (String, Integer, Double, or Boolean).
  • createAdminInterface=Set to ‘false’ to skip generating Struts configurations, Struts Forms, Struts Actions, and JSPs for the Administrator interface for the new entity or fields.
  • updateExistingEntity=If you are adding a new field to an existing entity, you should set this to true. If you are creating a brand new entity, set it to false. If it’s set to true, rather than create all the files for a brand new entity, it will just create the files needed to add the new field or fields. If you set overwriteExistingFiles to true, it will also attempt to merge just the new code for the new field(s) into the existing code.
  • overwriteExistingFiles=Set to true to have the Extender generate the code in the project’s WEB-INF directory itself, overwriting existing files (or merging into existing files if updateExistingEntity=true). Otherwise, the Extender places its output inside a new directory it will create, WEB-INF/extenderOutput. The suggestion is if you have a source control system, set this to true because you can easily revert the changes if you need to. It’s nice to overwrite because you can simply Refresh the project and use source control to review the diffs, and it’s easy to revert.
  • webinfDirectoryPath=Rare you would need to populate this, unless you have altered the directory structure of the project.

We hop you enjoy working with the Extender and that it saves you a ton of time. Drop us a line to let us know how it’s going!

About David Tobey

I'm a web developer and consultant based in lovely Schenectady, NY, where I run SoftSlate, LLC. In my twenties I worked in book publishing, where I met my wife. In my thirties I switched careers and became a computer programmer. I am still in the brainstorming phase for what to do in my forties, and I am quickly running out of time to make a decision. If you have any suggestions, please let me know. UPDATE: I have run out of time and received no (realistic) suggestions. I guess it's programming for another decade.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply