Modules:Analytics Generation Cubes
Languages: |
English | Français | Translate this article... |
Extend Generation of Cubes
It is possible to define a Cube as a Template, as explained in the Documentation, and then use this Template to generate the actual Cubes for the different Clients.
This is due to the fact that some Cube definitions might be dependent on Client's data.
By generating a Cube based on a Template, it is possible to replace some expressions by actual Client's data. For example, by default the expression @ad_client_id@ is replaced by the actual Client Id.
But in some scenarios that is not enough. That is why it is possible to extend the Process that generate the Cubes to take into account different requirements.
An example of this functionality can be found in the Multi-Dimensional Financial Reports.
Example
A Module is going to extend the generation of the Cubes for adding another parameter to replace, in this case the parameter @first_invoice_id@ will be replaced by the Id of the first Invoice created for a Client.
public class GeneratePAndLCubeFromTemplate extends GenerateFinancialCubesFromTemplate { private static final Logger log = Logger.getLogger(GeneratePAndLCubeFromTemplate.class); @Override public Set<String> getCubeTemplatesToGenerate() { Set<String> set = new HashSet<String>(); set.add("1E3B7EA7D12340618952D742E9B69EC2"); return set; } @Override public void processCube(JSONObject request, JSONObject params, CubeDefinition cube, CubeDefinition cubeTemplate, Client client) throws OBException { super.processCube(request, params, cube, cubeTemplate, client); cube.setSqlfilter(cube.getSqlfilter().replace("@first_invoice_id@ ", getFirstInvoiceId(client))); } }
- The first thing to notice is that the Java class must extend GenerateFinancialCubesFromTemplate class.
- Therefore, it must implement both getCubeTemplatesToGenerate and processCube methods.
- getCubeTemplatesToGenerate method returns a set of Strings that contains the Id's of the Cube Templates that are going to be affected by this code. In this example only the Cubes generated using the Cube Template with Id 1E3B7EA7D12340618952D742E9B69EC2 are going to be affected.
- processCube is the method that conatins the logic to process the Cube.
- In this example calls to the processCube method of the GenerateFinancialCubesFromTemplate class, which creates a Cube for each Client and replaces @ad_client_id@ with the actual Client Id.
- Then, for the Cube generated, this code replaces the parameter @first_invoice_id@ with the actual Id of the first Invoice of the Client, in the sqlFilter.
- The class GenerateFinancialCubesFromTemplate generates all the Cubes for each Client and then, in a loop, calls the method processCube for each Cube.