Search in sources :

Example 1 with ProcessorPipelineConfiguration

use of org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration in project studio by craftercms.

the class AssetProcessorPipelineImplTest method testProcessNewOutputKeepOriginal.

@Test
public void testProcessNewOutputKeepOriginal() throws Exception {
    ProcessorPipelineConfiguration config = createPipelineConfig(true, SAME_INPUT_AS_OUTPUT_PROCESSOR_TYPE, RANDOM_OUTPUT_PROCESSOR_TYPE);
    Path inputFile = createInputFile();
    Asset input = new Asset(INPUT_REPO_PATH, inputFile);
    List<Asset> outputs = pipeline.processAsset(config, input);
    assertNotNull(outputs);
    assertEquals(2, outputs.size());
    assertEquals(outputs.get(0).getRepoPath(), input.getRepoPath());
    assertEquals(outputs.get(0).getFilePath(), input.getFilePath());
    assertNotEquals(outputs.get(1).getRepoPath(), input.getRepoPath());
    assertNotEquals(outputs.get(1).getFilePath(), input.getFilePath());
}
Also used : Path(java.nio.file.Path) ProcessorPipelineConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration) Asset(org.craftercms.studio.api.v1.asset.Asset) Test(org.testng.annotations.Test)

Example 2 with ProcessorPipelineConfiguration

use of org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration in project studio by craftercms.

the class AssetProcessorPipelineImplTest method testProcessMultipleNewOutputsDropOriginal.

@Test
public void testProcessMultipleNewOutputsDropOriginal() throws Exception {
    ProcessorPipelineConfiguration config = createPipelineConfig(false, RANDOM_OUTPUT_PROCESSOR_TYPE, RANDOM_OUTPUT_PROCESSOR_TYPE);
    Path inputFile = createInputFile();
    Asset input = new Asset(INPUT_REPO_PATH, inputFile);
    List<Asset> outputs = pipeline.processAsset(config, input);
    assertNotNull(outputs);
    assertEquals(outputs.size(), 2);
    assertNotEquals(outputs.get(0).getRepoPath(), input.getRepoPath());
    assertNotEquals(outputs.get(0).getFilePath(), input.getFilePath());
    assertNotEquals(outputs.get(1).getRepoPath(), input.getRepoPath());
    assertNotEquals(outputs.get(1).getFilePath(), input.getFilePath());
}
Also used : Path(java.nio.file.Path) ProcessorPipelineConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration) Asset(org.craftercms.studio.api.v1.asset.Asset) Test(org.testng.annotations.Test)

Example 3 with ProcessorPipelineConfiguration

use of org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration in project studio by craftercms.

the class AssetProcessorPipelineImplTest method createPipelineConfig.

private ProcessorPipelineConfiguration createPipelineConfig(boolean keepOriginal, String... processorTypes) {
    List<ProcessorConfiguration> processorsConfig = new ArrayList<>(processorTypes.length);
    for (String processorType : processorTypes) {
        ProcessorConfiguration processorConfig = new ProcessorConfiguration();
        processorConfig.setType(processorType);
        processorsConfig.add(processorConfig);
    }
    ProcessorPipelineConfiguration config = new ProcessorPipelineConfiguration();
    config.setKeepOriginal(keepOriginal);
    config.setInputPathPattern(INPUT_PATH_PATTERN);
    config.setProcessorsConfig(processorsConfig);
    return config;
}
Also used : ProcessorConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration) ProcessorPipelineConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration) ArrayList(java.util.ArrayList)

Example 4 with ProcessorPipelineConfiguration

use of org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration in project studio by craftercms.

the class AssetProcessingConfigReaderImpl method readPipelineConfig.

@SuppressWarnings("unchecked")
private ProcessorPipelineConfiguration readPipelineConfig(HierarchicalConfiguration pipelineConfig) throws AssetProcessingConfigurationException {
    ProcessorPipelineConfiguration mappedPipelineConfig = new ProcessorPipelineConfiguration();
    mappedPipelineConfig.setInputPathPattern(getRequiredStringProperty(pipelineConfig, INPUT_PATH_PATTERN_CONFIG_KEY));
    mappedPipelineConfig.setKeepOriginal(pipelineConfig.getBoolean(KEEP_ORIGINAL_CONFIG_KEY, false));
    List<HierarchicalConfiguration> processorsConfig = getRequiredConfigurationsAt(pipelineConfig, PROCESSORS_CONFIG_KEY);
    List<ProcessorConfiguration> mappedProcessorsConfig = new ArrayList<>(processorsConfig.size());
    for (HierarchicalConfiguration processorConfig : processorsConfig) {
        mappedProcessorsConfig.add(readProcessorConfig(processorConfig));
    }
    mappedPipelineConfig.setProcessorsConfig(mappedProcessorsConfig);
    return mappedPipelineConfig;
}
Also used : ProcessorConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration) ProcessorPipelineConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Example 5 with ProcessorPipelineConfiguration

use of org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration in project studio by craftercms.

the class AssetProcessorPipelineImpl method processAsset.

@Override
public List<Asset> processAsset(ProcessorPipelineConfiguration config, Asset input) throws AssetProcessingException {
    Matcher inputPatMatcher = matchForProcessing(config, input);
    if (inputPatMatcher != null) {
        Set<Asset> outputs = new LinkedHashSet<>();
        Asset originalInput = input;
        Map<ProcessorConfiguration, AssetProcessor> processors = getProcessors(config);
        if (config.isKeepOriginal()) {
            outputs.add(originalInput);
        }
        for (Map.Entry<ProcessorConfiguration, AssetProcessor> entry : processors.entrySet()) {
            Asset output = entry.getValue().processAsset(entry.getKey(), inputPatMatcher, input);
            outputs.add(output);
            input = output;
        }
        if (!config.isKeepOriginal() && outputs.contains(originalInput)) {
            outputs.remove(originalInput);
        }
        return new ArrayList<>(outputs);
    } else {
        return Collections.emptyList();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcessorConfiguration(org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Asset(org.craftercms.studio.api.v1.asset.Asset) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AssetProcessor(org.craftercms.studio.api.v1.asset.processing.AssetProcessor)

Aggregations

ProcessorPipelineConfiguration (org.craftercms.studio.api.v1.asset.processing.ProcessorPipelineConfiguration)8 Asset (org.craftercms.studio.api.v1.asset.Asset)7 Path (java.nio.file.Path)5 Test (org.testng.annotations.Test)5 ArrayList (java.util.ArrayList)3 ProcessorConfiguration (org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration)3 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Matcher (java.util.regex.Matcher)1 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)1 AssetProcessor (org.craftercms.studio.api.v1.asset.processing.AssetProcessor)1 AssetProcessorPipeline (org.craftercms.studio.api.v1.asset.processing.AssetProcessorPipeline)1 AssetProcessingException (org.craftercms.studio.api.v1.exception.AssetProcessingException)1 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)1 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)1