use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeController method findRevisions.
@ResponseBody
@RequestMapping(value = "{backendId}/revisions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Tree node audit - read all revisions", nickname = "getTreeNodeRevisions", 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 Resources<?> findRevisions(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable("backendId") String backendId, Pageable pageable) {
IdmTreeNodeDto treeNode = getDto(backendId);
if (treeNode == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("treeNode", backendId));
}
Page<IdmAuditDto> results = this.auditService.findRevisionsForEntity(IdmTreeNode.class.getSimpleName(), UUID.fromString(backendId), pageable);
return toResources(results, IdmTreeNode.class);
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class IdmAuditController method previousVersion.
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{revId}/diff/previous")
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Audit log detail", nickname = "getAuditLogPreviousVersion", response = IdmAuditDto.class, tags = { IdmAuditController.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 = "") }) }, notes = "Returns previous version for given audit log")
public ResponseEntity<?> previousVersion(@ApiParam(value = "Audit log's identifier.", required = true) @PathVariable @NotNull String revId) {
IdmAuditDto currentAudit = auditService.get(revId);
IdmAuditDto previousAudit;
ResponseEntity<IdmAuditDto> resource = null;
try {
IdmAuditDto dto = null;
previousAudit = auditService.findPreviousRevision(Long.valueOf(currentAudit.getId().toString()));
// previous version dost'n exist
if (previousAudit != null) {
dto = new IdmAuditDto();
mapper.map(previousAudit, dto);
dto.setRevisionValues(auditService.getValuesFromVersion(auditService.findPreviousVersion(Class.forName(previousAudit.getType()), previousAudit.getEntityId(), Long.valueOf(previousAudit.getId().toString()))));
resource = new ResponseEntity<IdmAuditDto>(dto, HttpStatus.OK);
} else {
resource = new ResponseEntity<IdmAuditDto>(HttpStatus.NOT_FOUND);
}
} catch (ClassNotFoundException e) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit class", currentAudit.getType()), e);
}
return resource;
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditService method findPreviousVersion.
@Override
public Object findPreviousVersion(Long currentRevisionId) {
IdmAuditDto revision = this.get(currentRevisionId);
Object result = null;
IdmAuditDto previousRevision;
try {
previousRevision = this.findPreviousRevision(currentRevisionId);
if (previousRevision != null) {
result = this.find(Class.forName(previousRevision.getType()), previousRevision.getEntityId(), Long.valueOf(previousRevision.getId().toString()));
}
} catch (ClassNotFoundException e) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("class", revision.getType()), e);
}
return result;
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditService method getDiffBetweenVersion.
@Override
public Map<String, Object> getDiffBetweenVersion(String clazz, Long firstRevId, Long secondRevId) {
Map<String, Object> result = new HashMap<>();
IdmAuditDto firstRevision = this.get(firstRevId);
// first revision must exist
if (firstRevision == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit", firstRevId));
}
if (clazz == null) {
clazz = firstRevision.getType();
}
IdmAuditDto secondRevision = null;
if (secondRevId == null) {
try {
secondRevision = (IdmAuditDto) this.findPreviousVersion(Class.forName(clazz), firstRevision.getEntityId(), Long.valueOf(firstRevision.getId().toString()));
} catch (NumberFormatException e) {
throw new ResultCodeException(CoreResultCode.BAD_VALUE, ImmutableMap.of("audit", firstRevision.getId()), e);
} catch (ClassNotFoundException e) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit class", clazz), e);
}
} else {
secondRevision = this.get(secondRevId);
}
// check if we have second revision
if (secondRevision == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit", secondRevId));
}
// check if revision are from same type (class, entity id)
if (!firstRevision.getEntityId().equals(secondRevision.getEntityId())) {
throw new ResultCodeException(CoreResultCode.AUDIT_REVISION_NOT_SAME, ImmutableMap.of("revision", clazz));
}
// now we will receive version from audit tables
try {
Object firstVersion = this.getRevision(clazz, firstRevision.getEntityId(), firstRevId);
Object secondVersion = this.getRevision(clazz, secondRevision.getEntityId(), secondRevId);
List<String> auditedClass = this.getAllAuditedEntitiesNames();
Map<String, Object> firstValues = null;
Map<String, Object> secondValues = null;
// first revision is DEL, all attributes are null
if (firstRevision.getModification().equals(RevisionType.DEL.name())) {
firstValues = Collections.emptyMap();
} else {
firstValues = this.getValuesFromVersion(firstVersion, auditedClass);
}
if (secondRevision.getModification().equals(RevisionType.DEL.name())) {
secondValues = Collections.emptyMap();
} else {
secondValues = this.getValuesFromVersion(secondVersion, auditedClass);
}
Set<Entry<String, Object>> entries = firstValues.entrySet();
if (entries.isEmpty()) {
entries = secondValues.entrySet();
}
for (Entry<String, Object> entry : entries) {
if (!Objects.equals(entry.getValue(), secondValues.get(entry.getKey()))) {
result.put(entry.getKey(), secondValues.get(entry.getKey()));
}
}
} catch (ClassNotFoundException e) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit class", clazz), e);
}
return result;
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditService method findRevisions.
@Override
public <T> List<IdmAuditDto> findRevisions(Class<T> classType, UUID entityId) {
IdmAuditFilter filter = new IdmAuditFilter();
filter.setEntityId(entityId);
filter.setType(classType.getName());
Pageable page = new PageRequest(0, Integer.MAX_VALUE, new Sort("timestamp"));
Page<IdmAuditDto> result = this.find(filter, page);
return result.getContent();
}
Aggregations