void persistConfiguration() {
   List<PastSnapshot> pastSnapshots = configuration.getProjectPastSnapshots();
   for (PastSnapshot pastSnapshot : pastSnapshots) {
     projectSnapshot = session.reattach(Snapshot.class, projectSnapshot.getId());
     projectSnapshot.setPeriodMode(pastSnapshot.getIndex(), pastSnapshot.getMode());
     projectSnapshot.setPeriodModeParameter(
         pastSnapshot.getIndex(), pastSnapshot.getModeParameter());
     projectSnapshot.setPeriodDate(pastSnapshot.getIndex(), pastSnapshot.getTargetDate());
     session.save(projectSnapshot);
   }
   session.commit();
 }
 /**
  * Only used to get the real date of the snapshot on the current period. The date is used to
  * calculate new_violations measures
  */
 @CheckForNull
 private Snapshot findSnapshot(Snapshot projectSnapshot) {
   String hql =
       "from "
           + Snapshot.class.getSimpleName()
           + " where resourceId=:resourceId and (rootId=:rootSnapshotId or id=:rootSnapshotId)";
   List<Snapshot> snapshots =
       session
           .createQuery(hql)
           .setParameter("resourceId", projectSnapshot.getResourceId())
           .setParameter("rootSnapshotId", projectSnapshot.getId())
           .setMaxResults(1)
           .getResultList();
   return snapshots.isEmpty() ? null : snapshots.get(0);
 }
Ejemplo n.º 3
0
 private static Snapshot snapshot(int id) {
   Snapshot snapshot = mock(Snapshot.class);
   when(snapshot.getId()).thenReturn(id);
   return snapshot;
 }