JavaScript Error in BIRT - java

I have been assigned to clean up a project for a client that uses BIRT reporting. I have fixed most of the issues but I still have one report that is not working and is returning an error. The error is:
Row (id = 1467):
+ There are errors evaluating script "var fileName = row["Attached_File"];
params["HyperlinkParameter"].value = ImageDecoder.decodeDocs(row["Ecrash_Attach"],fileName);":
Wrapped java.lang.NullPointerException (/report/body/table[#id="61"]/detail/row[#id="70"]/cell[#id="71"]/grid[#id="1460"]/row[#id="1462"]/cell[#id="1463"]/table[#id="1464"]/detail/row[#id="1467"]/method[#name="onCreate"]#2)
I can post the full stack trace if someone wants it but for now I will omit it since it is very long.
Here is the source of the decodeDocs method:
public static String decodeDocs(byte[] source, String fileName) {
String randName = "";
byte[] docSource = null;
if ( Base64.isArrayByteBase64(source) ){
docSource = Base64.decodeBase64(source);
}
documentZipPath = writeByteStreamToFile(source);
randName = writeByteStreamToFile(docSource, fileName);
return randName;
}
I am pretty well lost on this one. The error looks to be telling me there is an error on line two of the script which is:
var fileName = row["Attached_File"];
params["HyperlinkParameter"].value = ImageDecoder.decodeDocs(row["Ecrash_Attach"],fileName);
This is written in the OnCreate method of the report. Any help, even clues would be greatly appreciated. If you would like to see the report just ask and I will post the xml for it.

A common mistake I make in BIRT is to access the value of a null report parameter.
In your case, could params["HyperlinkParameter"] be null?

Related

Issue with storing image files for profile pictures

I'm doing a coursework project for university and I'm in charge of getting the profile system functioning. Our lecturer has given us some sample code to get a file-upload working which I'm going to use for the user's profile picture however even though my code looks to be very similar I just can't seem to get it working. The issue is that the file won't actually create and save in my project, yet the code my lecturer gave me does!
Here is the code the lecturer gave me:
NewsStory newsstory = new NewsStory();
newsstory.uniqueid = "story_"+System.currentTimeMillis();
newsstory.dateItWasPublished = System.currentTimeMillis();
newsstory.title = toProcess.params.get("title");
newsstory.description = toProcess.params.get("description");
newsstory.journalists.add(toProcess.params.get("journalist"));
newsstory.filepathToImage = toProcess.params.get("fileupload");
File uploaded = new File(newsstory.filepathToImage);
int ind = newsstory.filepathToImage.lastIndexOf('.');
String extension = newsstory.filepathToImage.substring(ind);
uploaded.renameTo(new File("httpdocs/"+newsstory.uniqueid+extension));
newsstory.filepathToImage = newsstory.uniqueid+extension;
//At this point you would normally add the newsstory to the database
MVMap<String, NewsStory> newsStories = db.s.openMap("NewsStories");
newsStories.put(newsstory.uniqueid, newsstory);
This basically takes in a String from a fileupload paramater passed in through a form and runs the code below. Here is my code:
user.userEmail = toProcess.params.get("email");
user.profilePicturePath = toProcess.params.get("filepath");
System.out.println(user.profilePicturePath);
File uploaded = new File(user.profilePicturePath);
int ind = user.profilePicturePath.lastIndexOf('.');
String extension = user.profilePicturePath.substring(ind);
uploaded.renameTo(new File("httpdocs/"+user.username+"ProfilePicture"+extension));
user.profilePicturePath = user.username+"ProfilePicture"+extension;
System.out.println(user.profilePicturePath);
users.put(user.username, user);
db.commit();
Does anyone know why I might be having this issue?

Create BE Initiative, BE Feature and CPM Feature using Rally Rest Client in Java

We are trying to automate the project migration from one Rally workspace to other. Everything seems to work fine like we are able to migrate project and related releases/iterations/userstories/tasks from one workspace to another workspace.
But while trying to migrate BE Initiative/BE Feature/CPM Feature we are getting some exception related to Null Pointer exception but the error we are getting in Response doesn't seem to give much info.
A sample of code is -
String oldProjectObjectId = "12345";
String newProjectObjectId = "67890";
String oldRallyWorkspaceObjectId = "32145";
String newRallyWorkspaceObjectId = "67894";
QueryResponse beInitiativeResponse = queryRally("portfolioitem/beinitiative", "/project/"+this.oldProjectObjectId, "/workspace/"+this.oldRallyWorkspaceObjectId);
int beInitiativeCount = beInitiativeResponse.getTotalResultCount();
if(beInitiativeCount >0){
JsonArray initiativeArray = beInitiativeResponse.getResults();
for(int i=0; i< initiativeArray.size();i++){
JsonObject beInitiativeObject = initiativeArray.get(i).getAsJsonObject();
String oldBeInitiativeObjectId = beInitiativeObject.get("ObjectID").getAsString();
String oldBeInitiativeName = beInitiativeObject.get("_refObjectName").getAsString();
String owner = getObjectId(beInitiativeObject, "Owner");
JsonObject BeInitiativeCreateObject = getJsonObject(oldBeInitiativeName, "/project/"+this.newProjectObjectId, "/workspace/"+this.newRallyWorkspaceObjectId, owner);
CreateResponse beInitiativeCreateResponse = createInRally("portfolioitem/beinitiative", BeInitiativeCreateObject);
if(beInitiativeCreateResponse.wasSuccessful()){
String newBeInitiativeObjectId = beInitiativeCreateResponse.getObject().get("ObjectID").getAsString();
String mapKey = oldBeInitiativeObjectId;
String mapValue= newBeInitiativeObjectId;
this.beInitiativesHashMap.put(mapKey, mapValue);
}
else{
String[] errorList;
errorList = beInitiativeCreateResponse.getErrors();
for (int j = 0; j < errorList.length; j++) {
System.out.println(errorList[j]);
}
}
}
}
queryRally and createInRally functions use Rally rest client to fetch and create the required projects and associated attributes like releases, iterations etc.
After executing CreateResponse beInitiativeCreateResponse = createInRally("portfolioitem/beinitiative", BeInitiativeCreateObject); when it's trying to execute if(beInitiativeCreateResponse.wasSuccessful()) it is instead going to else block and thus printing the below mentioned error.
An unexpected error has occurred.We have recorded this error and will begin to investigate it. In the meantime, if you would like to speak with our Support Team, please reference the information below:java.lang.NullPointerException2017-12-05 11:01 AM PST America/Los_Angeles
But the important point that is when trying to migrate projects and it's related attributes like release/iterations etc. withing same Rally workspace the above piece of code works just fine.
Update1:
While analysing the issue I made the following observations -
The workspace in which I am trying to create the BeInitiative doesn't have BEinitiative, Be Feature, CPM Feature options in Portfolio items dropdown. Rather it has Theme, Initiative and Feature options in it.
Therefore, I think I was getting the previouly mentioned error. Now I made the following changes to the code.
CreateResponse beInitiativeCreateResponse = createInRally("portfolioitem/theme", themeCreateObject);
So now instead of creating the BEInitiative I am trying to create the theme only in new workspace but getting the following error -
Requested type name \"/portfolioitem/theme\" is unknown.
The object that i am passing to CreateResponse function is -
{"Name":"xyz","Project":"/project/1804","Workspace":"/workspace/139"}
Also code for createInRally function is as mentioned below -
public CreateResponse createInRally( String query, JsonObject object) throws IOException{
CreateRequest createRequest = new CreateRequest(query, object);
CreateResponse createResponse = restApi.create(createRequest);
return createResponse;
}
The Unknown Type error was occurring as a result of not passing the workspace's object id in which we were trying to create the portfolio item.
So after modifying the createInRally function to include the workspace object id we were able to create the initiative portfolio item.
The modified createInRally function is as shown below-
CreateRequest createRequest = new CreateRequest(query, object);
createRequest.addParam("workspace", "/workspace/1333333333");
CreateResponse createResponse = restApi.create(createRequest);
return createResponse;
So this is definitely an error in the web services api. You should never get 500 responses with an unhandled nullpointer. My initial guess is that when you're creating your new object some field on it is still referencing an object in the old workspace, and when we try to correctly hook up all the associations it fails to read one of those objects in the new workspace. Can you provide some more information about what your actual object you're sending to create looks like? Specifically what object relationships are you including (that may not be valid in the new workspace)?

Cannot report new bugs to Bugzilla via J2Bugzilla

I tried searching this topic but nothing seems to cover my exact problem. I have a java and jsp program where I would like to be able to report bugs to my Bugzilla installation. I have been testing the method I created against the Bugzilla landfill first but I cant get it to work.
My problem is that I have tried all the sample code and I still end up with the same error which seems to stem from executeMethod().
Here is the sample of my jsp page which calls the method of my java class:
<jsp:useBean id="error" class="bug.TestClass" scope="session"/>
<% String result = error.reportBug("error");
out.print(result);%>
The Java method, which I have blocked out the username and password to Bugzillla landfill but I have checked and they are correct:
public static String reportBug(String bugError) {
try {
BugzillaConnector conn = new BugzillaConnector();
conn.connectTo("http://landfill.bugzilla.org/");
BugzillaMethod logIn = new LogIn ("*****#hotmail.com", "****");
conn.executeMethod(logIn);
BugFactory factory = new BugFactory();
Bug bug = factory.newBug()
.setOperatingSystem("WINDOWS")
.setPlatform("PC")
.setPriority("P1")
.setProduct("FoodReplicator")
.setComponent("Salt")
.setSummary(bugError)
.setVersion("1.0")
.setDescription("It doesn't work.")
.createBug();
ReportBug report = new ReportBug(bug);
conn.executeMethod(report);
int id = report.getID();
result += "Successful";
} catch (Exception e) {
result = e.toString();
}
return result;
}
And here is the error I am getting when I open the jsp page:
com.j2bugzilla.base.BugzillaException: An unknown error was encountered; fault code: 0
I have been working on this for days so any help would be really appreciated. Thanks
I met the same issue. Then I update j2bugzilla jar from 2.0 to 2.2.1. Then it works.

comparing two baselines in RTC/Jazz with plain java

I try to compare two snapshots from one stream programamtically in plain java...
Step 1: getting my stream (working)
IWorkspaceConnection stream = null;
List<IWorkspaceConnection> list = RtcAdapter.inst().getStreams(); //my library
for (IWorkspaceConnection connection: list){
if (connection.getName().equalsIgnoreCase("myStreamName") ){
stream = connection;
break;
}
}//now we have found our stream
Step 2: getting base lines (working)
List<IBaselineSet> snapShotList =
RtcAdapter.inst().getSnapShotsFromStream(stream);
IBaselineSet snapShot0 = null;
IBaselineSet snapShot1 = null;
for (IBaselineSet snapShot: snapShotList){
if (snapShot.getName().equalsIgnoreCase("mySnapShotName0") ){
snapShot0 = snapShot;
}
if (snapShot.getName().equalsIgnoreCase("mySnapShotName1") ){
snapShot1 = snapShot;
}
}//now we've got also my two snapShots
Step 3: comparing each other (not working)
IUpdateReport report =
workspaceManager.compareBaselineSetConfigurations(
snapShot0, snapShot0, stream.getComponents(), monitor);
my report is empty... --annoying--
report=com.ibm.team.scm.common.internal.dto.impl.UpdateReportImpl#1de5a20 (stateBefore: <unset>, stateAfter: <unset>)
i also tried to get the ChangeHistorySyncReport...
IChangeHistorySyncReport report =
workspaceManager.compareBaselineSets(
snapShot0, snapShot1, componentList(stream), monitor);
also the report is empty...
so how do I create a proper report? or how can I compare two baselines? (what am I doing wrong?
report.getAffectedComponents() returns an empty array, as well does report.getModifiedComponents()
UPDATE
as far a s i know now i must inspect the ChangeHistorySyncReport... and when i print my report it says:
com.ibm.team.scm.common.internal.dto.impl.ChangeHistorySyncReportImpl#150f091 (localTime: <unset>, remoteTime: <unset>, compareFlags: <unset>)
this makes my question deeper - how can i set better CompareFlags?
GOD it took me ages....
but first things first: it was totally right to use the IChangeHistorySyncReport instead of
IUpdateReport...
so what was wrong?
IWorkspaceConnection stream; //is not null, already instantiated somewhere else
IBaselineSet bl0 = (IBaselineSet)
itemManager.fetchCompleteItem(baseLineHandle0, IItemManager.DEFAULT, monitor);
IBaselineSet bl1 = (IBaselineSet)
itemManager.fetchCompleteItem(baseLineHandle1, IItemManager.DEFAULT, monitor);
IChangeHistorySyncReport report =
workspaceManager.compareBaselineSets(bl0, bl1, getComponentHandles(stream), monitor);
a simply code change solves the problem
//have a close look: 3.rd param is now null!!
IChangeHistorySyncReport report =
workspaceManager.compareBaselineSets(bl0, bl1, null, monitor);
by the way, there was another tricky part, when i browsed up the report:
System.out.println("report: "+report );
System.out.println("incoming: "+report.incomingChangeSets() );
output:
report = com.ibm.team.scm.common.internal.dto.impl.ChangeHistorySyncReportImpl#127c1ae (localTime: <unset>, remoteTime: <unset>, compareFlags: <unset>)
incoming []
looked empty ot first sight - but digging deeper i found out that i simply had to ask for report.outgoingChangeSets() which brings out a great sum of (expected) changes...
but when i exchange the baseline workspaceManager.compareBaselineSets(bl1, bl0, null, monitor); then
report.outgoingChangeSets() is empty and
report.incomingChangeSets() brings the correct results!!
update:
using the compare baseline method i can now provide a full diff on several components!!!

Request parameters not recognised by DropletInvoker.invokeDroplet

I'm trying to invoke RQLQueryForEach droplet from using DUST's DropletInvoker by using below code.
HeadPipelineServlet dynamoHandler = (HeadPipelineServlet) Nucleus.getGlobalNucleus().resolveName("/atg/dynamo/servlet/dafpipeline/DynamoHandler");
DynamoHttpServletRequest request = dynamoHandler.getRequest(null);
ByteBuffer buffer = ByteBuffer.allocate(1024);
TestingDynamoHttpServletRequest wrappedRequest = new TestingDynamoHttpServletRequest(request, buffer);
TestingDynamoHttpServletResponse wrappedResponce = new TestingDynamoHttpServletResponse(request.getResponse());
DynamoServlet droplet = (DynamoServlet) wrappedRequest.resolveName("/atg/dynamo/droplet/RQLQueryForEach");
wrappedRequest.setParameter("repository", "/atg/userprofiling/ProfileAdapterRepository");
wrappedRequest.setParameter("itemDescriptor", "user");
wrappedRequest.setParameter("transactionManager", "/atg/dynamo/transaction/TransactionManager");
wrappedRequest.setParameter("queryRQL", "ALL");
DropletInvoker mDropletInvoker = new DropletInvoker(Nucleus.getGlobalNucleus());
DropletResult result = mDropletInvoker.invokeDroplet(droplet, null, wrappedRequest, wrappedResponce);
assertNotNull("Check that output got rendered",result.getRenderedOutputParameter("output"));
invokeDroplet method is failing with exception "javax.servlet.ServletException: required parameter 'repository' not passed to droplet." Can any one point me in the right direction, what is that I'm doing incorrectly?
Here is the full stack trace...
javax.servlet.ServletException: required parameter 'repository' not passed to droplet
at atg.repository.servlet.RQLQueryForEach.getRangeResults(RQLQueryForEach.java:254)
at atg.repository.servlet.RQLQueryForEach.getResults(RQLQueryForEach.java:220)
at atg.repository.servlet.RQLQueryForEach.service(RQLQueryForEach.java:179)
at atg.servlet.DynamoServlet.service(DynamoServlet.java:152)
I could solve the problem using additional parameters. However the i still couldn't figure out why my original code isn't working.
Workaround I found
HeadPipelineServlet dynamoHandler = (HeadPipelineServlet) Nucleus.getGlobalNucleus().resolveName("/atg/dynamo/servlet/dafpipeline/DynamoHandler");
Map<String,Object> additionalParams = new HashMap<>();
additionalParams.put("repository", "/atg/userprofiling/ProfileAdapterRepository");
additionalParams.put("itemDescriptor", "user");
additionalParams.put("queryRQL", "ALL");
DropletInvoker mDropletInvoker = new DropletInvoker(Nucleus.getGlobalNucleus());
DropletResult result = mDropletInvoker.invokeDroplet("/atg/dynamo/droplet/RQLQueryForEach",additionalParams);
Are you building your dust code properly? The error only suggests that the input parameter repository is not sent in the request.
Was there a point when the below line was not in your code. If you have added it, probably your changes have not been built. Could you clean your project and try again. Other than this I don't see any thing wrong with your code. Also if you are using eclipse, probably your Build Automatically under Projects menu is not checked.
wrappedRequest.setParameter("repository", "/atg/userprofiling/ProfileAdapterRepository");

Categories