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

[WINDUP-3561] - Update static reports to PF4 - mandatory reports #891

Merged
merged 6 commits into from
Mar 31, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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 org.jboss.windup.web.services.servlet;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.regex.Pattern;

/**
* When user requests static report files:
* 'static-report/{reportNumber}/settings.js' or 'static-report/{reportNumber}/windup.js'
* then redirect request to 'static-report/{reportNumber}/settings.js.ejs' or 'static-report/{reportNumber}/windup.js.ejs'
* <p>
* When user requests 'static-report/{reportNumber}/api/*'
* then redirect request to 'static-report/{reportNumber}/api/*.json'
*/
public class FileDefaultServletFilter implements Filter {

// public static final Pattern staticReportApi = Pattern.compile("\\/static-report\\/[0-9]\\/api\\/\\w+.json$");
public static final Pattern staticSettingsJS = Pattern.compile("\\/windup-ui\\/api\\/static-report\\/[0-9]\\/settings\\.js");
public static final Pattern staticWindupJS = Pattern.compile("\\/windup-ui\\/api\\/static-report\\/[0-9]\\/windup\\.js");
public static final Pattern staticReportApi = Pattern.compile("\\/windup-ui\\/api\\/static-report\\/[0-9]\\/api\\/.+$");

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
String requestURI = httpServletRequest.getRequestURI();

HttpServletResponse httpResponse = (HttpServletResponse) response;

if (staticSettingsJS.matcher(requestURI).matches() || staticWindupJS.matcher(requestURI).matches()) {
String newURI = requestURI.concat(".ejs");
httpResponse.sendRedirect(newURI);
} else if (staticReportApi.matcher(requestURI).matches() && !requestURI.endsWith(".json")) {
String newURI = requestURI.concat(".json");
httpResponse.sendRedirect(newURI);
} else {
chain.doFilter(request, response);
}
}

}
9 changes: 9 additions & 0 deletions services/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<param-value>org.jboss.resteasy.plugins.stats.RegistryStatsResource</param-value>
</context-param>

<filter>
<filter-name>FileServletFilter</filter-name>
<filter-class>org.jboss.windup.web.services.servlet.FileDefaultServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>FileServletFilter</filter-name>
<url-pattern>/static-report/*</url-pattern>
</filter-mapping>

<servlet>
<description>Serves static files.</description>
<servlet-name>FileServlet</servlet-name>
Expand Down
1 change: 1 addition & 0 deletions ui-pf4/src/main/webapp/src/Constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export enum AdvancedOptionsFieldKey {
SOURCE_MODE = "sourceMode",
ANALYZE_KNOWN_LIBRARIES = "analyzeKnownLibraries",
TRANSTRACTION_ANALYSIS = "enableTransactionAnalysis",
LEGACY_REPORTS = "legacyReports",
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface FormValues {
[AdvancedOptionsFieldKey.SOURCE_MODE]?: boolean;
[AdvancedOptionsFieldKey.ANALYZE_KNOWN_LIBRARIES]?: boolean;
[AdvancedOptionsFieldKey.TRANSTRACTION_ANALYSIS]?: boolean;
[AdvancedOptionsFieldKey.LEGACY_REPORTS]?: boolean;
}

export interface AdvancedOptionsFormProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ export const Fields: Map<AdvancedOptionsFieldKey, IFieldInfo> = new Map([
type: "switch",
},
],
[
AdvancedOptionsFieldKey.LEGACY_REPORTS,
{
label: "Legacy reports",
type: "switch",
},
],
]);

// Schema
Expand Down