Search in sources :

Example 6 with Operation

use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.

the class GaussianBlur method buildOperation.

@Override
public Operation buildOperation(Map<String, String> parameterMap, InputStream artifactStream, String mimeType) {
    String key = FilterTypeEnum.GAUSSIANBLUR.toString().toLowerCase();
    if (!containsMyFilterParams(key, parameterMap)) {
        return null;
    }
    Operation operation = new Operation();
    operation.setName(key);
    String factor = parameterMap.get(key + "-factor");
    operation.setFactor(factor == null ? null : Double.valueOf(factor));
    UnmarshalledParameter kernelSize = new UnmarshalledParameter();
    String kernelSizeApplyFactor = parameterMap.get(key + "-kernel-size-apply-factor");
    kernelSize.setApplyFactor(kernelSizeApplyFactor == null ? false : Boolean.valueOf(kernelSizeApplyFactor));
    kernelSize.setName("kernel-size");
    kernelSize.setType(ParameterTypeEnum.INT.toString());
    kernelSize.setValue(parameterMap.get(key + "-kernel-size-amount"));
    UnmarshalledParameter numOfPasses = new UnmarshalledParameter();
    String numOfPassesApplyFactor = parameterMap.get(key + "-num-passes-apply-factor");
    numOfPasses.setApplyFactor(numOfPassesApplyFactor == null ? false : Boolean.valueOf(numOfPassesApplyFactor));
    numOfPasses.setName("num-passes");
    numOfPasses.setType(ParameterTypeEnum.INT.toString());
    numOfPasses.setValue(parameterMap.get(key + "-num-passes-amount"));
    operation.setParameters(new UnmarshalledParameter[] { kernelSize, numOfPasses });
    return operation;
}
Also used : UnmarshalledParameter(org.broadleafcommerce.openadmin.server.service.artifact.image.effects.chain.UnmarshalledParameter) Operation(org.broadleafcommerce.openadmin.server.service.artifact.image.Operation)

Example 7 with Operation

use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.

the class Rotate method buildOperation.

@Override
public Operation buildOperation(Map<String, String> parameterMap, InputStream artifactStream, String mimeType) {
    String key = FilterTypeEnum.ROTATE.toString().toLowerCase();
    if (!containsMyFilterParams(key, parameterMap)) {
        return null;
    }
    Operation operation = new Operation();
    operation.setName(key);
    String factor = parameterMap.get(key + "-factor");
    operation.setFactor(factor == null ? null : Double.valueOf(factor));
    UnmarshalledParameter rotate = new UnmarshalledParameter();
    String rotateApplyFactor = parameterMap.get(key + "-rotate-apply-factor");
    rotate.setApplyFactor(rotateApplyFactor == null ? false : Boolean.valueOf(rotateApplyFactor));
    rotate.setName("rotate");
    rotate.setType(ParameterTypeEnum.DOUBLE.toString());
    rotate.setValue(parameterMap.get(key + "-rotate-amount"));
    operation.setParameters(new UnmarshalledParameter[] { rotate });
    return operation;
}
Also used : UnmarshalledParameter(org.broadleafcommerce.openadmin.server.service.artifact.image.effects.chain.UnmarshalledParameter) Operation(org.broadleafcommerce.openadmin.server.service.artifact.image.Operation)

Example 8 with Operation

use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.

the class UnsharpMask method buildOperation.

@Override
public Operation buildOperation(Map<String, String> parameterMap, InputStream artifactStream, String mimeType) {
    String key = FilterTypeEnum.UNSHARPMASK.toString().toLowerCase();
    if (!containsMyFilterParams(key, parameterMap)) {
        return null;
    }
    Operation operation = new Operation();
    operation.setName(key);
    String factor = parameterMap.get(key + "-factor");
    operation.setFactor(factor == null ? null : Double.valueOf(factor));
    UnmarshalledParameter amount = new UnmarshalledParameter();
    String amountApplyFactor = parameterMap.get(key + "-value-apply-factor");
    amount.setApplyFactor(amountApplyFactor == null ? false : Boolean.valueOf(amountApplyFactor));
    amount.setName("value");
    amount.setType(ParameterTypeEnum.FLOAT.toString());
    amount.setValue(parameterMap.get(key + "-value-amount"));
    UnmarshalledParameter radius = new UnmarshalledParameter();
    String radiusApplyFactor = parameterMap.get(key + "-radius-apply-factor");
    radius.setApplyFactor(radiusApplyFactor == null ? false : Boolean.valueOf(radiusApplyFactor));
    radius.setName("radius");
    radius.setType(ParameterTypeEnum.INT.toString());
    radius.setValue(parameterMap.get(key + "-radius-amount"));
    operation.setParameters(new UnmarshalledParameter[] { amount, radius });
    return operation;
}
Also used : UnmarshalledParameter(org.broadleafcommerce.openadmin.server.service.artifact.image.effects.chain.UnmarshalledParameter) Operation(org.broadleafcommerce.openadmin.server.service.artifact.image.Operation)

Example 9 with Operation

use of org.broadleafcommerce.openadmin.server.service.artifact.image.Operation in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetStorageServiceImpl method getCacheFileModel.

@Override
public Map<String, String> getCacheFileModel(String fullUrl, Map<String, String> parameterMap) throws Exception {
    StaticAsset staticAsset = findStaticAsset(fullUrl);
    if (staticAsset == null) {
        throw new AssetNotFoundException("Unable to find an asset for the url (" + fullUrl + ")");
    }
    String mimeType = staticAsset.getMimeType();
    // extract the values for any named parameters
    Map<String, String> convertedParameters = namedOperationManager.manageNamedParameters(parameterMap);
    String cachedFileName = constructCacheFileName(staticAsset, convertedParameters);
    // Look for a shared file (this represents a file that was based on a file originally in the classpath.
    File cacheFile = getFileFromLocalRepository(cachedFileName);
    if (cacheFile.exists()) {
        return buildModel(cacheFile.getAbsolutePath(), mimeType);
    }
    // Obtain the base file (that we may need to convert based on the parameters
    String baseCachedFileName = constructCacheFileName(staticAsset, null);
    File baseLocalFile = getFileFromLocalRepository(baseCachedFileName);
    if (!baseLocalFile.exists()) {
        if (broadleafFileService.checkForResourceOnClassPath(staticAsset.getFullUrl())) {
            cacheFile = broadleafFileService.getSharedLocalResource(cachedFileName);
            baseLocalFile = broadleafFileService.getSharedLocalResource(baseCachedFileName);
            createLocalFileFromClassPathResource(staticAsset, baseLocalFile);
        } else {
            baseLocalFile = lookupAssetAndCreateLocalFile(staticAsset, baseLocalFile);
        }
    }
    if (convertedParameters.isEmpty()) {
        return buildModel(baseLocalFile.getAbsolutePath(), mimeType);
    } else {
        FileInputStream assetStream = new FileInputStream(baseLocalFile);
        BufferedInputStream original = new BufferedInputStream(assetStream);
        original.mark(0);
        Operation[] operations = artifactService.buildOperations(convertedParameters, original, staticAsset.getMimeType());
        InputStream converted = artifactService.convert(original, operations, staticAsset.getMimeType());
        createLocalFileFromInputStream(converted, cacheFile);
        if ("image/gif".equals(mimeType)) {
            mimeType = "image/png";
        }
        return buildModel(cacheFile.getAbsolutePath(), mimeType);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) GloballySharedInputStream(org.broadleafcommerce.common.file.service.GloballySharedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StaticAsset(org.broadleafcommerce.cms.file.domain.StaticAsset) AssetNotFoundException(org.broadleafcommerce.cms.common.AssetNotFoundException) Operation(org.broadleafcommerce.openadmin.server.service.artifact.image.Operation) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream)

Aggregations

Operation (org.broadleafcommerce.openadmin.server.service.artifact.image.Operation)9 UnmarshalledParameter (org.broadleafcommerce.openadmin.server.service.artifact.image.effects.chain.UnmarshalledParameter)7 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 AssetNotFoundException (org.broadleafcommerce.cms.common.AssetNotFoundException)1 StaticAsset (org.broadleafcommerce.cms.file.domain.StaticAsset)1 GloballySharedInputStream (org.broadleafcommerce.common.file.service.GloballySharedInputStream)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1