Source code: com/flexstor/flexdbserver/services/asset/AddAssetFieldsToChild.java
1 /*
2 * AddAssetFieldsToChild.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:29 $ 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.Enumeration;
14 import java.util.Hashtable;
15 import java.util.Vector;
16
17 import com.flexstor.common.data.ActionData;
18 import com.flexstor.common.data.ActionResult;
19 import com.flexstor.common.data.ejb.disguiserecord.DisguiseAssetRecordData;
20 import com.flexstor.common.data.ejb.disguiserecord.DisguiseRecordData;
21 import com.flexstor.common.importprocessor.ImportCtlData;
22 import com.flexstor.common.importprocessor.ImportData;
23 import com.flexstor.common.importprocessor.ImportResult;
24 import com.flexstor.common.services.ServiceArgumentsI;
25 import com.flexstor.common.util.Diagnostic;
26 import com.flexstor.ejb.bucket.persist.ServerBucketExtendData;
27 import com.flexstor.ejb.disguise.persist.ServerDisguiseExtendData;
28 import com.flexstor.flexdbserver.disguise.DisguiseLoader;
29 import com.flexstor.flexdbserver.services.Service;
30 import com.flexstor.flexdbserver.services.ServiceContext;
31
32 /**
33 * Template Class to create an Import Service for FLEXSTORdb
34 */
35 public class AddAssetFieldsToChild
36 implements Service
37 {
38
39 protected Hashtable servers = new Hashtable();
40
41 // Used for logging errors
42 public final static String IDENTIFIER = "$Id: AddAssetFieldsToChild.java,v 1.4 2003/08/11 02:22:29 aleric Exp $";
43
44 String sRoleOut = null;
45 String sTypeOut = null;
46 String sFlagOut = null;
47
48 protected ServiceContext context;
49
50 // The data object
51 private ImportData refImportData = null;
52 private ServerDisguiseExtendData myServDisgExtend = null;
53 private DisguiseRecordData refDisguiseRecord = null;
54 private ServerBucketExtendData [] allBucketExtend = null;
55
56 private static String sDisguise = new String();
57 protected boolean successful = true;
58
59 /**
60 * Calls before the service is initialized (before initData is called) to
61 * pass information about the environment in which the service is running.
62 * This environment consists of information about the properties set for the
63 * service in one of these files (services.config, roletype_services.config,
64 * or *.ctl), plus methods to access other information such as an instance
65 * of the service broker to invoke other services, the transaction id for
66 * the service, file separator character and local path for the installation
67 * directory and configuration directory.
68 *
69 * @param context Holds information about the environment in which the service
70 * is running.
71 */
72 public void setServiceContext( ServiceContext context )
73 {
74 this.context = context;
75 }
76
77 /**
78 * Data initialization method called at the beginning of the service.
79 *
80 * @param Action is the super class of the data wrapper object
81 * which contains all the information for executing the service.
82 */
83 public void initData( ActionData actionData )
84 {
85 refImportData = (ImportData) actionData;
86
87 // Get some info from the .ctl file. This should all be in the refImportData
88 ImportCtlData refCtlData = refImportData.getCtlDataRef();
89 sDisguise = refCtlData.getValuePerKey("application name");
90 }
91
92
93
94 /**
95 * Start of the Service
96 *
97 * @return a Result object with the an updated data object.
98 */
99 public ActionResult go()
100 {
101 DisguiseAssetRecordData aChildAsset = null;
102 DisguiseAssetRecordData theParentAsset = null;
103
104 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT,"AAFTC service Started");
105
106 successful = true;
107
108 // get the input assets, according to the role, type and flag specified
109 // in remote_server.config or TypeServiceDat.config
110 String sRoleIn = context.getProperty(ServiceArgumentsI.ROLE_DATA_SOURCE);
111 String sTypeIn = context.getProperty(ServiceArgumentsI.TYPE_DATA_SOURCE);
112 String sFlagIn = context.getProperty(ServiceArgumentsI.FLAG_DATA_SOURCE);
113
114 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "AAFTC:Role(in) = " + sRoleIn);
115 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "AAFTC:Type(in) = " + sTypeIn);
116 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "AAFTC:Flag(in) = " + sFlagIn);
117
118 sRoleOut = context.getProperty(ServiceArgumentsI.ROLE_DATA_DESTINATION);
119 sTypeOut = context.getProperty(ServiceArgumentsI.TYPE_DATA_DESTINATION);
120 sFlagOut = context.getProperty(ServiceArgumentsI.FLAG_DATA_DESTINATION);
121
122 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "AAFTC:Role(out) = " + sRoleOut);
123 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "AAFTC:Type(out) = " + sTypeOut);
124 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "AAFTC:Flag(out) = " + sFlagOut);
125
126
127
128 ImportResult result = null;
129
130 if( refImportData == null ) {
131 BGPDebug("refImportData was null");
132 result = new ImportResult(false);
133 return result;
134 }
135
136 // Get the reference to the DisguiseRecordData
137 refDisguiseRecord = refImportData.getDisguiseRecordRef();
138 if( refDisguiseRecord == null ) {
139 BGPDebug("refDisguiseRecod was null");
140 successful = false;
141 }
142
143 try {
144 myServDisgExtend = DisguiseLoader.getDisguise(sDisguise);
145 }
146 catch (Exception e) {
147 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT,"Exception getting disguise: " + e);
148 e.printStackTrace();
149 }
150
151
152 // This is a vector of ServerBucketExtendData Objects (all our buckets)
153 Vector myBucketDataObjects = myServDisgExtend.getBucketDataObjects();
154
155 // I'd like an array of SBEDs for all buckets, please.
156 allBucketExtend = new ServerBucketExtendData[myBucketDataObjects.size()];
157
158 for (int i=0; i<allBucketExtend.length; i++) {
159 allBucketExtend[i] = (ServerBucketExtendData) myBucketDataObjects.elementAt(i);
160 }
161
162 Vector vAssetsIn = null;
163
164 if( sRoleIn==null || sTypeIn==null || sFlagIn==null )
165 {
166 BGPDebug("Null service flags");
167 successful = false;
168 }
169 else
170 {
171 vAssetsIn = refDisguiseRecord.getAssets(sRoleIn, sTypeIn, sFlagIn);
172 if( vAssetsIn == null ) {
173 BGPDebug("No assets of specified Role/Type/Flag to operate on...");
174 successful = false;
175 } else {
176 Enumeration assets = vAssetsIn.elements();
177
178 if (assets.hasMoreElements() == false) {
179 BGPDebug("Empty asset list.");
180 }
181
182 // Process each asset in each element in ImportData
183 while(assets.hasMoreElements())
184 {
185 aChildAsset = (DisguiseAssetRecordData)assets.nextElement();
186
187 theParentAsset = aChildAsset.getParent();
188 if (theParentAsset == null) {
189 BGPDebug("Are you sure this is a child asset?");
190 successful = false;
191 } else {
192 Hashtable hParentData = theParentAsset.getUserData();
193 Hashtable hChildData = aChildAsset.getUserData();
194 if (hParentData.size() > 0) {
195 Enumeration dataKeys = hParentData.keys();
196 String sKey, sVal;
197 while(dataKeys.hasMoreElements()) {
198 sKey = new String((String)dataKeys.nextElement());
199 sVal = new String((String)hParentData.get(sKey));
200 // If the child already has data, don't overwrite it!
201 if(hChildData.get(sKey) == null) {
202 BGPDebug("copying ["+sKey+"/"+sVal+"] to child");
203 aChildAsset.addUserData(sKey,sVal);
204 } else {
205 BGPDebug("child-"+sKey+" already set to ["+hChildData.get(sKey)+"]");
206 }
207 }
208 } else {
209 BGPDebug("The parent's hUserData was empty.");
210 }
211 }
212 }
213 }
214 }
215
216
217 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, "Done with AAFTC service");
218
219 if( successful == false )
220 {
221 result = new ImportResult(false);
222 } else {
223 result = new ImportResult(true);
224 result.setImportData(refImportData);
225 }
226
227 return result;
228 }
229
230
231
232 /*
233 * BGPDebug(String of debug text)
234 */
235 void BGPDebug(String sSomeString)
236 {
237 boolean printMessages = true;
238 if (printMessages == true)
239 Diagnostic.trace(Diagnostic.APPSERVER_IMPORT, sSomeString);
240 }
241
242
243 }
244