gpt4 book ai didi

java - Polarion WorkItem 类 getter 方法返回 null

转载 作者:行者123 更新时间:2023-12-01 14:18:55 31 4
gpt4 key购买 nike

我正在尝试编写一个 Java 程序,从 Polarion 获取工作记录信息并将其写入 DAT 文件以供以后使用。

我已成功连接到我们的服务器并检索了 WorkItem 对象,但所有 getter 方法(除了 getUri() 之外)似乎都不起作用,这造成了问题,因为我需要使用 WorkItem 类的 getWorkRecords() 方法来满足项目的要求。

我已经在我们的主 Polarion 服务器和“临时”服务器上尝试了该类的所有 getter 方法,我们将其用作诸如我正在尝试编写的程序及其上的程序之类的测试区域我有完全权限。

无论权限如何,我只是查询我创建并分配给自己的一些虚拟工作项,因此不应该有任何权限问题,因为我只是尝试查看我自己的工作项。

以下是该程序的代码:

package test;
//stg= 10.4.1.50
//main= 10.4.1.10


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.xml.rpc.ServiceException;

import com.polarion.alm.ws.client.WebServiceFactory;
import com.polarion.alm.ws.client.session.SessionWebService;
import com.polarion.alm.ws.client.tracker.TrackerWebService;
import com.polarion.alm.ws.client.types.tracker.WorkItem;
import com.polarion.alm.ws.client.types.tracker.WorkRecord;


public class WorkrecordImporter {

private WebServiceFactory factory;
private TrackerWebService trackerService;
private SessionWebService sessionService;
private WorkItem[] workItems;
private ArrayList<WorkRecord> workRecords;
private String password = //insertpasswordhere;//no peaking

public WorkrecordImporter()throws ServiceException, IOException, ClassNotFoundException{

initializeFields();//initializes all of the Web Services and arrays
//step one
getWorkItems();
//readDATFile();
//step two
getWorkRecords();
//$$$
printWorkRecords();
//$$$$$
writeDATFile();

}
//you know what this does.
public void printWorkRecords(){
for(int temp = 0; temp < workItems.length; temp++){

System.out.println(workItems[temp].getUri().toString());
}
}
public void writeDATFile() throws IOException{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:\\Users\\sweidenkopf\\workspace\\test\\filename.dat"));
try {
out.writeObject(workRecords);
} finally {
// Make sure to close the file when done
out.close();
}
}
/**
* This method sets up the WebServiceFactory at the specified URL. It then initializes the web services, logs in the
* session service, and initializes the arrays.
* @throws MalformedURLException
* @throws ServiceException
* @throws RemoteException
*/
public void initializeFields() throws MalformedURLException, ServiceException, RemoteException{
factory = new WebServiceFactory("//insert url here");
trackerService = factory.getTrackerService();
sessionService = factory.getSessionService();
sessionService.logIn("sweidenkopf", password);
workRecords = new ArrayList<>();
}
public void getWorkItems()throws MalformedURLException, ServiceException, RemoteException{
sessionService.beginTransaction();
workItems = trackerService.queryWorkItems("workRecords.user.id:sweidenkopf", null, null);
sessionService.endTransaction(false);
}
public void getWorkRecords()throws MalformedURLException, ServiceException, RemoteException{
sessionService.beginTransaction();
for(int k = 0; k < workItems.length; k++)
{System.out.println("This is working");
try{//not every work item has work records
System.out.println(workItems[k].getWorkRecords());
WorkRecord[] temp;
temp = workItems[k].getWorkRecords();
for(int x = 0; x < temp.length; x++){
System.out.println("This is working fine");
workRecords.add(temp[x]);
}
}catch(NullPointerException e){
System.out.println("I must regretfully inform you that I have grave news; your endeavors have not been successfull.");
continue;
}
}
System.out.println(workRecords.toString());
sessionService.endTransaction(false);
}
public void readDATFile() throws FileNotFoundException, IOException, ClassNotFoundException{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("C:\\Users\\sweidenkopf\\workspace\\test\\filename.dat"));

try{
Object temp = in.readObject();
workRecords = (ArrayList) temp;
}
finally{
in.close();
}
}
}

最重要的部分当然是我的代码中的getWorkRecords()方法。如您所见,它包含我用于调试目的的语句 System.out.println(workItems[k].getWorkRecords());。此语句返回 null,而在该语句中替换时唯一不返回 null 的 WorkItem 方法是 getUri()。此外,该方法中的 try-catch block 始终捕获 NullPointerException,因为 for 循环包含 temp.length,temp 是一个变量,应包含 getWorkRecords() 方法的返回值。

总结这里的主要问题是我无法从 getWorkRecords()WorkItem 的任何其他 getter 方法返回任何内容类(class)。这令人费解,因为 getUri() 方法正在成功执行,因为我的代码中的 printWorkRecords() 方法成功打印了所有 WorkItem 的 URI code> 从我的查询中返回对象。

有没有任何 Polarion 专家以前遇到过这个问题?有谁知道我做错了什么?根据具体情况,我倾向于认为这是一个错误。

最佳答案

如果您查看我对 queryWorkItems() 方法的调用,您会注意到在查询参数之后我指定了两个空参数。第一个指定您希望如何对返回的工作项进行排序(目前这无关紧要),但第二个是一个名为 fieldsString 数组,用于指定哪个您希望与 WorkItems 本身一起返回的 WorkItem 字段。显然,如果您像我一样将其设置为 null,它默认只返回 URI。对于其他内容,例如作者、工作记录和类型,您必须将它们放入 String 数组中,并在调用该方法时传递该数组。

关于java - Polarion WorkItem 类 getter 方法返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17821417/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com