TAProductionType extends HadoopProductionType { @Override public Production createProduction(ProductionRequest productionRequest) throws ProductionException { final List<DateRange> dateRanges = L3ProductionType.getDateRanges(productionRequest, "1m"); if (dateRanges.size() == 0) { throw new ProductionException("Time range is zero"); } final String productionId = Production.createId(productionRequest.getProductionType()); final String productionName = productionRequest.getProductionName(createProductionName("Trend analysis ", productionRequest)); final Geometry regionGeometry = productionRequest.getRegionGeometry(); final String l3ConfigXml = L3ProductionType.getL3ConfigXml(productionRequest); TAConfig taConfig = null; if (productionRequest.getParameters().containsKey(JobConfigNames.CALVALUS_TA_PARAMETERS)) { final String taParameters = productionRequest.getParameter(JobConfigNames.CALVALUS_TA_PARAMETERS, true); try { taConfig = TAConfig.fromXml(taParameters); } catch (BindingException e) { throw new ProductionException("Parsing request ta parameters failed: " + taParameters); } } if (taConfig == null || taConfig.getRegions().length == 0) { taConfig = new TAConfig(new TAConfig.RegionConfiguration(productionRequest.getString("regionName"), regionGeometry)); } final String stagingDir = productionRequest.getStagingDirectory(productionId); final boolean autoStaging = productionRequest.getBoolean("autoStaging", true); final boolean isSkipL3 = productionRequest.getBoolean(JobConfigNames.CALVALUS_TA_SKIPL3_FLAG, false); Workflow.Sequential taSequence = new Workflow.Sequential(); Workflow.Parallel l3Set = new Workflow.Parallel(); StringBuffer l3OutputDirs = new StringBuffer(); for (int i = 0; i < dateRanges.size(); i++) { final DateRange dateRange = dateRanges.get(i); final String centreDate = ProductionRequest.getDateFormat().format(new Date((dateRange.getStartDate().getTime() + dateRange.getStopDate().getTime()) / 2)); final String l3OutputDir = getOutputPath(productionRequest, productionId, "-L3-" + centreDate); if (! isSkipL3) { final L3WorkflowItem l3WorkflowItem = createL3WorkflowItem(productionRequest, productionName, l3ConfigXml, regionGeometry, dateRange, centreDate, l3OutputDir); l3Set.add(l3WorkflowItem); } if (i != 0) { l3OutputDirs.append(","); } l3OutputDirs.append(l3OutputDir); } final String taOutputDir = getOutputPath(productionRequest, productionId, "-TA"); final TAWorkflowItem taWorkflowItem = createTaWorkflowItem(productionRequest, productionName, l3ConfigXml, taConfig, dateRanges, l3OutputDirs, taOutputDir); if (! isSkipL3) { taSequence.add(l3Set); } taSequence.add(taWorkflowItem); return new Production(productionId, productionName, taOutputDir, stagingDir, autoStaging, productionRequest, taSequence); } TAProductionType(FileSystemService fileSystemService, HadoopProcessingService processingService,
                            StagingService stagingService); @Override Production createProduction(ProductionRequest productionRequest);  }
@Test public void testCreateProduction() throws ProductionException, IOException { ProductionRequest productionRequest = createValidTAProductionRequest(); Production production = productionType.createProduction(productionRequest); assertNotNull(production); assertEquals("Trend analysis BandMaths 2010-06-01 to 2010-06-15 (wonderland)", production.getName()); assertEquals(true, production.getStagingPath().startsWith("ewa/")); assertEquals(true, production.getId().contains("_" + "TA" + "_")); assertNotNull(production.getWorkflow()); assertNotNull(production.getWorkflow().getItems()); assertEquals(2, production.getWorkflow().getItems().length); testItem(production.getWorkflow().getItems()[0].getItems()[0], "2010-06-01", "2010-06-03"); testItem(production.getWorkflow().getItems()[0].getItems()[1], "2010-06-04", "2010-06-06"); testItem(production.getWorkflow().getItems()[0].getItems()[2], "2010-06-07", "2010-06-09"); testItem(production.getWorkflow().getItems()[0].getItems()[3], "2010-06-10", "2010-06-12"); testItem(production.getWorkflow().getItems()[0].getItems()[4], "2010-06-13", "2010-06-15"); testTaItem(production.getWorkflow().getItems()[1], "2010-06-01", "2010-06-15", (L3WorkflowItem) production.getWorkflow().getItems()[0].getItems()[0]); }