如何使用Java API从完整性PTC项目中提取附件

时间:2018-04-04 17:44:39

标签: mks-integrity

我试图从我的Windows PC上提取Linux服务器上的完整性PTC项目的附件,但它一直给我错误。完全相同的命令在命令行中工作

IntegrationPoint integrationPoint =
    IntegrationPointFactory.getInstance().createIntegrationPoint(
        hostName,
        port,
        APIVersion.API_4_16);

System.out.println("Start download Attachment");
// Start the Integrity client.
integrationPoint.setAutoStartIntegrityClient(true);

// Connect to the Integrity server.
Session session = integrationPoint.createSession(username, password);
Command command = new Command(Command.IM, "extractattachments");
command.addOption(new Option("issue", itemID));
command.addOption(new Option("field", "Text Attachments"));
command.addSelection(attachment);
Response response = session.createCmdRunner().execute(command);

我收到错误消息

尝试获取下一个名称时遇到错误:文件路径必须植根于/export/home/ptc/Integrity/ILMServer11.0/data/tmp:当前文件为/export/home/ptc/Integrity/ILMServer11.0 /bin/C:\Workspace\document/bear.jpg

无论何时我将cwd添加到命令中它只是附加我在/ bin之后放置的内容它说它是InvalidCommandSelectionException和CommandException

1 个答案:

答案 0 :(得分:1)

您错过了outputFile命令中的extractattachments选项。

这段代码按我预期的方式工作......

IntegrationPointFactory ipfact = IntegrationPointFactory.getInstance();

IntegrationPoint ip = ipfact.createIntegrationPoint(hostname, port, APIVersion.API_4_16);

Session session = ip.createNamedSession("test", APIVersion.API_4_16, user, passwd);

CmdRunner cr = session.createCmdRunner();

Command cmd = new Command(Command.IM, "extractattachments");
cmd.addSelection(attachmentName);
cmd.addOption(new Option("issue", issueid));
cmd.addOption(new FileOption("outputFile", "d:/data/" + attachmentName));

cr.execute(cmd);

cr.release();

ip.release();