use of com.haulmont.cuba.core.entity.EntitySnapshot in project cuba by cuba-platform.
the class EntityDiffManager method getDifference.
public EntityDiff getDifference(@Nullable EntitySnapshot first, EntitySnapshot second) {
// Sort snapshots by date, first - old, second - new
long firstTime = 0;
if (first != null && first.getSnapshotDate() != null)
firstTime = first.getSnapshotDate().getTime();
long secondTime = 0;
if (second != null && second.getSnapshotDate() != null)
secondTime = second.getSnapshotDate().getTime();
if (secondTime < firstTime) {
EntitySnapshot snapshot = first;
first = second;
second = snapshot;
}
checkNotNull(second, "Diff could not be create for null snapshot");
// Extract views
View firstView = first != null ? snapshotAPI.extractView(first) : null;
View secondView = snapshotAPI.extractView(second);
// Get view for diff
View diffView;
if (firstView != null)
diffView = ViewHelper.intersectViews(firstView, secondView);
else
diffView = secondView;
// Diff
return getDifferenceByView(first, second, diffView);
}
use of com.haulmont.cuba.core.entity.EntitySnapshot in project cuba by cuba-platform.
the class EntityDiffViewer method compareSnapshots.
@SuppressWarnings("unused")
public void compareSnapshots() {
entityDiffDs.setItem(null);
EntitySnapshot firstSnap = null;
EntitySnapshot secondSnap = null;
Set selected = snapshotsTable.getSelected();
Object[] selectedItems = selected.toArray();
if ((selected.size() == 2)) {
firstSnap = (EntitySnapshot) selectedItems[0];
secondSnap = (EntitySnapshot) selectedItems[1];
} else if (selected.size() == 1) {
secondSnap = (EntitySnapshot) selectedItems[0];
firstSnap = snapshotsDs.getLatestSnapshot();
if (firstSnap == secondSnap)
firstSnap = null;
}
if ((secondSnap != null) || (firstSnap != null)) {
EntityDiff diff = diffDs.loadDiff(firstSnap, secondSnap);
entityDiffDs.setItem(diff);
}
diffTable.refresh();
diffTable.expandAll();
}
use of com.haulmont.cuba.core.entity.EntitySnapshot in project cuba by cuba-platform.
the class EntityManagerTest method testMergeEmbedded.
@Test
public void testMergeEmbedded() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
EntitySnapshot entitySnapshot = cont.metadata().create(EntitySnapshot.class);
entitySnapshot.setObjectEntityId(1);
EntitySnapshot mergedEntitySnapshot = em.merge(entitySnapshot);
assertNotNull(mergedEntitySnapshot.getEntity());
assertEquals(1, mergedEntitySnapshot.getEntity().getObjectEntityId());
} finally {
tx.end();
}
}
use of com.haulmont.cuba.core.entity.EntitySnapshot in project cuba by cuba-platform.
the class NonEntityQueryTest method setUp.
@Before
public void setUp() throws Exception {
dataManager = AppBeans.get(DataManager.class);
passwordEncryption = AppBeans.get(PasswordEncryption.class);
QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
runner.update("delete from SYS_SERVER");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession userSession = uss.getUserSession();
Server server = new Server();
server.setName("someServer");
server.setRunning(false);
serverId = server.getId();
em.persist(server);
EntitySnapshot entitySnapshot = cont.metadata().create(EntitySnapshot.class);
entitySnapshot.setSnapshotDate(new Date());
entitySnapshot.setAuthor(userSession.getCurrentOrSubstitutedUser());
entitySnapshotId = entitySnapshot.getId();
em.persist(entitySnapshot);
Role role1 = new Role();
role1Id = role1.getId();
role1.setName("testRole1");
em.persist(role1);
Permission permission1 = new Permission();
permission1Id = permission1.getId();
permission1.setRole(role1);
permission1.setType(PermissionType.ENTITY_ATTR);
permission1.setTarget("sys$Server:name");
permission1.setValue(0);
em.persist(permission1);
Permission permission2 = new Permission();
permission2Id = permission2.getId();
permission2.setRole(role1);
permission2.setType(PermissionType.ENTITY_OP);
permission2.setTarget("sys$EntitySnapshot:read");
permission2.setValue(0);
em.persist(permission2);
Group group1 = new Group();
group1Id = group1.getId();
group1.setName("testGroup1");
em.persist(group1);
User user1 = new User();
user1Id = user1.getId();
user1.setName(USER_NAME_1);
user1.setLogin(USER_NAME_1);
user1.setPassword(passwordEncryption.getPasswordHash(user1Id, USER_PASSWORD));
user1.setGroup(group1);
em.persist(user1);
UserRole userRole1 = new UserRole();
userRole1Id = userRole1.getId();
userRole1.setUser(user1);
userRole1.setRole(role1);
em.persist(userRole1);
Group group2 = new Group();
group2Id = group2.getId();
group2.setName("testGroup2");
em.persist(group2);
Constraint constraint1 = new Constraint();
constraint1Id = constraint1.getId();
constraint1.setEntityName("sys$Server");
constraint1.setWhereClause("{E}.running = true");
constraint1.setGroup(group2);
em.persist(constraint1);
Constraint constraint2 = new Constraint();
constraint2Id = constraint2.getId();
constraint2.setEntityName("sys$EntitySnapshot");
constraint2.setCheckType(ConstraintCheckType.MEMORY);
constraint2.setGroovyScript("{E}.viewXml = 'xml'");
constraint2.setGroup(group2);
em.persist(constraint2);
User user2 = new User();
user2Id = user2.getId();
user2.setName(USER_NAME_2);
user2.setLogin(USER_NAME_2);
user2.setPassword(passwordEncryption.getPasswordHash(user2Id, USER_PASSWORD));
user2.setGroup(group2);
em.persist(user2);
tx.commit();
} finally {
tx.end();
}
}
Aggregations