123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 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;
- /*
- * 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.
- */
- /**
- * Append more rows to uploaded file
- *
- */
- public class AppendFileExample {
- /**
- * @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 appended to
- * 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.println("Correct arguments: origin fileWithCredentials fileStoreId sourceDir filename");
- System.err.println("origin - ca server url origin, e.g. http://localhost:9300/");
- System.err.println("fileWithCredentials - login credentials relative file path");
- System.err.println("fileStoreId - store id of the file to be appended to");
- System.err.println("sourceDir - directory containing file relative to current , e.g. \"resources\"");
- System.err.println("filename - file to upload name, e.g. \"pizza.xlsx\"");
- 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], appendFileName = args[4];
- // Post the file.
- String response = helper.appendFile(uploadedFileId, dir, appendFileName);
- JSONObject json = JSONObject.parse(response);
- String uploadedId = (String) json.get("id");
- System.out.println("File is uploaded : " + uploadedId);
- } catch (UnexpectedHTTPResponseException e) {
- try {
- System.out.println("Response : " + ModelingHelper.httpEntityToString(e.getResponse().getEntity()));
- } catch (IOException io) {
- }
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|