Source code: com/flexstor/flexdbserver/services/asset/context/ContextIndexPreService.java
1 /*
2 * ContextIndexPreService.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:42 $ 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.context;
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 * ContextIndexPreService <BR>
30 * <BLOCKQUOTE>
31 * Adds to the ImportData object the information needed by the Oracle Context Cartridge to
32 * index assets according to the protocol specified (FILE or HTTP). If the protocol selected
33 * for indexing is either FILE or HTTP, then this service must be run before running the
34 * ContextService; however, if the protocol selected is BLOB, the ContextIndexPreService is
35 * not required. This service must be run prior to the DBUpdateService.
36 * </BLOCKQUOTE>
37 * </P>
38 *
39 * Configurable Properties in roletype_services.config <BR>
40 *
41 * <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="3">
42 * <CAPTION ALIGN=TOP>
43 * <B> In/Out Properties for Assets </B>
44 * </CAPTION>
45 * <TR>
46 * <FONT SIZE=+1><B>
47 * <TH WIDTH="120">Attribute</TH>
48 * <TH WIDTH="30">IN</TH> <TH WIDTH="30">OUT</TH> <TH WIDTH="30">Default IN</TH> <TH WIDTH="30">Default OUT</TH>
49 * </B></FONT>
50 * </TR>
51 * <TR>
52 * <TH ALIGN=LEFT><FONT SIZE=+1><B>ROLE</B></FONT></TH>
53 * <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER> ALL </TD> <TD ALIGN=CENTER> ALL </TD>
54 * </TR>
55 * <TR><TH> Highres </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
56 * <TR><TH> Lowres </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
57 * <TR><TH> Thumbnail </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
58 * <TR><TH> Layout </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
59 * <TR><TH> Video </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
60 * <TR><TH> Audio </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
61 * <TR>
62 * <TH ALIGN=LEFT><FONT SIZE=+1><B>TYPE</B></FONT></TH>
63 * <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> ALL </TD> <TD ALIGN=CENTER> ALL </TD></TR>
64 * </TR>
65 * <TR>
66 * <TH ALIGN=LEFT><FONT SIZE=+1><B>FLAG</B></FONT></TH>
67 * </TR>
68 * <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>
69 * <TR><TH> CHLDREN </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
70 * <TR><TH> ALL </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
71 * <TR><TH> TEMP_PARENT </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
72 * <TR><TH> TEMP_CHILDREN </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
73 * <TR><TH> TEMP_ALL </TH> <TD ALIGN=CENTER> X </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD> <TD ALIGN=CENTER>   </TD></TR>
74 * </TABLE>
75 *
76 * <P>
77 * protocol: The protocol used to access the files while indexing. The protocol will
78 * define how the information needed by the Context Cartridge is formatted (optional;
79 * defaults to HTTP). <BR>
80 * Legal values: FILE or HTTP <BR>
81 * </P>
82 *
83 * <P>
84 * Input Data Object <BR>
85 * <BLOCKQUOTE>
86 * com.flexstor.common.importprocessor.ImportData
87 * </BLOCKQUOTE>
88 * </P>
89 *
90 * <P>
91 * Output Data Object <BR>
92 * <BLOCKQUOTE>
93 * com.flexstor.common.importprocessor.ImportResult
94 * </BLOCKQUOTE>
95 * </P>
96 */
97 public class ContextIndexPreService
98 implements Service
99 {
100 public final static String IDENTIFIER="$Id: ContextIndexPreService.java,v 1.4 2003/08/11 02:22:42 aleric Exp $";
101
102 private static final String HTTP = "HTTP";
103 private static final String FILE = "FILE";
104
105 protected ServiceContext context;
106
107 protected ImportData data = null;
108 protected String sThisService = "";
109
110 public ContextIndexPreService()
111 {
112 super();
113
114 //more initialization
115 }
116
117 /**
118 * Calls before the service is initialized (before initData is called) to
119 * pass information about the environment in which the service is running.
120 * This environment consists of information about the properties set for the
121 * service in one of these files (services.config, roletype_services.config,
122 * or *.ctl), plus methods to access other information such as an instance
123 * of the service broker to invoke other services, the transaction id for
124 * the service, file separator character and local path for the installation
125 * directory and configuration directory.
126 *
127 * @param context Holds information about the environment in which the service
128 * is running.
129 */
130 public void setServiceContext( ServiceContext context )
131 {
132 this.context = context;
133 }
134
135 /**
136 * Data initialization method called at the beginning of the service.
137 *
138 * @param ActionData is the super class of the ImportData wrapper object
139 * which contains DisguiseRecords, which again contains more
140 * DisguiseBucketRecord(s) and/or ElementRecord(s). Finally
141 * there are DisguiseAssetRecord(s) that is useful to extract
142 * information for the preparation of iMedia Text indexing.
143 */
144 public void initData( ActionData actionData )
145 {
146 data = (ImportData)actionData;
147 }
148
149 /**
150 * Start of the iMedia Text pre-indexing Service.
151 *
152 * @return a Result object with the iMedia Text 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, sFileName, sFullTextPath;
186 for ( int i = 0; i < vInAssets.size(); i++ )
187 {
188 assetIn = (DisguiseAssetRecordData) vInAssets.elementAt(i);
189 assetOut = (DisguiseAssetRecordData) vOutAssets.elementAt(i);
190 // get the server, location and filename
191 sServer = ServerList.getDNSName( assetIn.getServer() );
192 sLocation = assetIn.getLocation();
193 sFileName = assetIn.getFileName();
194
195 // Set the full text path
196 if ( sProtocol.equals( HTTP ) )
197 {
198 sFullTextPath = "http://" + sServer + "/" + sLocation + sFileName;
199 // Replace special characters with its %nn counter part
200 sFullTextPath = StringUtil.encodeURLString( sFullTextPath );
201 }
202 else
203 sFullTextPath = "/" + sLocation + sFileName;
204
205 assetOut.setFullTextPath( sFullTextPath );
206 assetOut.setContextProtocol( sProtocol.toUpperCase() );
207 }
208 }
209
210 // Pre-Index Service completed successfully.
211 ImportResult result = new ImportResult(true);
212 result.setImportData(data);
213 return result;
214 }
215 }
216