BICC Reset to Full Extract by Offering ID using groovy script
ODI procedure:
import oracle.odi.core.OdiInstance
import java.sql.Connection
import java.sql.Statement
import java.sql.ResultSet
import groovy.json.*
import java.net.URL
import java.net.HttpURLConnection
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.HttpHost;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.auth.AuthScope;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.util.EntityUtils;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
// Enter username, pwd
username="XX_SVC_BICC"
//password="************"
//password="<@=odiRef.getInfo ("BICC_CRM")@>"
password = "<@=odiRef.getDataServerInfo("BICC_PASSWORD", "BICC_CRM") @>"
// Create Connection object to the schema
Connection con = odiRef.getJDBCConnectionFromLSchema( "<%=odiRef.getOption("DB_SCHEMA")%>", "<%=odiRef.getOption("ODI_CONTEXT")%>" )
// Create SQL Statement
Statement stmt = con.createStatement()
// Credentials for basic authorization need to be passed through as username:pwd
userCredentials = username + ":" + password;
// Basic authorization is set up, but the encoding for credentials need to be changed.
basicAuth = 'Basic '+javax.xml.bind.DatatypeConverter.printBase64Binary(userCredentials.getBytes())
// Get the Encoding
String encoding = Base64.getEncoder().encodeToString(userCredentials.getBytes("utf-8"))
sql = "select distinct OFFERING_ID from " + "<%=odiRef.getOption("DB_SCHEMA")%>" + "." + "<%=odiRef.getOption("BICC_OFFERING_DATASTORE_TABLE")%>"
try {
ResultSet rs = stmt.executeQuery( sql )
while (rs.next()) {
println('--------------------------------------------------------------------')
println('Reset to Full Extract for Offering: ' + rs.getString("OFFERING_ID"))
address = "https://ea-" + "<%=odiRef.getOption("BICC_INSTANCE")%>" + ".fa.us2.oraclecloud.com/biacm/rest/meta/offerings/"+ rs.getString("OFFERING_ID") +"/actions/resetToFull"
println(address)
urlInfo = address.toURL() // Variable converted to URL
connection = urlInfo.openConnection()
connection.setRequestMethod("POST")
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("Content-Type", "application/json")
connection.setDoInput(true)
connection.setDoOutput(true)
connection.setRequestProperty("Content-Length", encoding.length().toString())
connection.setRequestProperty("Authorization", 'Basic '+encoding)
DataOutputStream writer = new DataOutputStream(connection.getOutputStream())
writer.writeBytes("REPLACE ME WITH DATA TO BE WRITTEN")
writer.flush()
println "Connection Class: " + connection.class
int respCode = connection.getResponseCode()
println "Response Code/Message: " + respCode
connection.disconnect()
}
} finally {
if (stmt != null) { stmt.closeOnCompletion() }
}
No comments:
Post a Comment