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);
}
}
Related
Thank you
I just want to thank you for clicking on this question! I've tried my best to make this as thorough as possible.
but still, feel free to let me know if you need to clarify anything further!
if you think the question is too long. you can just read the third & fourth part and post your own solution down here!
Setup
Mongodb Java driver: org.mongodb:mongo-java-driver:3.11.0-rc0
What I want to do
find a specific document with a specific "name" field.
then update the other field or the whole document.
Example Document
// the document that I am trying to find in db
{
"_id":"5de6af7cfa42833bd9849477",
"name":"Richard Koba",
"skills":[]
}
// the document that I have
{
"name":"Richard Koba",
"skills":[jump, dance, sing]
}
// final result in db
{
"_id":"5de6af7cfa42833bd9849477",
"name":"Richard Koba",
"skills":[jump, dance, sing]
}
What I am doing now
// finding a document with same "name" field as input doc and update it with doc
public MongoCollection updateDocument(Document doc, String colName) {
MongoCollection collection;
// make sure collection exist
try {
collection = connectCollection(colName); // returns MongoCollection Obj
} catch (CollectionNotFoundException e) {
MessageHandler.errorMessage(e.getMessage());
return null;
}
// trying to find the document.
if (collection.find(eq("name", doc.get("name"))).first() == null) {
// if document not found, insert a new one
collection.insertOne(doc);
} else {
// if the document found, replace/update it with the one I have
collection.replaceOne(eq("name", doc.get("name")), doc);
}
return collection;
}
What I found about my false solution
collection.find(eq("name", doc.get("name"))).first() never returns null.
Java only tells me it returns an Object. MongoDB Documentation tells me it is a TResult, which point back to MongoIterable<TResult>. I am stuck here.
the code outcome is that none of the documents is inserted/updated in the end.
Reference
https://mongodb.github.io/mongo-java-driver/3.11/javadoc/com/mongodb/client/MongoIterable.html#first()
I tried some code and this works fine. This is not much different from your code.
Created a document from mongo shell:
MongoDB Enterprise > db.users.findOne()
{
"_id" : "5de6af7cfa42833bd9849477",
"name" : "Richard Koba",
"skills" : [ ]
}
My Java Code:
// Test input documents
private Document doc1 = new Document()
.append("name", "Richard Koba")
.append("skills", Arrays.asList("jump", "dance", "sing"));
private Document doc2 = new Document()
.append("name", "Richard K")
.append("skills", Arrays.asList("sings"));
When doc1 is passed to the following method the result is: "### Doc FOUND". And, with doc2 the result is "### Doc NOT found".
private void checkDocument(Document doc) {
MongoClient mongoClient = MongoClients.create("mongodb://localhost/");
MongoDatabase database = mongoClient.getDatabase("javadb");
MongoCollection<Document> collection = database.getCollection("users");
if (collection.find(eq("name", doc.get("name"))).first() == null) {
System.out.println("### Doc NOT found");
}
else {
System.out.println("### Doc FOUND");
}
}
I also tried this, with the same results.
Document d = collection.find(eq("name", doc.get("name"))).first();
if (d == null) { // ... }
I also tried this; works fine too.
if (collection.find(queryFilter).iterator().tryNext() == null) { // ... }
I think there might be some other issue with your code or the database / collection. Some debugging and testing with new data might reveal the real issue.
Did you check if the document already exists in the collection, from mongo shell or Compass tools?
Are you using the right database and collection names?
After each test run are you verifying the data in the database if it is updated / inserted?
collection.find(eq("name", doc.get("name"))).first() never returns
null.
With the code I posted above, the find query did return null when the users collection was empty.
collection.find() return an array of documents. What you actually want here is collection.findOneAndUpdate()
After you get a TDoucment object from findOneAndUpdate, you can use a ObjectMapper e.g.jackson to map it back to a java object
I am using below code and it returns some information about "Filed Against"
attribute. But there I am not able to find attribute data. Please help
IAttribute someAttribute= workItemClient.findAttribute(projectAreaHandle, workItem.CATEGORY_PROPERTY, monitor);
Using below code to find out the work item by Id :
workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
int id = new Integer("339406").intValue();
IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, monitor);
using this work item I want to fetch parent and children like Epic and story work items related to the work item. And then there attributes like story status, story planned for etc.
From this thread:
You can't just put a string in there, I think.
You have to find the category object from the string and then put in the ICategory object.
That means:
private static String CATEGORY_NAME = "UI1";
List<ICategory> findCategories = workItemCommon.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
for(ICategory category : findCategories) {
if(category.getName().contains(CATEGORY_NAME)){
filedAgainstAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.CATEGORY_PROPERTY, auditableClient, monitor);
filedAgainstExpression = new AttributeExpression(filedAgainstAttribute, AttributeOperation.EQUALS, category);
}
}
I want to have a changefeed on one attribute of my object in rethinkdb in the java language.
I tried this:
Cursor curs = r.db("mytestdb").
table("tennis").
get(Constants.WORKING_PROJECT_ID).
getField("time").
changes().
run(conn);
for (Object doc : curs) {
System.out.println(doc);
}
but I get this com.rethinkdb.gen.exc.ReqlQueryLogicError: Cannot convert STRING to SEQUENCE as an Exception.
Im really new to rethinkDB. Can someone help me ?
getField("time") gets particular field value, you can't subscribe on value.
That's what this com.rethinkdb.gen.exc.ReqlQueryLogicError: Cannot convert STRING to SEQUENCE says.
You can filter changes you want to get:
Cursor curs = r.db("mytestdb").
table("tennis").get(Constants.WORKING_PROJECT_ID)
.filter(row -> row.g("new_val").g("time").ne(row.g("old_val").g("time")))
.changes().run(conn);
for (Object doc : curs) {
}
I have this data on my mongodb database:
{
"_id" : BinData(3, "bU0bX4VEAMnW7AJ28wXcoA=="),
"online" : false,
"money" : 0,
"rank" : "USER",
"ban" : {
"end" : NumberLong("3027259780628"),
"reason" : "hello"
}
}
and I use this code to access to the ban.end sub-field saved in it:
final Document doc = collcetion.find(new Document("_id", myId)).
projection(Projections.include("ban.end"));
System.out.println(doc); // here is all ok.
// It print out the _id with the
// ban and the end values.
final long a = doc.getLong("ban.end"); // nullptr exception because
// I tryied to do this:
long a = (Long) null;
Is there any way to fix the null pointer reported above? I think I failed something with mongodb, I'm not sure in using ban.end as field name.
I already tried to get, for example, the money value and it works.
getLong returns a Long, not a long. See http://api.mongodb.org/java/current/org/bson/Document.html#getLong-java.lang.Object-.
In other words, you're getting the nullpointer because you're implicitly unboxing it. Just use
final long a = doc.getLong("ban.end");
instead, the handle the null case separately.
I'm not sure in using "ban.end" as field name.
Sadly, you are. You need to get the ban objcect first, before you could access its end attribute.
The logic remains the same for whatever versions.
code in 3.0.4 version of the java driver,
DBCursor docs = collection.find(new BasicDBObject("_id", myId),
new BasicDBObject("ban.end", 1));
while (docs.hasNext())
{
BasicDBObject banObj = (BasicDBObject) docs.next().get("ban");
long end = banObj.getLong("end");
System.out.println(end);
}
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!!!