Source code: com/flexstor/flexdbserver/services/asset/vir/VIRPreIdxService.java
1 /*
2 * VIRPreIdxService.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:49 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.flexdbserver.services.asset.vir;
12
13 import java.util.Vector;
14
15 import com.flexstor.common.data.ActionData;
16 import com.flexstor.common.data.ActionResult;
17 import com.flexstor.common.data.ejb.disguiserecord.DisguiseAssetRecordData;
18 import com.flexstor.common.data.ejb.disguiserecord.DisguiseRecordData;
19 import com.flexstor.common.importprocessor.ImportData;
20 import com.flexstor.common.importprocessor.ImportResult;
21 import com.flexstor.common.services.ServiceArgumentsI;
22 import com.flexstor.common.util.ServerList;
23 import com.flexstor.common.util.StringUtil;
24 import com.flexstor.flexdbserver.services.Service;
25 import com.flexstor.flexdbserver.services.ServiceContext;
26
27 /**
28 * <P>
29 * VIRPreService <BR>
30 * <BLOCKQUOTE>
31 * Adds to the ImportData object the information needed by the Oracle VIR Cartridge to index
32 * assets according to the protocol specified (FILE or HTTP). This service must be run prior
33 * to the DBUpdateService.
34 * </BLOCKQUOTE>
35 * </P>
36 *
37 * Configurable Properties in roletype_services.config <BR>
38 *
39 * <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="3">
40 * <CAPTION ALIGN=TOP>
41 * <B> In/Out Properties for Assets </B>
42 * </CAPTION>
43 * <TR>
44 * <FONT SIZE=+1><B>
45 * <TH WIDTH="120">Attribute</TH>
46 * <TH WIDTH="30">IN</TH> <TH WIDTH="30">OUT</TH> <TH WIDTH="30">Default IN</TH> <TH WIDTH="30">Default OUT</TH>
47 * </B></FONT>
48 * </TR>
49 * <TR>
50 * <TH ALIGN=LEFT><FONT SIZE=+1><B>ROLE</B></FONT></TH>
51 * <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER> ALL </TD> <TD ALIGN=CENTER> ALL </TD>
52 * </TR>
53 * <TR><TH> Highres </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
54 * <TR><TH> Lowres </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
55 * <TR><TH> Thumbnail </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
56 * <TR><TH> Layout </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
57 * <TR><TH> Video </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
58 * <TR><TH> Audio </TH> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
59 * <TR>
60 * <TH ALIGN=LEFT><FONT SIZE=+1><B>TYPE</B></FONT></TH>
61 * <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> ALL </TD> <TD ALIGN=CENTER> ALL </TD></TR>
62 * </TR>
63 * <TR>
64 * <TH ALIGN=LEFT><FONT SIZE=+1><B>FLAG</B></FONT></TH>
65 * </TR>
66 * <TR><TH> PARENT </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD></TR>
67 * <TR><TH> CHLDREN </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
68 * <TR><TH> ALL </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
69 * <TR><TH> TEMP_PARENT </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
70 * <TR><TH> TEMP_CHILDREN </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
71 * <TR><TH> TEMP_ALL </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
72 * </TABLE>
73 *
74 * <P>
75 * protocol: The protocol used to access the files while indexing. The protocol will define how
76 * the information needed by the VIR Cartridge is formatted (optional; default to HTTP). <BR>
77 * Legal values: FILE or HTTP <BR>
78 * </P>
79 *
80 * <P>
81 * Input Data Object <BR>
82 * <BLOCKQUOTE>
83 * com.flexstor.common.importprocessor.ImportData
84 * </BLOCKQUOTE>
85 * </P>
86 *
87 * <P>
88 * Output Data Object <BR>
89 * <BLOCKQUOTE>
90 * com.flexstor.common.importprocessor.ImportResult
91 * </BLOCKQUOTE>
92 * </P>
93 */
94 public class VIRPreIdxService
95 implements Service
96 {
97 public static final String IDENTIFIER = "$Id: VIRPreIdxService.java,v 1.4 2003/08/11 02:22:49 aleric Exp $";
98
99 protected static final String HTTP = "HTTP";
100 protected static final String FILE = "FILE";
101
102 protected ServiceContext context;
103
104 protected int in = 0;
105 protected int out = 0;
106 protected String sFullPath = null;
107 protected ImportData data = null;
108
109 public VIRPreIdxService()
110 {
111 super();
112
113 //more initialization
114 }
115
116 /**
117 * Calls before the service is initialized (before initData is called) to
118 * pass information about the environment in which the service is running.
119 * This environment consists of information about the properties set for the
120 * service in one of these files (services.config, roletype_services.config,
121 * or *.ctl), plus methods to access other information such as an instance
122 * of the service broker to invoke other services, the transaction id for
123 * the service, file separator character and local path for the installation
124 * directory and configuration directory.
125 *
126 * @param context Holds information about the environment in which the service
127 * is running.
128 */
129 public void setServiceContext( ServiceContext context )
130 {
131 this.context = context;
132 }
133
134 /**
135 * Data initialization method called at the beginning of the service.
136 *
137 * @param ActionData is the super class of the ImportData wrapper object
138 * which contains one DisguiseRecord, which again contains more
139 * DisguiseBucketRecord(s) and/or ElementRecord(s). Finally
140 * there are DisguiseAssetRecord(s) that is useful to extract
141 * information for the preparation of VIR analysing/indexing.
142 */
143 public void initData( ActionData actionData )
144 {
145 //sThisService = Resources.get(number);
146 data = (ImportData)actionData;
147 }
148
149 /**
150 * Start of the VIR pre-indexing Service.
151 *
152 * @return a Result object with the VIR pre-indexing process results.
153 */
154 public ActionResult go()
155 {
156 //get ROLE values corresponding to "highres", "lowres", etc.
157 String role_in = context.getProperty(ServiceArgumentsI.ROLE_DATA_SOURCE);
158 String role_out = context.getProperty(ServiceArgumentsI.ROLE_DATA_DESTINATION);
159
160 // get the TYPE values
161 String type_in = context.getProperty(ServiceArgumentsI.TYPE_DATA_SOURCE);
162 String type_out = context.getProperty(ServiceArgumentsI.TYPE_DATA_DESTINATION);
163
164 //get FLAG values corresponding to "parent", "temp", etc.
165 String flag_in = context.getProperty(ServiceArgumentsI.FLAG_DATA_SOURCE);
166 String flag_out = context.getProperty(ServiceArgumentsI.FLAG_DATA_DESTINATION);
167
168 String sProtocol = context.getProperty("protocol");
169 if ( sProtocol == null || ( sProtocol.equalsIgnoreCase(HTTP) == false &&
170 sProtocol.equalsIgnoreCase(FILE) == false ) )
171 {
172 sProtocol = HTTP;
173 }
174
175 //downcast to a ImportData object and get the DisguiseRecord
176 DisguiseRecordData disguiseData = data.getDisguiseRecordRef();
177
178 // get the list of in and out assets and set the full_text_path field
179 Vector vInAssets = disguiseData.getAssets( role_in, type_in, flag_in );
180 Vector vOutAssets = disguiseData.getAssets( role_out, type_out, flag_out );
181
182 if ( vInAssets != null && vInAssets.size() > 0 )
183 {
184 DisguiseAssetRecordData assetIn, assetOut;
185 String sServer, sLocation, sVisualPath;
186 for ( int i = 0; i < vInAssets.size(); i++ )
187 {
188 assetIn = (DisguiseAssetRecordData) vInAssets.elementAt(i);
189 assetOut = (DisguiseAssetRecordData) vOutAssets.elementAt(i);
190
191 if ( sProtocol.equalsIgnoreCase(HTTP) )
192 {
193 // get the server, location and filename
194 sServer = ServerList.getDNSName( assetIn.getServer() );
195 sLocation = assetIn.getLocation();
196 // Set the visual path
197 sVisualPath = sServer + "/" + sLocation.substring( 0, sLocation.length() - 1 ); // remote trailing slash
198 System.out.println("sServer is: " + sServer);
199 System.out.println("sLocation is: " + sLocation);
200 System.out.println("Filename is: " + assetOut.getFileName());
201 System.out.println("sVisualPath is: " + sVisualPath);
202 // Replace special characters with its %nn couter part
203 sVisualPath = StringUtil.encodeURLString( sVisualPath );
204 }
205 else
206 sVisualPath = "ORDVIRDIR"; // The VIR Dir object
207
208 assetOut.setVisualPath( sVisualPath );
209 assetOut.setVIRProtocol( sProtocol.toUpperCase() );
210 }
211 }
212
213 // Pre-Index Service completed successfully.
214 ImportResult result = new ImportResult(true);
215 result.setImportData(data);
216 return result;
217 }
218
219 } // end of class