public void saveDependency(Project project, Dependency dependency, Dependency parentDependency) {
Snapshot fromSnapshot = resourcePersister.saveResource(project, dependency.getFrom());
Snapshot toSnapshot = resourcePersister.saveResource(project, dependency.getTo());
Snapshot projectSnapshot = resourcePersister.getSnapshotOrFail(project);
DependencyDto model = new DependencyDto();
model.setProjectSnapshotId(projectSnapshot.getId());
model.setUsage(dependency.getUsage());
model.setWeight(dependency.getWeight());
model.setFromResourceId(fromSnapshot.getResourceId());
model.setFromScope(fromSnapshot.getScope());
model.setFromSnapshotId(fromSnapshot.getId());
model.setToResourceId(toSnapshot.getResourceId());
model.setToSnapshotId(toSnapshot.getId());
model.setToScope(toSnapshot.getScope());
if (parentDependency != null) {
// assume that it has been previously saved
model.setParentDependencyId(parentDependency.getId());
}
session.save(model);
dependency.setId(model.getId());
}