Snippets
Created by
Jonathan Hult
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | import java.io.IOException;
import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.IdcClientManager;
import oracle.stellent.ridc.IdcContext;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.model.DataResultSet;
import oracle.stellent.ridc.model.serialize.HdaBinderSerializer;
import oracle.stellent.ridc.protocol.ServiceResponse;
import oracle.stellent.ridc.protocol.intradoc.IntradocClient;
/*
* @author Jonathan Hult
*
* This class is used to import an archive batch file using RIDC
*/
public class RIDCImportBatchFile {
// RIDC connection information
private static final String IDC_PROTOCOL = "idc://";
private static final String RIDC_SERVER = "localhost";
private static final String RIDC_PORT = "4444";
private static IdcClientManager m_idcClientManager;
private static IntradocClient m_idcClient;
private static final String UTF8 = "UTF-8";
// Service parameters
private static final String IDC_SERVICE = "IdcService";
private static final String IMPORT_BATCHFILE = "IMPORT_BATCHFILE";
private static final String GET_BATCHFILES = "GET_BATCHFILES";
private static final String IDC_NAME = "IDC_Name";
private static final String IDC_NAME_VALUE = "cs";
private static final String A_ARCHIVE_NAME = "aArchiveName";
private static final String A_ARCHIVE_NAME_VALUE = "ss_to_prod";
// User to execute service calls as
private static final String USER = "sysadmin";
// Used for GET_BATCHFILES
private static final String BATCH_FILES = "BatchFiles";
// Used for IMPORT_BATCHFILE
private static final String BATCH_FILE = "BatchFile";
/**
* @param args
* @throws IOException
*/
public static void main(final String[] args) {
try {
// Get ResultSet BatchFiles from service GET_BATCHFILES
final DataResultSet batchFiles = getBatchFiles();
// Import batch file
importBatchFile(batchFiles);
} catch (final IdcClientException ice) {
ice.printStackTrace(System.out);
}
}
/**
* This method executes GET_BATCHFILES and returns the BatchFiles ResultSet.
* @return BatchFiles ResultSet
* @throws IdcClientException
*/
private static DataResultSet getBatchFiles() throws IdcClientException {
// DataBinder for service call
DataBinder serviceBinder = getNewDataBinder();
// Set service parameters
serviceBinder.putLocal(IDC_SERVICE, GET_BATCHFILES);
serviceBinder.putLocal(IDC_NAME, IDC_NAME_VALUE);
serviceBinder.putLocal(A_ARCHIVE_NAME, A_ARCHIVE_NAME_VALUE);
// Execute service
serviceBinder = executeService(serviceBinder, USER);
// Return BatchFiles ResultSet
return serviceBinder.getResultSet(BATCH_FILES);
}
/**
* This method executes IMPORT_BATCHFILE.
* @param batchFiles ResultSet BatchFiles from service GET_BATCHFILES.
* @throws IdcClientException
*/
private static void importBatchFile(final DataResultSet batchFiles) throws IdcClientException {
// DataBinder for service call
final DataBinder serviceBinder = getNewDataBinder();
// Set service parameters
serviceBinder.putLocal(IDC_SERVICE, IMPORT_BATCHFILE);
serviceBinder.putLocal(IDC_NAME, IDC_NAME_VALUE);
serviceBinder.putLocal(A_ARCHIVE_NAME, A_ARCHIVE_NAME_VALUE);
serviceBinder.addResultSet(BATCH_FILE, batchFiles);
// Execute service
executeService(serviceBinder, USER);
}
/**
* This method executes a service.
* @param binder DataBinder containing service parameters.
* @param userName User to execute service as.
* @return DataBinder from service call
* @throws IdcClientException
* @throws IOException
*/
public static DataBinder executeService(DataBinder binder, final String userName) throws IdcClientException {
final HdaBinderSerializer serializer = new HdaBinderSerializer(UTF8, getIntradocClient().getDataFactory());
try {
System.out.println("Service binder before executing:");
serializer.serializeBinder(System.out, binder);
} catch (final IOException ioe) {
ioe.printStackTrace(System.out);
}
// Execute the request
final ServiceResponse response = getIntradocClient().sendRequest(new IdcContext(userName), binder);
System.out.println("Successfully called service");
// Get the response as a DataBinder
binder = response.getResponseAsBinder();
try {
System.out.println("Service binder after executing:");
serializer.serializeBinder(System.out, binder);
} catch (final IOException ioe) {
ioe.printStackTrace(System.out);
}
// Return the response as a DataBinder
return binder;
}
/**
* This method returns IdcClientManager.
* @return IdcClientManager
*/
public static IdcClientManager getIdcClientManager() {
if (m_idcClientManager == null) {
// Needed to create IntradocClient
m_idcClientManager = new IdcClientManager();
}
return m_idcClientManager;
}
/**
* This method returns a IntradocClient object.
* @return IntradocClient
* @throws IdcClientException
*/
public static IntradocClient getIntradocClient() throws IdcClientException {
if (m_idcClient == null) {
// Client to talk to WebCenter Content
m_idcClient = (IntradocClient) getIdcClientManager().createClient(IDC_PROTOCOL + RIDC_SERVER + ":" + RIDC_PORT);
}
return m_idcClient;
}
/**
* This method returns a new DataBinder.
* @return New DataBinder
* @throws IdcClientException
*/
public static DataBinder getNewDataBinder() throws IdcClientException {
return getIntradocClient().createBinder();
}
}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.