use of org.hibernate.envers.exception.RevisionDoesNotExistException in project hibernate-orm by hibernate.
the class AuditReaderImpl method getRevisionDate.
@Override
public Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionDateQuery(session, revision);
try {
final Object timestampObject = query.uniqueResult();
if (timestampObject == null) {
throw new RevisionDoesNotExistException(revision);
}
// The timestamp object is either a date or a long
return timestampObject instanceof Date ? (Date) timestampObject : new Date((Long) timestampObject);
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.envers.exception.RevisionDoesNotExistException in project hibernate-orm by hibernate.
the class AuditReaderImpl method findRevision.
@Override
@SuppressWarnings({ "unchecked" })
public <T> T findRevision(Class<T> revisionEntityClass, Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException {
revisionEntityClass = getTargetClassIfProxied(revisionEntityClass);
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
final Set<Number> revisions = new HashSet<>(1);
revisions.add(revision);
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
try {
final T revisionData = (T) query.uniqueResult();
if (revisionData == null) {
throw new RevisionDoesNotExistException(revision);
}
return revisionData;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.envers.exception.RevisionDoesNotExistException in project hibernate-orm by hibernate.
the class AuditReaderImpl method getRevisionNumberForDate.
@Override
public Number getRevisionNumberForDate(Date date) {
checkNotNull(date, "Date of revision");
checkSession();
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery(session, date);
try {
final Number res = (Number) query.uniqueResult();
if (res == null) {
throw new RevisionDoesNotExistException(date);
}
return res;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.envers.exception.RevisionDoesNotExistException in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method findRevision.
@ResponseBody
@RequestMapping(value = "/{backendId}/revisions/{revId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity audit - read revision detail", nickname = "getIdentityRevision", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> findRevision(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable("backendId") String backendId, @ApiParam(value = "Revision identifier.", required = true) @PathVariable("revId") Long revId) {
IdmIdentityDto originalEntity = getDto(backendId);
if (originalEntity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
//
IdmIdentity revisionIdentity;
try {
revisionIdentity = this.auditService.findRevision(IdmIdentity.class, originalEntity.getId(), revId);
} catch (RevisionDoesNotExistException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("revision", revId), ex);
}
// FIXME: to dto
return new ResponseEntity<>(revisionIdentity, HttpStatus.OK);
}
use of org.hibernate.envers.exception.RevisionDoesNotExistException in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeController method findRevision.
@ResponseBody
@RequestMapping(value = "{backendId}/revisions/{revId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Tree node audit - read revision detail", nickname = "getTreeNodeRevision", tags = { IdmTreeNodeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }) })
public ResponseEntity<?> findRevision(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable("backendId") String backendId, @ApiParam(value = "Revision identifier.", required = true) @PathVariable("revId") Long revId) {
IdmTreeNodeDto treeNode = getDto(backendId);
if (treeNode == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("treeNode", backendId));
}
IdmTreeNode revision;
try {
revision = this.auditService.findRevision(IdmTreeNode.class, treeNode.getId(), revId);
} catch (RevisionDoesNotExistException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("revision", revId), ex);
}
// TODO: dto
return new ResponseEntity<>(revision, HttpStatus.OK);
}
Aggregations