PerficientDigital / AEM-DataLayer

Simple DataLayer API for Adobe Experience Manager
Apache License 2.0
34 stars 13 forks source link

Several changes/cleanups + added some unit tests #13

Closed paul-bjorkstrand closed 5 years ago

paul-bjorkstrand commented 5 years ago

The commits have the details of each change, but in general these are cleanups/refactorings with a few goals in mind

  1. Make the code testable.
  2. Make the code more maintainable (e.g. reducing complexity a la Sonar rules).
  3. Fix a potential bug when creating a model without specifying what type of model you want..
  4. Fix a potential bug when there is a resourceSuperType cycle when there

There is a chance that Sling Models will give you the wrong type of model, even if a class exists that implements the ComponentDataElement interface, unless you explicitly ask for a model of that type. This was done by using createModel instead of getModelFrom*. The former allows you to specify a type to use, and takes advantage of the ResourceTypeBasedResourcePicker, which is set to a higher precedence than the default FirstImplementationPicker. This problem would be exacerbated by Sling Models Exporters, where you would have two models (the exporter model, and the data layer model) both specifying the resource type.

Another benefit of using createModel is type-safety: it is a generic method that returns an instance of your type, eliminating the explicit check & cast.