Search in sources :

Example 1 with AuditEventV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response in project cloudbreak by hortonworks.

the class AuditGetAction method action.

@Override
public AuditTestDto action(TestContext testContext, AuditTestDto testDto, CloudbreakClient client) throws Exception {
    AuditEventV4Response response = client.getDefaultClient().auditV4Endpoint().getAuditEventById(client.getWorkspaceId(), testDto.getAuditId());
    testDto.setResponse(response);
    Log.whenJson(LOGGER, " Audit listed successfully:\n", testDto.getResponse());
    return testDto;
}
Also used : AuditEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response)

Example 2 with AuditEventV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response in project cloudbreak by hortonworks.

the class AuditEventServiceTest method testGetAuditEventByWorkspaceIdWhenEventExistsAndHasPermissionToReadItThenTheExpectedEventShouldReturn.

@Test
public void testGetAuditEventByWorkspaceIdWhenEventExistsAndHasPermissionToReadItThenTheExpectedEventShouldReturn() {
    AuditEventV4Response expected = mock(AuditEventV4Response.class);
    StructuredEventEntity repoResult = new StructuredEventEntity();
    when(structuredEventEntityToAuditEventV4ResponseConverter.convert(repoResult)).thenReturn(expected);
    when(legacyStructuredEventDBService.findByWorkspaceIdAndId(TEST_DEFAULT_ORG_ID, TEST_AUDIT_ID)).thenReturn(repoResult);
    AuditEventV4Response actual = underTest.getAuditEventByWorkspaceId(TEST_DEFAULT_ORG_ID, TEST_AUDIT_ID);
    Assert.assertEquals(expected, actual);
    verify(structuredEventEntityToAuditEventV4ResponseConverter, times(1)).convert(repoResult);
    verify(legacyStructuredEventDBService, times(1)).findByWorkspaceIdAndId(TEST_DEFAULT_ORG_ID, TEST_AUDIT_ID);
}
Also used : StructuredEventEntity(com.sequenceiq.cloudbreak.domain.StructuredEventEntity) AuditEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response) Test(org.junit.Test)

Example 3 with AuditEventV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response in project cloudbreak by hortonworks.

the class AuditEventServiceTest method testGetAuditEventWhenEventExistsAndHasPermissionToReadItThenTheExpectedEventShouldReturn.

@Test
public void testGetAuditEventWhenEventExistsAndHasPermissionToReadItThenTheExpectedEventShouldReturn() {
    AuditEventV4Response expected = mock(AuditEventV4Response.class);
    StructuredEventEntity repoResult = new StructuredEventEntity();
    when(structuredEventEntityToAuditEventV4ResponseConverter.convert(repoResult)).thenReturn(expected);
    when(legacyStructuredEventDBService.findByWorkspaceIdAndId(TEST_DEFAULT_ORG_ID, TEST_AUDIT_ID)).thenReturn(repoResult);
    AuditEventV4Response actual = underTest.getAuditEvent(TEST_AUDIT_ID);
    Assert.assertEquals(expected, actual);
    verify(structuredEventEntityToAuditEventV4ResponseConverter, times(1)).convert(repoResult);
    verify(legacyStructuredEventDBService, times(1)).findByWorkspaceIdAndId(TEST_DEFAULT_ORG_ID, TEST_AUDIT_ID);
}
Also used : StructuredEventEntity(com.sequenceiq.cloudbreak.domain.StructuredEventEntity) AuditEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response) Test(org.junit.Test)

Example 4 with AuditEventV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response in project cloudbreak by hortonworks.

the class AuditEventV4Controller method getAuditEventsZipResponse.

private Response getAuditEventsZipResponse(Collection<AuditEventV4Response> auditEventV4Responses, String resourceType) {
    StreamingOutput streamingOutput = output -> {
        try (ZipOutputStream zipOutputStream = new ZipOutputStream(output)) {
            zipOutputStream.putNextEntry(new ZipEntry("struct-events.json"));
            zipOutputStream.write(JsonUtil.writeValueAsString(auditEventV4Responses).getBytes());
            zipOutputStream.closeEntry();
        }
    };
    String fileName = String.format("audit-%s.zip", resourceType);
    return Response.ok(streamingOutput).header("content-disposition", String.format("attachment; filename = %s", fileName)).build();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) AuditEventV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.AuditEventV4Endpoint) DisableCheckPermissions(com.sequenceiq.authorization.annotation.DisableCheckPermissions) Collection(java.util.Collection) StreamingOutput(javax.ws.rs.core.StreamingOutput) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Controller(org.springframework.stereotype.Controller) AuditEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response) Inject(javax.inject.Inject) CloudbreakRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService) List(java.util.List) AuditEventV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Responses) Response(javax.ws.rs.core.Response) AuditEventService(com.sequenceiq.cloudbreak.service.audit.AuditEventService) ZipEntry(java.util.zip.ZipEntry) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 5 with AuditEventV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response in project cloudbreak by hortonworks.

the class AuditEventService method getAuditEventsByWorkspaceId.

public List<AuditEventV4Response> getAuditEventsByWorkspaceId(Long workspaceId, String resourceType, Long resourceId, String resourceCrn) {
    User user = userService.getOrCreate(legacyRestRequestThreadLocalService.getCloudbreakUser());
    Workspace workspace = getWorkspaceService().get(workspaceId, user);
    List<AuditEventV4Response> auditEventV4Responses = getEventsForUserWithTypeAndResourceIdByWorkspace(workspace, resourceType, resourceId, resourceCrn);
    auditEventV4Responses.sort(new AuditEventComparator().reversed());
    return auditEventV4Responses;
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) AuditEventComparator(com.sequenceiq.cloudbreak.comparator.audit.AuditEventComparator) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) AuditEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response)

Aggregations

AuditEventV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Response)5 StructuredEventEntity (com.sequenceiq.cloudbreak.domain.StructuredEventEntity)2 Test (org.junit.Test)2 DisableCheckPermissions (com.sequenceiq.authorization.annotation.DisableCheckPermissions)1 AuditEventV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.audits.AuditEventV4Endpoint)1 AuditEventV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.audits.responses.AuditEventV4Responses)1 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)1 AuditEventComparator (com.sequenceiq.cloudbreak.comparator.audit.AuditEventComparator)1 AuditEventService (com.sequenceiq.cloudbreak.service.audit.AuditEventService)1 CloudbreakRestRequestThreadLocalService (com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService)1 User (com.sequenceiq.cloudbreak.workspace.model.User)1 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)1 Collection (java.util.Collection)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Inject (javax.inject.Inject)1 Response (javax.ws.rs.core.Response)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Controller (org.springframework.stereotype.Controller)1