KB Articles

 

KB Article # 18393

Topic/Category: Sharepoint, Scripting, Export

Issue: Sharepoint 2013 has issues with export. The stack trace ends with “Caused by: org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: One or more of the input parameters to the service method is missing or invalid.”

 

 

Solution:

 

Issue is resolved in 4.5.

A workaround comes in the form of a custom scripting solution developed by PS that you can use to template your own solution.
Sample:
ScriptExport.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

import com.ephesoft.dcma.script.IJDomScript;
import com.ephesoft.dcma.util.logger.EphesoftLogger;
import com.ephesoft.dcma.util.logger.ScriptLoggerFactory;

/*
* @author Ephesoft Professional Services
* @version 1.0
*/

public class ScriptExport implements IJDomScript {

private static EphesoftLogger LOGGER = ScriptLoggerFactory.getLogger(ScriptExport.class);

String BATCH_LOCAL_PATH_VALUE;
String BATCHNAME_VALUE = “”;
String BATCHLOCALPATH_VALUE = “”;
String BATCHCLASSID_VALUE = “”;
String BATCHINSTANCEID_VALUE = “”;

Properties DLF_MAPPING_PROPS;
Properties CMIS_EXPORT_PROPS;

// used to store the CMIS connection session
private static Session session;

// Connection Details for Session
private static String REPOSITORYUSERNAME;
private static String REPOSITORYPASSWORD;
private static String REPOSITORYURL;

// Index Field Array
List<Map<String, String>> valueMapList = new ArrayList<Map<String, String>>();
Map<String, String> indexMap = new HashMap<String, String>();

Element ROOT;

// Turn on Debugging
private Boolean IS_DEBUG = true;

public Object execute(Document document, String methodName, String docIdentifier) {
Exception exception = null;
try {

if (null == document) {
LOGGER.error(“Input document is null.”);
return null;
}

LOGGER.info(“************* Inside ExportScript scripts.”);
LOGGER.info(“************* Start execution of the ExportScript scripts.”);

// Add New Methods Below Here
init(document);
connectToSP();

LOGGER.info(“************* End execution of the ScriptExport scripts.”);
} catch (Exception e) {
LOGGER.error(“************* Error occurred in scripts.” + e.getMessage());
exception = e;
e.printStackTrace();
}
return exception;
}

@SuppressWarnings(“unchecked”)
private void connectToSP() throws FileNotFoundException {
Map<String, String> param = new HashMap<String, String>();

param.put(SessionParameter.USER, REPOSITORYUSERNAME);
param.put(SessionParameter.PASSWORD, REPOSITORYPASSWORD);
param.put(SessionParameter.ATOMPUB_URL, REPOSITORYURL);
param.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
param.put(SessionParameter.LOCALE_ISO3166_COUNTRY, “”);
param.put(SessionParameter.LOCALE_ISO639_LANGUAGE, “en”);
param.put(SessionParameter.LOCALE_VARIANT, “US”);
SessionFactory f = SessionFactoryImpl.newInstance();
Repository soleRepository = f.getRepositories(param).get(0);
session = soleRepository.createSession();

Folder folder = session.getRootFolder();
List<Element> docList = ROOT.getChild(“Documents”).getChildren(“Document”);
if (docList == null) {
return;
}
for (Element doc : docList) {
String filePath = doc.getChildText(“FinalMultiPagePdfFilePath”);
List<Element> indexList = doc.getChild(“DocumentLevelFields”).getChildren(“DocumentLevelField”);
for (Element index : indexList) {
String indexValue = index.getChildText(“Value”);
String indexName = index.getChildText(“Name”);
indexMap.put(indexName, indexValue);
}
valueMapList.add(indexMap);
getIndexFieldValues();
uploadDoc(folder, filePath);
}
}

//Uploads document to created folder object
@SuppressWarnings({ “rawtypes”, “unchecked” })
private void uploadDoc(Folder folder, String filePath) throws FileNotFoundException {

File file = new File(filePath);
InputStream is = new FileInputStream(file);
long length = file.length();
BigInteger bi = BigInteger.valueOf(length);
ContentStream contentStream = new ContentStreamImpl(file.getName(), bi, “application/pdf”, is);
Map properties = new HashMap();
properties.put(PropertyIds.OBJECT_TYPE_ID, “0x010100A3D487EE1F3D184FBCFFEB9C7AD149470064971C51FB9CC44F87156B42F137496D”);
properties.put(PropertyIds.NAME, file.getName());
properties.put(“InvoiceNumber”, invNum);
properties.put(“VendorName”, vendor);
//properties.put(“VendorID”, vNum);
properties.put(“VendorAddress”, vAdd);
properties.put(“VendorCity”, vCity);
properties.put(“VendorState”, vState);
properties.put(“VendorZipCode”, vZip);
properties.put(“InvoiceDate”, invDate);
properties.put(“PONumber”, po);
properties.put(“Account”, acct);
properties.put(“InvoiceTotal”, total);
properties.put(“ShipToName”, shipTo);
properties.put(“ShipToAddress”, shipAdd);
properties.put(“ShipToCity”, shipCity);
properties.put(“ShipToState”, shipState);
properties.put(“ShipToZipCode”, shipZip);
properties.put(“BillToName”, billTo);
properties.put(“BillToAddress”, billAdd);
properties.put(“BillToCity”, billCity);
properties.put(“BillToState”, billState);
properties.put(“BillToZipCode”, billZip);
properties.put(“BillForName”, billFor);
properties.put(“BillForAddress”, billForA);
properties.put(“BillForCity”, billForC);
properties.put(“BillForState”, billForS);
properties.put(“BillForZipCode”, billForZ);
properties.put(“Contractor”, contractor);
properties.put(“Project”, project);
org.apache.chemistry.opencmis.client.api.Document doc = folder.createDocument(properties, contentStream,
VersioningState.MINOR);
writeDebug(“Document ID: ” + doc.getId());
}

private void init(Document document) throws IOException {

ROOT = document.getRootElement();

BATCHCLASSID_VALUE = ROOT.getChildText(“BatchClassIdentifier”);
BATCHLOCALPATH_VALUE = ROOT.getChildText(“BatchLocalPath”);
BATCHINSTANCEID_VALUE = ROOT.getChildText(“BatchInstanceIdentifier”);
DLF_MAPPING_PROPS = readDLFConfigProperties(“DLF-Attribute-mapping.properties”);
CMIS_EXPORT_PROPS = readKeyWordProperties(“CMISExportConfig.properties”);

REPOSITORYUSERNAME = CMIS_EXPORT_PROPS.getProperty(“REPOSITORYUSERNAME”);
REPOSITORYPASSWORD = CMIS_EXPORT_PROPS.getProperty(“REPOSITORYPASSWORD”);
REPOSITORYURL = CMIS_EXPORT_PROPS.getProperty(“REPOSITORYURL”);
CMIS_EXPORT_PROPS.getProperty(“REPOSITORYFOLDERNAME”);
}

private Properties readDLFConfigProperties(String fileName) throws IOException {
Properties prop = new Properties();
String pathToScriptConfig = BATCHLOCALPATH_VALUE.replaceFirst(“ephesoft-system-folder”, “”) + BATCHCLASSID_VALUE
+ File.separator + “cmis-plugin-mapping”;
String propFileName = pathToScriptConfig + File.separator + fileName;
String propFileContents = readPropertyFileContents(propFileName);

prop.load(new StringReader(propFileContents.replace(“\\”, “\\\\”)));
return prop;

}

private Properties readKeyWordProperties(String fileName) throws IOException {

Properties prop = new Properties();
String pathToScriptConfig = BATCHLOCALPATH_VALUE.replaceFirst(“ephesoft-system-folder”, “”) + BATCHCLASSID_VALUE
+ File.separator + “script-config”;
String propFileName = pathToScriptConfig + File.separator + fileName;

String propFileContents = readPropertyFileContents(propFileName);

prop.load(new StringReader(propFileContents.replace(“\\”, “\\\\”)));
return prop;
}

@SuppressWarnings(“resource”)
private String readPropertyFileContents(String path) throws FileNotFoundException {

String content = new Scanner(new File(path)).useDelimiter(“\\Z”).next();
return content;
}

@SuppressWarnings(“unchecked”)
public List<Element> getDesiredDocTypeList(Document document, String desiredDocType) {
List<Element> desiredDocList = new ArrayList<Element>();

List<Element> docList = ROOT.getChild(“Documents”).getChildren(“Document”);
for (int i = 0; i < docList.size(); i++) {
Element doc = docList.get(i);
String docType = doc.getChildText(“Type”);
if (docType.equals(desiredDocType)) {
desiredDocList.add(doc);
}
}
return desiredDocList;
}

@SuppressWarnings(“unchecked”)
public static List<String> getDocTypeList(Document document) {
List<String> docListList = new ArrayList<String>();
Element root = document.getRootElement();
List<Element> docList = root.getChild(“Documents”).getChildren(“Document”);
for (int i = 0; i < docList.size(); i++) {
Element doc = docList.get(i);
String docType = doc.getChildText(“Type”);
if (!docListList.contains(docType))
docListList.add(docType);
}
return docListList;
}

private void writeDebug(String Data) {
if (IS_DEBUG) {
Date now = new Date();
System.out.println(“**o(^_^)o** ” + now.toString() + ” : ” + Data);
}
LOGGER.info(“**o(^_^)o** ” + Data);
}

public static void main(String args[]) {
String filePath = “C:/Users/Hotmannj/Music/BI5_batch.xml”;
try {
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(filePath);

ScriptExport se = new ScriptExport();
se.execute(doc, null, null);
} catch (Exception x) {
}
}

public void getIndexFieldValues() {

for (int i = 0; i < valueMapList.size(); i++) {
Map<String, String> mapValue = valueMapList.get(i);
vNum = mapValue.get(“VendorNumber”);
vAdd = mapValue.get(“VendorAddress”);
vCity = mapValue.get(“VendorCity”);
vState = mapValue.get(“VendorState”);
vZip = mapValue.get(“VendorZip”);
invNum = mapValue.get(“InvoiceNumber”);
po = mapValue.get(“PONumber”);
acct = mapValue.get(“AccountNumber”);
shipTo = mapValue.get(“ShipToName”);
shipAdd = mapValue.get(“ShipToAddress”);
shipCity = mapValue.get(“ShipToCity”);
shipState = mapValue.get(“ShipToState”);
shipZip = mapValue.get(“ShipToZip”);
billTo = mapValue.get(“BillToName”);
billAdd = mapValue.get(“BillToAddress”);
billCity = mapValue.get(“BillToCity”);
billState = mapValue.get(“BillToState”);
billZip = mapValue.get(“BillToZip”);
billFor = mapValue.get(“BillFor”);
billForA = mapValue.get(“BillForAddress”);
billForC = mapValue.get(“BillForCity”);
billForS = mapValue.get(“BillForState”);
billForZ = mapValue.get(“BillForZip”);
project = mapValue.get(“Project”);
contractor = mapValue.get(“Contractor”);

if (mapValue.get(“InvoiceDate”) != null) {
DateFormat df = new SimpleDateFormat(“MM/dd/yyyy”);
try {
invDate = df.parse(mapValue.get(“InvoiceDate”));
total = Double.parseDouble(mapValue.get(“TotalAmount”).replace(“,”, “”));
vendor = mapValue.get(“VendorName”).replace(“&”, “and”);
} catch (ParseException e) {
e.printStackTrace();
}
} else {
invDate = null;
}
}
}

// Index Fields from Batch.xml
String vendor = null;
String vNum = null;
String vAdd = null;
String vCity = null;
String vState = null;
String vZip = null;
String invNum = null;
Date invDate = null;
String po = null;
String acct = null;
Double total = null;
String shipTo = null;
String shipAdd = null;
String shipCity = null;
String shipState = null;
String shipZip = null;
String billTo = null;
String billAdd = null;
String billCity = null;
String billState = null;
String billZip = null;
String billFor = null;
String billForA = null;
String billForC = null;
String billForS = null;
String billForZ = null;
String project = null;
String contractor = null;

}

CMISExportConfig.properties

# Connection details for the CMIS Server
REPOSITORYUSERNAME=acme\joeuser
REPOSITORYPASSWORD=Password123
REPOSITORYURL=http://acmeshrpt/sites/ACTS/_vti_bin/cmis/rest/76ad627b-8384-42cc-81ca-a748c5905895?getRepositoryInfo

< Back|KB Main Page | Next KB Article >

Was this article helpful to you?

Walter Lee