use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CommentManager method appendComment.
/**
* This function provides the append comment functionality for any given Implementation of a
* {@link CommentingStrategy}. It uses the methods of the interface to only have one algorithm
* with different objects that can be commented.
*
* @param strategy The {@link CommentingStrategy} which holds the function forwarders.
* @param commentText The commenting text to append.
*
* @return The generated comment.
*
* @throws CouldntSaveDataException if the comment could not be stored in the database.
* @throws CouldntLoadDataException if the list of comments now associated with the commented
* object could not be loaded from the database.
*/
private synchronized List<IComment> appendComment(final CommentingStrategy strategy, final String commentText) throws CouldntSaveDataException, CouldntLoadDataException {
final IUser user = CUserManager.get(provider).getCurrentActiveUser();
final List<IComment> currentComments = new ArrayList<IComment>();
if (strategy.isStored()) {
currentComments.addAll(strategy.appendComment(commentText, user.getUserId()));
} else {
currentComments.addAll(strategy.getComments() == null ? new ArrayList<IComment>() : Lists.newArrayList(strategy.getComments()));
final IComment parent = currentComments.isEmpty() ? null : Iterables.getLast(currentComments);
final IComment newComment = new CComment(null, user, parent, commentText);
currentComments.add(newComment);
}
strategy.saveComments(currentComments);
for (final IComment comment : currentComments) {
commentIdToComment.put(comment.getId(), comment);
}
for (final CommentListener listener : listeners) {
try {
strategy.sendAppendedCommentNotifcation(listener, Iterables.getLast(currentComments));
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return currentComments;
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CViewInserterTest method test.
@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
ConfigManager.instance().read();
final INaviModule mockModule = new MockModule();
final MockSqlProvider mockProvider = new MockSqlProvider();
final CUserManager userManager = CUserManager.get(mockProvider);
final IUser user = userManager.addUser(" VIEW INSERTER USER ");
userManager.setCurrentActiveUser(user);
final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
view.load();
final MockFunction mockFunction = new MockFunction(mockProvider);
final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
@SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
final MockInstruction instruction1 = new MockInstruction();
final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
@SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
final CTextNode tnode1 = view.getContent().createTextNode(comments);
@SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
gnode1.appendComment("TEST GROUP NODE COMMENT 1");
final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
view2.load();
CViewInserter.insertView(view, view2);
final List<INaviViewNode> nodes = view2.getGraph().getNodes();
assertEquals(view2.getNodeCount(), 6);
assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CUserManager method getUserByUserName.
/**
* Returns a user by reference of name.
*
* @param userName The user name of the user to search for.
*
* @return The user if found null otherwise.
*/
public synchronized IUser getUserByUserName(final String userName) {
Preconditions.checkNotNull(userName, "IE02728: userName argument can not be null");
for (final IUser storedUser : users) {
if (storedUser.getUserName().equalsIgnoreCase(userName)) {
return storedUser;
}
}
// if it is not found locally it might be present in the database therefore sync after the local
// users have been checked.
syncUsers();
for (final IUser storedUser : users) {
if (storedUser.getUserName().equalsIgnoreCase(userName)) {
return storedUser;
}
}
return null;
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CUserManager method containsUserName.
/**
* Checks the stored user names against a provided user name.
*
* @param userName The user name to be checked.
*
* @return true if the user names already contain the given user name.
*/
public synchronized boolean containsUserName(final String userName) {
Preconditions.checkNotNull(userName, "IE02720: userName argument can not be null");
syncUsers();
for (final IUser storedUser : users) {
if (storedUser.getUserName().equalsIgnoreCase(userName)) {
return true;
}
}
return false;
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CUserManager method editUserName.
/**
* Edits a users user name to something else.
*
* @param user The user where the name should be changed.
* @param userName The user name to change the name of the user to.
*
* @return The new user.
* @throws CouldntSaveDataException
*/
public synchronized IUser editUserName(final IUser user, final String userName) throws CouldntSaveDataException {
Preconditions.checkNotNull(user, "IE02723: user argument can not be null");
Preconditions.checkNotNull(userName, "IE02724: userName argument can not be null");
if (!users.contains(user)) {
throw new IllegalStateException("IE02725: User is not known to the user management.");
}
if (containsUserName(userName)) {
throw new IllegalStateException("IE02726: User name is already in use by another user.");
}
final IUser newUser = provider.editUserName(user, userName);
for (final IUserManagerListener listener : listeners) {
try {
listener.editedUser(newUser);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return newUser;
}
Aggregations