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.contentstorage.reference; 017 018import java.util.EnumSet; 019import java.util.List; 020 021import service.tut.pori.contentanalysis.CAContentCore.ServiceType; 022import service.tut.pori.contentstorage.MediaList; 023import service.tut.pori.contentstorage.URLContentStorage; 024import twitter4j.Logger; 025import core.tut.pori.http.parameters.Limits; 026import core.tut.pori.users.UserIdentity; 027 028/** 029 * The reference implementations for Content Storage Service. 030 * 031 */ 032public final class ContentStorageReferenceCore { 033 private static final ContentXMLObjectCreator CREATOR = new ContentXMLObjectCreator(null); 034 private static final Logger LOGGER = Logger.getLogger(ContentStorageReferenceCore.class); 035 private static final EnumSet<ServiceType> SERVICE_TYPES = EnumSet.of(URLContentStorage.SERVICE_TYPE); 036 037 /** 038 * 039 */ 040 private ContentStorageReferenceCore(){ 041 // nothing needed 042 } 043 044 /** 045 * 046 * @param authenticatedUser 047 * @param backendId 048 * @param serviceTypes 049 */ 050 public static void synchronize(UserIdentity authenticatedUser, int[] backendId, EnumSet<ServiceType> serviceTypes) { 051 LOGGER.info((authenticatedUser == null ? "No logged in user." : "Ignoring the logged in user, id: "+authenticatedUser.getUserId())); // only notify of the logged in status 052 } 053 054 /** 055 * simulates adding URLs for analysis. Note that the URLs will not be validated by this method, and can be any strings. 056 * 057 * @param authenticatedUser 058 * @param backendId value is ignored 059 * @param urls values themselves are ignored, count is used for populating appropriate media list 060 * @return media list or null if no URLs were given 061 */ 062 public static MediaList addUrls(UserIdentity authenticatedUser, int[] backendId, List<String> urls) { 063 if(urls == null || urls.isEmpty()){ 064 LOGGER.debug("No URLs given."); 065 return null; 066 } 067 068 if(UserIdentity.isValid(authenticatedUser)){ 069 LOGGER.info("Logged in user, id: "+authenticatedUser.getUserId()); 070 }else{ 071 LOGGER.info("No logged in user."); 072 authenticatedUser = CREATOR.createUserIdentity(); 073 } 074 Limits limits = new Limits(0, urls.size()); 075 076 return CREATOR.createMediaList(limits, SERVICE_TYPES, authenticatedUser); 077 } 078 079 /** 080 * 081 * @param limits 082 * @return randomly generated media list 083 */ 084 public static MediaList generateMediaList(Limits limits) { 085 return CREATOR.createMediaList(limits, SERVICE_TYPES, CREATOR.createUserIdentity()); 086 } 087}