Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright 2014 CapitalOne, LLC.
* Further development Copyright 2022 Sapient Corporation.
*
* 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.publicissapient.kpidashboard.apis.appsetting.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Configuration properties for help and documentation resources.
*
* @author aksshriv1
*/
@Component
@ConfigurationProperties(prefix = "help")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class HelpConfig {

private String productDocumentationUrl;
private String apiDocumentationUrl;
private String videoTutorialsUrl;
private String raiseTicketUrl;
private String supportChannelUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright 2014 CapitalOne, LLC.
* Further development Copyright 2022 Sapient Corporation.
*
* 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.publicissapient.kpidashboard.apis.appsetting.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Configuration properties for Potential Economic Benefits Calculator.
*
* @author aksshriv1
*/
@Component
@ConfigurationProperties(prefix = "peb")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PEBConfig {

private Integer totalDevelopers;
private Double avgCostPerDeveloper;
private String timeDuration;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/*******************************************************************************
* Copyright 2014 CapitalOne, LLC.
* Further development Copyright 2022 Sapient Corporation.
* 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.publicissapient.kpidashboard.apis.appsetting.rest;

import com.publicissapient.kpidashboard.apis.appsetting.config.HelpConfig;
import com.publicissapient.kpidashboard.apis.appsetting.config.PEBConfig;
import com.publicissapient.kpidashboard.apis.model.ServiceResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* REST controller for managing help and documentation resources.
* Provides endpoints to retrieve help configuration and redirect to external documentation URLs.
*
* @author aksshriv1
*/
@RestController
@RequestMapping("/help")
@Tag(name = "Help", description = "Endpoints for managing support and documentation resources")
@Slf4j
public class HelpAndSupportController {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it help controller when this is actually an endpoint for managing documentations?

@RequestMapping("/documentation") and then have the required endpoints beneath it


@Autowired
private HelpConfig helpConfig;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the constructor based injection along with @requiredargsconstructor


public void setHelpConfig(HelpConfig helpConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Lombok annotations

this.helpConfig = helpConfig;
}

/**
* Retrieves all configured help resource URLs.
* Returns a map containing URLs for product documentation, API documentation,
* video tutorials, ticket raising, and support channels.
*
* @return ResponseEntity containing a map of help resource names to their URLs
*/
@GetMapping(value = "/config", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "Get Help Configuration",
description = "Retrieves all configured help resource URLs including documentation, tutorials, and support channels")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "Successfully retrieved help configuration",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ServiceResponse.class))
})
})
public ResponseEntity<ServiceResponse> getHelpConfig() {
log.info("Fetching help configuration");
Map<String, String> resourceLinks = new LinkedHashMap<>();
resourceLinks.put("productDocumentation", helpConfig.getProductDocumentationUrl() != null ? helpConfig.getProductDocumentationUrl() : "");
resourceLinks.put("apiDocumentation", helpConfig.getApiDocumentationUrl() != null ? helpConfig.getApiDocumentationUrl() : "");
resourceLinks.put("videoTutorials", helpConfig.getVideoTutorialsUrl() != null ? helpConfig.getVideoTutorialsUrl() : "");
resourceLinks.put("raiseTicket", helpConfig.getRaiseTicketUrl() != null ? helpConfig.getRaiseTicketUrl() : "");
resourceLinks.put("supportChannel", helpConfig.getSupportChannelUrl() != null ? helpConfig.getSupportChannelUrl() : "");
log.info("Help configuration retrieved successfully");
return ResponseEntity.ok(new ServiceResponse(true, "Help and Support configuration retrieved successfully", resourceLinks));
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a DTO instead of using a map

}

/**
* Redirects to the API documentation URL.
*
* @return ResponseEntity with HTTP 302 redirect or 404 if URL is not configured
*/
@GetMapping("/api-documentation")
@Operation(
summary = "Redirect to API Documentation",
description = "Redirects to the configured API documentation URL")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "302",
description = "Successfully redirected to API documentation"),
@ApiResponse(
responseCode = "404",
description = "API documentation URL is not configured")
})
public ResponseEntity<Void> redirectToApiDocumentation() {
log.info("Redirecting to API documentation");
return redirectToUrl(helpConfig.getApiDocumentationUrl(), "API documentation");
}

/**
* Redirects to the product documentation URL.
*
* @return ResponseEntity with HTTP 302 redirect or 404 if URL is not configured
*/
@GetMapping("/product-documentation")
@Operation(
summary = "Redirect to Product Documentation",
description = "Redirects to the configured product documentation URL")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "302",
description = "Successfully redirected to product documentation"),
@ApiResponse(
responseCode = "404",
description = "Product documentation URL is not configured")
})
public ResponseEntity<Void> redirectToProductDocumentation() {
log.info("Redirecting to product documentation");
return redirectToUrl(helpConfig.getProductDocumentationUrl(), "Product documentation");
}

/**
* Redirects to the video tutorials URL.
*
* @return ResponseEntity with HTTP 302 redirect or 404 if URL is not configured
*/
@GetMapping("/video-tutorials")
@Operation(
summary = "Redirect to Video Tutorials",
description = "Redirects to the configured video tutorials URL")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "302",
description = "Successfully redirected to video tutorials"),
@ApiResponse(
responseCode = "404",
description = "Video tutorials URL is not configured")
})
public ResponseEntity<Void> redirectToVideoTutorials() {
log.info("Redirecting to video tutorials");
return redirectToUrl(helpConfig.getVideoTutorialsUrl(), "Video tutorials");
}

/**
* Redirects to the ticket raising URL.
*
* @return ResponseEntity with HTTP 302 redirect or 404 if URL is not configured
*/
@GetMapping("/raise-ticket")
@Operation(
summary = "Redirect to Raise Ticket",
description = "Redirects to the configured ticket raising URL")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "302",
description = "Successfully redirected to ticket raising page"),
@ApiResponse(
responseCode = "404",
description = "Ticket raising URL is not configured")
})
public ResponseEntity<Void> redirectToRaiseTicket() {
log.info("Redirecting to raise ticket");
return redirectToUrl(helpConfig.getRaiseTicketUrl(), "Raise ticket");
}

/**
* Redirects to the support channel URL.
*
* @return ResponseEntity with HTTP 302 redirect or 404 if URL is not configured
*/
@GetMapping("/support-channel")
@Operation(
summary = "Redirect to Support Channel",
description = "Redirects to the configured support channel URL")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "302",
description = "Successfully redirected to support channel"),
@ApiResponse(
responseCode = "404",
description = "Support channel URL is not configured")
})
public ResponseEntity<Void> redirectToSupportChannel() {
log.info("Redirecting to support channel");
return redirectToUrl(helpConfig.getSupportChannelUrl(), "Support channel");
}

/**
* Helper method to perform URL redirection.
* Validates the URL and returns appropriate HTTP status.
*
* @param url the URL to redirect to
* @param resourceName the name of the resource being redirected to
* @return ResponseEntity with HTTP 302 (Found) for valid URLs or 404 (Not Found) for invalid/empty URLs
*/
private ResponseEntity<Void> redirectToUrl(String url, String resourceName) {
if (url == null || url.trim().isEmpty()) {
log.warn("{} URL is not configured", resourceName);
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
log.info("Redirecting to {} URL: {}", resourceName, url);
return ResponseEntity.status(HttpStatus.FOUND).location(URI.create(url)).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.publicissapient.kpidashboard.apis.appsetting.rest;

import com.publicissapient.kpidashboard.apis.appsetting.config.PEBConfig;
import com.publicissapient.kpidashboard.apis.model.ServiceResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

@RestController
@RequestMapping("/peb")
@Tag(name = "PotentialEconomicBenefit", description = "Endpoints for PEB Calculator Configuration")
@Slf4j
public class PEBConfigController {

@Autowired
private PEBConfig pebConfig;

public void setPebConfig(PEBConfig pebConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please apply the same review comments as received for "HelpAndSupportController"

this.pebConfig = pebConfig;
}

/**
* Retrieves Potential Economic Benefits configuration.
*
* @return ResponseEntity containing PEB configuration parameters
*/
@GetMapping(value = "/configs", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "Get Economic Benefits Configuration",
description = "Retrieves Potential Economic Benefits calculator configuration parameters")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "Successfully retrieved PEB configuration",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ServiceResponse.class))
})
})
public ResponseEntity<ServiceResponse> getEconomicBenefitsConfig() {
log.info("Fetching economic benefits configuration");
Map<String, Object> pebData = new LinkedHashMap<>();
pebData.put("totalDevelopers", pebConfig.getTotalDevelopers() != null ? pebConfig.getTotalDevelopers() : 30);
pebData.put("avgCostPerDeveloper", pebConfig.getAvgCostPerDeveloper() != null ? pebConfig.getAvgCostPerDeveloper() : 100000.00);
pebData.put("timeDuration", pebConfig.getTimeDuration() != null ? pebConfig.getTimeDuration() : "Per Year");
log.info("Economic benefits configuration retrieved successfully");
return ResponseEntity.ok(new ServiceResponse(true, "Economic benefits configuration retrieved successfully", pebData));
}
}
Loading