Skip to content

Commit

Permalink
Merge pull request #2106 from reportportal/EPMRPP-96944
Browse files Browse the repository at this point in the history
EPMRPP-96944 || Fix incorrect history field values
  • Loading branch information
pbortnik authored Nov 25, 2024
2 parents 155e8ba + 104b943 commit ec591c6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;
import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS;
import java.util.Map;
Expand All @@ -33,7 +32,7 @@ public interface ServerAdminHandler {
/**
* Get all server settings
*
* @return {@link ServerSettingsResource}
* @return {@link Map}
*/
Map<String, String> getServerSettings();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.epam.ta.reportportal.core.admin;

import static com.epam.ta.reportportal.entity.ServerSettingsConstants.ANALYTICS_CONFIG_PREFIX;
import static com.epam.ta.reportportal.ws.converter.converters.ServerSettingsConverter.TO_RESOURCE;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toMap;

Expand All @@ -28,6 +29,7 @@
import com.epam.ta.reportportal.dao.ServerSettingsRepository;
import com.epam.ta.reportportal.entity.ServerSettings;
import com.epam.ta.reportportal.model.settings.AnalyticsResource;
import com.epam.ta.reportportal.model.settings.ServerSettingsResource;
import com.epam.ta.reportportal.model.settings.UpdateSettingsRq;
import com.epam.ta.reportportal.ws.converter.converters.ServerSettingsConverter;
import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS;
Expand All @@ -51,7 +53,7 @@ public class ServerAdminHandlerImpl implements ServerAdminHandler {

@Override
public Map<String, String> getServerSettings() {
return ServerSettingsConverter.TO_RESOURCE.apply(
return ServerSettingsConverter.TO_RESOURCES.apply(
serverSettingsRepository.selectServerSettings());
}

Expand Down Expand Up @@ -83,9 +85,12 @@ public OperationCompletionRS updateServerSettings(UpdateSettingsRq request,
ServerSettings serverSettings = serverSettingsRepository.findByKey(request.getKey())
.orElseThrow(() -> new ReportPortalException(ErrorType.SERVER_SETTINGS_NOT_FOUND,
request.getKey()));
ServerSettingsResource before = TO_RESOURCE.apply(serverSettings);

serverSettings.setValue(request.getValue());
ServerSettings saved = serverSettingsRepository.save(serverSettings);
messageBus.publishActivity(new SettingsUpdatedEvent(serverSettings, saved,
serverSettingsRepository.save(serverSettings);

messageBus.publishActivity(new SettingsUpdatedEvent(before, TO_RESOURCE.apply(serverSettings),
user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Server Settings were successfully updated.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import com.epam.ta.reportportal.entity.activity.EventObject;
import com.epam.ta.reportportal.entity.activity.EventPriority;
import com.epam.ta.reportportal.entity.activity.EventSubject;
import com.epam.ta.reportportal.model.settings.ServerSettingsResource;

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

public SettingsUpdatedEvent(ServerSettings before, ServerSettings after, Long userId,
public SettingsUpdatedEvent(ServerSettingsResource before, ServerSettingsResource after, Long userId,
String userLogin) {
super(userId, userLogin, before, after);
}
Expand All @@ -44,7 +45,7 @@ public Activity toActivity() {
.addAction(EventAction.UPDATE)
.addEventName(ActivityAction.UPDATE_INSTANCE.getValue())
.addPriority(EventPriority.HIGH)
.addObjectName(getAfter().getKey())
.addObjectName("instanceSetting")
.addObjectType(EventObject.INSTANCE)
.addSubjectId(getUserId())
.addSubjectName(getUserLogin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public CreateUserBidRS createUserBid(CreateUserRQ request, ReportPortalUser logg
String emailURL) {

if (isSsoEnabled()) {
throw new ReportPortalException(FORBIDDEN_OPERATION, "Cannot invite user while SSO enabled.");
throw new ReportPortalException(ACCESS_DENIED, "Cannot invite user if SSO enabled.");
}

final Project defaultProject = getProjectHandler.get(normalizeId(request.getDefaultProject()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ServerSettingsInfoContributor(ServerSettingsRepository settingsRepository
public Map<String, ?> contribute() {
Map<String, Object> info = new HashMap<>();
List<ServerSettings> all = settingsRepository.selectServerSettings();
Map<String, String> result = ServerSettingsConverter.TO_RESOURCE.apply(all);
Map<String, String> result = ServerSettingsConverter.TO_RESOURCES.apply(all);
info.put("result", result);
return info;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.ta.reportportal.model.settings;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
* Global server settings response of stored properties
*
* @author Andrei_Ramanchuk
* @author <a href="mailto:[email protected]">Pavel Bortnik</a>
*/
@JsonInclude(Include.NON_NULL)
@Data
@Builder
@AllArgsConstructor
public class ServerSettingsResource {

private String profile;

private boolean active;

@JsonProperty(value = "serverEmailConfig")
private ServerEmailResource serverEmailResource;

// private Map<String, OAuthDetailsResource> oauthConfigs;

private Map<String, AnalyticsResource> analyticsResource;

public void setProfile(String id) {
this.profile = id;
}

public String getProfile() {
return profile;
}

public void setActive(boolean is) {
this.active = is;
}

public boolean getActive() {
return active;
}

public void setServerEmailResource(ServerEmailResource config) {
this.serverEmailResource = config;
}

public ServerEmailResource getServerEmailResource() {
return serverEmailResource;
}

// public Map<String, OAuthDetailsResource> getOauthConfigs() {
// return oauthConfigs;
// }

// public void setOauthConfigs(Map<String, OAuthDetailsResource> oauthConfigs) {
// this.oauthConfigs = oauthConfigs;
// }
private String key;

public Map<String, AnalyticsResource> getAnalyticsResource() {
return analyticsResource;
}
private String value;

public void setAnalyticsResource(Map<String, AnalyticsResource> analyticsResource) {
this.analyticsResource = analyticsResource;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
/*
* Copyright 2019 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.model.settings;

import javax.validation.constraints.NotEmpty;
import lombok.Data;

/**
* @author <a href="mailto:[email protected]">Pavel Bortnik</a>
*/
@Data
public class UpdateSettingsRq {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import static com.epam.reportportal.rules.commons.validation.BusinessRule.expect;

import com.epam.ta.reportportal.entity.ServerSettings;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.ta.reportportal.entity.ServerSettings;
import com.epam.ta.reportportal.model.settings.ServerSettingsResource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -33,15 +34,18 @@
*/
public final class ServerSettingsConverter {

private ServerSettingsConverter() {
//static only
}
public static final Function<ServerSettings, ServerSettingsResource> TO_RESOURCE = serverSettings -> new ServerSettingsResource(
serverSettings.getKey(), serverSettings.getValue());

public static final Function<List<ServerSettings>, Map<String, String>> TO_RESOURCE = serverSettings -> {
public static final Function<List<ServerSettings>, Map<String, String>> TO_RESOURCES = serverSettings -> {
expect(serverSettings, CollectionUtils::isNotEmpty).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND,
"default");
return serverSettings.stream()
.collect(Collectors.toMap(ServerSettings::getKey, ServerSettings::getValue));
};

private ServerSettingsConverter() {
//static only
}

}

0 comments on commit ec591c6

Please sign in to comment.