001/**
002 * Copyright 2015 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package service.tut.pori.subtitles.reference;
017
018import org.apache.log4j.Logger;
019
020import service.tut.pori.contentanalysis.Definitions;
021import service.tut.pori.contentanalysis.MediaObjectList;
022import service.tut.pori.contentanalysis.video.reference.VideoXMLObjectCreator;
023import service.tut.pori.subtitles.WebVTTSubtitle;
024import service.tut.pori.subtitles.SubtitlesCore.FileFormat;
025import service.tut.pori.subtitles.SubtitlesCore.SubtitleFormat;
026import core.tut.pori.http.StringResponse.StringData;
027import core.tut.pori.http.parameters.DataGroups;
028import core.tut.pori.http.parameters.Limits;
029import core.tut.pori.users.UserIdentity;
030
031/**
032 * Subtitle service reference core
033 * 
034 */
035public final class SubtitlesReferenceCore {
036  private static final VideoXMLObjectCreator CREATOR = new VideoXMLObjectCreator(null);
037  private static final DataGroups DEFAULT_DATAGROUPS = new DataGroups(Definitions.DATA_GROUP_TIMECODES);
038  private static final Limits DEFAULT_LIMTS;
039  static{
040    DEFAULT_LIMTS = new Limits(0, 0);
041    DEFAULT_LIMTS.setTypeLimits(0, 9, Definitions.ELEMENT_MEDIA_OBJECTLIST);
042  }
043  private static final Logger LOGGER = Logger.getLogger(SubtitlesReferenceCore.class);
044  
045  /**
046   * 
047   */
048  private SubtitlesReferenceCore(){
049    // nothing needed
050  }
051
052  /**
053   * 
054   * @param authenticatedUser value is only logged
055   * @param guid value is ignored
056   * @param fileFormat
057   * @param subtitleFormat
058   * @param userIdFilter value is ignored
059   * @return the formatted data
060   * @throws UnsupportedOperationException on unsupported {@link service.tut.pori.subtitles.SubtitlesCore.FileFormat} or {@link service.tut.pori.subtitles.SubtitlesCore.SubtitleFormat}
061   */
062  public static StringData generateSubtitles(UserIdentity authenticatedUser, String guid, FileFormat fileFormat, SubtitleFormat subtitleFormat, long[] userIdFilter) throws UnsupportedOperationException {
063    if(subtitleFormat != SubtitleFormat.INDIVIDUAL){
064      throw new IllegalArgumentException("Unsupported subtitle format for this validator: "+subtitleFormat.toFormatString());
065    }
066    
067    LOGGER.info((authenticatedUser == null ? "No logged in user." : "Ignoring the logged in user, id: "+authenticatedUser.getUserId()));  // only notify of the logged in status
068    MediaObjectList mediaObjects = CREATOR.createMediaObjectList(null, DEFAULT_DATAGROUPS, DEFAULT_LIMTS, null);
069    
070    StringData data = null;
071    switch(fileFormat){
072      case WEBVTT:
073        WebVTTSubtitle vSub = new WebVTTSubtitle();
074        vSub.setSubtitleFormat(subtitleFormat);
075        vSub.setMediaObjects(mediaObjects);
076        data = vSub;
077        break;
078      default:
079        throw new UnsupportedOperationException("Unsupported "+FileFormat.class.toString()+" : "+fileFormat.name());
080    }
081    
082    return data;
083  }
084}