comparing two baselines in RTC/Jazz with plain java - 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!!!

Related

How to fetch change set by work item link targetRef URI?

First please let me know the difference between these two
com.ibm.team.filesystem.workitems.change_set
com.ibm.team.workitem.linktype.scm.tracksChanges
Because I have found some change set links using trackschanges Id and after that when I try to fetchCompleteItem for the link it return null or exception like that data is not present in the database. I am using the below code to fetchCompleteItem.
Really stuck here please help:
for(Object wI : links){
ILink link = (ILink) wI;
Object source = link.getTargetRef().resolve();
IChangeSetHandle changeSetHandle = (IChangeSetHandle) link.getTargetRef().resolve();
wiHandles.add((IChangeSetHandle) link.getTargetRef().resolve());
if (source instanceof IChangeSetHandle) {
changeSet = (IChangeSet) repo.itemManager().fetchCompleteItem(
changeSetHandle,
IItemManager.DEFAULT, monitor);
System.out.println("changeset---1"+changeSet);
}
}

CSS validation with AntiSamy

I have a String, and I want to validate whether it is a valid CSS value or not. In the documentation of AntiSamy, I found that I might be able to use CSSValidator.isValidProperty (http://javadox.com/org.owasp/antisamy/1.4/org/owasp/validator/css/CssValidator) to do so. However, the type of the second param requires LexicalUnit.
Is there another way to validate a String with AnitSamy?
I think what you want is the CssScanner.
/****** pull out style tag from html *****/
Pattern p = Pattern.compile("<style>([\\s\\S]+?)</style>");
Matcher m = p.matcher(validHTML);
// if we find a match, get the group
if (m.find()) {
// get the matching group
codeGroup = m.group(1);
}
/****** block for checking all css for validity *****/
InternalPolicy policy = null;
try {
policy = (InternalPolicy) InternalPolicy.getInstance("antisamy-ebay.xml");
} catch (PolicyException e) {
e.printStackTrace();
}
ResourceBundle messages = ResourceBundle.getBundle("AntiSamy", Locale.getDefault());
CssScanner scanner = new CssScanner(policy, messages);
CleanResults results = scanner.scanStyleSheet(codeGroup, Integer.MAX_VALUE);
validCSS = results.getCleanHTML().toString();
That is the part of the code that worked for me. Let me know if any of this does not work for you, I have variables declared at the top of the code because I am also handling html validation in here too. So some variables are not in this code. But it should point you in the right direction. Also, you need a policy in place, I chose the ebay policy, this guides the whitelist of what the css will allow for the resulting output. I have not used the CssValidator, so I am not sure how they compare, but CssScanner does a great job of giving back clean css.

Why would this cause a StringIndexOutOfBoundsException? Android

I am working on a small file manager to help me learn the basics of android, but I keep running into an error. WHenever I have a lot of items in the folder, it crashes and I get a message similar to this one,
java.lang.StringIndexOutOfBoundsException: length=26; regionStart=23; regionLength=-2
What could be causing this? The line it points to is line 2:
1.)String mimeType = "";
2.)mimeType = URLConnection.guessContentTypeFromName(f.getName());
You are missing some key lines we need to see, such as where f (a File? a URI?) is defined. However when I have seen this problem before it was caused by a URI with no Protocol set.
Making sure you have an extension and using MimeTypeMap#getMimeTypeFromExtension() is probably a good bet too
This error happens to me when the URL has a fragment, which can be identified by a # followed by some value. (For more on URL fragments, see https://www.w3.org/Addressing/URL/4_2_Fragments.html)
The URL fragment is not helpful in guessing content type, and since it is problematic in this case, it should be removed before calling URLConnection.guessContentTypeFromName().
Here is a simple function that returns a URL without the fragment:
private fun getSafeUrlForGuessing(url: String): String {
return try {
val uri = Uri.parse(url)
if (uri.scheme?.startsWith("http") == true) {
uri.buildUpon()
.fragment(null) // URLs with fragments cause URLConnection.guessContentTypeFromName() to throw
.build()
.toString()
} else {
url
}
} catch (error: Throwable) {
url
}
}

Is there a limit on the number of comments to be extracted from Youtube?

I am trying to extract comments on some YouTubeVideos using the youtube-api with Java. Everything is going fine except the fact that I am not able to extract all the comments if the video has a large number of comments (it stops at somewhere in between 950 and 999). I am following a simple method of paging through the CommentFeed of the VideoEntry, getting comments on each page and then storing each comment in an ArrayList before writing them in an XML file. Here is my code for retrieving the comments
int commentCount = 0;
CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
do {
//Gets each comment in the current feed and prints to the console
for(CommentEntry comment : commentFeed.getEntries()) {
commentCount++;
System.out.println("Comment " + commentCount + " plain text content: " + comment.getPlainTextContent());
}
//Checks if there is a next page of comment feeds
if (commentFeed.getNextLink() != null) {
commentFeed = service.getFeed(new URL(commentFeed.getNextLink().getHref()), CommentFeed.class);
}
else {
commentFeed = null;
}
}
while (commentFeed != null);
My question is: Is there some limit on the number of comments that I could extract or am I doing something wrong?
use/refer this
String commentUrl = videoEntry.getComments().getFeedLink().getHref();
CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
for(CommentEntry comment : commentFeed.getEntries()) {
System.out.println(comment.getPlainTextContent());
}
source
Max number of results per iteration is 50 (it seems) as mentioned here
and you can use start-index to retrieve multiple result sets as mentioned here
Google Search API and as well as Youtube Comments search limits max. 1000 results and u cant extract more than 1000 results

JavaScript Error in BIRT

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?

Categories