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.ArrayList; 019import java.util.EnumSet; 020import java.util.List; 021import java.util.Random; 022import java.util.UUID; 023 024import service.tut.pori.contentanalysis.CAContentCore.ServiceType; 025import service.tut.pori.contentanalysis.CAContentCore.Visibility; 026import service.tut.pori.contentanalysis.Media; 027import service.tut.pori.contentanalysis.Photo; 028import service.tut.pori.contentanalysis.reference.CAXMLObjectCreator; 029import service.tut.pori.contentanalysis.video.Video; 030import service.tut.pori.contentstorage.Definitions; 031import service.tut.pori.contentstorage.MediaList; 032import service.tut.pori.contentstorage.URLContentStorage; 033import core.tut.pori.http.parameters.Limits; 034import core.tut.pori.users.UserIdentity; 035 036/** 037 * Class that can be used to created example objects/object lists. 038 */ 039public class ContentXMLObjectCreator { 040 private CAXMLObjectCreator _CACreator = null; 041 042 /** 043 * 044 * @param seed for random generator, or null to use default (system time in nanoseconds) 045 */ 046 public ContentXMLObjectCreator(Long seed){ 047 if(seed == null){ 048 seed = System.nanoTime(); 049 } 050 _CACreator = new CAXMLObjectCreator(seed); 051 } 052 053 /** 054 * @return randomly generated user identity 055 * @see service.tut.pori.contentanalysis.reference.CAXMLObjectCreator#createUserIdentity() 056 */ 057 public UserIdentity createUserIdentity() { 058 return _CACreator.createUserIdentity(); 059 } 060 061 /** 062 * 063 * @param limits 064 * @param serviceTypes 065 * @param userId 066 * @return randomly generated service types 067 */ 068 public MediaList createMediaList(Limits limits, EnumSet<ServiceType> serviceTypes, UserIdentity userId){ 069 int count = limits.getMaxItems(Definitions.ELEMENT_MEDIALIST); 070 List<Media> media = new ArrayList<>(count); 071 Random r = _CACreator.getRandom(); 072 for(int i=0;i<count;++i){ 073 Media m = null; 074 if(r.nextBoolean()){ 075 m = new Photo(); 076 }else{ 077 m = new Video(); 078 } 079 m.setGUID(UUID.randomUUID().toString()); 080 m.setOwnerUserId(userId); 081 m.setServiceType(URLContentStorage.SERVICE_TYPE); 082 m.setVisibility(Visibility.PUBLIC); 083 media.add(m); 084 } 085 086 MediaList mediaList = new MediaList(); 087 mediaList.setMedia(media); 088 return mediaList; 089 } 090}