use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testAppendFunctionNodeCommentSync.
@Test
public void testAppendFunctionNodeCommentSync() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException, InterruptedException {
databaseOneCallGraph = databaseOneModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
databaseOneCallGraph.load();
final INaviFunctionNode databaseOneFunctionNode = (INaviFunctionNode) databaseOneCallGraph.getGraph().getNodes().get(1);
databaseTwoCallGraph = databaseTwoModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
databaseTwoCallGraph.load();
final INaviFunctionNode databaseTwoFunctionNode = (INaviFunctionNode) databaseTwoCallGraph.getGraph().getNodes().get(1);
final List<IComment> oneBefore = databaseOneFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseOneFunctionNode.getLocalFunctionComment();
final List<IComment> twoBefore = databaseTwoFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseTwoFunctionNode.getLocalFunctionComment();
assertEquals(oneBefore, twoBefore);
databaseOneFunctionNode.appendLocalFunctionComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOneFunctionNode.getLocalFunctionComment();
final List<IComment> twoAfter = databaseTwoFunctionNode.getLocalFunctionComment();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testEditLocalCodeNodeCommentSync.
@Test
public void testEditLocalCodeNodeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(2);
final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(2);
final List<IComment> oneBefore = databaseOnecodeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getLocalCodeNodeComment();
final List<IComment> twoBefore = databaseTwocodeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getLocalCodeNodeComment();
assertEquals(oneBefore, twoBefore);
final List<IComment> comments = databaseOnecodeNode.getComments().appendLocalCodeNodeComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) BEFORE ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOnecodeNode.getComments().getLocalCodeNodeComment();
final List<IComment> twoAfter = databaseTwocodeNode.getComments().getLocalCodeNodeComment();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
final int oneTwoSize = oneAfter.size();
final int twoTwoSize = twoAfter.size();
databaseOnecodeNode.getComments().editLocalCodeNodeComment(Iterables.getLast(comments), " TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) AFTER ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneThree = databaseOnecodeNode.getComments().getLocalCodeNodeComment();
final List<IComment> twoThree = databaseTwocodeNode.getComments().getLocalCodeNodeComment();
assertEquals(oneTwoSize, oneThree.size());
assertEquals(twoTwoSize, twoThree.size());
assertEquals(oneThree, twoThree);
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testEditGlobalCodeNodeCommentSync.
@Test
public void testEditGlobalCodeNodeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(1);
final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(1);
final List<IComment> oneBefore = databaseOnecodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
final List<IComment> twoBefore = databaseTwocodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
assertEquals(oneBefore, twoBefore);
databaseOnecodeNode.getComments().appendGlobalCodeNodeComment(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) BEFORE ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
final List<IComment> twoAfter = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
final int oneTwoSize = oneAfter.size();
final int twoTwoSize = twoAfter.size();
databaseOnecodeNode.getComments().editGlobalCodeNodeComment(Iterables.getLast(databaseOnecodeNode.getComments().getGlobalCodeNodeComment()), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneThree = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
final List<IComment> twoThree = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
assertEquals(oneTwoSize, oneThree.size());
assertEquals(twoTwoSize, twoThree.size());
assertEquals(oneThree, twoThree);
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLCommentFunctions method loadCommentByCommentId.
/**
* Loads comments by a comment root id it returns all ancestors of the comment.
*
* @param provider The provider used to access the database.
* @param commentRootId The comment root id where to start the recursive query.
* @return An array of comments from and including the comment referenced by the comment root id.
*
* @throws CouldntLoadDataException if the data could not be loaded from the database.
*/
public static ArrayList<IComment> loadCommentByCommentId(final SQLProvider provider, final int commentRootId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE00440: connection argument can not be null");
final HashMap<Integer, IComment> commentIdToComment = new HashMap<>();
final ArrayList<IComment> comments = new ArrayList<>();
final String commentQuery = "SELECT * FROM get_all_comment_ancestors(" + commentRootId + ");";
try (ResultSet resultSet = provider.getConnection().executeQuery(commentQuery, true)) {
while (resultSet.next()) {
resultSet.getInt("level");
final int commentId = resultSet.getInt("id");
Integer parentId = resultSet.getInt("parent_id");
if (resultSet.wasNull()) {
parentId = null;
}
final int userId = resultSet.getInt("user_id");
final String commentText = resultSet.getString("comment");
final CComment comment = new CComment(commentId, CUserManager.get(provider).getUserById(userId), commentIdToComment.get(parentId), commentText);
commentIdToComment.put(commentId, comment);
comments.add(comment);
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return comments;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class GlobalCodeNodeCommentSynchronizer method updateOpenViews.
/**
* Pushes a new global code node comment to all open views.
*
* @param module The module whose views require updating.
* @param codeNode The code node that has the new comment.
* @param comments The new comment of the code node.
*
* @throws CouldntSaveDataException Thrown if updating the code node comments failed.
*/
public static void updateOpenViews(final INaviModule module, final INaviCodeNode codeNode, final ArrayList<IComment> comments) throws CouldntSaveDataException {
if (module.isLoaded()) {
final List<INaviCodeNode> nodelist = new ArrayList<INaviCodeNode>();
for (final INaviView view : module.getContent().getViewContainer().getViews()) {
if (view.isLoaded()) {
nodelist.addAll(collectNodes(view, codeNode));
}
}
final List<IComment> codeNodeComments = codeNode.getComments().getGlobalCodeNodeComment();
for (final INaviCodeNode currentCodeNode : nodelist) {
final List<IComment> currentNodeComments = currentCodeNode.getComments().getGlobalCodeNodeComment();
if (codeNodeComments.equals(currentNodeComments)) {
continue;
} else {
currentCodeNode.getComments().initializeGlobalCodeNodeComment(comments);
}
}
}
}
Aggregations