diff --git a/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandler.java b/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandler.java index 3a75dfbac9..eaa99d28f5 100644 --- a/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandler.java +++ b/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandler.java @@ -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; @@ -33,7 +32,7 @@ public interface ServerAdminHandler { /** * Get all server settings * - * @return {@link ServerSettingsResource} + * @return {@link Map} */ Map getServerSettings(); diff --git a/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandlerImpl.java b/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandlerImpl.java index d6ade9e72d..d6e8089f82 100644 --- a/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandlerImpl.java +++ b/src/main/java/com/epam/ta/reportportal/core/admin/ServerAdminHandlerImpl.java @@ -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; @@ -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; @@ -51,7 +53,7 @@ public class ServerAdminHandlerImpl implements ServerAdminHandler { @Override public Map getServerSettings() { - return ServerSettingsConverter.TO_RESOURCE.apply( + return ServerSettingsConverter.TO_RESOURCES.apply( serverSettingsRepository.selectServerSettings()); } @@ -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."); } diff --git a/src/main/java/com/epam/ta/reportportal/core/events/activity/SettingsUpdatedEvent.java b/src/main/java/com/epam/ta/reportportal/core/events/activity/SettingsUpdatedEvent.java index 77f7ddbbd2..b7a1f53ca8 100644 --- a/src/main/java/com/epam/ta/reportportal/core/events/activity/SettingsUpdatedEvent.java +++ b/src/main/java/com/epam/ta/reportportal/core/events/activity/SettingsUpdatedEvent.java @@ -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 Pavel Bortnik */ -public class SettingsUpdatedEvent extends AroundEvent implements ActivityEvent { +public class SettingsUpdatedEvent extends AroundEvent 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); } @@ -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()) diff --git a/src/main/java/com/epam/ta/reportportal/core/user/impl/CreateUserHandlerImpl.java b/src/main/java/com/epam/ta/reportportal/core/user/impl/CreateUserHandlerImpl.java index 4f2c921386..bfd99155d7 100644 --- a/src/main/java/com/epam/ta/reportportal/core/user/impl/CreateUserHandlerImpl.java +++ b/src/main/java/com/epam/ta/reportportal/core/user/impl/CreateUserHandlerImpl.java @@ -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())); diff --git a/src/main/java/com/epam/ta/reportportal/info/ServerSettingsInfoContributor.java b/src/main/java/com/epam/ta/reportportal/info/ServerSettingsInfoContributor.java index 9a494c5379..41db8f593e 100644 --- a/src/main/java/com/epam/ta/reportportal/info/ServerSettingsInfoContributor.java +++ b/src/main/java/com/epam/ta/reportportal/info/ServerSettingsInfoContributor.java @@ -45,7 +45,7 @@ public ServerSettingsInfoContributor(ServerSettingsRepository settingsRepository public Map contribute() { Map info = new HashMap<>(); List all = settingsRepository.selectServerSettings(); - Map result = ServerSettingsConverter.TO_RESOURCE.apply(all); + Map result = ServerSettingsConverter.TO_RESOURCES.apply(all); info.put("result", result); return info; diff --git a/src/main/java/com/epam/ta/reportportal/model/settings/ServerSettingsResource.java b/src/main/java/com/epam/ta/reportportal/model/settings/ServerSettingsResource.java index 51c24a23ec..5fde105424 100644 --- a/src/main/java/com/epam/ta/reportportal/model/settings/ServerSettingsResource.java +++ b/src/main/java/com/epam/ta/reportportal/model/settings/ServerSettingsResource.java @@ -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 Pavel Bortnik */ -@JsonInclude(Include.NON_NULL) +@Data +@Builder +@AllArgsConstructor public class ServerSettingsResource { - private String profile; - - private boolean active; - - @JsonProperty(value = "serverEmailConfig") - private ServerEmailResource serverEmailResource; - - // private Map oauthConfigs; - - private Map 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 getOauthConfigs() { - // return oauthConfigs; - // } - - // public void setOauthConfigs(Map oauthConfigs) { - // this.oauthConfigs = oauthConfigs; - // } + private String key; - public Map getAnalyticsResource() { - return analyticsResource; - } + private String value; - public void setAnalyticsResource(Map analyticsResource) { - this.analyticsResource = analyticsResource; - } } diff --git a/src/main/java/com/epam/ta/reportportal/model/settings/UpdateSettingsRq.java b/src/main/java/com/epam/ta/reportportal/model/settings/UpdateSettingsRq.java index 2ae251d1d7..5ec587ed2e 100644 --- a/src/main/java/com/epam/ta/reportportal/model/settings/UpdateSettingsRq.java +++ b/src/main/java/com/epam/ta/reportportal/model/settings/UpdateSettingsRq.java @@ -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 Pavel Bortnik + */ @Data public class UpdateSettingsRq { diff --git a/src/main/java/com/epam/ta/reportportal/ws/converter/converters/ServerSettingsConverter.java b/src/main/java/com/epam/ta/reportportal/ws/converter/converters/ServerSettingsConverter.java index b145502de7..14c7ebc10c 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/converter/converters/ServerSettingsConverter.java +++ b/src/main/java/com/epam/ta/reportportal/ws/converter/converters/ServerSettingsConverter.java @@ -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; @@ -33,15 +34,18 @@ */ public final class ServerSettingsConverter { - private ServerSettingsConverter() { - //static only - } + public static final Function TO_RESOURCE = serverSettings -> new ServerSettingsResource( + serverSettings.getKey(), serverSettings.getValue()); - public static final Function, Map> TO_RESOURCE = serverSettings -> { + public static final Function, Map> 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 + } + }