View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.parisvideo.service;
35  
36  import java.util.Arrays;
37  import java.util.Calendar;
38  import java.util.Collections;
39  import java.util.List;
40  
41  import org.apache.axis.client.Call;
42  import org.apache.axis.client.Stub;
43  
44  import com.tvnavig.server.asset.service.common.MetaValueResult;
45  import com.tvnavig.server.searchengine.SearchAssetService;
46  import com.tvnavig.server.searchengine.SearchAssetServiceService;
47  import com.tvnavig.server.searchengine.SearchAssetServiceServiceLocator;
48  import com.tvnavig.server.searchengine.service.common.AssetOGC;
49  import com.tvnavig.server.searchengine.service.common.AssetPlayer;
50  import com.tvnavig.server.user.UserService;
51  import com.tvnavig.server.user.UserServiceService;
52  import com.tvnavig.server.user.UserServiceServiceLocator;
53  import com.tvnavig.server.user.service.common.UserDomainResult;
54  import com.tvnavig.server.user.service.common.UserServiceResult;
55  
56  /**
57   * This class allows to get video from ParisTV (from wsdl files with Axis 1.4)
58   * http://v01-adminvnavig.apps.paris.mdp/tvnavig/default/services
59   * http://v01-vnavig.apps.paris.mdp
60   * 
61   * One can access those webservices from Paris intranet only
62   * 
63   * See junit test to understand how it works.
64   */
65  public class ParisvideoService
66  {
67  	/**
68  	 * get the domain list for a give login/password
69  	 */
70  	public UserDomainResult[] getDomain(String login, String password) throws Exception
71  	{
72  		Call.setTransportForProtocol( "http", SingleSessionHttpTransport.class );
73  
74  		UserServiceService uss = new UserServiceServiceLocator();
75  		UserService port = uss.getUserService(  );
76  		( ( Stub ) port )._setProperty( Stub.SESSION_MAINTAIN_PROPERTY, true );
77  		
78  		UserServiceResult usr = port.authenticate(login, password);
79  		UserDomainResult[] udrArray = port.getDomainsFromUser(usr.getUserId());
80  		return udrArray;
81  	}
82  
83  	/**
84  	 * Get videos from webservices. You need to be connected first.
85  	 * 
86  	 * @param domainId there are domains for each account
87  	 * @param searchSubject
88  	 * @param metaValues
89  	 * @param beginDate
90  	 * @param endDate
91  	 * @param format
92  	 * @return the list of videos (AssetOGC is a object genereated by the WSDL)
93  	 * @throws Exception
94  	 */
95  	public List<AssetOGC> getVideos(Integer domainId, String searchSubject, MetaValueResult[] metaValues, Calendar beginDate, Calendar endDate, String format) throws Exception
96  	{
97  		SearchAssetServiceService as = new SearchAssetServiceServiceLocator();
98  		SearchAssetService portAS = as.getSearchAssetService();
99  		( ( Stub ) portAS )._setProperty( Stub.SESSION_MAINTAIN_PROPERTY, true );
100 		
101 		 AssetOGC[] list = portAS.getAssetsList(domainId, searchSubject, metaValues, beginDate, endDate, format);
102 		 List<AssetOGC> videos = Arrays.asList( list );
103 		 Collections.sort(videos);
104 		 return videos;
105 	}
106 
107 	/**
108 	 * get video from its ID
109 	 */
110 	public AssetPlayer getVideo(int videoId) throws Exception
111 	{
112 		SearchAssetServiceService as = new SearchAssetServiceServiceLocator();
113 		SearchAssetService portAS = as.getSearchAssetService();
114 		( ( Stub ) portAS )._setProperty( Stub.SESSION_MAINTAIN_PROPERTY, true );
115 
116 		AssetPlayer ap = portAS.getAssetPlayer( videoId );
117 		return ap;
118 	}
119 }