Hi All,
I am trying to access the existing file from KDB using method cs.download(documentId, ContentConstants.VERSION_CURRENT, Boolean.valueOf(false)),
I'm facing a error :
ERROR com.appiancorp.connectedsystems.http.execution.AppianHttpRequestExecutor - ConnectorRuntimeException [title=The requested URL cannot be found, The external system did not find the requested URL or is refusing to allow access]
Can some one help me on this.
Thanks
Discussion posts and replies are publicly visible
Agree with raghuvarann, please check the security privileges for the users trying to access the file.
Ok, Please share me those details. And in addition I have shared a sample code for an alternative API which I have always used.
If you just want read/write a appian document, you can do it through this java api. I have used this api in all the smartservices which involves file manipulation, And it works fine
Long documentId = 123L; /* Input document ID */ String filePath = cs.getInternalFilename(_cs.getVersion(documentId,ContentConstants.VERSION_CURRENT)); /* you will get something like, C:\appian\_admin\accdocs1\1\10000001.pdf */ File jAppianFile = new File(filePath);
Thanks,
Raghu
I'm attaching the code, this may help you . package com.xyz.plugin; import java.io.File; import java.io.FileOutputStream; import java.util.Scanner; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import com.appiancorp.suiteapi.common.Name; import com.appiancorp.suiteapi.content.ContentConstants; import com.appiancorp.suiteapi.content.ContentService; import com.appiancorp.suiteapi.knowledge.Document; import com.appiancorp.suiteapi.knowledge.DocumentDataType; import com.appiancorp.suiteapi.process.exceptions.SmartServiceException; import com.appiancorp.suiteapi.process.framework.AppianSmartService; import com.appiancorp.suiteapi.process.framework.Input; import com.appiancorp.suiteapi.process.framework.Required; import com.appiancorp.suiteapi.process.framework.SmartServiceContext; import com.appiancorp.suiteapi.process.palette.IdentityManagement; import com.xyz.plugin.model.Type2; @IdentityManagement public class xyzDecisionTable extends AppianSmartService { protected final SmartServiceContext smartServiceCtx; protected final ContentService cs; private static final Logger LOG = Logger.getLogger(xyzDecisionTable.class); private Long sourceDocument; private Long resultDocument; public xyzDecisionTable(SmartServiceContext smartServiceCtx, ContentService cs) { super(); LOG.info("Super call"); this.smartServiceCtx = smartServiceCtx; this.cs = cs; } @Override public void run() throws SmartServiceException { // TODO Auto-generated method stub try { LOG.info("Pradeep : " + "Run started"); String[] ruleSet = new String[] { "RuleSet", "rules" }; String[] imports = new String[] { "import", "com.appian.test.Type2" }; String[] ruleTable = new String[] { "RuleTableMctRules" }; String[] condition = new String[] { "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "CONDITION", "ACTION" }; String[] objectOftype = new String[] { "MctType2:Type2" }; String[] params = new String[] { "recordType==\"$param\"", "arrivalStation==\"$param\"", "time==\"$param\"", "internationalOrDomesticStatus==\"$param\"", "depatureStation==\"$param\"", "arrivalCarrier==\"$param\"", "arrivalCodeShareIndicator==\"$param\"", "arrivalCodeShareOperatingCarrier==\"$param\"", "depatureCarrier==\"$param\"", "depatureCodeShareIndicator==\"$param\"", "depatureCodeShareOperatingCarrier==\"$param\"", "arrivalAircraftType==\"$param\"", "arrivalAircraftBody==\"$param\"", "depatureAircraftType==\"$param\"", "epatureAircraftBody==\"$param\"", "arrivalTerminal==\"$param\"", "depatureTerminal==\"$param\"", "previousCountry==\"$param\"", "previousStation==\"$param\"", "nextCountry==\"$param\"", "nextStation==\"$param\"", "arrivalFlightNumberRangeStart==\"$param\"", "arrivalFlightNumberRangeEnd==\"$param\"", "depatureFlightNumberRangeStart==\"$param\"", "depatureFlightNumberRangeEnd==\"$param\"", "previousState==\"$param\"", "nextState==\"$param\"", "previousRegion==\"$param\"", "nextRegion==\"$param\"", "effectiveFromDate==\"$param\"", "effectiveToDate==\"$param\"", "carrierSupression==\"$param\"", "supressionIndicator==\"$param\"", "supressionRegion==\"$param\"", "supressionCountry==\"$param\"", "supressionState==\"$param\"", "submittingCarrierIdentifier==\"$param\"", "filingDate==\"$param\"", "actionIndicator==\"$param\"", "spare==\"$param\"", "recordSerialNumber==\"$param\"", "MctType2.setRunTimeValue(\"$param\");" }; Document d = xyzDecisionTable.getDocumentFromAppian(cs, sourceDocument); String path = xyzDecisionTable.getInternalFilePath(cs, d); // FileOutputStream fileOut = new FileOutputStream(FILE_NAME); File file = new File(path); LOG.info("uploaded file path : " + path); SXSSFWorkbook workbook = new SXSSFWorkbook(100); Sheet sh = workbook.createSheet(); Row ruleSetRow = sh.createRow(0); for (int i = 0; i < ruleSet.length; i++) { Cell cell = ruleSetRow.createCell(i); cell.setCellValue(ruleSet[i]); } Row importsRow = sh.createRow(1); for (int i = 0; i < imports.length; i++) { Cell cell = importsRow.createCell(i); cell.setCellValue(imports[i]); } Row ruleTableRow = sh.createRow(2); for (int i = 0; i < ruleTable.length; i++) { Cell cell = ruleTableRow.createCell(i); cell.setCellValue(ruleTable[i]); } Row conditionRow = sh.createRow(3); for (int i = 0; i < condition.length; i++) { Cell cell = conditionRow.createCell(i); cell.setCellValue(condition[i]); } Row objectOftypeRow = sh.createRow(4); for (int i = 0; i < objectOftype.length; i++) { Cell cell = objectOftypeRow.createCell(i); cell.setCellValue(objectOftype[i]); } sh.addMergedRegion(new CellRangeAddress(4, 4, 0, 40)); Row paramsRow = sh.createRow(5); for (int i = 0; i < params.length; i++) { Cell cell = paramsRow.createCell(i); cell.setCellValue(params[i]); } int rowNum = 6; Scanner sc1 = new Scanner(file); while (sc1.hasNextLine()) { String line = sc1.nextLine(); Type2 type2 = new Type2(); type2.setRecordType("" + line.charAt(0)); type2.setArrivalStation(line.substring(1, 4)); type2.setTime(line.substring(4, 8)); type2.setInternationalOrDomesticStatus(line.substring(8, 10)); type2.setDepatureStation(line.substring(10, 13)); type2.setArrivalCarrier(line.substring(13, 15)); type2.setArrivalCodeShareIndicator(line.substring(15, 16)); type2.setArrivalCodeShareOperatingCarrier(line.substring(16, 18)); type2.setDepatureCarrier(line.substring(18, 20)); type2.setDepatureCodeShareIndicator(line.substring(20, 21)); type2.setDepatureCodeShareOperatingCarrier(line.substring(21, 23)); type2.setArrivalAircraftType(line.substring(23, 26)); type2.setArrivalAircraftBody(line.substring(26, 27)); type2.setDepatureAircraftType(line.substring(27, 30)); type2.setDepatureAircraftBody(line.substring(30, 31)); type2.setArrivalTerminal(line.substring(31, 33)); type2.setDepatureTerminal(line.substring(33, 35)); type2.setPreviousCountry(line.substring(35, 37)); type2.setPreviousStation(line.substring(37, 40)); type2.setNextCountry(line.substring(40, 42)); type2.setNextStation(line.substring(42, 45)); type2.setArrivalFlightNumberRangeStart(line.substring(45, 49)); type2.setArrivalFlightNumberRangeEnd(line.substring(49, 53)); type2.setDepatureFlightNumberRangeStart(line.substring(53, 57)); type2.setDepatureFlightNumberRangeEnd(line.substring(57, 61)); type2.setPreviousState(line.substring(61, 63)); type2.setNextState(line.substring(63, 65)); type2.setPreviousRegion(line.substring(65, 68)); type2.setNextRegion(line.substring(68, 71)); type2.setEffectiveFromDate(line.substring(71, 78)); type2.setEffectiveToDate(line.substring(78, 85)); type2.setCarrierSupression(line.substring(85, 86)); type2.setSupressionIndicator(line.substring(86, 87)); type2.setSupressionRegion(line.substring(87, 90)); type2.setSupressionCountry(line.substring(90, 92)); type2.setSupressionState(line.substring(92, 94)); type2.setSubmittingCarrierIdentifier(line.substring(94, 96)); type2.setFilingDate(line.substring(96, 103)); type2.setActionIndicator(line.substring(103, 104)); type2.setSpare(line.substring(104, 194)); type2.setRecordSerialNumber(line.substring(194, 200)); type2.setRunTimeValue("" + rowNum); Row row = sh.createRow(rowNum++); row.createCell(0).setCellValue(type2.getRecordType()); row.createCell(1).setCellValue(type2.getArrivalStation()); row.createCell(2).setCellValue(type2.getTime()); row.createCell(3).setCellValue(type2.getInternationalOrDomesticStatus()); row.createCell(4).setCellValue(type2.getDepatureStation()); row.createCell(5).setCellValue(type2.getArrivalCarrier()); row.createCell(6).setCellValue(type2.getArrivalCodeShareIndicator()); row.createCell(7).setCellValue(type2.getArrivalCodeShareOperatingCarrier()); row.createCell(8).setCellValue(type2.getDepatureCarrier()); row.createCell(9).setCellValue(type2.getDepatureCodeShareIndicator()); row.createCell(10).setCellValue(type2.getDepatureCodeShareOperatingCarrier()); row.createCell(11).setCellValue(type2.getArrivalAircraftType()); row.createCell(12).setCellValue(type2.getArrivalAircraftBody()); row.createCell(13).setCellValue(type2.getDepatureAircraftType()); row.createCell(14).setCellValue(type2.getDepatureAircraftBody()); row.createCell(15).setCellValue(type2.getArrivalTerminal()); row.createCell(16).setCellValue(type2.getDepatureTerminal()); row.createCell(17).setCellValue(type2.getPreviousCountry()); row.createCell(18).setCellValue(type2.getPreviousStation()); row.createCell(19).setCellValue(type2.getNextCountry()); row.createCell(20).setCellValue(type2.getNextStation()); row.createCell(21).setCellValue(type2.getArrivalFlightNumberRangeStart()); row.createCell(22).setCellValue(type2.getArrivalFlightNumberRangeEnd()); row.createCell(23).setCellValue(type2.getDepatureFlightNumberRangeStart()); row.createCell(24).setCellValue(type2.getDepatureFlightNumberRangeEnd()); row.createCell(25).setCellValue(type2.getPreviousState()); row.createCell(26).setCellValue(type2.getNextState()); row.createCell(27).setCellValue(type2.getPreviousRegion()); row.createCell(28).setCellValue(type2.getNextRegion()); row.createCell(29).setCellValue(type2.getEffectiveFromDate()); row.createCell(30).setCellValue(type2.getEffectiveToDate()); row.createCell(31).setCellValue(type2.getCarrierSupression()); row.createCell(32).setCellValue(type2.getSupressionIndicator()); row.createCell(33).setCellValue(type2.getSupressionRegion()); row.createCell(34).setCellValue(type2.getSupressionCountry()); row.createCell(35).setCellValue(type2.getSupressionState()); row.createCell(36).setCellValue(type2.getSubmittingCarrierIdentifier()); row.createCell(37).setCellValue(type2.getFilingDate()); row.createCell(38).setCellValue(type2.getActionIndicator()); row.createCell(39).setCellValue(type2.getSpare()); row.createCell(40).setCellValue(type2.getRecordSerialNumber()); row.createCell(41).setCellValue(type2.getRunTimeValue()); type2 = null; if (rowNum % 100 == 0) { ((SXSSFSheet) sh).flushRows(100); } } sc1.close(); LOG.info("Rules File createed"); // creates a document // AppianUtils.createDocumentInAppian(cs, path, null, sourceDocument, // d.getName(), d.getDescription()); String fileName = FilenameUtils.getBaseName(path); LOG.info("Pradeep " + fileName); Document newDoc = null; Long newDocumentId = null; newDoc = new Document(d.getCurrentContentId(), "rules", "xlsx"); newDoc.setState(ContentConstants.STATE_PUBLISHED); newDocumentId = cs.create(d, ContentConstants.UNIQUE_NONE); newDoc.setId(newDocumentId); LOG.info("Pradeep " + newDocumentId); String dpath = xyzDecisionTable.getInternalFilePath(cs, newDoc); LOG.info("Pradeep " + dpath); File f = new File(dpath); FileOutputStream out = new FileOutputStream(f); workbook.write(out); // fileOut.close(); out.close(); workbook.close(); resultDocument = newDocumentId; } catch (Exception e) { LOG.info("Pradeep Error Occured"); LOG.info(e); } } public static Document getDocumentFromAppian(ContentService cs, Long documentId) throws Exception { Document[] docs = (Document[]) cs.download(documentId, ContentConstants.VERSION_CURRENT, Boolean.valueOf(false)); if (docs.length > 0) { LOG.info("Document size in k : " + docs[0].getSizeInKB()); LOG.info("Document : " + docs[0]); LOG.info("Document Id : " + documentId); return docs[0]; } else { return null; } } public static String getInternalFilePath(ContentService cs, Document d) throws Exception { String path = cs.getInternalFilename(d.getId()); if (StringUtils.isBlank(path)) { path = d.getInternalFilename(); } return path; } @Input(required = Required.ALWAYS) @Name("sourceDocument") @DocumentDataType public void setSourceDocument(Long val) { this.sourceDocument = val; } @Name("resultDocument") @DocumentDataType public Long getResultDocument() { return resultDocument; } }
** UPDATED THE EMBEDDED CODE IN PREVIOUS REPLY **