Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SavedImage supports extra params #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

Expand All @@ -30,11 +32,17 @@ public class SavedImage implements Serializable {
public final S3Location s3Destination;
public final AzureLocation azureDestination;

private final Map<String, Object> params;

public SavedImage(String imageIdentifier, Integer quality, boolean saveMetadata, boolean skip, S3Location s3Destination, AzureLocation azureDestination) {
this(imageIdentifier, quality, saveMetadata, skip, s3Destination, azureDestination, null);
this(imageIdentifier, quality, saveMetadata, skip, s3Destination, azureDestination, null, null);
}

public SavedImage(String imageIdentifier, Integer quality, boolean saveMetadata, boolean skip, S3Location s3Destination, AzureLocation azureDestination, Map<String, Object> setExif) {
this(imageIdentifier, quality, saveMetadata, skip, s3Destination, azureDestination, setExif, null);
}

public SavedImage(String imageIdentifier, Integer quality, boolean saveMetadata, boolean skip, S3Location s3Destination, AzureLocation azureDestination, Map<String, Object> setExif, Map<String, Object> params) {
if(s3Destination != null && azureDestination != null)
throw new IllegalArgumentException("only one destination location may be specified");

Expand All @@ -49,6 +57,12 @@ public SavedImage(String imageIdentifier, Integer quality, boolean saveMetadata,
this.azureDestination = azureDestination;

this.setExif = setExif;
this.params = params;
}

@JsonAnyGetter
public Map<String, Object> getParams() {
return params;
}

public static Builder withId(String imageIdentifier) {
Expand All @@ -60,6 +74,7 @@ public static class Builder {
private Integer quality;
private boolean saveMetadata = false;
private Map<String, Object> exif = new HashMap<String, Object>();
private Map<String, Object> params = null;

public Builder(String imageIdentifier) {
this.imageIdentifier = imageIdentifier;
Expand All @@ -76,32 +91,44 @@ public Builder withMetadata() {
}

public Builder withExifHeader(String key, Object value) {
exif.put(key, value);
exif.put(key, value);
return this;
}

public Builder withParam(String key, Object value) {
if(params == null) {
params = new HashMap<String, Object>();
}
params.put(key, value);
return this;
}

private Map<String, Object> exifOrNull() {
return exif.isEmpty() ? null : exif;
return exif.isEmpty() ? null : exif;
}

private Map<String, Object> paramsOrNull() {
return params;
}

public SavedImage toS3(S3Location s3Destination) {
return new SavedImage(imageIdentifier, quality, saveMetadata, false, s3Destination, null, exifOrNull());
return new SavedImage(imageIdentifier, quality, saveMetadata, false, s3Destination, null, exifOrNull(), paramsOrNull());
}

public SavedImage toS3(String bucket, String key) {
return toS3(S3Location.of(bucket, key));
}

public SavedImage toAzure(AzureLocation azureDestination) {
return new SavedImage(imageIdentifier, quality, saveMetadata, false, null, azureDestination, exifOrNull());
return new SavedImage(imageIdentifier, quality, saveMetadata, false, null, azureDestination, exifOrNull(), paramsOrNull());
}

public SavedImage toAzure(String accountName, String sharedAccessSignature) {
return toAzure(AzureLocation.of(accountName, sharedAccessSignature));
}

public SavedImage toBlitlineContainer() {
return new SavedImage(imageIdentifier, quality, saveMetadata, false, null, null, exifOrNull());
return new SavedImage(imageIdentifier, quality, saveMetadata, false, null, null, exifOrNull(), paramsOrNull());
}

public SavedImage butSkipSave() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void testJackson() throws JsonProcessingException {
.toS3(S3Location.of("my-bucket-name", "abcd1234random.jpg"));
System.out.println(mapper.writeValueAsString(save));

save = SavedImage.withId("extraparams").withQuality(90).withParam("png_quantize", true).withParam("extension", ".png").toAzure(AzureLocation.of("myAccount", "http://gobbledygook"));
System.out.println(mapper.writeValueAsString(save));

save = SavedImage.withId("4321nonrandom").withQuality(90).toAzure(AzureLocation.of("myAccount", "http://gobbledygook"));
System.out.println(mapper.writeValueAsString(save));

Expand Down