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.contentanalysis.video;
017
018import java.util.Collections;
019import java.util.EnumSet;
020
021import service.tut.pori.contentanalysis.PhotoParameters.AnalysisType;
022import service.tut.pori.contentanalysis.CAContentCore.ServiceType;
023import service.tut.pori.contentanalysis.Definitions;
024import service.tut.pori.contentanalysis.MediaObjectList;
025import core.tut.pori.context.ServiceInitializer;
026import core.tut.pori.http.parameters.DataGroups;
027import core.tut.pori.http.parameters.Limits;
028import core.tut.pori.users.UserIdentity;
029
030/**
031 * Video search core methods.
032 * 
033 */
034public final class VideoSearchCore {
035  /**
036   * 
037   */
038  private VideoSearchCore(){
039    // nothing needed
040  }
041
042  /**
043   * 
044   * @param authenticatedUser
045   * @param objects
046   * @param dataGroups
047   * @param limits
048   * @param serviceTypes
049   * @param userIdFilters
050   * @return list of videos or null if none was found
051   * @throws IllegalArgumentException on bad input data
052   */
053  public static VideoList similarVideosByObject(UserIdentity authenticatedUser, MediaObjectList objects, DataGroups dataGroups, Limits limits, EnumSet<ServiceType> serviceTypes, long[] userIdFilters) throws IllegalArgumentException {
054    if(!MediaObjectList.isEmpty(objects)){
055      return ServiceInitializer.getDAOHandler().getSolrDAO(VideoDAO.class).search(authenticatedUser, dataGroups, null, limits, objects, serviceTypes, userIdFilters);
056    }else{
057      throw new IllegalArgumentException("Empty object list.");
058    }
059  }
060  
061  /**
062   * 
063   * @param authenticatedUser
064   * @param analysisTypes 
065   * @param guid
066   * @param dataGroups
067   * @param limits
068   * @param serviceTypes
069   * @param userIdFilters
070   * @return list of videos or null if none was found
071   * @throws IllegalArgumentException
072   */
073  public static VideoList searchByGUID(UserIdentity authenticatedUser, EnumSet<AnalysisType> analysisTypes, String guid, DataGroups dataGroups, Limits limits, EnumSet<ServiceType> serviceTypes, long[] userIdFilters) throws IllegalArgumentException{
074    if(VideoList.isEmpty(ServiceInitializer.getDAOHandler().getSolrDAO(VideoDAO.class).search(authenticatedUser, null, Collections.nCopies(1, guid), null, null, null, null))){  // do not use serviceTypes or userIdFilters for existence check of reference video
075      throw new IllegalArgumentException("Invalid "+Definitions.PARAMETER_GUID+" or permission denied.");
076    }
077    
078    return VideoSearchTask.getTaskByGUID(authenticatedUser, analysisTypes, dataGroups, guid, limits, serviceTypes, userIdFilters).execute();
079  }
080}