Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/flexdbserver/services/asset/ActionDataCreateService.java


1   /*
2    * ActionDataCreateService.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:28 $ 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;
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.AssetRecordData;
18  import com.flexstor.common.data.TraversalInfo;
19  import com.flexstor.common.data.TraversalItem;
20  import com.flexstor.common.data.ejb.disguiserecord.DisguiseAssetRecordData;
21  import com.flexstor.common.data.ejb.disguiserecord.DisguiseBucketRecordData;
22  import com.flexstor.common.data.ejb.disguiserecord.DisguiseElementRecordData;
23  import com.flexstor.common.data.ejb.disguiserecord.DisguiseRecordData;
24  import com.flexstor.common.importprocessor.ImportData;
25  import com.flexstor.common.importprocessor.ImportResult;
26  import com.flexstor.common.resources.Resources;
27  import com.flexstor.common.services.ServiceArgumentsI;
28  import com.flexstor.common.util.FlexHashtable;
29  import com.flexstor.flexdbserver.services.Service;
30  import com.flexstor.flexdbserver.services.ServiceContext;
31  
32  
33  /**
34   * <P>
35   * ActionDataCreateService <BR>
36   * <BLOCKQUOTE>
37   *    Creates a ActionData object from an existent ImportData.
38   * </BLOCKQUOTE>
39   * </P>
40   *
41   * Configurable Properties in roletype_services.config <BR>
42   *
43   * <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="3">
44   * <CAPTION ALIGN=TOP>
45   *    <B> In/Out Properties for Assets </B>
46   * </CAPTION>
47   *     <TR>
48   *        <FONT SIZE=+1><B>
49   *        <TH WIDTH="120">Attribute</TH>
50   *                                   <TH WIDTH="30">IN</TH>           <TH WIDTH="30">OUT</TH>          <TH WIDTH="30">Default IN</TH>  <TH WIDTH="30">Default OUT</TH>
51   *        </B></FONT>
52   *     </TR>
53   *     <TR>
54   *        <TH ALIGN=LEFT><FONT SIZE=+1><B>ROLE</B></FONT></TH>
55   *                                   <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> ALL </TD>      <TD ALIGN=CENTER> &nbsp </TD>
56   *     </TR>
57   *     <TR><TH> Highres </TH>        <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
58   *     <TR><TH> Lowres </TH>         <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
59   *     <TR><TH> Thumbnail </TH>      <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
60   *     <TR><TH> Layout </TH>         <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
61   *     <TR><TH> Video </TH>          <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
62   *     <TR><TH> Audio </TH>          <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
63   *     <TR>
64   *        <TH ALIGN=LEFT><FONT SIZE=+1><B>TYPE</B></FONT></TH>
65   *                                   <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> ALL </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
66   *     </TR>
67   *     <TR>
68   *        <TH ALIGN=LEFT><FONT SIZE=+1><B>FLAG</B></FONT></TH>
69   *     </TR>
70   *     <TR><TH> PARENT </TH>         <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD></TR>
71   *     <TR><TH> CHLDREN </TH>        <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
72   *     <TR><TH> ALL </TH>            <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
73   *     <TR><TH> TEMP_PARENT </TH>    <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
74   *     <TR><TH> TEMP_CHILDREN </TH>  <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
75   *     <TR><TH> TEMP_ALL </TH>       <TD ALIGN=CENTER> X </TD>        <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD>    <TD ALIGN=CENTER> &nbsp </TD></TR>
76   * </TABLE>
77   *
78   * <P>
79   * Input Data Object <BR>
80   * <BLOCKQUOTE>
81   *    com.flexstor.common.importprocessor.ImportData
82   * </BLOCKQUOTE>
83   * </P>
84   *
85   * <P>
86   * Output Data Object <BR>
87   * <BLOCKQUOTE>
88   *    com.flexstor.common.importprocessor.ImportResult: call getData() to retrieve ActionData
89   * </BLOCKQUOTE>
90   * </P>
91   */
92  public class ActionDataCreateService
93     implements Service
94     {
95     // To get the version number from MKS
96     public final static String IDENTIFIER="$Id: ActionDataCreateService.java,v 1.4 2003/08/11 02:22:28 aleric Exp $";
97  
98     protected  ServiceContext context;
99     protected  int id = -1;
100    private  ImportData  importData      = null;
101    private  String        sThisService    = null;
102    private  int           nDisguiseId     = -1;
103    private  String        sRoleIn, sTypeIn, sFlagIn;
104 
105    /**
106     * Calls before the service is initialized (before initData is called) to 
107     * pass information about the environment in which the service is running.
108     * This environment consists of information about the properties set for the
109     * service in one of these files (services.config, roletype_services.config,
110     * or *.ctl), plus methods to access other information such as an instance
111     * of the service broker to invoke other services, the transaction id for
112     * the service, file separator character and local path for the installation
113     * directory and configuration directory.
114     * 
115     * @param context Holds information about the environment in which the service
116     *                is running.
117     */
118    public void setServiceContext( ServiceContext context )
119    {
120       this.context = context;
121       this.id = context.getTransactionId();
122    }
123    
124    public void initData(ActionData actionData)
125    {
126       importData = (ImportData) actionData;
127 
128       //6917=ActionData Create service
129       sThisService = Resources.get(6917) + " (" + id + ")";
130    }
131 
132    public ActionResult go()
133    {
134       boolean bSuccess = true;
135 
136       // Get a new ActionData by clonning the ActionData object part of ImportData object
137       ActionData actionData = (ActionData) importData.clone();
138 
139       // Get Role, Type and Flag values from property list (AssetService)
140       sRoleIn  = context.getProperty(ServiceArgumentsI.ROLE_DATA_SOURCE);
141       sTypeIn  = context.getProperty(ServiceArgumentsI.TYPE_DATA_SOURCE);
142       sFlagIn  = context.getProperty(ServiceArgumentsI.FLAG_DATA_SOURCE);
143 
144       DisguiseRecordData disguiseRecord = importData.getDisguiseRecordRef();
145       if ( disguiseRecord != null )
146       {
147          // set the disguise id
148          nDisguiseId = disguiseRecord.getDisguiseId();
149 
150          Vector vAssets = new Vector();
151          Vector vTraversalItems = new Vector();
152          DisguiseBucketRecordData[] saBuckets = disguiseRecord.getBuckets();
153 
154          // Retrieve assets and bucket information
155          parseBuckets( saBuckets, vAssets, vTraversalItems );
156 
157          // Add assets found to ActionData object
158          actionData.setRecords( vAssets );
159       }
160       else
161          bSuccess = false;
162 
163       ImportResult result = new ImportResult( bSuccess );
164       result.setData( actionData );
165       return result;
166    }
167 
168    private void parseBuckets( DisguiseBucketRecordData[] saBuckets, Vector vAssets, Vector vTraversalItems )
169    {
170       if ( saBuckets != null && saBuckets.length > 0 )
171       {
172          DisguiseBucketRecordData bucket;
173          for ( int i = 0; i < saBuckets.length; i++ )
174          {
175             bucket = saBuckets[i];
176             // Add this bucket traversal info to the traversal item Vector
177             vTraversalItems.addElement( new TraversalItem(bucket.getRecordId(), bucket.getBucketStructId()) );
178 
179             // call recursively to process child buckets
180             parseBuckets( bucket.getBuckets(), vAssets, vTraversalItems );
181 
182             // Now look for assets in the elements of this bucket
183             parseElements( bucket.getElements(), vAssets, vTraversalItems );
184 
185             // Remove last element on the traversal path
186             vTraversalItems.removeElementAt( vTraversalItems.size() - 1 );
187          }
188       }
189    }
190 
191    private void parseElements( DisguiseElementRecordData[] saElements, Vector vAssets, Vector vTraversalItems )
192    {
193       if ( saElements != null && saElements.length > 0 )
194       {
195          DisguiseElementRecordData element;
196          for ( int i = 0; i < saElements.length; i++ )
197          {
198             element = saElements[i];
199             // Add this element traversal info to the traversal item Vector
200             vTraversalItems.addElement( new TraversalItem(element.getRecordId(), element.getBucketStructId()) );
201 
202             // Now add the assets to the Vector of assets
203             parseAsset( element.getParentAsset(), vAssets, vTraversalItems );
204 
205             // Remove last element on the traversal path
206             vTraversalItems.removeElementAt( vTraversalItems.size() - 1 );
207          }
208       }
209    }
210 
211    private void parseAsset( DisguiseAssetRecordData asset, Vector vAssets, Vector vTraversalItems )
212    {
213       if ( asset != null )
214       {
215          Vector vTraversalInfo = new Vector(1);
216          vTraversalInfo.addElement( new TraversalInfo(nDisguiseId, (Vector)vTraversalItems.clone()) );
217          // Get the assets that will be added to this ActionData object
218          Vector vInputAssets = new Vector();
219          asset.getAssets( vInputAssets, sRoleIn, sTypeIn, sFlagIn );
220          if ( vInputAssets != null && vInputAssets.size() > 0 )
221          {
222             for ( int i = 0; i < vInputAssets.size(); i++ )
223                vAssets.addElement( createRecord((DisguiseAssetRecordData)vInputAssets.elementAt(i), vTraversalInfo) );
224          }
225       }
226    }
227 
228    private AssetRecordData createRecord( DisguiseAssetRecordData asset, Vector vTraversalInfo )
229    {
230       AssetRecordData record = new AssetRecordData();
231       // Set the traversal path
232       record.setTraversalPathInfo( vTraversalInfo );
233       // Set the rest of the information
234       setInfo( record, asset );
235 
236       // Lets check if this asset has any child
237       DisguiseAssetRecordData[] saChildAssets = asset.getChildAssets();
238       if ( saChildAssets != null && saChildAssets.length > 0 )
239       {
240          for ( int i = 0; i < saChildAssets.length; i++ )
241             record.addChildRecord( createRecord(saChildAssets[i], vTraversalInfo) );
242       }
243 
244       return record;
245    }
246 
247    private void setInfo( AssetRecordData record, DisguiseAssetRecordData asset )
248    {
249       record.setRecordId( asset.getRecordId() );
250       record.setStructureId( asset.getBucketStructId() );
251       //record.setBucketType( int nBucketType );
252       record.setData( asset.getUserData() );
253       FlexHashtable hProperties = asset.getProperties();
254       if ( hProperties != null )
255          record.setProperties( (FlexHashtable)asset.getProperties().clone() );
256       record.setRoleId( new Integer(asset.getAssetRoleId()) );
257       record.setServer( asset.getServer() );
258       record.setLocation( asset.getLocation() );
259       record.setFileName( asset.getFileName() );
260       record.setFileSize( new Long(asset.getFileSize()) );
261       record.setAppleTalkVendor( new Integer(asset.getAppleTalkVendor()) );
262       record.setDefaultViewAssetId( new Long(asset.getDefaultViewAssetId()) );
263    }
264 }
265