0

我正在尝试编写一个 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()中的方法。如您所见,它包含我用于调试目的的语句。该语句返回,并且在该语句中替换时唯一不返回 null 的方法是。此外,该方法中的 try-catch 块总是捕获 a因为循环 contains , temp 是一个应该包含方法返回的变量。System.out.println(workItems[k].getWorkRecords());nullWorkItemgetUri()NullPointerExceptionfortemp.lengthgetWorkRecords()

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

有没有遇到过这个问题的 Polarion 专家?有谁知道我做错了什么?我倾向于认为这是一个基于情况的错误。

4

1 回答 1

1

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

于 2013-07-25T22:38:01.563 回答