use of com.google.security.zynamics.binnavi.Database.CProjectViewGenerator in project binnavi by google.
the class CViewTest method testSomeOverwrittenMethods.
@Test
public void testSomeOverwrittenMethods() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException {
final CProjectViewGenerator generator = new CProjectViewGenerator(m_sql, new MockProject());
final CView view = generator.generate(6, "Blub", "Bla", ViewType.Native, GraphType.FLOWGRAPH, new Date(1234), new Date(12345), 123, 700, new HashSet<CTag>(), new HashSet<CTag>(), false);
assertEquals(6, view.getConfiguration().getId());
view.load();
assertNotNull(view.getBasicBlockEdges());
assertNotNull(view.getBasicBlocks());
assertNotNull(view.getClass());
assertNotNull(view.getConfiguration());
assertNotNull(view.getContent());
assertNotNull(view.getDerivedViews());
assertEquals(0, view.getEdgeCount());
assertNotNull(view.getGraph());
assertEquals(GraphType.MIXED_GRAPH, view.getGraphType());
assertEquals(-1, view.getLoadState());
assertEquals("Blub", view.getName());
assertEquals(0, view.getNodeCount());
assertNotNull(view.getNodeTags());
assertEquals(ViewType.Native, view.getType());
assertTrue(view.isLoaded());
assertFalse(view.isStared());
try {
view.save();
fail();
} catch (final IllegalArgumentException e) {
}
assertFalse(view.wasModified());
view.close();
}
use of com.google.security.zynamics.binnavi.Database.CProjectViewGenerator in project binnavi by google.
the class CProjectContent method createView.
/**
* Creates a new empty view with the given name and description in the project. The new view is
* not stored in the database until INaviView::save is called.
*
* @param name The name of the new view.
* @param description The description of the new view.
*
* @return The new view that was created in the project.
*/
public INaviView createView(final String name, final String description) {
final Date date = new Date();
final CProjectViewGenerator generator = new CProjectViewGenerator(m_provider, m_project);
final CView view = generator.generate(-1, name, description, ViewType.NonNative, GraphType.MIXED_GRAPH, date, date, 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
try {
view.load();
} catch (CouldntLoadDataException | CPartialLoadException | LoadCancelledException e) {
// This can not happen; new views with ID -1 do not access the database
// when they are loaded.
CUtilityFunctions.logException(e);
}
addView(view);
return view;
}
use of com.google.security.zynamics.binnavi.Database.CProjectViewGenerator in project binnavi by google.
the class PostgreSQLViewsLoader method processQueryResults.
/**
* Processes the results of a view loading query.
*
* @param resultSet Contains the results of the SQL query.
* @param project The project the views were loaded for.
* @param tags Map that contains the tags the views are tagged with.
* @param nodeTagManager Provides the node tags.
* @param provider The connection to the database.
* @param views The loaded views are stored in this list.
* @param viewType View type of the loaded views.
* @param graphType Graph type of the loaded views.
*
* @return The loaded views.
*
* @throws SQLException Thrown if the views could not be loaded.
*/
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviProject project, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), project, nodeTagManager);
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean starState = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
final CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
}
return views;
} finally {
resultSet.close();
}
}
use of com.google.security.zynamics.binnavi.Database.CProjectViewGenerator in project binnavi by google.
the class PostgreSQLViewNotificationParser method informProjectNotification.
/**
* The inform function for notifications from the bn_project_views table. This function is used
* when a project view is created or deleted.
*
* @param projectNotificationContainer The {@link ViewNotificationContainer} to use as data
* source.
* @param provider The {@link SQLProvider} to access the database.
* @throws CouldntLoadDataException if the information could not be loaded from the database.
*/
private void informProjectNotification(final ViewNotificationContainer projectNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
if (projectNotificationContainer.getDatabaseOperation().equals("INSERT")) {
final INaviProject project = projectNotificationContainer.getNotificationProject().get();
if (!project.isLoaded()) {
return;
}
final Integer viewId = projectNotificationContainer.getViewId();
final ImmutableNaviViewConfiguration databaseViewConfiguration = provider.loadFlowGraphInformation(project, viewId);
final CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
final INaviView view = generator.generate(databaseViewConfiguration);
project.getContent().addView(view);
}
if (projectNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
// updates will not happen as this is only a mapping of id to id.
return;
}
if (projectNotificationContainer.getDatabaseOperation().equals("DELETE")) {
final INaviProject project = projectNotificationContainer.getNotificationProject().get();
if (!project.isLoaded()) {
return;
}
final Integer viewId = projectNotificationContainer.getViewId();
final INaviView view = ViewManager.get(provider).getView(viewId);
project.getContent().deleteViewInternal(view);
}
}
use of com.google.security.zynamics.binnavi.Database.CProjectViewGenerator in project binnavi by google.
the class PostgreSQLViewCreator method createView.
/**
* Creates a new view by copying an existing view.
*
* @param provider The connection to the database.
* @param project The project the new view is added to.
* @param view The view to be copied.
* @param name The name of the new view.
* @param description The description of the new view.
* @return The created view.
* @throws CouldntSaveDataException Thrown if the view could not be saved.
*/
public static CView createView(final AbstractSQLProvider provider, final INaviProject project, final INaviView view, final String name, final String description) throws CouldntSaveDataException {
Preconditions.checkNotNull(project, "Error: Project argument can not be null");
Preconditions.checkNotNull(view, "IE02273: View argument can not be null");
Preconditions.checkNotNull(name, "IE02274: Name argument can not be null");
Preconditions.checkState(view.inSameDatabase(provider), "Error: View is not part of this database");
return createView(provider, project.getConfiguration().getId(), view, name, description, CTableNames.PROJECTS_TABLE, CTableNames.PROJECT_VIEWS_TABLE, new CProjectViewGenerator(provider, project));
}
Aggregations