Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-96944 || Add tracking event when user changes instance invitation settings #2105

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation 'com.epam.reportportal:commons'
implementation 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-dao:5730610'
implementation 'com.github.reportportal:commons-dao:e25b121'
implementation 'com.github.reportportal:commons:develop-SNAPSHOT'
implementation 'com.github.reportportal:plugin-api:develop-SNAPSHOT'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.epam.ta.reportportal.core.admin;

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.model.settings.AnalyticsResource;
import com.epam.ta.reportportal.model.settings.ServerSettingsResource;
import com.epam.ta.reportportal.model.settings.UpdateSettingsRq;
Expand Down Expand Up @@ -50,5 +51,5 @@ public interface ServerAdminHandler {
* @param request {@link UpdateSettingsRq}
* @return Operation results
*/
OperationCompletionRS updateServerSettings(UpdateSettingsRq request);
OperationCompletionRS updateServerSettings(UpdateSettingsRq request, ReportPortalUser user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.core.events.MessageBus;
import com.epam.ta.reportportal.core.events.activity.SettingsUpdatedEvent;
import com.epam.ta.reportportal.dao.ServerSettingsRepository;
import com.epam.ta.reportportal.entity.ServerSettings;
import com.epam.ta.reportportal.model.settings.AnalyticsResource;
Expand All @@ -30,7 +33,7 @@
import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
Expand All @@ -39,14 +42,12 @@
* @author Andrei_Ramanchuk
*/
@Service
@RequiredArgsConstructor
public class ServerAdminHandlerImpl implements ServerAdminHandler {

private final ServerSettingsRepository serverSettingsRepository;

@Autowired
public ServerAdminHandlerImpl(ServerSettingsRepository serverSettingsRepository) {
this.serverSettingsRepository = serverSettingsRepository;
}
private final MessageBus messageBus;

@Override
public Map<String, String> getServerSettings() {
Expand Down Expand Up @@ -77,12 +78,15 @@ public OperationCompletionRS saveAnalyticsSettings(AnalyticsResource analyticsRe
}

@Override
public OperationCompletionRS updateServerSettings(UpdateSettingsRq request) {
public OperationCompletionRS updateServerSettings(UpdateSettingsRq request,
ReportPortalUser user) {
ServerSettings serverSettings = serverSettingsRepository.findByKey(request.getKey())
.orElseThrow(() -> new ReportPortalException(ErrorType.SERVER_SETTINGS_NOT_FOUND,
request.getKey()));
serverSettings.setValue(request.getValue());
serverSettingsRepository.save(serverSettings);
ServerSettings saved = serverSettingsRepository.save(serverSettings);
messageBus.publishActivity(new SettingsUpdatedEvent(serverSettings, saved,
user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Server Settings were successfully updated.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.epam.ta.reportportal.core.events.activity;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck> reported by reviewdog 🐶
'package' should be separated from previous line.


import static com.epam.ta.reportportal.core.events.activity.util.ActivityDetailsUtil.VALUE;

import com.epam.ta.reportportal.builder.ActivityBuilder;
import com.epam.ta.reportportal.core.events.ActivityEvent;
import com.epam.ta.reportportal.entity.ServerSettings;
import com.epam.ta.reportportal.entity.activity.Activity;
import com.epam.ta.reportportal.entity.activity.ActivityAction;
import com.epam.ta.reportportal.entity.activity.EventAction;
import com.epam.ta.reportportal.entity.activity.EventObject;
import com.epam.ta.reportportal.entity.activity.EventPriority;
import com.epam.ta.reportportal.entity.activity.EventSubject;

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck> reported by reviewdog 🐶
Summary javadoc is missing.

* @author <a href="mailto:[email protected]">Pavel Bortnik</a>
*/
public class SettingsUpdatedEvent extends AroundEvent<ServerSettings> implements ActivityEvent {

public SettingsUpdatedEvent(ServerSettings before, ServerSettings after, Long userId,
String userLogin) {
super(userId, userLogin, before, after);
}

@Override
public Activity toActivity() {
ActivityBuilder builder = new ActivityBuilder()
.addCreatedNow()
.addAction(EventAction.UPDATE)
.addEventName(ActivityAction.UPDATE_INSTANCE.getValue())
.addPriority(EventPriority.HIGH)
.addObjectName(getAfter().getKey())
.addObjectType(EventObject.INSTANCE)
.addSubjectId(getUserId())
.addSubjectName(getUserLogin())
.addSubjectType(EventSubject.USER)
.addHistoryField(getAfter().getKey(), getBefore().getValue(), getAfter().getValue());
return builder.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private ActivityDetailsUtil() {
}

public static final String NAME = "name";

public static final String VALUE = "value";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck> reported by reviewdog 🐶
'member def modifier' has incorrect indentation level 8, expected level should be 2.

public static final String DESCRIPTION = "description";
public static final String EMPTY_FIELD = "";
public static final String TICKET_ID = "ticketId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public OperationCompletionRS saveAnalyticsSettings(
public OperationCompletionRS updateServerSettings(
@RequestBody @Validated UpdateSettingsRq request,
@AuthenticationPrincipal ReportPortalUser user) {
return serverHandler.updateServerSettings(request);
return serverHandler.updateServerSettings(request, user);
}

@Transactional(readOnly = true)
Expand Down
Loading