Search in sources :

Example 1 with RevisionDoesNotExistException

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);
    }
}
Also used : NonUniqueResultException(org.hibernate.NonUniqueResultException) AuditException(org.hibernate.envers.exception.AuditException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) Date(java.util.Date)

Example 2 with RevisionDoesNotExistException

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);
    }
}
Also used : NonUniqueResultException(org.hibernate.NonUniqueResultException) AuditException(org.hibernate.envers.exception.AuditException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) HashSet(java.util.HashSet)

Example 3 with RevisionDoesNotExistException

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);
    }
}
Also used : NonUniqueResultException(org.hibernate.NonUniqueResultException) AuditException(org.hibernate.envers.exception.AuditException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException)

Example 4 with RevisionDoesNotExistException

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RevisionDoesNotExistException

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RevisionDoesNotExistException (org.hibernate.envers.exception.RevisionDoesNotExistException)6 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 NonUniqueResultException (org.hibernate.NonUniqueResultException)3 AuditException (org.hibernate.envers.exception.AuditException)3 ResponseEntity (org.springframework.http.ResponseEntity)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)1 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)1 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)1 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1