Source code: com/flexstor/flexdbserver/services/asset/ImportActionDataServiceManager.java
1 /*
2 * ImportActionDataServiceManager.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 com.flexstor.common.constants.ServicesI;
14 import com.flexstor.common.data.ActionData;
15 import com.flexstor.common.data.ActionResult;
16 import com.flexstor.common.errorlogger.FlexError;
17 import com.flexstor.common.importprocessor.ImportData;
18 import com.flexstor.common.resources.Resources;
19 import com.flexstor.common.services.SrvcNotAvailException;
20 import com.flexstor.common.threadmgr.ThreadCallbackI;
21 import com.flexstor.flexdbserver.services.ServiceManager;
22 import com.flexstor.flexdbserver.transactionmanager.TransMngImport;
23
24 /**
25 * CheckOutServiceManager provides functionality to control the
26 * sequencial execution of Services during the check-in process
27 */
28 public class ImportActionDataServiceManager
29 extends ServiceManager
30 {
31 // To get the version number from MKS
32 public final static String IDENTIFIER="$Id: ImportActionDataServiceManager.java,v 1.3 2003/08/11 02:22:28 aleric Exp $";
33
34 protected String sCtlFile = "";
35 protected ActionData data = null;
36
37 public ImportActionDataServiceManager( String sIdentifier, ActionData data, ThreadCallbackI caller )
38 {
39 super( data, caller );
40 this.sCtlFile = sIdentifier;
41 this.data = data;
42 }
43
44 /**
45 * Main loop for sequencial execution of Services.
46 */
47 public ActionResult execute()
48 throws InterruptedException
49 {
50 boolean bContinue = false;
51 try
52 {
53 ActionResult result = doService( ServicesI.IMPORTDATA_CREATE_SERVICE, data );
54 if ( result == null )
55 bContinue = false;
56 else
57 bContinue = result.isSuccess();
58
59 // Before executing a service, we should check if an interrupt request has been
60 // placed, and if so, throw an InterruptedException to abort this operation
61 if ( abortManager() )
62 throw new InterruptedException();
63
64 if ( bContinue )
65 {
66 ImportData importData = (ImportData) result.getData();
67 if ( importData != null )
68 {
69
70 // If this service is called from an import (from the GUI), then replace the
71 // already persisted data object (ActionData) with the redefined object
72 // ImportData.
73 TransMngImport tmImport = new TransMngImport( data.getTransId() );
74 if ( tmImport.getTransType() == tmImport.TYPE_IMPORT )
75 tmImport.replaceDataObject( importData );
76 else
77 {
78 // Set the update flat to true, since we just want to update the file and role
79 // information for an asset.
80 importData.setUpdate( true );
81 }
82
83 result = doService( ServicesI.IMPORT_ASSET_SERVICE, importData );
84 if ( result == null )
85 bContinue = false;
86 else
87 bContinue = result.isSuccess();
88 }
89 else
90 bContinue = false;
91 }
92 }
93 catch( SrvcNotAvailException e )
94 {
95 //6313=Regenerate Thumbnail Service
96 new FlexError(FlexError.CRITICAL, Resources.get(6313), IDENTIFIER, e);
97 bContinue = false;
98 }
99
100 ActionResult actionResult = new ActionResult( bContinue );
101 if ( !bContinue )
102 actionResult.setBadRecords( data.getRecords() );
103 actionResult.setData( data );
104 actionResult.setId( data.getTransId() );
105 return actionResult;
106 }
107
108 protected ActionResult getResultObjectOnAbnormalEnding()
109 {
110 ActionResult actionResult = new ActionResult( false );
111 actionResult.setBadRecords( data.getRecords() );
112 return actionResult;
113 }
114 } // end of class