1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /***************************************************************************************
- * IBM Confidential
- *
- * OCO Source Materials
- *
- * IBM Cognos Products: Moser
- *
- * (C) Copyright IBM Corp. 2020
- *
- * The source code for this program is not published or otherwise
- * divested of its trade secrets, irrespective of what has been
- * deposited with the U.S. Copyright Office.
- *
- ***************************************************************************************/
- import java.io.IOException;
- import com.ibm.bi.platform.modeling.sdk.examples.FileImportHelper;
- import com.ibm.bi.platform.modeling.sdk.examples.internal.ModelingHelper;
- import com.ibm.bi.platform.modeling.sdk.examples.internal.UnexpectedHTTPResponseException;
- import com.ibm.json.java.JSONObject;
- /**
- * Replace file example
- *
- */
- public class ReplaceFileExample {
- /**
- * @param args
- * args[0] ca server url origin, e.g. http://localhost:9300/
- * args[1] login credentials relative file path
- * args[2] store id of the file to be replaced
- * args[3] directory containing file relative to current , e.g. "resources/"
- * args[4] file to upload name, e.g. "pizza.xlsx"
- */
- public static void main(String[] args) {
- if (args.length < 5) {
- System.err.print("Correct arguments: origin fileWithCredentials fileStoreID sourceDir filename");
- return;
- }
- String origin = args[0];
- try {
- FileImportHelper helper = new FileImportHelper(origin);
- String credentials = ModelingHelper.stringFromFile(args[1]);
- helper.authenticate(credentials);
- String uploadedFileId = args[2], dir = args[3], filename = args[4];
- // Post the file.
- String response = helper.replaceFile(uploadedFileId, dir, filename);
- JSONObject json = JSONObject.parse(response);
- String uploadedId = (String) json.get("id");
- System.out.println("File is replaced : " + uploadedId);
- } catch (UnexpectedHTTPResponseException e) {
- try {
- System.out.println("Response : " + ModelingHelper.httpEntityToString(e.getResponse().getEntity()));
- } catch (IOException io) {
- }
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|