diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/EventDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/EventDialog.java index 153c80ca8c7..a7fb83b66e5 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/EventDialog.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/EventDialog.java @@ -33,10 +33,8 @@ import com.sap.sailing.gwt.ui.shared.CourseAreaDTO; import com.sap.sailing.gwt.ui.shared.EventDTO; import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO; import com.sap.sailing.gwt.ui.shared.VenueDTO; -import com.sap.sse.common.observer.ObservableBoolean; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.client.IconResources; -import com.sap.sse.gwt.client.Notification; -import com.sap.sse.gwt.client.Notification.NotificationType; import com.sap.sse.gwt.client.controls.datetime.DateAndTimeInput; import com.sap.sse.gwt.client.controls.listedit.GenericStringListEditorComposite; import com.sap.sse.gwt.client.controls.listedit.GenericStringListInlineEditorComposite; @@ -271,7 +269,7 @@ public abstract class EventDialog extends DataEntryDialogWithDateTimeBox implements Observer, GenericObserver{ +public abstract class ImageDialog extends DataEntryDialog + implements Observer, GenericObserver { private final SailingServiceAsync sailingService; protected final StringMessages stringMessages; @@ -49,88 +50,99 @@ public abstract class ImageDialog extends DataEntryDialog protected TextBox copyrightTextBox; protected IntegerBox widthInPxBox; protected IntegerBox heightInPxBox; - protected StringListInlineEditorComposite tagsListEditor; + protected final StringListInlineEditorComposite tagsListEditor; protected Image image; - protected List doResize; - protected Label doResizeLabel; + private final ExpandedUiWithCheckboxes expandedUi; private final BusyIndicator busyIndicator; - protected static class ImageParameterValidator implements Validator{ - private StringMessages stringMessages; + protected static class ImageParameterValidator implements Validator { + private final StringMessages stringMessages; private List doResize; private final ObservableBoolean storageServiceAvailable; - public ImageParameterValidator(StringMessages stringMessages, ArrayList doResize, ObservableBoolean storageServiceAvailable) { + + public ImageParameterValidator(StringMessages stringMessages, ObservableBoolean storageServiceAvailable) { this.stringMessages = stringMessages; - this.doResize = doResize; this.storageServiceAvailable = storageServiceAvailable; + this.doResize = new ArrayList(); + } + + public void setCheckBoxes(List doResize) { + this.doResize = doResize; } @Override - public String getErrorMessage(ImageResizingTaskDTO resizingTask) { + public String getErrorMessage(final ImageResizingTaskDTO resizingTask) { String errorMessage = null; - ImageDTO imageToValidate = resizingTask.getImage(); - Integer imageWidth = imageToValidate.getWidthInPx(); - Integer imageHeight = imageToValidate.getHeightInPx(); + final ImageDTO imageToValidate = resizingTask.getImage(); + final Integer imageWidth = imageToValidate.getWidthInPx(); + final Integer imageHeight = imageToValidate.getHeightInPx(); if (imageToValidate.getSourceRef() == null || imageToValidate.getSourceRef().isEmpty()) { errorMessage = stringMessages.pleaseEnterNonEmptyUrlOrUploadImage(); } else if (imageWidth == null || imageHeight == null) { errorMessage = stringMessages.couldNotRetrieveImageSizeYet(); } else { - //check if image is too small for resizing + // check if image is too small for resizing errorMessage = ""; - for(MediaTagConstants mediaTag : MediaTagConstants.values()) { - if(imageToValidate.hasTag(mediaTag.getName()) && (imageWidth < mediaTag.getMinWidth() || imageHeight < mediaTag.getMinHeight())) { + for (MediaTagConstants mediaTag : MediaTagConstants.values()) { + if (imageToValidate.hasTag(mediaTag.getName()) + && (imageWidth < mediaTag.getMinWidth() || imageHeight < mediaTag.getMinHeight())) { errorMessage += getImageToSmallErrorMessage(mediaTag, stringMessages) + "\n"; } } - if (errorMessage.equals("")) {//Check if image ratio fits for resizing + if (errorMessage.equals("")) {// Check if image ratio fits for resizing errorMessage = imageRatioFits(imageToValidate); } - if (errorMessage.equals("")) {//check for ckeckboxes and resizing + if (errorMessage.equals("")) {// check for ckeckboxes and resizing for (MediaTagConstants mediaTag : MediaTagConstants.values()) { - if (imageToValidate.hasTag(mediaTag.getName()) && (imageWidth > mediaTag.getMaxWidth() || imageHeight > mediaTag.getMaxHeight())) { + final CheckBox checkBox = getCheckBoxForTag(mediaTag.getName(), imageToValidate); + if (imageToValidate.hasTag(mediaTag.getName()) + && (imageWidth > mediaTag.getMaxWidth() || imageHeight > mediaTag.getMaxHeight())) { if (!resizingTask.getResizingTask().contains(mediaTag)) { errorMessage += getSizeErrorMessage(mediaTag, stringMessages) + "\n"; - getCheckBoxForTag(mediaTag.getName(), imageToValidate).setStyleName(GenericStringListInlineEditorWithCheckboxesComposite.ExpandedUi.getErrorStyle()); + checkBox.setStyleName(ExpandedUiWithCheckboxes.getErrorStyle()); + if (!errorMessage.equals("") && !storageServiceAvailable.getValue()) { + checkBox.setEnabled(false); + } } else { - getCheckBoxForTag(mediaTag.getName(), imageToValidate).setStyleName(GenericStringListInlineEditorWithCheckboxesComposite.ExpandedUi.getNormalStyle()); + checkBox.setStyleName(ExpandedUiWithCheckboxes.getNormalStyle()); } } else { - CheckBox checkBox = getCheckBoxForTag(mediaTag.getName(), imageToValidate); - checkBox.setStyleName(GenericStringListInlineEditorWithCheckboxesComposite.ExpandedUi.getInvisibleStyle()); + checkBox.setStyleName(ExpandedUiWithCheckboxes.getInvisibleStyle()); checkBox.setValue(false); } } } - if(!errorMessage.equals("") && !storageServiceAvailable.getValue()) { + if (!errorMessage.equals("") && !storageServiceAvailable.getValue()) { errorMessage += stringMessages.automaticResizeNeedsStorageService() + "\n"; } } if (errorMessage.equals("")) { - errorMessage = null; + errorMessage = null; } return errorMessage; } - private CheckBox getCheckBoxForTag(String tag, ImageDTO imageToValidate) { - List tags = imageToValidate.getTags(); + private CheckBox getCheckBoxForTag(final String tag, final ImageDTO imageToValidate) { + final List tags = imageToValidate.getTags(); CheckBox toReturn = null; for (int i = 0; i < tags.size(); i++) { if (tags.get(i).equals(tag)) { toReturn = doResize.get(i); } } - return toReturn == null ? new CheckBox() : toReturn;//new checkbox instead of null, so there is no need for a null check. this will be deleted from garbage collector anyway + return toReturn == null ? new CheckBox() : toReturn; + // new checkbox instead of null, so there is no need for a null check. this will be deleted from garbage + // collector anyway } private String imageRatioFits(ImageDTO imageToValidate) { String errorMessage = ""; - double ratio = ((double)imageToValidate.getWidthInPx())/imageToValidate.getHeightInPx(); - for(MediaTagConstants mediaTag : MediaTagConstants.values()) { - if(imageToValidate.hasTag(mediaTag.getName())) { - double minRatio = ((double)mediaTag.getMaxWidth())/mediaTag.getMinHeight(); - double maxRatio = ((double)mediaTag.getMinWidth())/mediaTag.getMaxHeight(); + final double ratio = ((double) imageToValidate.getWidthInPx()) / imageToValidate.getHeightInPx(); + for (MediaTagConstants mediaTag : MediaTagConstants.values()) { + if (imageToValidate.hasTag(mediaTag.getName())) { + final double minRatio = ((double) mediaTag.getMaxWidth()) / mediaTag.getMinHeight(); + final double maxRatio = ((double) mediaTag.getMinWidth()) / mediaTag.getMaxHeight(); if (minRatio < ratio || maxRatio > ratio) { errorMessage += stringMessages.imageResizeError(mediaTag.getName(), minRatio, maxRatio, ratio); } @@ -140,25 +152,31 @@ public abstract class ImageDialog extends DataEntryDialog } private String getSizeErrorMessage(MediaTagConstants mediaTag, StringMessages stringMessages) { - String errorMessage = stringMessages.imageSizeError(mediaTag.getName(), mediaTag.getMinWidth(), mediaTag.getMaxWidth(), mediaTag.getMinHeight(), mediaTag.getMaxHeight()); + String errorMessage = stringMessages.imageSizeError(mediaTag.getName(), mediaTag.getMinWidth(), + mediaTag.getMaxWidth(), mediaTag.getMinHeight(), mediaTag.getMaxHeight()); return errorMessage; } private String getImageToSmallErrorMessage(MediaTagConstants mediaTag, StringMessages stringMessages) { - String errorMessage = stringMessages.imageToSmallError(mediaTag.getName(),mediaTag.getMinWidth(),mediaTag.getMinHeight()); + String errorMessage = stringMessages.imageToSmallError(mediaTag.getName(), mediaTag.getMinWidth(), + mediaTag.getMinHeight()); return errorMessage; } } - public ImageDialog(Date creationDate, SailingServiceAsync sailingService, StringMessages stringMessages, ObservableBoolean storageServiceAvailable, DialogCallback dialogCallback) { - this(creationDate, sailingService, stringMessages, new ArrayList<>(), stringMessages.allowResizing(), storageServiceAvailable, dialogCallback); + + public ImageDialog(Date creationDate, SailingServiceAsync sailingService, StringMessages stringMessages, + ObservableBoolean storageServiceAvailable, DialogCallback callback) { + this(creationDate, sailingService, stringMessages, storageServiceAvailable, + new ImageParameterValidator(stringMessages, storageServiceAvailable), callback); } - - private ImageDialog(Date creationDate, SailingServiceAsync sailingService, StringMessages stringMessages, ArrayList doResize, String resizeStringMessage, ObservableBoolean storageServiceAvailable, DialogCallback callback) { - super(stringMessages.image(), null, stringMessages.ok(), stringMessages.cancel(), new ImageParameterValidator(stringMessages, doResize, storageServiceAvailable), callback); + + private ImageDialog(Date creationDate, SailingServiceAsync sailingService, StringMessages stringMessages, + ObservableBoolean storageServiceAvailable, ImageParameterValidator validator, + DialogCallback callback) { + super(stringMessages.image(), null, stringMessages.ok(), stringMessages.cancel(), validator, callback); this.stringMessages = stringMessages; this.sailingService = sailingService; this.creationDate = creationDate; - this.doResize = doResize; storageServiceAvailable.registerObserver(this); getDialogBox().getWidget().setWidth("730px"); busyIndicator = new SimpleBusyIndicator(); @@ -194,9 +212,10 @@ public abstract class ImageDialog extends DataEntryDialog } }); imageURLAndUploadComposite.setUploadEnabled(storageServiceAvailable.getValue()); - GenericStringListInlineEditorWithCheckboxesComposite.ExpandedUi expandedUi = new GenericStringListInlineEditorWithCheckboxesComposite.ExpandedUi(stringMessages, IconResources.INSTANCE.removeIcon(), /* suggestValues */ - MediaTagConstants.imageTagSuggestions, stringMessages.enterTagsForTheImage(), 30, doResize, stringMessages.allowResizing()); + expandedUi = new ExpandedUiWithCheckboxes(stringMessages, IconResources.INSTANCE.removeIcon(), /* suggestValues */ + MediaTagConstants.imageTagSuggestions, stringMessages.enterTagsForTheImage(), 30, stringMessages.allowResizing()); expandedUi.registerObserver(this); + validator.setCheckBoxes(expandedUi.getCheckBoxes()); tagsListEditor = new StringListInlineEditorComposite(Collections. emptyList(), expandedUi); tagsListEditor.addValueChangeHandler(new ValueChangeHandler>() { @Override @@ -208,17 +227,18 @@ public abstract class ImageDialog extends DataEntryDialog @Override protected ImageResizingTaskDTO getResult() { - List tags = new ArrayList(); - for (String tag: tagsListEditor.getValue()) { + final List tags = new ArrayList(); + for (String tag : tagsListEditor.getValue()) { tags.add(tag); } - List resizingTask = new ArrayList(); - for (int i= 0; i < tags.size(); i++) { - if (Arrays.asList(MediaTagConstants.values()).contains(MediaTagConstants.fromName(tags.get(i))) && doResize.get(i).getValue()) { + final List resizingTask = new ArrayList(); + for (int i = 0; i < tags.size(); i++) { + if (Arrays.asList(MediaTagConstants.values()).contains(MediaTagConstants.fromName(tags.get(i))) + && expandedUi.getCheckBoxes().get(i).getValue()) { resizingTask.add(MediaTagConstants.fromName(tags.get(i))); } } - ImageDTO image = new ImageDTO(imageURLAndUploadComposite.getURL(), creationDate); + final ImageDTO image = new ImageDTO(imageURLAndUploadComposite.getURL(), creationDate); image.setTitle(titleTextBox.getValue()); image.setSubtitle(subtitleTextBox.getValue()); image.setCopyright(copyrightTextBox.getValue()); @@ -273,13 +293,16 @@ public abstract class ImageDialog extends DataEntryDialog return imageURLAndUploadComposite.getInitialFocusWidget(); } + /** + * See {@link Observer#getNotified()} + */ @Override public void getNotified() { - validateAndUpdate(); + validateAndUpdate(); } @Override public void getNotified(Boolean data) { - imageURLAndUploadComposite.setUploadEnabled(data.booleanValue()); + imageURLAndUploadComposite.setUploadEnabled(data.booleanValue()); } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImageEditDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImageEditDialog.java index 37a086f480e..726143f2acc 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImageEditDialog.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImageEditDialog.java @@ -6,7 +6,7 @@ import java.util.List; import com.google.gwt.user.client.ui.Label; import com.sap.sailing.gwt.ui.client.SailingServiceAsync; import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sse.common.observer.ObservableBoolean; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.client.media.ImageDTO; import com.sap.sse.gwt.client.media.ImageResizingTaskDTO; diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImagesListComposite.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImagesListComposite.java index d22f232d946..3a433a91fe4 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImagesListComposite.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImagesListComposite.java @@ -32,8 +32,8 @@ import com.sap.sailing.gwt.ui.client.SailingServiceAsync; import com.sap.sailing.gwt.ui.client.StringMessages; import com.sap.sailing.gwt.ui.common.client.DateAndTimeFormatterUtil; import com.sap.sse.common.media.MediaTagConstants; -import com.sap.sse.common.observer.ObservableBoolean; import com.sap.sse.common.util.NaturalComparator; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.client.Notification; import com.sap.sse.gwt.client.Notification.NotificationType; import com.sap.sse.gwt.client.celltable.BaseCelltable; @@ -54,6 +54,7 @@ public class ImagesListComposite extends Composite { private SingleSelectionModel imageSelectionModel; private ListDataProvider imageListDataProvider; private final Label noImagesLabel; + private final ObservableBoolean storageServiceAvailable; private final SimplePanel mainPanel; private final VerticalPanel panel; @@ -74,9 +75,11 @@ public class ImagesListComposite extends Composite { private final AdminConsoleTableResources tableRes = GWT.create(AdminConsoleTableResources.class); - public ImagesListComposite(SailingServiceAsync sailingService, final StringMessages stringMessages, ObservableBoolean storageServiceAvailable) { + public ImagesListComposite(final SailingServiceAsync sailingService, final StringMessages stringMessages, + final ObservableBoolean storageServiceAvailable) { this.sailingService = sailingService; this.stringMessages = stringMessages; + this.storageServiceAvailable = storageServiceAvailable; mainPanel = new SimplePanel(); panel = new VerticalPanel(); mainPanel.setWidget(panel); @@ -89,7 +92,7 @@ public class ImagesListComposite extends Composite { addPhotoBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateImageDialog(MediaTagConstants.GALLERY.getName(), storageServiceAvailable); + openCreateImageDialog(MediaTagConstants.GALLERY.getName()); } }); imagesControlsPanel.add(addPhotoBtn); @@ -98,7 +101,7 @@ public class ImagesListComposite extends Composite { addStateImageBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateImageDialog(MediaTagConstants.STAGE.getName(), storageServiceAvailable); + openCreateImageDialog(MediaTagConstants.STAGE.getName()); } }); imagesControlsPanel.add(addStateImageBtn); @@ -107,7 +110,7 @@ public class ImagesListComposite extends Composite { addEventTeaseImageBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateImageDialog(MediaTagConstants.TEASER.getName(), storageServiceAvailable); + openCreateImageDialog(MediaTagConstants.TEASER.getName()); } }); imagesControlsPanel.add(addEventTeaseImageBtn); @@ -116,14 +119,14 @@ public class ImagesListComposite extends Composite { addLogoImageBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateImageDialog(MediaTagConstants.LOGO.getName(), storageServiceAvailable); + openCreateImageDialog(MediaTagConstants.LOGO.getName()); } }); imagesControlsPanel.add(addLogoImageBtn); imageSelectionModel = new SingleSelectionModel(); imageListDataProvider = new ListDataProvider(); - imageTable = createImagesTable(storageServiceAvailable); + imageTable = createImagesTable(); imageTable.ensureDebugId("ImagesCellTable"); imageTable.setVisible(false); @@ -143,7 +146,7 @@ public class ImagesListComposite extends Composite { initWidget(mainPanel); } - private CellTable createImagesTable(ObservableBoolean storageServiceAvailable) { + private CellTable createImagesTable() { CellTable table = new BaseCelltable(/* pageSize */10000, tableRes); imageListDataProvider.addDataDisplay(table); table.setWidth("100%"); @@ -220,7 +223,7 @@ public class ImagesListComposite extends Composite { imageListDataProvider.getList().remove(image); updateTableVisisbilty(); } else if (ImageConfigImagesBarCell.ACTION_EDIT.equals(value)) { - openEditImageDialog(image, storageServiceAvailable); + openEditImageDialog(image); } } }); @@ -268,9 +271,9 @@ public class ImagesListComposite extends Composite { return result; } - private void openCreateImageDialog(String initialTag, ObservableBoolean storageServiceAvailable) { - ImageCreateDialog dialog = new ImageCreateDialog(initialTag, sailingService, stringMessages, storageServiceAvailable, - new DialogCallback() { + private void openCreateImageDialog(String initialTag) { + ImageCreateDialog dialog = new ImageCreateDialog(initialTag, sailingService, stringMessages, + storageServiceAvailable, new DialogCallback() { @Override public void cancel() { } @@ -283,9 +286,9 @@ public class ImagesListComposite extends Composite { dialog.show(); } - private void openEditImageDialog(final ImageDTO selectedImage, ObservableBoolean storageServiceAvailable) { - ImageEditDialog dialog = new ImageEditDialog(selectedImage, sailingService, stringMessages, storageServiceAvailable, - new DialogCallback() { + private void openEditImageDialog(final ImageDTO selectedImage) { + ImageEditDialog dialog = new ImageEditDialog(selectedImage, sailingService, stringMessages, + storageServiceAvailable, new DialogCallback() { @Override public void cancel() { } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoCreateDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoCreateDialog.java index 9370111a1e3..8514a14d5f8 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoCreateDialog.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoCreateDialog.java @@ -7,7 +7,7 @@ import java.util.List; import com.google.gwt.user.client.ui.Label; import com.sap.sailing.gwt.ui.client.StringMessages; import com.sap.sse.common.media.MimeType; -import com.sap.sse.common.observer.ObservableBoolean; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.client.media.VideoDTO; public class VideoCreateDialog extends VideoDialog { diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java index c1c201708b9..a27cf840629 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java @@ -18,8 +18,8 @@ import com.sap.sailing.gwt.ui.client.StringMessages; import com.sap.sse.common.Util; import com.sap.sse.common.media.MediaTagConstants; import com.sap.sse.common.media.MimeType; -import com.sap.sse.common.observer.GenericObserver; -import com.sap.sse.common.observer.ObservableBoolean; +import com.sap.sse.common.util.GenericObserver; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.adminconsole.URLFieldWithFileUpload; import com.sap.sse.gwt.client.GWTLocaleUtil; import com.sap.sse.gwt.client.IconResources; @@ -42,7 +42,6 @@ public abstract class VideoDialog extends DataEntryDialog implements G protected IntegerBox lengthIntegerBox; protected final URLFieldWithFileUpload thumbnailURLAndUploadComposite; protected StringListInlineEditorComposite tagsListEditor; - private final ObservableBoolean storageServiceAvailable; protected static class VideoParameterValidator implements Validator { private StringMessages stringMessages; @@ -69,7 +68,6 @@ public abstract class VideoDialog extends DataEntryDialog implements G callback); this.stringMessages = stringMessages; this.creationDate = createdAtDate; - this.storageServiceAvailable = storageServiceAvailable; storageServiceAvailable.registerObserver(this); getDialogBox().getWidget().setWidth("730px"); @@ -198,7 +196,7 @@ public abstract class VideoDialog extends DataEntryDialog implements G @Override public void getNotified(Boolean data) { - videoURLAndUploadComposite.setUploadEnabled(storageServiceAvailable.getValue()); - thumbnailURLAndUploadComposite.setUploadEnabled(storageServiceAvailable.getValue()); + videoURLAndUploadComposite.setUploadEnabled(data.booleanValue()); + thumbnailURLAndUploadComposite.setUploadEnabled(data.booleanValue()); } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoEditDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoEditDialog.java index b65c3f1c7bd..debe1dd4f21 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoEditDialog.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoEditDialog.java @@ -5,7 +5,7 @@ import java.util.List; import com.google.gwt.user.client.ui.Label; import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sse.common.observer.ObservableBoolean; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.client.media.VideoDTO; public class VideoEditDialog extends VideoDialog { diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideosListComposite.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideosListComposite.java index 9ab41b06447..445976e8c19 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideosListComposite.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideosListComposite.java @@ -30,8 +30,8 @@ import com.google.gwt.view.client.SingleSelectionModel; import com.sap.sailing.gwt.ui.client.StringMessages; import com.sap.sailing.gwt.ui.common.client.DateAndTimeFormatterUtil; import com.sap.sse.common.media.MediaTagConstants; -import com.sap.sse.common.observer.ObservableBoolean; import com.sap.sse.common.util.NaturalComparator; +import com.sap.sse.common.util.ObservableBoolean; import com.sap.sse.gwt.client.celltable.BaseCelltable; import com.sap.sse.gwt.client.dialog.DataEntryDialog.DialogCallback; import com.sap.sse.gwt.client.media.VideoDTO; @@ -48,6 +48,7 @@ public class VideosListComposite extends Composite { private SingleSelectionModel videoSelectionModel; private ListDataProvider videoListDataProvider; private final Label noVideosLabel; + private final ObservableBoolean storageServiceAvailable; private final SimplePanel mainPanel; private final VerticalPanel panel; @@ -70,6 +71,7 @@ public class VideosListComposite extends Composite { public VideosListComposite(final StringMessages stringMessages, ObservableBoolean storageServiceAvailable) { this.stringMessages = stringMessages; + this.storageServiceAvailable = storageServiceAvailable; mainPanel = new SimplePanel(); panel = new VerticalPanel(); mainPanel.setWidget(panel); @@ -82,7 +84,7 @@ public class VideosListComposite extends Composite { createVideoBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateVideoDialog(MediaTagConstants.GALLERY.getName(), storageServiceAvailable); + openCreateVideoDialog(MediaTagConstants.GALLERY.getName()); } }); videosControlsPanel.add(createVideoBtn); @@ -91,7 +93,7 @@ public class VideosListComposite extends Composite { addLiveStreamBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateVideoDialog(MediaTagConstants.LIVESTREAM.getName(), storageServiceAvailable); + openCreateVideoDialog(MediaTagConstants.LIVESTREAM.getName()); } }); videosControlsPanel.add(addLiveStreamBtn); @@ -100,14 +102,14 @@ public class VideosListComposite extends Composite { addHighlightBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - openCreateVideoDialog(MediaTagConstants.HIGHLIGHT.getName(), storageServiceAvailable); + openCreateVideoDialog(MediaTagConstants.HIGHLIGHT.getName()); } }); videosControlsPanel.add(addHighlightBtn); videoSelectionModel = new SingleSelectionModel(); videoListDataProvider = new ListDataProvider(); - videoTable = createVideosTable(storageServiceAvailable); + videoTable = createVideosTable(); videoTable.ensureDebugId("VideosCellTable"); videoTable.setVisible(false); @@ -127,7 +129,7 @@ public class VideosListComposite extends Composite { initWidget(mainPanel); } - private CellTable createVideosTable(ObservableBoolean storageServiceAvailable) { + private CellTable createVideosTable() { CellTable table = new BaseCelltable(/* pageSize */10000, tableRes); videoListDataProvider.addDataDisplay(table); table.setWidth("100%"); @@ -196,7 +198,7 @@ public class VideosListComposite extends Composite { videoListDataProvider.getList().remove(video); updateTableVisisbilty(); } else if (ImageConfigImagesBarCell.ACTION_EDIT.equals(value)) { - openEditVideoDialog(video, storageServiceAvailable); + openEditVideoDialog(video); } } }); @@ -244,34 +246,36 @@ public class VideosListComposite extends Composite { return result; } - private void openCreateVideoDialog(String initialTag, ObservableBoolean storageServiceAvailable) { - VideoCreateDialog dialog = new VideoCreateDialog(initialTag, stringMessages, storageServiceAvailable, new DialogCallback() { - @Override - public void cancel() { - } + private void openCreateVideoDialog(String initialTag) { + VideoCreateDialog dialog = new VideoCreateDialog(initialTag, stringMessages, storageServiceAvailable, + new DialogCallback() { + @Override + public void cancel() { + } - @Override - public void ok(VideoDTO newVideo) { - videoListDataProvider.getList().add(newVideo); - updateTableVisisbilty(); - } - }); + @Override + public void ok(VideoDTO newVideo) { + videoListDataProvider.getList().add(newVideo); + updateTableVisisbilty(); + } + }); dialog.show(); } - private void openEditVideoDialog(final VideoDTO selectedVideo, ObservableBoolean storageServiceAvailable) { - VideoEditDialog dialog = new VideoEditDialog(selectedVideo, stringMessages, storageServiceAvailable, new DialogCallback() { - @Override - public void cancel() { - } + private void openEditVideoDialog(final VideoDTO selectedVideo) { + VideoEditDialog dialog = new VideoEditDialog(selectedVideo, stringMessages, storageServiceAvailable, + new DialogCallback() { + @Override + public void cancel() { + } - @Override - public void ok(VideoDTO updatedVideo) { - videoListDataProvider.getList().remove(selectedVideo); - videoListDataProvider.getList().add(updatedVideo); - updateTableVisisbilty(); - } - }); + @Override + public void ok(VideoDTO updatedVideo) { + videoListDataProvider.getList().remove(selectedVideo); + videoListDataProvider.getList().add(updatedVideo); + updateTableVisisbilty(); + } + }); dialog.show(); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java index 455943b69cb..22e384b62af 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java @@ -787,6 +787,9 @@ public interface SailingService extends RemoteService, FileStorageManagementGwtS /** * Resizes an ImageDTO that is part of an ImageResizingTaskDTO into an array of resized versions. This array contains only one entry in most real cases + * + * @author Robin Fleige (D067799) + * * @param imageResizingTask is an ImageResizingTaskDTO with the information on how the image saved in the ImageDTO should be resized * @return returns an array of ImageDTOs, that contain the resized variants of the ImageDTO in toResizeImage * @throws Exception can throw different type of exceptions diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.java index 9b7515d442f..0dd9b930360 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.java @@ -2104,6 +2104,5 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages, String allowResizing(); String resizeSuccessfull(); String resizeUnsuccessfull(); - String setUpStorageService(); String automaticResizeNeedsStorageService(); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.properties b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.properties index 40d8aaf8f3c..0671a9a7b8a 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.properties +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.properties @@ -2100,4 +2100,4 @@ allowResizing=Allow resizing resizeSuccessfull=Resizing successfully finished resizeUnsuccessfull=Resizing not possible setUpStorageService=Please set up a file storage service first -automaticResizeNeedsStorageService=Automatic Resizing needs a working FileStorageService +automaticResizeNeedsStorageService=Automatic Resizing needs a working FileStorageService. \ No newline at end of file diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties index 15ee0d4500c..20fdc5e3342 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties @@ -2095,4 +2095,4 @@ allowResizing=Skalierung erlauben resizeSuccessfull=Skalierung erfolgreich abgeschlossen resizeUnsuccessfull=Skalierung nicht möglich setUpStorageService=Bitte setze zuerst einen Datei Speicher auf -automaticResizeNeedsStorageService=Die automatische Skalierung benötigt einen funktionierenden FileStorageService \ No newline at end of file +automaticResizeNeedsStorageService=Die automatische Skalierung benötigt einen funktionierenden FileStorageService. \ No newline at end of file diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index 86bfea5ecc8..5646306fbb0 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -7890,21 +7890,27 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S } } + /** + * See {@link SailingService#resizeImage(ImageResizingTaskDTO)} + */ @Override - public ImageDTO[] resizeImage(ImageResizingTaskDTO resizingTask) throws Exception { - ImageConverter converter = new ImageConverter(); + public ImageDTO[] resizeImage(final ImageResizingTaskDTO resizingTask) throws Exception { + final ImageConverter converter = new ImageConverter(); // calculating the fileType of the image by its uri - String sourceRef = resizingTask.getImage().getSourceRef(); - String fileType = sourceRef.substring(sourceRef.lastIndexOf(".") + 1); - ImageWithMetadata imageAndMetadata = converter.loadImage(HttpUrlConnectionHelper.redirectConnection(new URL(sourceRef)).getInputStream(), fileType); - List resizedImages = converter.convertImage(imageAndMetadata.getImage(), resizingTask.getResizingTask()); - List sourceRefs = storeImages(resizedImages, fileType, imageAndMetadata.getMetadata()); - List resizedImagesAsDTOs = createImageDTOsFromURLsAndResizingTask(sourceRefs,resizingTask, resizedImages); - for(String tag : resizingTask.getImage().getTags()) { - MediaTagConstants predefinedTag = MediaTagConstants.fromName(tag); - if(predefinedTag != null && !resizingTask.getResizingTask().contains(predefinedTag)) { - ImageDTO image = resizingTask.getImage(); - for(MediaTagConstants tagConstant : resizingTask.getResizingTask()) { + final String sourceRef = resizingTask.getImage().getSourceRef(); + final String fileType = sourceRef.substring(sourceRef.lastIndexOf(".") + 1); + final ImageWithMetadata imageAndMetadata = converter + .loadImage(HttpUrlConnectionHelper.redirectConnection(new URL(sourceRef)).getInputStream(), fileType); + final List resizedImages = converter.convertImage(imageAndMetadata.getImage(), + resizingTask.getResizingTask()); + final List sourceRefs = storeImages(resizedImages, fileType, imageAndMetadata.getMetadata()); + final List resizedImagesAsDTOs = createImageDTOsFromURLsAndResizingTask(sourceRefs, resizingTask, + resizedImages); + for (String tag : resizingTask.getImage().getTags()) { + final MediaTagConstants predefinedTag = MediaTagConstants.fromName(tag); + if (predefinedTag != null && !resizingTask.getResizingTask().contains(predefinedTag)) { + final ImageDTO image = resizingTask.getImage(); + for (MediaTagConstants tagConstant : resizingTask.getResizingTask()) { image.getTags().remove(tagConstant.getName()); } resizedImagesAsDTOs.add(image); @@ -7912,13 +7918,27 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S } return resizedImagesAsDTOs.toArray(new ImageDTO[resizedImages.size()]); } - - private List createImageDTOsFromURLsAndResizingTask(List sourceRefs, - ImageResizingTaskDTO resizingTask, List images) { - List imageDTOs = new ArrayList(); - for(int i= 0; i < sourceRefs.size(); i++) { - ImageDTO imageDTO = resizingTask.cloneImageDTO(); - for(MediaTagConstants tag : MediaTagConstants.values()) { + + /** + * Takes a list of source URLs, the resizing task and the sizes of the resized images to create a ImageDTO for every + * resized image + * + * @author Robin Fleige (D067799) + * + * @param sourceRefs + * list of source URLs + * @param resizingTask + * the resizing task, with information about resizes and the original ImageDTO + * @param images + * the BufferedImages, used to get their width and height + * @returns a List of ImageDTOs that contains an ImageDTO per resized image + */ + private List createImageDTOsFromURLsAndResizingTask(final List sourceRefs, + final ImageResizingTaskDTO resizingTask, final List images) { + final List imageDTOs = new ArrayList(); + for (int i = 0; i < sourceRefs.size(); i++) { + final ImageDTO imageDTO = resizingTask.cloneImageDTO(); + for (MediaTagConstants tag : MediaTagConstants.values()) { imageDTO.getTags().remove(tag.getName()); } imageDTO.getTags().add(resizingTask.getResizingTask().get(i).getName()); @@ -7929,13 +7949,29 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S return imageDTOs; } - private List storeImages(List resizedImages, String fileType, IIOMetadata metadata) { - List sourceRefs = new ArrayList<>(); - for(BufferedImage resizedImage : resizedImages) { - InputStream fileStorageStream = new ImageConverter().imageWithMetadataToInputStream(resizedImage, metadata, fileType); + /** + * Stores a list of BufferedImages and returns a list of URLs as Strings under which the BufferedImages are stored + * + * @author Robin Fleige (D067799) + * + * @param resizedImages + * the BufferedImages that will be stored + * @param fileType + * the format of the image, for example "png", "jpeg" or "jpg" + * @param metadata + * the metadata of the original image + * @returns a list of URLs as Strings under which the BufferedImages are stored + */ + private List storeImages(final List resizedImages, final String fileType, + final IIOMetadata metadata) { + final List sourceRefs = new ArrayList<>(); + for (final BufferedImage resizedImage : resizedImages) { + final InputStream fileStorageStream = new ImageConverter().imageWithMetadataToInputStream(resizedImage, + metadata, fileType); try { - sourceRefs.add(getService().getFileStorageManagementService().getActiveFileStorageService().storeFile( - fileStorageStream, "." + fileType, new Long(fileStorageStream.available())).toString()); + sourceRefs.add(getService().getFileStorageManagementService().getActiveFileStorageService() + .storeFile(fileStorageStream, "." + fileType, new Long(fileStorageStream.available())) + .toString()); } catch (NoCorrespondingServiceRegisteredException | IOException | OperationFailedException | InvalidPropertiesException e) { logger.log(Level.SEVERE, "Could not store file. Cause: " + e.getMessage()); diff --git a/java/com.sap.sse.common/META-INF/MANIFEST.MF b/java/com.sap.sse.common/META-INF/MANIFEST.MF index 7e7c811d558..91d636a67e0 100644 --- a/java/com.sap.sse.common/META-INF/MANIFEST.MF +++ b/java/com.sap.sse.common/META-INF/MANIFEST.MF @@ -10,7 +10,6 @@ Export-Package: com.sap.sse.common, com.sap.sse.common.impl, com.sap.sse.common.mail, com.sap.sse.common.media, - com.sap.sse.common.observer, com.sap.sse.common.scalablevalue, com.sap.sse.common.search, com.sap.sse.common.settings, diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/media/MediaTagConstants.java b/java/com.sap.sse.common/src/com/sap/sse/common/media/MediaTagConstants.java index 72080fc723f..cd353af4537 100644 --- a/java/com.sap.sse.common/src/com/sap/sse/common/media/MediaTagConstants.java +++ b/java/com.sap.sse.common/src/com/sap/sse/common/media/MediaTagConstants.java @@ -6,21 +6,28 @@ import java.util.List; import java.util.Set; public enum MediaTagConstants { - GALLERY("Gallery", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), - STAGE("Stage", 1440/2, 1440*2, 580/2, 580*2),// perfect fit would be 1440 x 580 - LOGO("Logo", 140/2, 140*4, 140/2, 140*4),// perfect fit would be 140 x 140 - TEASER("Teaser", 370/2, 370*3, 240/2, 240*3),// perfect fit would be 370 x 240 - SPONSOR("Sponsor", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), - HIGHLIGHT("Highlight", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), - LIVESTREAM("Livestream", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), - FEATURED("Featured", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), + GALLERY("Gallery", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), + STAGE("Stage", 1440 / 2, 1440 * 2, 580 / 2, 580 * 2), // perfect fit would be 1440 x 580 + LOGO("Logo", 140 / 2, 140 * 4, 140 / 2, 140 * 4), // perfect fit would be 140 x 140 + TEASER("Teaser", 370 / 2, 370 * 3, 240 / 2, 240 * 3), // perfect fit would be 370 x 240 + SPONSOR("Sponsor", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), + HIGHLIGHT("Highlight", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), + LIVESTREAM("Livestream", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), + FEATURED("Featured", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE), BIGSCREEN("BigScreen", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE); - private String name; - private int minWidth; - private int maxWidth; - private int minHeight; - private int maxHeight; + private final String name; + private final int minWidth; + private final int maxWidth; + private final int minHeight; + private final int maxHeight; + + public static final List imageTagSuggestions = Arrays.asList(new String[] { BIGSCREEN.getName(), + STAGE.getName(), TEASER.getName(), SPONSOR.getName(), LOGO.getName(), GALLERY.getName() }); + public static final List videoTagSuggestions = Arrays.asList(new String[] { BIGSCREEN.getName(), + LIVESTREAM.getName(), HIGHLIGHT.getName(), FEATURED.getName(), STAGE.getName() }); + public static final Set SUPPORTED_VIDEO_TYPES = new HashSet<>(Arrays.asList(MimeType.youtube, + MimeType.vimeo, MimeType.mp4, MimeType.mp4panorama, MimeType.mp4panoramaflip)); private MediaTagConstants(String name, int minWidth, int maxWidth, int minHeight, int maxHeight) { this.name = name; @@ -60,11 +67,4 @@ public enum MediaTagConstants { return toReturn; } - public static final List imageTagSuggestions = Arrays.asList(new String[] { BIGSCREEN.getName(), - STAGE.getName(), TEASER.getName(), SPONSOR.getName(), LOGO.getName(), GALLERY.getName() }); - public static final List videoTagSuggestions = Arrays.asList(new String[] { BIGSCREEN.getName(), - LIVESTREAM.getName(), HIGHLIGHT.getName(), FEATURED.getName(), STAGE.getName() }); - public static final Set SUPPORTED_VIDEO_TYPES = new HashSet<>(Arrays.asList(MimeType.youtube, - MimeType.vimeo, MimeType.mp4, MimeType.mp4panorama, MimeType.mp4panoramaflip)); - } diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/observer/GenericObservable.java b/java/com.sap.sse.common/src/com/sap/sse/common/observer/GenericObservable.java deleted file mode 100644 index 5217fd8d3d1..00000000000 --- a/java/com.sap.sse.common/src/com/sap/sse/common/observer/GenericObservable.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.sap.sse.common.observer; - -public interface GenericObservable { - public void registerObserver(GenericObserver observer); - public void unregisterObserver(GenericObserver observer); - public void notifyObserver(T data); -} diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/observer/GenericObserver.java b/java/com.sap.sse.common/src/com/sap/sse/common/observer/GenericObserver.java deleted file mode 100644 index be3723ca644..00000000000 --- a/java/com.sap.sse.common/src/com/sap/sse/common/observer/GenericObserver.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.sap.sse.common.observer; - -public interface GenericObserver { - void getNotified(T data); -} diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/observer/Observer.java b/java/com.sap.sse.common/src/com/sap/sse/common/observer/Observer.java deleted file mode 100644 index 90f45bef570..00000000000 --- a/java/com.sap.sse.common/src/com/sap/sse/common/observer/Observer.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.sap.sse.common.observer; - -public interface Observer { - void getNotified(); -} diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/util/GenericObservable.java b/java/com.sap.sse.common/src/com/sap/sse/common/util/GenericObservable.java new file mode 100644 index 00000000000..805f9585774 --- /dev/null +++ b/java/com.sap.sse.common/src/com/sap/sse/common/util/GenericObservable.java @@ -0,0 +1,17 @@ +package com.sap.sse.common.util; + +/** + * + * @author Robin Fleige (D067799) + * + * @param the class of the observable object + * + * An Interface for an Observable Object in push-update-notification style + */ +public interface GenericObservable { + public void registerObserver(GenericObserver observer); + + public void unregisterObserver(GenericObserver observer); + + public void notifyObserver(T data); +} diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/util/GenericObserver.java b/java/com.sap.sse.common/src/com/sap/sse/common/util/GenericObserver.java new file mode 100644 index 00000000000..9b48812ce67 --- /dev/null +++ b/java/com.sap.sse.common/src/com/sap/sse/common/util/GenericObserver.java @@ -0,0 +1,12 @@ +package com.sap.sse.common.util; + +/** + * + * @author Robin Fleige (D067799) + * + * @param + * the type of the observable object An Interface for an Observer in push-update-notification style + */ +public interface GenericObserver { + void getNotified(T data); +} diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/observer/Observable.java b/java/com.sap.sse.common/src/com/sap/sse/common/util/Observable.java similarity index 53% rename from java/com.sap.sse.common/src/com/sap/sse/common/observer/Observable.java rename to java/com.sap.sse.common/src/com/sap/sse/common/util/Observable.java index 848364d3cfc..e1235adbc6e 100644 --- a/java/com.sap.sse.common/src/com/sap/sse/common/observer/Observable.java +++ b/java/com.sap.sse.common/src/com/sap/sse/common/util/Observable.java @@ -1,7 +1,15 @@ -package com.sap.sse.common.observer; +package com.sap.sse.common.util; +/** + * An Interface for an Observable Object in push-notification style + * + * @author Robin Fleige (D067799) + * + */ public interface Observable { public void registerObserver(Observer observer); + public void unregisterObserver(Observer observer); + public void notifyObserver(); } diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/observer/ObservableBoolean.java b/java/com.sap.sse.common/src/com/sap/sse/common/util/ObservableBoolean.java similarity index 66% rename from java/com.sap.sse.common/src/com/sap/sse/common/observer/ObservableBoolean.java rename to java/com.sap.sse.common/src/com/sap/sse/common/util/ObservableBoolean.java index 9c03018a04e..6e0a56a350a 100644 --- a/java/com.sap.sse.common/src/com/sap/sse/common/observer/ObservableBoolean.java +++ b/java/com.sap.sse.common/src/com/sap/sse/common/util/ObservableBoolean.java @@ -1,26 +1,35 @@ -package com.sap.sse.common.observer; +package com.sap.sse.common.util; import java.util.ArrayList; import java.util.List; +/** + * + * @author Robin Fleige(D067799) + * + * A class for the implementation of an observable boolean + */ public class ObservableBoolean implements GenericObservable { private Boolean value; - private List> observer = new ArrayList>(); + private final List> observer; + public ObservableBoolean(Boolean value) { this.value = value; + observer = new ArrayList>(); } + public void setValue(Boolean value) { this.value = value; notifyObserver(value); } - + public Boolean getValue() { return value; } - + @Override public void registerObserver(GenericObserver observer) { - this.observer.add(observer); + this.observer.add(observer); } @Override @@ -30,7 +39,7 @@ public class ObservableBoolean implements GenericObservable { @Override public void notifyObserver(Boolean data) { - for(GenericObserver observer : this.observer){ + for (GenericObserver observer : this.observer) { observer.getNotified(data); } } diff --git a/java/com.sap.sse.common/src/com/sap/sse/common/util/Observer.java b/java/com.sap.sse.common/src/com/sap/sse/common/util/Observer.java new file mode 100644 index 00000000000..c7991bd8d29 --- /dev/null +++ b/java/com.sap.sse.common/src/com/sap/sse/common/util/Observer.java @@ -0,0 +1,11 @@ +package com.sap.sse.common.util; + +/** + * + * @author Robin Fleige(D067799) + * + * An Interface for an Observer in push-notification style + */ +public interface Observer { + void getNotified(); +} diff --git a/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/StringMessages.java b/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/StringMessages.java index 2ba8ea6bec7..aa9457f3c25 100755 --- a/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/StringMessages.java +++ b/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/StringMessages.java @@ -93,4 +93,6 @@ public interface StringMessages extends Messages { String explainReplicationServletPort(); String ok(); + + String setUpStorageService(); } diff --git a/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/URLFieldWithFileUpload.java b/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/URLFieldWithFileUpload.java index 981ab8f5098..991e6343a34 100755 --- a/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/URLFieldWithFileUpload.java +++ b/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/URLFieldWithFileUpload.java @@ -46,8 +46,11 @@ public class URLFieldWithFileUpload extends Composite implements HasValue + * The type of the items in the list + */ +public class ExpandedUiWithCheckboxes extends GenericStringListInlineEditorComposite.ExpandedUi + implements Observable { + + private final List checkBoxes; + private final String checkBoxText; + private final List observer; + static final ListEditorResources ress = GWT.create(ListEditorResources.class); + + /** + * Creates an editable list with checkboxes for every entry + * + * @param stringMessages + * the holder of the used strings + * @param removeImage + * the icon for removing an entry from the editor + * @param suggestValues + * values that will be suggested when entering something into the editor + * @param placeholderTextForAddTextbox + * @param textBoxSize + * the size if the textbox + * @param checkBoxText + * the text shown next to the checkboxes + */ + public ExpandedUiWithCheckboxes(StringMessages stringMessages, ImageResource removeImage, + List suggestValues, String placeholderTextForAddTextbox, int textBoxSize, String checkBoxText) { + super(stringMessages, removeImage, suggestValues, placeholderTextForAddTextbox, textBoxSize); + this.checkBoxes = new ArrayList(); + observer = new ArrayList(); + this.checkBoxText = checkBoxText; + ress.css().ensureInjected(); + } + + /** + * Used for the css styles + */ + interface ListEditorResources extends ClientBundle { + @Source("ListEditor.gss") + ListEditorCSS css(); + } + + interface ListEditorCSS extends CssResource { + String checkBoxInvisible(); + + String checkBoxNormal(); + + String checkBoxError(); + } + + /** + * Returns the checkboxes,so they can be accessed from another class + * + * @returns the checkboxes + */ + public List getCheckBoxes() { + return checkBoxes; + } + + /** + * used to set the checkbox style from another class + * + * @returns String the StyleName of the style + */ + public static String getInvisibleStyle() { + return ress.css().checkBoxInvisible(); + } + + public static String getErrorStyle() { + return ress.css().checkBoxError(); + } + + public static String getNormalStyle() { + return ress.css().checkBoxNormal(); + } + + /** + * See {@link ExpandedListEditorUi#addRow(Object)} + */ + @Override + protected void addRow(ValueType newValue) { + super.addRow(newValue); + final CheckBox checkBox = new CheckBox(checkBoxText); + checkBox.setStylePrimaryName(getInvisibleStyle()); + checkBox.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + CheckBox source = (CheckBox) event.getSource(); + if (source.getValue()) { + source.setStylePrimaryName(getNormalStyle()); + } else { + source.setStylePrimaryName(getErrorStyle()); + } + notifyObserver(); + } + }); + checkBoxes.add(checkBox); + expandedValuesGrid.setWidget(expandedValuesGrid.getRowCount() - 1, 2, checkBox); + } + + /** + * See {@link ListEditorUiStrategy#initWidget()} + */ + @Override + public Widget initWidget() { + expandedValuesGrid = new Grid(0, 3); + expandedValuesGrid.ensureDebugId("ExpandedValuesGrid"); + + VerticalPanel panel = new VerticalPanel(); + panel.add(createAddWidget()); + panel.add(expandedValuesGrid); + return panel; + + } + + /** + * See {@link ListEditorUiStrategy#onRowRemoved(int)} + */ + @Override + public void onRowRemoved(int rowIndex) { + checkBoxes.remove(rowIndex); + } + + /** + * See {@link GenericObservable#notifyObserver()} + */ + @Override + public void notifyObserver() { + for (Observer observer : this.observer) { + observer.getNotified(); + } + } + + /** + * See {@link GenericObservable#registerObserver(com.sap.sse.common.util.GenericObserver))} + */ + @Override + public void registerObserver(Observer observer) { + this.observer.add(observer); + } + + /** + * See {@link GenericObservable#unregisterObserver(com.sap.sse.common.util.GenericObserver)()} + */ + @Override + public void unregisterObserver(Observer observer) { + this.observer.remove(observer); + } +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/controls/listedit/GenericStringListInlineEditorWithCheckboxesComposite.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/controls/listedit/GenericStringListInlineEditorWithCheckboxesComposite.java deleted file mode 100644 index 591638c75b1..00000000000 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/controls/listedit/GenericStringListInlineEditorWithCheckboxesComposite.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.sap.sse.gwt.client.controls.listedit; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.shared.GWT; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.CssResource; -import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.Grid; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; -import com.sap.sse.common.observer.Observable; -import com.sap.sse.common.observer.Observer; -import com.sap.sse.gwt.client.StringMessages; - -public abstract class GenericStringListInlineEditorWithCheckboxesComposite - extends GenericStringListInlineEditorComposite { - - public GenericStringListInlineEditorWithCheckboxesComposite(Iterable initialValues, - StringMessages stringMessages, ImageResource removeImage, List suggestValues, int textBoxSize) { - super(initialValues, stringMessages, removeImage, suggestValues, textBoxSize); - } - - public static class ExpandedUi extends GenericStringListInlineEditorComposite.ExpandedUi implements Observable{ - - private List checkBoxes; - private String checkBoxText; - private List observer = new ArrayList(); - static final ListEditorResources ress = GWT.create(ListEditorResources.class); - - public ExpandedUi(StringMessages stringMessages, ImageResource removeImage, List suggestValues, - String placeholderTextForAddTextbox, int textBoxSize, List checkBoxes, String checkBoxText) { - super(stringMessages, removeImage, suggestValues, placeholderTextForAddTextbox, textBoxSize); - this.checkBoxes = checkBoxes; - this.checkBoxText = checkBoxText; - ress.css().ensureInjected(); - } - - interface ListEditorResources extends ClientBundle { - @Source("ListEditor.gss") - ListEditorCSS css(); - } - - interface ListEditorCSS extends CssResource { - String checkBoxInvisible(); - String checkBoxNormal(); - String checkBoxError(); - } - - @Override - protected void addRow(ValueType newValue) { - super.addRow(newValue); - CheckBox checkBox = new CheckBox(checkBoxText); - checkBox.setStylePrimaryName(getInvisibleStyle()); - checkBox.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - CheckBox source = (CheckBox) event.getSource(); - if (source.getValue()) { - source.setStylePrimaryName(getNormalStyle()); - } else { - source.setStylePrimaryName(getErrorStyle()); - } - notifyObserver(); - } - }); - checkBoxes.add(checkBox); - expandedValuesGrid.setWidget(expandedValuesGrid.getRowCount() - 1, 2, checkBox); - } - - public static String getInvisibleStyle() { - return ress.css().checkBoxInvisible(); - } - - public static String getErrorStyle() { - return ress.css().checkBoxError(); - } - - public static String getNormalStyle() { - return ress.css().checkBoxNormal(); - } - - @Override - public Widget initWidget() { - expandedValuesGrid = new Grid(0, 3); - expandedValuesGrid.ensureDebugId("ExpandedValuesGrid"); - - VerticalPanel panel = new VerticalPanel(); - panel.add(createAddWidget()); - panel.add(expandedValuesGrid); - return panel; - - } - - @Override - public void onRowRemoved(int rowIndex) { - checkBoxes.remove(rowIndex); - } - - @Override - public void notifyObserver() { - for(Observer observer : this.observer){ - observer.getNotified(); - } - } - - @Override - public void registerObserver(Observer observer) { - this.observer.add(observer); - } - - @Override - public void unregisterObserver(Observer observer) { - this.observer.remove(observer); - } - } -} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/media/ImageResizingTaskDTO.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/media/ImageResizingTaskDTO.java index 10d1a45ec18..004fb33f4e2 100644 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/media/ImageResizingTaskDTO.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/media/ImageResizingTaskDTO.java @@ -8,47 +8,82 @@ import com.google.gwt.user.client.rpc.IsSerializable; import com.sap.sse.common.media.MediaTagConstants; import com.sap.sse.common.media.MimeType; +/** + * Used to transfer an ImageDTO and a list of MediaTagConstants which store information on how to resize the image + * + * @author Robin Fleige(D067799) + * + */ public class ImageResizingTaskDTO implements IsSerializable { - - ImageDTO image; - List resizingTask; + + private ImageDTO image; + private List resizingTask; /** for GWT */ @Deprecated protected ImageResizingTaskDTO() { } + /** + * Creates an ImageDTO from the parameters + * + * @param imageRef + * needed for creating ImageDTO + * @param createdAtDate + * needed for creating ImageDTO + * @param resizingTask + * stored Information about resizing + */ public ImageResizingTaskDTO(String imageRef, Date createdAtDate, List resizingTask) { this(new ImageDTO(imageRef, createdAtDate), resizingTask); } + /** + * + * @param image + * the stored ImageDTO + * @param resizingTask + * stored Information about resizing + */ public ImageResizingTaskDTO(ImageDTO image, List resizingTask) { this.image = image; this.resizingTask = resizingTask; } - public ImageDTO getImage() { - return image; - } - - public List getResizingTask(){ - return resizingTask; - } + /** + * @returns the ImageDTO + */ + public ImageDTO getImage() { + return image; + } - public ImageDTO cloneImageDTO() { - ImageDTO toReturn = new ImageDTO(image.getSourceRef(), image.getCreatedAtDate()); - toReturn.setTitle(image.getTitle()); - toReturn.setCopyright(image.getCopyright()); - toReturn.setLocale(image.getLocale()); - toReturn.setMimeType(MimeType.byName(image.getMimeType().name())); - // creating a new mimetype object so they do not use the same reference - toReturn.setSizeInPx(image.getWidthInPx(), image.getHeightInPx()); - toReturn.setSubtitle(image.getSubtitle()); - List tags = new ArrayList<>(); - // Creating a new list, so they have the same tags, but not use the same reference to these tags, otherwise they - // could affect each other by editing this list - tags.addAll(image.getTags()); - toReturn.setTags(tags); - return toReturn; - } + /** + * @returns the List of MediaTagConstants + */ + public List getResizingTask() { + return resizingTask; + } + + /** + * Creates a clone of the ImageDTo with new references, so they do not interfere Used for resizing to edit + * afterwards, to easily copy all data from the original ImageDTO + * + * @returns a clone of the ImageDTO + */ + public ImageDTO cloneImageDTO() { + final ImageDTO toReturn = new ImageDTO(image.getSourceRef(), image.getCreatedAtDate()); + toReturn.setTitle(image.getTitle()); + toReturn.setCopyright(image.getCopyright()); + toReturn.setLocale(image.getLocale()); + // creating a new mimetype object so they do not use the same reference + toReturn.setMimeType(MimeType.byName(image.getMimeType().name())); + toReturn.setSizeInPx(image.getWidthInPx(), image.getHeightInPx()); + toReturn.setSubtitle(image.getSubtitle()); + // Creating a new list, so they have the same tags, but not use the same reference to these tags, otherwise they + // could affect each other by editing this list + final List tags = new ArrayList<>(); + tags.addAll(image.getTags()); + toReturn.setTags(tags); + return toReturn; + } } \ No newline at end of file diff --git a/java/com.sap.sse.test/src/com/sap/sse/test/ImageConverterTest.java b/java/com.sap.sse.test/src/com/sap/sse/test/ImageConverterTest.java index a7ebc9f7c5a..f4550018a19 100644 --- a/java/com.sap.sse.test/src/com/sap/sse/test/ImageConverterTest.java +++ b/java/com.sap.sse.test/src/com/sap/sse/test/ImageConverterTest.java @@ -13,6 +13,11 @@ import org.junit.Test; import com.sap.sse.util.ImageConverter; import com.sap.sse.util.ImageConverter.ImageWithMetadata; +/** + * + * @author Robin Fleige(D067799) + * + */ public class ImageConverterTest { private ImageConverter converter; private ImageWithMetadata pngImage; @@ -26,6 +31,9 @@ public class ImageConverterTest { private final int doubleSize = baseSize * 2; private final int minSize = 0; + /** + * Setting up the testing environment + */ @Before public void setUp() { converter = new ImageConverter(); @@ -33,6 +41,9 @@ public class ImageConverterTest { jpgImage = converter.loadImage(new ByteArrayInputStream(onePixelJpgExample), "jpg"); } + /** + * Tests the calculation of the dimensions, which is used for resizing the image to a fitting size + */ @Test public void testCalculateDimensions() { int[] dimensions; @@ -49,6 +60,9 @@ public class ImageConverterTest { assertNull(dimensions); } + /** + * Tests the conversions that are done while resizing an image + */ @Test public void testConversions() { byte[] byteArray; diff --git a/java/com.sap.sse/src/com/sap/sse/util/ImageConverter.java b/java/com.sap.sse/src/com/sap/sse/util/ImageConverter.java index 5fca2c7ef63..1f428c0e0e3 100644 --- a/java/com.sap.sse/src/com/sap/sse/util/ImageConverter.java +++ b/java/com.sap.sse/src/com/sap/sse/util/ImageConverter.java @@ -34,19 +34,23 @@ public class ImageConverter { private static final Logger logger = Logger.getLogger(ImageConverter.class.getName()); /** - * Empty constructor + * Writes a BufferedImage to an InputStream. This should only be used as a backup, if + * {@link ImageConverter#imageWithMetadataToInputStream(BufferedImage, IIOMetadata, String)} fails + * + * @param image + * The BufferedImage that should be converted + * @param imageFormat + * the format of the image, for example "png", "jpeg" or "jpg" + * @returns an InputStream with the Information of the Image */ - public ImageConverter() { - } - - private InputStream imageToInputStream(BufferedImage image, String imageFormat) { + private InputStream imageToInputStream(final BufferedImage image, final String imageFormat) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ImageIO.write(image, imageFormat, bos); } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage()); } - byte[] arr = bos.toByteArray(); + final byte[] arr = bos.toByteArray(); return new ByteArrayInputStream(arr); } @@ -67,13 +71,17 @@ public class ImageConverter { * @returns the resized BufferedImage. Returns null, if BufferedImage is null, or if the defined bounds do not fit * the image */ - public BufferedImage resize(BufferedImage image, int minWidth, int maxWidth, int minHeight, int maxHeight) { - int[] dimensions = calculateDimensions(image.getWidth(), image.getHeight(), minWidth, maxWidth, minHeight, + public BufferedImage resize(final BufferedImage image, final int minWidth, final int maxWidth, final int minHeight, + final int maxHeight) { + final int[] dimensions = calculateDimensions(image.getWidth(), image.getHeight(), minWidth, maxWidth, minHeight, maxHeight); + final BufferedImage resizedImage; if (dimensions != null) { - return resize(image, dimensions[0], dimensions[1]); + resizedImage = resize(image, dimensions[0], dimensions[1]); + } else { + resizedImage = null; } - return null; + return resizedImage; } /** @@ -95,32 +103,51 @@ public class ImageConverter { * @returns an array of two integers, where the first entry is the fitting width and the second is the fitting * height. returns null, if the defined bounds do not fit the current size */ - public int[] calculateDimensions(double width, double height, double minWidth, double maxWidth, double minHeight, - double maxHeight) { + public int[] calculateDimensions(final double width, final double height, final double minWidth, + final double maxWidth, final double minHeight, final double maxHeight) { + int[] dimensions = new int[2]; if (maxWidth >= 0 && maxHeight >= 0 && maxHeight > minHeight && maxWidth > minWidth && width > minWidth && height > minHeight) { if (maxWidth <= width || maxHeight <= height) { if (width / maxWidth > height / maxHeight) { - maxHeight = height / width * maxWidth; - if (maxHeight >= minHeight) { - return new int[] { (int) maxWidth, (int) maxHeight }; + dimensions[1] = (int) maxWidth; + dimensions[1] = (int) (height / width * maxWidth); + if (dimensions[1] >= minHeight) { + dimensions[0] = (int) maxWidth; + } else { + dimensions = null; } } else { - maxWidth = width / height * maxHeight; - if (maxWidth >= minWidth) { - return new int[] { (int) maxWidth, (int) maxHeight }; + dimensions[0] = (int) (width / height * maxHeight); + if (dimensions[0] >= minWidth) { + dimensions[1] = (int) maxHeight; + } else { + dimensions = null; } } } else { - return new int[] { (int) width, (int) height }; + dimensions[0] = (int) width; + dimensions[1] = (int) height; } } - return null; + return dimensions; } - private BufferedImage resize(BufferedImage image, int demandedWidth, int demandedHeight) { - BufferedImage resizedImage = new BufferedImage((int) demandedWidth, (int) demandedHeight, image.getType()); - Graphics2D g = resizedImage.createGraphics(); + /** + * Resizes an BufferedImage, to the width and height. + * + * @param image + * The BufferedImage that should be resized + * @param demandWidth + * the width the image should have after resizing + * @param demandHeight + * the height the image should have after resizing + * @returns the resized BufferedImage. Returns null, if BufferedImage is null + */ + private BufferedImage resize(final BufferedImage image, final int demandedWidth, final int demandedHeight) { + final BufferedImage resizedImage = new BufferedImage((int) demandedWidth, (int) demandedHeight, + image.getType()); + final Graphics2D g = resizedImage.createGraphics(); g.drawImage(image, 0, 0, (int) demandedWidth, (int) demandedHeight, null); g.dispose(); return resizedImage; @@ -138,22 +165,22 @@ public class ImageConverter { * @returns an InputStream (ByteArrayInputStream) with the data of the BufferedImage and if possible with the * IIOMetadata. Returnds null if the image is null or the imageFormat is incorrect */ - public InputStream imageWithMetadataToInputStream(BufferedImage bufferdImage, IIOMetadata metadata, - String imageFormat) { + public InputStream imageWithMetadataToInputStream(final BufferedImage bufferdImage, final IIOMetadata metadata, + final String imageFormat) { byte[] bytes = null; if (metadata != null) { // trying to obtain OutputStream of the image with EXIF data try (ImageOutputStream ios = ImageIO.createImageOutputStream(new ByteArrayOutputStream())) { // the following should write the exif data of the image to all copies of the image, it should already // work, but due to a bug the data array stays empty - Iterator writers = ImageIO.getImageWritersBySuffix(imageFormat); + final Iterator writers = ImageIO.getImageWritersBySuffix(imageFormat); while (writers.hasNext() && bytes == null) { - ImageWriter writer = writers.next(); + final ImageWriter writer = writers.next(); if (writer != null) { writer.setOutput(ios); - IIOImage iioImage = new IIOImage(bufferdImage, null, metadata); - ImageWriteParam param = writer.getDefaultWriteParam(); - IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param); + final IIOImage iioImage = new IIOImage(bufferdImage, null, metadata); + final ImageWriteParam param = writer.getDefaultWriteParam(); + final IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param); writer.write(streamMetadata, iioImage, param); writer.dispose(); bytes = new byte[toIntExact(ios.length())]; @@ -172,7 +199,7 @@ public class ImageConverter { logger.log(Level.INFO, e.getMessage()); } // if obtaining an OutputStream if the image with EXIF data did not work, then write it without } - InputStream toReturn; + final InputStream toReturn; if (bytes == null) { toReturn = imageToInputStream(bufferdImage, imageFormat); } else {// if it did work, then write the OutputStream to the FileStorageService @@ -188,7 +215,7 @@ public class ImageConverter { * the inputstream that should be stored in the ByteArray * @returns an Array of Bytes with the data of the inputstream */ - public byte[] inputStreamToByteArray(InputStream inputStream) { + public byte[] inputStreamToByteArray(final InputStream inputStream) { byte[] byteArray = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -205,18 +232,27 @@ public class ImageConverter { return byteArray; } - private boolean isZeroByteArray(byte[] bytes) { + /** + * Checks if a byte array only contains zeros + * + * @param bytes + * an byte array + * @returns true if the byte array is null, empty or only contains zeros, otherwise false + */ + private boolean isZeroByteArray(final byte[] bytes) { boolean toReturn = true; - for (int i = 0; i < bytes.length; i++) { - if (bytes[i] != 0) { - toReturn = false; + if (bytes != null) { + for (int i = 0; i < bytes.length; i++) { + if (bytes[i] != 0) { + toReturn = false; + } } } return toReturn; } /** - * Converts an inputstream that contains an image to a Base64 String + * Converts an InputStream that contains an image to a Base64 String * * @param inputStream * the InputStream that should be converted @@ -225,7 +261,7 @@ public class ImageConverter { * @returns the Base64 representation of the InputStream * @throws IOException */ - public String convertToBase64(InputStream inputStream, String imageFormat) throws IOException { + public String convertToBase64(final InputStream inputStream, final String imageFormat) throws IOException { return convertToBase64(bufferedImageToByteArray(loadBufferedImageFromInputStream(inputStream), imageFormat)); } @@ -239,21 +275,36 @@ public class ImageConverter { * @returns the Base64 representation of the image * @throws IOException */ - public String convertToBase64(BufferedImage image, String imageFormat) throws IOException { + public String convertToBase64(final BufferedImage image, final String imageFormat) throws IOException { return convertToBase64(bufferedImageToByteArray(image, imageFormat)); } - private String convertToBase64(byte[] bytes) { + /** + * Converts an array of bytes to a Base64 String + * + * @param bytes + * an array of bytes + * @returns the Base64 representation of the byte array + */ + private String convertToBase64(final byte[] bytes) { return Base64Utils.toBase64(bytes); } - private BufferedImage loadBufferedImageFromInputStream(InputStream is) { + /** + * Converts an InputStream to a BufferedImage. This should only be used as a backup, if + * {@link ImageConverter#loadImage(InputStream, String)} fails + * + * @param inputStream + * @return + */ + private BufferedImage loadBufferedImageFromInputStream(final InputStream inputStream) { + BufferedImage image = null; try { - return ImageIO.read(is); + image = ImageIO.read(inputStream); } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage()); } - return null; + return image; } // looses metadata, so should not be used for storing an image, but only for showing an image @@ -270,7 +321,7 @@ public class ImageConverter { * the format of the image, for example "png", "jpeg" or "jpg" * @returns an ByteArray with all the information of the image */ - public byte[] bufferedImageToByteArray(BufferedImage image, String imageFormat) { + public byte[] bufferedImageToByteArray(final BufferedImage image, final String imageFormat) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ImageIO.write(image, imageFormat, baos); @@ -291,8 +342,8 @@ public class ImageConverter { * @returns a list of BufferedImages, that contains as many BufferedImages as resizingTask contains * {@link MediaTagConstants} */ - public List convertImage(BufferedImage image, List resizingTasks) { - List resizedImages = new ArrayList<>(); + public List convertImage(final BufferedImage image, final List resizingTasks) { + final List resizedImages = new ArrayList<>(); for (MediaTagConstants tag : resizingTasks) { resizedImages .add(resize(image, tag.getMinWidth(), tag.getMaxWidth(), tag.getMinHeight(), tag.getMaxHeight())); @@ -310,17 +361,17 @@ public class ImageConverter { * @returns an {@link ImageWithMetadata} that contains the BufferedImage and the IIOMetadata of the image If the * loading of the IIOMetadata does not work, returns an {@link ImageWithMetadata} where metadata is null */ - public ImageWithMetadata loadImage(InputStream inputStream, String imageFormat) { + public ImageWithMetadata loadImage(final InputStream inputStream, final String imageFormat) { // trying to receive the EXIF data and loading the image. If this does not work only the image is loaded - ImageConverter converter = new ImageConverter(); + final ImageConverter converter = new ImageConverter(); BufferedImage image = null; IIOMetadata metadata = null; boolean loaded = false; byte[] bytes = converter.inputStreamToByteArray(inputStream); try { - Iterator readerIterator = ImageIO.getImageReadersBySuffix(imageFormat); + final Iterator readerIterator = ImageIO.getImageReadersBySuffix(imageFormat); while (readerIterator.hasNext() && !loaded) { - ImageReader reader = readerIterator.next(); + final ImageReader reader = readerIterator.next(); reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(bytes))); metadata = reader.getImageMetadata(0); image = reader.read(0);