sovled master merge conflicts in dashboards EventLogo

This commit is contained in:
Alexander Ries committed 2015-06-16 22:43:12 +02:00
commit 79aeb1c8a6
175 files changed
+7566 -3882

No files matched your search

@@ -1,118 +0,0 @@
package com.sap.sse.common.media;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
/**
* Common media data for media items
*
* @author pgtaboada
*
*/
public class AbstractMediaDTO implements Serializable, Comparable<AbstractMediaDTO> {
private static final long serialVersionUID = 1L;
/**
* TODO: would "caption" be a better name?
*/
private String title;
/**
* TODO: should we provide a subtitle?
*/
protected String subtitle;
/**
* This information should be used for chronological ordering
* TODO: Must not be null. We need to find a way to
* migrate data!
*/
protected Date createdAtDate;
/**
* TODO: initially I though of "author", but I am not sure if we need the author name. But we probably will need
* some place to store copyright information...
*/
protected String copyright;
private MimeType mimeType;
/**
* TODO: tags will give us some way to categorize medias. If we pass this information to the frontend, we need some
* nice idea to show display this data. for now it should be something restricted to the backend domain modell
*/
private HashSet<String> tags = new HashSet<String>();
/**
* URL pointing to the media data.
*/
private String sourceRef;
/**
* Default constructor required for GWT serialization.
*/
protected AbstractMediaDTO() {
}
/**
* Media item with minimal set of information
*
* @param sourceRef
* @param mimeType
*/
public AbstractMediaDTO(String sourceRef, MimeType mimeType, Date createdAtDate) {
this.mimeType = mimeType;
this.sourceRef = sourceRef;
this.createdAtDate = createdAtDate;
}
public MimeType getMimeType() {
return mimeType;
}
public String getSourceRef() {
return sourceRef;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public HashSet<String> getTags() {
return tags;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public Date getCreatedAtDate() {
return createdAtDate;
}
public void setCreatedAtDate(Date createdAtDate) {
this.createdAtDate = createdAtDate;
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
@Override
public int compareTo(AbstractMediaDTO o) {
return createdAtDate.compareTo(o.createdAtDate);
}
}
@@ -0,0 +1,136 @@
package com.sap.sse.common.media;
import java.io.Serializable;
import java.net.URL;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util;
/**
* Common media data for media items
*
* @author pgtaboada
*
*/
public abstract class AbstractMediaDescriptor implements MediaDescriptor, Serializable {
private static final long serialVersionUID = -6671425870632517274L;
protected String title;
protected String subtitle;
protected TimePoint createdAtDate;
protected String copyright;
protected MimeType mimeType;
protected Set<String> tags = new LinkedHashSet<String>();
protected URL url;
protected Locale locale;
/**
* Media item with minimal set of information
* @param url
* @param mimeType
*/
public AbstractMediaDescriptor(URL url, MimeType mimeType, TimePoint createdAtDate) {
this.mimeType = mimeType;
this.url = url;
this.createdAtDate = createdAtDate;
}
@Override
public MimeType getMimeType() {
return mimeType;
}
@Override
public URL getURL() {
return url;
}
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@Override
public Set<String> getTags() {
return tags;
}
@Override
public void setTags(Iterable<String> tags) {
this.tags.clear();
if (tags != null) {
Util.addAll(tags, this.tags);
}
}
@Override
public boolean addTag(String tagName) {
return tags.add(tagName);
}
@Override
public boolean removeTag(String tagName) {
return tags.remove(tagName);
}
@Override
public String getSubtitle() {
return subtitle;
}
@Override
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
@Override
public TimePoint getCreatedAtDate() {
return createdAtDate;
}
@Override
public void setCreatedAtDate(TimePoint createdAtDate) {
this.createdAtDate = createdAtDate;
}
@Override
public String getCopyright() {
return copyright;
}
@Override
public void setCopyright(String copyright) {
this.copyright = copyright;
}
@Override
public Locale getLocale() {
return locale;
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
}
@Override
public boolean hasTag(String tagName) {
return tags.contains(tagName);
}
}
@@ -0,0 +1,14 @@
package com.sap.sse.common.media;
import com.sap.sse.common.Util.Pair;
public interface ImageDescriptor extends MediaDescriptor {
void setSize(Pair<Integer, Integer> size);
void setSize(Integer widthInPx, Integer heightInPx);
Integer getWidthInPx();
Integer getHeightInPx();
boolean hasSize();
int getArea();
}
@@ -0,0 +1,62 @@
package com.sap.sse.common.media;
import java.net.URL;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util.Pair;
public class ImageDescriptorImpl extends AbstractMediaDescriptor implements ImageDescriptor {
private static final long serialVersionUID = -702731462768602331L;
private Integer widthInPx;
private Integer heightInPx;
/**
* @param imageURL
* @param size
*/
public ImageDescriptorImpl(URL imageURL, TimePoint createdAtDate) {
super(imageURL, MimeType.image, createdAtDate);
}
@Override
public Integer getWidthInPx() {
return widthInPx;
}
@Override
public Integer getHeightInPx() {
return heightInPx;
}
@Override
public void setSize(Pair<Integer, Integer> size) {
if (size != null) {
this.widthInPx = size.getA();
this.heightInPx = size.getB();
} else {
this.widthInPx = null;
this.heightInPx = null;
}
}
@Override
public void setSize(Integer widthInPx, Integer heightInPx) {
this.widthInPx = widthInPx;
this.heightInPx = heightInPx;
}
@Override
public boolean hasSize() {
return widthInPx != null && heightInPx != null;
}
@Override
public int getArea() {
if(hasSize()) {
return widthInPx * heightInPx;
}
return 0;
}
}
@@ -1,42 +0,0 @@
package com.sap.sse.common.media;
import java.util.Date;
public class ImageMetadataDTO extends AbstractMediaDTO {
private static final long serialVersionUID = 1L;
private int widthInPx;
private int heightInPx;
protected ImageMetadataDTO() {
}
/**
* TODO: should we use imagesize, or should we store height and width? For now, this is a convenience method...
*
* @param imageURL
* @param size
*/
public ImageMetadataDTO(String imageURL, ImageSize size, Date createdAtDate) {
super(imageURL, MimeType.image, createdAtDate);
this.widthInPx = size.getWidth();
this.heightInPx = size.getHeight();
}
public ImageMetadataDTO(String imageURL, int heightInPx, int widthInPx, Date createdAtDate) {
super(imageURL, MimeType.image, createdAtDate);
this.widthInPx = widthInPx;
this.heightInPx = heightInPx;
}
public int getWidthInPx() {
return widthInPx;
}
public int getHeightInPx() {
return heightInPx;
}
}
@@ -0,0 +1,36 @@
package com.sap.sse.common.media;
import java.io.Serializable;
import java.net.URL;
import java.util.Locale;
import com.sap.sse.common.TimePoint;
/**
* A common media interface for all kinds of media like images or videos.
*/
public interface MediaDescriptor extends Serializable {
MimeType getMimeType();
URL getURL();
String getTitle();
void setTitle(String title);
Iterable<String> getTags();
void setTags(Iterable<String> tags);
boolean addTag(String tagName);
boolean removeTag(String tagName);
boolean hasTag(String tagName);
String getSubtitle();
void setSubtitle(String subtitle);
TimePoint getCreatedAtDate();
void setCreatedAtDate(TimePoint createdAtDate);
String getCopyright();
void setCopyright(String copyright);
Locale getLocale();
void setLocale(Locale locale);
}
@@ -0,0 +1,12 @@
package com.sap.sse.common.media;
public interface MediaTagConstants {
static final String GALLERY = "Gallery";
static final String STAGE = "Stage";
static final String LOGO = "Logo";
static final String TEASER = "Teaser";
static final String SPONSOR = "Sponsor";
static final String HIGHLIGHT = "Highlight";
static final String LIVESTREAM = "Livestream";
static final String FEATURED = "Featured";
}
@@ -0,0 +1,99 @@
package com.sap.sse.common.media;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import com.sap.sse.common.Util.Pair;
public class MediaUtils {
private static final Logger logger = Logger.getLogger(MediaUtils.class.getName());
/**
* Youtube regex detection from:
* http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url, mantish Mar 4
* at 15:33
*/
private static final Pattern YOUTUBE_ID_REGEX = Pattern
.compile("^.*(youtu.be/|v/|u/\\w/|embed/|watch\\?v=|\\&v=)([^#\\&\\?]+).*$");
private static final Pattern VIMEO_REGEX = Pattern.compile("^.*(vimeo\\.com\\/).*");
private static final Pattern MP4_REGEX = Pattern.compile(".*\\.mp4$");
/**
* Detect mimetype for given url.
*
* @param url
* the source pointing to the video mediafile
* @return mimetype detected or MimeType.unknown
*/
public static MimeType detectMimeTypeFromUrl(String url) {
if (YOUTUBE_ID_REGEX.matcher(url).matches()) {
return MimeType.youtube;
} else if (VIMEO_REGEX.matcher(url).matches()) {
return MimeType.vimeo;
} else if (MP4_REGEX.matcher(url).matches()) {
return MimeType.mp4;
} else {
return MimeType.unknown;
}
}
public static Pair<Integer, Integer> getImageDimensions(URL imageURL) {
Future<Pair<Integer, Integer>> imageSizeCalculator = getOrCreateImageSizeCalculator(imageURL);
try {
return imageSizeCalculator.get();
} catch (Exception e) {
return null;
}
}
private static final ExecutorService executor = Executors.newCachedThreadPool();
private static Future<Pair<Integer, Integer>> getOrCreateImageSizeCalculator(final URL imageURL) {
Future<Pair<Integer, Integer>> imageSizeFetcher = executor.submit(new Callable<Pair<Integer, Integer>>() {
@Override
public Pair<Integer, Integer> call() throws IOException {
Pair<Integer, Integer> result = null;
ImageInputStream in = null;
try {
URLConnection conn = imageURL.openConnection();
in = ImageIO.createImageInputStream(conn.getInputStream());
final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
if (readers.hasNext()) {
ImageReader reader = readers.next();
try {
reader.setInput(in);
result = new Pair<>(reader.getWidth(0), reader.getHeight(0));
} finally {
reader.dispose();
}
}
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Stale image URL: "+imageURL, ioe);
throw ioe;
} finally {
if (in != null) {
in.close();
}
}
return result;
}
});
return imageSizeFetcher;
}
}
@@ -0,0 +1,11 @@
package com.sap.sse.common.media;
import java.net.URL;
public interface VideoDescriptor extends MediaDescriptor {
Integer getLengthInSeconds();
void setLengthInSeconds(Integer lengthInSeconds);
URL getThumbnailURL();
void setThumbnailURL(URL thumbnailURL);
}
@@ -0,0 +1,40 @@
package com.sap.sse.common.media;
import java.net.URL;
import com.sap.sse.common.TimePoint;
public class VideoDescriptorImpl extends AbstractMediaDescriptor implements VideoDescriptor {
private static final long serialVersionUID = 2651747912466590862L;
private Integer lengthInSeconds;
/**
* URL to thumbnail image. This information works as override for youtube videos or as missing thumbnail
* information for other formats. It can be either a link to thumbnail or even be a data/url contaning the base64
* encoded image.
*/
private URL thumbnailURL;
public VideoDescriptorImpl(URL url, MimeType mimeType, TimePoint createdAtDate) {
super(url, mimeType, createdAtDate);
}
@Override
public Integer getLengthInSeconds() {
return lengthInSeconds;
}
public void setLengthInSeconds(Integer lengthInSeconds) {
this.lengthInSeconds = lengthInSeconds;
}
@Override
public URL getThumbnailURL() {
return thumbnailURL;
}
public void setThumbnailURL(URL thumbnailURL) {
this.thumbnailURL = thumbnailURL;
}
}
@@ -1,45 +0,0 @@
package com.sap.sse.common.media;
import java.util.Date;
public class VideoMetadataDTO extends AbstractMediaDTO {
private static final long serialVersionUID = 1L;
/**
* TODO: Do we really need video length? Should it be mandatory?
*/
private int lengthInSeconds;
/**
* URL Reference to thumbnail image. This information works as override for youtube videos or as missing thumbnail
* information for other formats. It can be either a link to thumbnail or even be a data/url contaning the base64
* encoded image.
*/
private String thumbnailRef;
protected VideoMetadataDTO() {
}
public VideoMetadataDTO(String url, MimeType mimeType, Date createdAtDate) {
super(url, mimeType, createdAtDate);
}
public int getLengthInSeconds() {
return lengthInSeconds;
}
public void setLengthInSeconds(int lengthInSeconds) {
this.lengthInSeconds = lengthInSeconds;
}
public void setThumbnailRef(String thumbnailRef) {
this.thumbnailRef = thumbnailRef;
}
public String getThumbnailRef() {
return thumbnailRef;
}
}
@@ -0,0 +1,25 @@
package com.sap.sse.common.media;
public interface WithImages {
/**
* Returns a non-<code>null</code> live but unmodifiable collection of image resources that can be
* used to represent the event, e.g., on a web page.
*
* @return a non-<code>null</code> value which may be empty
*/
Iterable<ImageDescriptor> getImages();
/**
* Replaces the {@link #getImages() current contents of the image sequence by the images in
* <code>images</code>.
*
* @param images
* if <code>null</code>, the internal sequence of images is cleared but remains valid (non-
* <code>null</code>)
*/
void setImages(Iterable<ImageDescriptor> images);
void addImage(ImageDescriptor image);
void removeImage(ImageDescriptor image);
}
@@ -0,0 +1,12 @@
package com.sap.sse.common.media;
import java.util.List;
public interface WithMedia extends WithImages, WithVideos {
ImageDescriptor findImageWithTag(String tagName);
List<ImageDescriptor> findImagesWithTag(String tagName);
boolean hasImageWithTag(String tagName);
VideoDescriptor findVideoWithTag(String tagName);
List<VideoDescriptor> findVideosWithTag(String tagName);
}
@@ -0,0 +1,26 @@
package com.sap.sse.common.media;
public interface WithVideos {
/**
* Returns a non-<code>null</code> live but unmodifiable collection of video resources that can be
* used to represent the event, e.g., on a web page.
*
* @return a non-<code>null</code> value which may be empty
*/
Iterable<VideoDescriptor> getVideos();
/**
* Replaces the {@link #getVideos() current contents of the video sequence by the videos in
* <code>videos</code>.
*
* @param videos
* if <code>null</code>, the internal sequence of videos is cleared but remains valid (non-
* <code>null</code>)
*/
void setVideos(Iterable<VideoDescriptor> videos);
void addVideo(VideoDescriptor video);
void removeVideo(VideoDescriptor video);
}