use of org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration 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;
}
use of org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration in project studio by craftercms.
the class ImageTransformingProcessorTest method testProcessWithNoOutputPathPattern.
@Test
public void testProcessWithNoOutputPathPattern() throws Exception {
ProcessorConfiguration config = createProcessorConfigWithNoOutputPattern();
Path inputFile = createInputFile();
Asset input = new Asset(INPUT_REPO_PATH, inputFile);
Asset output = processor.processAsset(config, createInputPathMatcher(), input);
assertNotNull(output);
assertEquals(output.getRepoPath(), input.getRepoPath());
assertEquals(output.getFilePath(), inputFile);
verify(transformer).transform(any(Path.class), eq(inputFile), eq(Collections.emptyMap()));
}
use of org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration in project studio by craftercms.
the class AbstractAssetProcessor method processAsset.
@Override
public Asset processAsset(ProcessorConfiguration config, Matcher inputPathMatcher, Asset input) throws AssetProcessingException {
try {
String outputRepoPath = getOutputRepoPath(config, inputPathMatcher);
if (StringUtils.isEmpty(outputRepoPath)) {
// No output repo path means write to the same input. So move the original file to a tmp location
// and make the output file be the input file
Path inputFilePath = moveToTmpFile(input.getRepoPath(), input.getFilePath());
Path outputFilePath = input.getFilePath();
Asset output = new Asset(input.getRepoPath(), outputFilePath);
logger.info("Asset processing: Type = {}, Input = {}, Output = {}", config.getType(), input, output);
try {
doProcessAsset(inputFilePath, outputFilePath, config.getParams());
} finally {
Files.delete(inputFilePath);
}
return output;
} else {
Path inputFilePath = input.getFilePath();
Path outputFilePath = createTmpFile(outputRepoPath);
Asset output = new Asset(outputRepoPath, outputFilePath);
logger.info("Asset processing: Type = {}, Input = {}, Output = {}", config.getType(), input, output);
doProcessAsset(inputFilePath, outputFilePath, config.getParams());
return output;
}
} catch (Exception e) {
throw new AssetProcessingException("Error while executing asset processor of type '" + config.getType() + "'", e);
}
}
use of org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration 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;
}
use of org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration 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();
}
}
Aggregations