use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.
the class AuditAdviceTest method testCascadingCreateWithAssociatedAuditable.
@Test
public void testCascadingCreateWithAssociatedAuditable() {
ExpressionExperiment ee = this.getTestPersistentCompleteExpressionExperiment(false);
ee = this.expressionExperimentService.load(ee.getId());
ee = expressionExperimentService.thawLite(ee);
assertEquals(16, ee.getBioAssays().size());
assertNotNull(ee.getBioAssays().iterator().next().getId());
assertEquals(1, ee.getAuditTrail().getEvents().size());
for (BioAssay prod : ee.getBioAssays()) {
assertNotNull(prod.getAuditTrail());
Collection<AuditEvent> events = this.auditTrailService.getEvents(prod);
assertEquals(1, events.size());
for (AuditEvent e : events) {
assertNotNull(e.getId());
assertEquals(AuditAction.CREATE, e.getAction());
}
}
}
use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.
the class AuditAdviceTest method testSimpleAuditCreateUpdateUser.
@Test
public void testSimpleAuditCreateUpdateUser() {
String USERNAME = RandomStringUtils.randomAlphabetic(BaseSpringContextTest.RANDOM_STRING_LENGTH);
String encodedPassword = passwordEncoder.encodePassword(USERNAME, USERNAME);
UserDetailsImpl u = new UserDetailsImpl(encodedPassword, USERNAME, true, null, null, null, new Date());
userManager.createUser(u);
User user = (User) userService.findByUserName(USERNAME);
List<AuditEvent> events = auditTrailService.getEvents(user);
assertEquals("Should have just one event, a 'create'", 1, events.size());
assertEquals(AuditAction.CREATE, events.get(0).getAction());
assertNotNull(events.get(0).getId());
// change something.
user.setEmail(RandomStringUtils.randomNumeric(10));
userService.update(user);
events = auditTrailService.getEvents(user);
int sizeAfterFirstUpdate = events.size();
assertEquals("Should have a 'create' and an 'update'", 2, sizeAfterFirstUpdate);
// debugging...
if (!events.get(0).getAction().equals(AuditAction.CREATE)) {
log.info("First event wasn't 'C', dumping trail");
for (AuditEvent ae : events) {
log.info(ae);
}
}
assertEquals(AuditAction.CREATE, events.get(0).getAction());
assertEquals(AuditAction.UPDATE, events.get(sizeAfterFirstUpdate - 1).getAction());
// third time.
// change something.
user.setEmail(RandomStringUtils.randomNumeric(10));
userService.update(user);
events = auditTrailService.getEvents(user);
assertEquals(3, user.getAuditTrail().getEvents().size());
assertEquals(AuditAction.UPDATE, events.get(2).getAction());
// cleanup
userManager.deleteUser(USERNAME);
}
use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.
the class AuditAdviceTest method checkAuditTrail.
private void checkAuditTrail(Auditable c, Collection<Long> trailIds, Collection<Long> eventIds) {
AuditTrail auditTrail = c.getAuditTrail();
assertNotNull("No audit trail for " + c, auditTrail);
trailIds.add(auditTrail.getId());
assertTrue("Trail but no events for " + c, auditTrail.getEvents().size() > 0);
for (AuditEvent ae : auditTrail.getEvents()) {
eventIds.add(ae.getId());
}
}
use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.
the class AbstractSpringAwareCLI method noNeedToRun.
/**
* @param auditable auditable
* @param eventClass can be null
* @return boolean
*/
protected boolean noNeedToRun(Auditable auditable, Class<? extends AuditEventType> eventClass) {
boolean needToRun = true;
Date skipIfLastRunLaterThan = this.getLimitingDate();
List<AuditEvent> events = this.auditEventService.getEvents(auditable);
// assume okay unless indicated otherwise
boolean okToRun = true;
// count.
for (int j = events.size() - 1; j >= 0; j--) {
AuditEvent event = events.get(j);
if (event == null) {
// legacy of ordered-list which could end up with gaps; should not be needed any more
continue;
}
AuditEventType eventType = event.getEventType();
if (eventType != null && eventClass != null && eventClass.isAssignableFrom(eventType.getClass()) && !eventType.getClass().getSimpleName().startsWith("Fail")) {
if (skipIfLastRunLaterThan != null) {
if (event.getDate().after(skipIfLastRunLaterThan)) {
AbstractCLI.log.info(auditable + ": " + " run more recently than " + skipIfLastRunLaterThan);
errorObjects.add(auditable + ": " + " run more recently than " + skipIfLastRunLaterThan);
needToRun = false;
}
} else {
// it has been run already at some point
needToRun = false;
}
}
}
/*
* Always skip if the object is curatable and troubled
*/
if (auditable instanceof Curatable) {
Curatable curatable = (Curatable) auditable;
// not ok if troubled
okToRun = !curatable.getCurationDetails().getTroubled();
// special case for expression experiments - check associated ADs.
if (okToRun && curatable instanceof ExpressionExperiment) {
ExpressionExperimentService ees = this.getBean(ExpressionExperimentService.class);
for (ArrayDesign ad : ees.getArrayDesignsUsed((ExpressionExperiment) auditable)) {
if (ad.getCurationDetails().getTroubled()) {
// not ok if even one parent AD is troubled, no need to check the remaining ones.
okToRun = false;
break;
}
}
}
if (!okToRun) {
AbstractCLI.log.info(auditable + ": has an active 'trouble' flag");
errorObjects.add(auditable + ": has an active 'trouble' flag");
}
}
return !needToRun || !okToRun;
}
use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.
the class ExpressionExperimentServiceImpl method getLastEvent.
/**
* @return a map of the expression experiment ids to the last audit event for the given audit event type the map
* can contain nulls if the specified auditEventType isn't found for a given expression experiment id
*/
private Map<Long, AuditEvent> getLastEvent(Collection<ExpressionExperiment> ees, AuditEventType type) {
Map<Long, AuditEvent> lastEventMap = new HashMap<>();
AuditEvent last;
for (ExpressionExperiment experiment : ees) {
last = this.auditEventDao.getLastEvent(experiment, type.getClass());
lastEventMap.put(experiment.getId(), last);
}
return lastEventMap;
}
Aggregations