Search in sources :

Example 1 with AssetProcessingException

use of org.craftercms.studio.api.v1.exception.AssetProcessingException 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);
    }
}
Also used : Path(java.nio.file.Path) Asset(org.craftercms.studio.api.v1.asset.Asset) AssetProcessingException(org.craftercms.studio.api.v1.exception.AssetProcessingException) AssetProcessingException(org.craftercms.studio.api.v1.exception.AssetProcessingException) IOException(java.io.IOException)

Example 2 with AssetProcessingException

use of org.craftercms.studio.api.v1.exception.AssetProcessingException 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)

Example 3 with AssetProcessingException

use of org.craftercms.studio.api.v1.exception.AssetProcessingException in project studio by craftercms.

the class AssetProcessorResolverImpl method getProcessor.

@Override
public AssetProcessor getProcessor(ProcessorConfiguration config) throws AssetProcessingException {
    String beanName = String.format(beanNameFormat, config.getType());
    AssetProcessor processor = applicationContext.getBean(beanName, AssetProcessor.class);
    if (processor != null) {
        return processor;
    } else {
        throw new AssetProcessingConfigurationException("Invalid processor type: " + config.getType());
    }
}
Also used : AssetProcessingConfigurationException(org.craftercms.studio.api.v1.exception.AssetProcessingConfigurationException) AssetProcessor(org.craftercms.studio.api.v1.asset.processing.AssetProcessor)

Aggregations

Asset (org.craftercms.studio.api.v1.asset.Asset)2 AssetProcessor (org.craftercms.studio.api.v1.asset.processing.AssetProcessor)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ProcessorConfiguration (org.craftercms.studio.api.v1.asset.processing.ProcessorConfiguration)1 AssetProcessingConfigurationException (org.craftercms.studio.api.v1.exception.AssetProcessingConfigurationException)1 AssetProcessingException (org.craftercms.studio.api.v1.exception.AssetProcessingException)1