// For views
if (project instanceof ResourceCopy) {
model.setCopyResourceId(((ResourceCopy) project).getCopyResourceId());
}
Snapshot parentSnapshot = null;
if (parent != null) {
// assume that the parent project has already been saved
parentSnapshot = snapshotsByResource.get(project.getParent());
model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
} else {
model.setRootId(null);
}
model = session.save(model);
project.setId(model.getId());
project.setUuid(model.getUuid());
Snapshot snapshot = new Snapshot(model, parentSnapshot);
snapshot.setVersion(project.getAnalysisVersion());
snapshot.setCreatedAt(project.getAnalysisDate());
snapshot.setBuildDate(new Date());
snapshot = session.save(snapshot);
session.commit();
if (!permissions.hasRoles(project)) {
permissions.grantDefaultRoles(project);