Skip to content

Commit

Permalink
Activitylog fix (#2168)
Browse files Browse the repository at this point in the history
* Updating activitylog on approvals

Signed-off-by: muralibasani <[email protected]>

* Update tests, model

Signed-off-by: muralibasani <[email protected]>

* Update ts

Signed-off-by: muralibasani <[email protected]>

* remove commented code

Signed-off-by: muralibasani <[email protected]>

* Revert openapi upgrade

Signed-off-by: muralibasani <[email protected]>

* Update ts

Signed-off-by: muralibasani <[email protected]>

* Review and add test

Signed-off-by: muralibasani <[email protected]>

---------

Signed-off-by: muralibasani <[email protected]>
Co-authored-by: muralibasani <[email protected]>
Co-authored-by: Mathieu Anderson <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2024
1 parent 9ddf2eb commit cb44cd4
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 172 deletions.
36 changes: 18 additions & 18 deletions coral/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1762,26 +1762,26 @@ export type components = {
password?: string;
accountFound?: boolean;
};
ActivityLog: {
ActivityLogModel: {
/** Format: int32 */
req_no?: number;
/** Format: int32 */
tenantId?: number;
activityName?: string;
activityType?: string;
req_no: number;
activityName: string;
activityType: string;
/** Format: date-time */
activityTime?: string;
activityTimeString?: string;
details?: string;
user?: string;
activityTime: string;
activityTimeString: string;
details: string;
user: string;
team: string;
/** Format: int32 */
teamId?: number;
env?: string;
envName?: string;
team?: string;
totalNoPages?: string;
currentPage?: string;
allPageNos?: string[];
teamId: number;
env: string;
/** Format: int32 */
tenantId: number;
envName: string;
totalNoPages: string;
allPageNos: string[];
currentPage: string;
};
AclsCountPerEnv: {
status?: string;
Expand Down Expand Up @@ -4247,7 +4247,7 @@ export type operations = {
/** @description OK */
200: {
content: {
"application/json": components["schemas"]["ActivityLog"][];
"application/json": components["schemas"]["ActivityLogModel"][];
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<shedlock.version>5.10.0</shedlock.version>
<snakeyaml.version>1.33</snakeyaml.version>
<springdoc-openapi-maven-plugin.version>1.4</springdoc-openapi-maven-plugin.version>
<springdoc-openapi-ui.version>2.3.0</springdoc-openapi-ui.version>
<springdoc-openapi-ui.version>2.2.0</springdoc-openapi-ui.version>
<!-- If the Integration Tests are timing out because the server is slow increase the number below. 120 attempts is equal to 60s each attempt gets a 500ms backoff -->
<spring.integration.test.timeout>120</spring.integration.test.timeout>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.aiven.klaw.controller;

import io.aiven.klaw.dao.ActivityLog;
import io.aiven.klaw.model.ActivityLogModel;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.response.DbAuthInfo;
import io.aiven.klaw.service.UiConfigControllerService;
Expand Down Expand Up @@ -50,7 +50,7 @@ public ResponseEntity<ApiResponse> sendMessageToAdmin(
value = "/getActivityLogPerEnv",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<ActivityLog>> showActivityLog(
public ResponseEntity<List<ActivityLogModel>> showActivityLog(
@RequestParam(value = "env", defaultValue = "") String env,
@RequestParam("pageNo") String pageNo,
@RequestParam(value = "currentPage", defaultValue = "") String currentPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public interface HandleDbRequests {

String insertMetrics(KwMetrics kwMetrics);

void insertIntoActivityLog(
String requestType,
int tenantId,
String operationType,
int teamId,
String details,
String envId,
String requestor);

/*--------------------Select */

List<Topic> getAllTopicsByTopicNameAndTeamIdAndTenantId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ public String insertMetrics(KwMetrics kwMetrics) {
return jdbcInsertHelper.insertMetrics(kwMetrics);
}

@Override
public void insertIntoActivityLog(
String requestType,
int tenantId,
String operationType,
int teamId,
String details,
String envId,
String requestor) {
jdbcInsertHelper.insertIntoActivityLog(
requestType, tenantId, operationType, teamId, details, envId, requestor);
}

@Override
public List<Topic> getAllTopicsByTopicNameAndTeamIdAndTenantId(
String topicName, int teamId, int tenantId) {
Expand Down
114 changes: 23 additions & 91 deletions core/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,7 @@ public synchronized Map<String, String> insertIntoRequestTopic(TopicRequest topi
topicRequest.setRequesttime((new Timestamp(System.currentTimeMillis())));
topicRequestsRepo.save(topicRequest);

UserInfo userInfo = jdbcSelectHelper.selectUserInfo(topicRequest.getRequestor());

ActivityLog activityLog = new ActivityLog();
activityLog.setReq_no(getNextActivityLogRequestId(topicRequest.getTenantId()));
activityLog.setActivityName("TopicRequest");
activityLog.setActivityType(topicRequest.getRequestOperationType());
activityLog.setActivityTime(new Timestamp(System.currentTimeMillis()));
activityLog.setTeamId(userInfo.getTeamId());
activityLog.setDetails(topicRequest.getTopicname());
activityLog.setUser(topicRequest.getRequestor());
activityLog.setEnv(topicRequest.getEnvironment());
activityLog.setTenantId(topicRequest.getTenantId());

if (ApiResultStatus.SUCCESS.value.equals(insertIntoActivityLog(activityLog))) {
hashMap.put("result", ApiResultStatus.SUCCESS.value);
} else {
hashMap.put("result", ApiResultStatus.FAILURE.value);
}
hashMap.put("result", ApiResultStatus.SUCCESS.value);

return hashMap;
}
Expand All @@ -144,25 +127,7 @@ public synchronized Map<String, String> insertIntoRequestConnector(
connectorRequest.setRequesttime((new Timestamp(System.currentTimeMillis())));
kafkaConnectorRequestsRepo.save(connectorRequest);

UserInfo userInfo = jdbcSelectHelper.selectUserInfo(connectorRequest.getRequestor());

ActivityLog activityLog = new ActivityLog();
activityLog.setReq_no(getNextActivityLogRequestId(connectorRequest.getTenantId()));
activityLog.setActivityName("ConnectorRequest");
activityLog.setActivityType(connectorRequest.getRequestOperationType());
activityLog.setActivityTime(new Timestamp(System.currentTimeMillis()));
activityLog.setTeamId(userInfo.getTeamId());
activityLog.setDetails(
connectorRequest.getConnectorName() + "," + connectorRequest.getRequestOperationType());
activityLog.setUser(connectorRequest.getRequestor());
activityLog.setEnv(connectorRequest.getEnvironment());
activityLog.setTenantId(connectorRequest.getTenantId());

if (ApiResultStatus.SUCCESS.value.equals(insertIntoActivityLog(activityLog))) {
hashMap.put("result", ApiResultStatus.SUCCESS.value);
} else {
hashMap.put("result", ApiResultStatus.FAILURE.value);
}
hashMap.put("result", ApiResultStatus.SUCCESS.value);

return hashMap;
}
Expand Down Expand Up @@ -254,28 +219,6 @@ synchronized Map<String, String> insertIntoRequestAcl(AclRequests aclReq) {
aclReq.setRequestingteam(userInfo.getTeamId());
aclRequestsRepo.save(aclReq);

ActivityLog activityLog = new ActivityLog();
activityLog.setReq_no(getNextActivityLogRequestId(aclReq.getTenantId()));
activityLog.setActivityName("AclRequest");
activityLog.setActivityType(aclReq.getRequestOperationType());
activityLog.setActivityTime(new Timestamp(System.currentTimeMillis()));
activityLog.setTeamId(userInfo.getTeamId());
activityLog.setDetails(
aclReq.getAcl_ip()
+ "-"
+ aclReq.getTopicname()
+ "-"
+ aclReq.getAcl_ssl()
+ "-"
+ aclReq.getConsumergroup()
+ "-"
+ aclReq.getAclType());
activityLog.setUser(aclReq.getRequestor());
activityLog.setEnv(aclReq.getEnvironment());
activityLog.setTenantId(aclReq.getTenantId());

// Insert into acl activity log
insertIntoActivityLog(activityLog);
hashMap.put("result", ApiResultStatus.SUCCESS.value);
return hashMap;
}
Expand All @@ -294,22 +237,6 @@ synchronized Map<String, String> insertIntoOperationalRequests(
operationalRequest.setRequesttime(new Timestamp(System.currentTimeMillis()));
operationalRequestsRepo.save(operationalRequest);

UserInfo userInfo = jdbcSelectHelper.selectUserInfo(operationalRequest.getRequestor());

ActivityLog activityLog = new ActivityLog();
activityLog.setReq_no(getNextActivityLogRequestId(operationalRequest.getTenantId()));
activityLog.setActivityName("OperationalRequest");
activityLog.setActivityType(operationalRequest.getOperationalRequestType().value);
activityLog.setActivityTime(new Timestamp(System.currentTimeMillis()));
activityLog.setTeamId(userInfo.getTeamId());
activityLog.setDetails(
operationalRequest.getTopicname() + "-" + operationalRequest.getConsumerGroup());
activityLog.setUser(operationalRequest.getRequestor());
activityLog.setEnv(operationalRequest.getEnvironment());
activityLog.setTenantId(operationalRequest.getTenantId());

// Insert into acl activity log
insertIntoActivityLog(activityLog);
hashMap.put("result", ApiResultStatus.SUCCESS.value);
return hashMap;
}
Expand Down Expand Up @@ -340,22 +267,6 @@ public synchronized String insertIntoRequestSchema(SchemaRequest schemaRequest)

schemaRequestRepo.save(schemaRequest);

UserInfo userInfo = jdbcSelectHelper.selectUserInfo(schemaRequest.getRequestor());

ActivityLog activityLog = new ActivityLog();
activityLog.setReq_no(getNextActivityLogRequestId(schemaRequest.getTenantId()));
activityLog.setActivityName("SchemaRequest");
activityLog.setActivityType("new");
activityLog.setActivityTime(new Timestamp(System.currentTimeMillis()));
activityLog.setTeamId(userInfo.getTeamId());
activityLog.setDetails(schemaRequest.getTopicname() + "-" + schemaRequest.getRemarks());
activityLog.setUser(schemaRequest.getRequestor());
activityLog.setEnv(schemaRequest.getEnvironment());
activityLog.setTenantId(schemaRequest.getTenantId());

// Insert into acl activity log
insertIntoActivityLog(activityLog);

return ApiResultStatus.SUCCESS.value;
}

Expand Down Expand Up @@ -626,4 +537,25 @@ public String insertProductDetails(ProductDetails productDetails) {
productDetailsRepo.save(productDetails);
return ApiResultStatus.SUCCESS.value;
}

public void insertIntoActivityLog(
String requestType,
int tenantId,
String operationType,
int teamId,
String details,
String envId,
String requestor) {
ActivityLog activityLog = new ActivityLog();
activityLog.setReq_no(getNextActivityLogRequestId(tenantId));
activityLog.setActivityName(requestType + " Request");
activityLog.setActivityType(operationType);
activityLog.setActivityTime(new Timestamp(System.currentTimeMillis()));
activityLog.setTeamId(teamId);
activityLog.setDetails(details);
activityLog.setUser(requestor);
activityLog.setEnv(envId);
activityLog.setTenantId(tenantId);
insertIntoActivityLog(activityLog);
}
}
31 changes: 20 additions & 11 deletions core/src/main/java/io/aiven/klaw/model/ActivityLogModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.aiven.klaw.model;

import jakarta.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
Expand All @@ -12,25 +13,33 @@
@ToString
public class ActivityLogModel implements Serializable {

private Integer req_no;
@NotNull private Integer req_no;

private String activityName;
@NotNull private String activityName;

private String activityType;
@NotNull private String activityType;

private Timestamp activityTime;
@NotNull private Timestamp activityTime;

private String activityTimeString;
@NotNull private String activityTimeString;

private String details;
@NotNull private String details;

private String user;
@NotNull private String user;

private String team;
@NotNull private String team;

private String env;
@NotNull private Integer teamId;

private String totalNoPages;
@NotNull private String env;

private List<String> allPageNos;
@NotNull private int tenantId;

@NotNull private String envName;

@NotNull private String totalNoPages;

@NotNull private List<String> allPageNos;

@NotNull private String currentPage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,30 @@ public ApiResponse approveAclRequests(String req_no)
if (!updateAclReqStatus.equals(ApiResultStatus.SUCCESS.value)) {
notifyUserType = ACL_REQUEST_FAILURE;
} else {
saveToTopicHistory(userDetails, tenantId, aclReq);
updateAuditAndHistory(userDetails, tenantId, dbHandle, aclReq);
}

return emailAndReturnClaimUpdate(aclReq, dbHandle, notifyUserType, updateAclReqStatus);
}

private void updateAuditAndHistory(
String userDetails, int tenantId, HandleDbRequests dbHandle, AclRequests aclReq) {
saveToTopicHistory(userDetails, tenantId, aclReq);
dbHandle.insertIntoActivityLog(
RequestEntityType.ACL.value,
tenantId,
aclReq.getRequestOperationType(),
aclReq.getTeamId(),
aclReq.getTopicname()
+ "-"
+ aclReq.getAclType()
+ (aclReq.getAcl_ip() != null ? aclReq.getAcl_ip() + "-" : "")
+ (aclReq.getAcl_ssl() != null ? aclReq.getAcl_ssl() + "-" : "")
+ (aclReq.getConsumergroup() != null ? aclReq.getConsumergroup() : ""),
aclReq.getEnvironment(),
aclReq.getRequestor());
}

private ApiResponse approveClaimAcl(
AclRequests aclReq, String userDetails, int tenantId, HandleDbRequests dbHandle)
throws KlawException, KlawBadRequestException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.aiven.klaw.model.enums.Order;
import io.aiven.klaw.model.enums.PermissionType;
import io.aiven.klaw.model.enums.PromotionStatusType;
import io.aiven.klaw.model.enums.RequestEntityType;
import io.aiven.klaw.model.enums.RequestOperationType;
import io.aiven.klaw.model.enums.RequestStatus;
import io.aiven.klaw.model.requests.KafkaConnectorModel;
Expand Down Expand Up @@ -709,8 +710,8 @@ public ApiResponse approveConnectorRequests(String connectorId)
tenantId);

if (Objects.equals(updateConnectorReqStatus, ApiResultStatus.SUCCESS.value)) {
setConnectorHistory(connectorRequest, userDetails, tenantId);
updateConnectorReqStatus = dbHandle.updateConnectorRequest(connectorRequest, userDetails);
updateAuditAndHistory(userDetails, tenantId, connectorRequest, dbHandle);
mailService.sendMail(
connectorRequest.getConnectorName(),
null,
Expand All @@ -728,6 +729,22 @@ public ApiResponse approveConnectorRequests(String connectorId)
: ApiResponse.notOk(updateConnectorReqStatus);
}

private void updateAuditAndHistory(
String userDetails,
int tenantId,
KafkaConnectorRequest connectorRequest,
HandleDbRequests dbHandle) {
setConnectorHistory(connectorRequest, userDetails, tenantId);
dbHandle.insertIntoActivityLog(
RequestEntityType.CONNECTOR.value,
tenantId,
connectorRequest.getRequestOperationType(),
connectorRequest.getTeamId(),
"Connector : " + connectorRequest.getConnectorName(),
connectorRequest.getEnvironment(),
connectorRequest.getRequestor());
}

private void setConnectorHistory(
KafkaConnectorRequest connectorRequest, String userName, int tenantId) {
try {
Expand Down
Loading

0 comments on commit cb44cd4

Please sign in to comment.