Skip to content

Commit

Permalink
new linux build, added skip license,
Browse files Browse the repository at this point in the history
linux cli version compatibility fix with NBIA 9.2
  • Loading branch information
jmwhorton committed Sep 11, 2024
1 parent 022a456 commit 2ed739c
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 20 deletions.
86 changes: 78 additions & 8 deletions software/nbia-download-manager/buildDMC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ant -f buildDMC.xml
<description>
Create a executable jar for Standalond Download Manager with Ant build script
</description>
<property name="JAVA_HOME" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home"/>
<property file="../build/defaultAHP3.properties"/>
<property name="projectName" value="StandaloneDM" />
<property name="common.dir" value="${basedir}/../" />
Expand All @@ -23,11 +22,11 @@ ant -f buildDMC.xml
<property name="javafx.run.width" value="800"/>
<property name="javafx.run.height" value="600"/>
<property name="package.dir" location="packages"/>
<!--property name="application.title" value="nbia-data-retriever" /-->
<property name="application.title" value="NBIA Data Retriever" />
<property name="application.title" value="nbia-data-retriever" />
<!--property name="application.title" value="NBIA Data Retriever" /-->
<property name="application.vendor" value="NCI, Leidos, Ellumen" />
<property name="package.resource.dir" location="packageSrc" />
<property name="package.version" value="4.4" />
<property name="package.version" value="4.4.3" />
<property name="copyright" value="(c) 2022 NCI, Leidos, Ellumen" />
<property name="icon.file.name" value="nbia-data-retriever.png" />

Expand Down Expand Up @@ -218,8 +217,81 @@ ant -f buildDMC.xml
<!-- Default, run this -->
<target name="run" depends="clean, compile, jar" />

<target xmlns:fx="javafx:com.sun.javafx.tools.ant" name="package" depends="clean, cleanPackage, jar">

<property name="jlink.output.dir" location="${basedir}/jlink-output" />

<target name="create-runtime-image" depends="clean, cleanPackage, jar">
<exec executable="jlink">
<arg value="--module-path" />
<arg value="${java.home}/jmods:/usr/lib/javafx-sdk-21.0.4/lib:${common.dir}/target/dist/exploded/nbia-download-manager/lib" />
<arg value="--add-modules" />
<arg value="java.base,java.logging,java.naming,java.management,javafx.controls,javafx.fxml,java.security.jgss,jdk.crypto.ec" />
<arg value="--output" />
<arg value="${jlink.output.dir}" />
<arg value="--strip-debug" />
<arg value="--compress" />
<arg value="2" />
<arg value="--no-header-files" />
<arg value="--no-man-pages" />
</exec>
</target>

<!-- Set the icon based on the OS -->
<condition property="icon.path" value="${package.resource.dir}/package/macosx/${icon.file.name}">
<os family="mac" />
</condition>
<condition property="icon.path" value="${package.resource.dir}/package/linux/${icon.file.name}">
<os family="unix" />
</condition>

<target name="package" depends="create-runtime-image">
<!-- Package using jpackage -->
<exec executable="jpackage">
<arg value="--input" />
<arg value="${dist.dir}" />
<arg value="--main-jar" />
<arg value="${projectName}.jar" />
<arg value="--name" />
<arg value="${application.title}" />
<arg value="--main-class" />
<arg value="${javafx.main.class}" />

<arg value="--runtime-image" />
<arg value="${jlink.output.dir}" />

<arg value="--icon" />
<arg value="${icon.path}" />
<arg value="--app-version" />
<arg value="${package.version}" />
<arg value="--type" />
<arg value="${native.bundles}" />
<arg value="--dest" />
<arg value="${package.dir}" />
<arg value="--verbose" />

<arg value="--vendor" />
<arg value="${application.vendor}" />
<arg value="--file-associations" />
<arg value="./file-associations.properties" />
<arg value="--license-file" />
<arg value="${package.resource.dir}/${license.file.name}" />
<arg value="--copyright" />
<arg value="${copyright}" />





</exec>

</target>

<!-- <target xmlns:fx="javafx:com.sun.javafx.tools.ant" name="package" depends="clean, cleanPackage, jar">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${java.home}/../lib/ant-javafx.jar;packageSrc;" />
<taskdef name="fx"
classname="com.sun.javafx.tools.ant.DeployTask"
classpath="${PATH_TO_FX}/javafx-controls.jar:${PATH_TO_FX}/javafx-base.jar:${PATH_TO_FX}/javafx-graphics.jar" />
<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" nativeBundles="${native.bundles}" outdir="${package.dir}" outfile="${application.title}" verbose="true">
<fx:platform>
<fx:jvmuserarg name="-Djava.net.preferIPv4Stack" value="true" />
Expand All @@ -229,7 +301,6 @@ ant -f buildDMC.xml
</fx:platform>
<fx:application id="standaloneDMApp" name="${application.title}" mainClass="${javafx.main.class}" version="${package.version}">
<!--fx:argument>sample.tcia</fx:argument-->
</fx:application>
<fx:resources>
Expand All @@ -242,7 +313,6 @@ ant -f buildDMC.xml
<fx:info title="${application.title}" vendor="${application.vendor}" category="public.app-category.medical" copyright="${copyright}" license="3 Clause BSD">
<fx:association extension="tcia" mimetype="application/x-nbia-manifest-file" description="Manifest file for NBIA Data Retriever" icon="${icon.file.name}">
</fx:association>
<!--fx:icon href="${package.resource.dir}/package/linux/${icon.file.name}" kind="default" width="32" height="32" depth="8"/-->
</fx:info>
<fx:bundleArgument arg="win.exe.systemWide" value="true"/>
Expand All @@ -252,6 +322,6 @@ ant -f buildDMC.xml
<fx:bundleArgument arg="email" value="[email protected]"/>
</fx:deploy>
</target>
</target>-->

</project>
7 changes: 7 additions & 0 deletions software/nbia-download-manager/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ L-->
</publications>

<dependencies>
<dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.17.1" conf="compile->master;runtime->master"/>
<dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.17.1" conf="compile->master;runtime->master"/>
<dependency org="org.apache.logging.log4j" name="log4j-1.2-api" rev="2.17.1" conf="compile->master;runtime->master"/>
<dependency org="org.apache.logging.log4j" name="log4j-slf4j2-impl" rev="2.19.0" conf="compile->master;runtime->master"/>
<dependency org="ch.qos.reload4j" name="reload4j" rev="1.2.18.3" conf="compile->master;runtime->master"/>
<dependency org="org.slf4j" name="slf4j-reload4j" rev="1.7.36" conf="compile->master;runtime->master"/>

<dependency org="junit" name="junit" rev="4.5" conf="test->master"/>
<dependency org="cobertura" name="cobertura" rev="1.9.3-asmhack" conf="test->default"/>
<dependency org="javancss" name="javancss" rev="29.50" conf="test->default"/>
Expand Down
11 changes: 11 additions & 0 deletions software/nbia-download-manager/packageSrc/StandaloneDMLicense.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright 2022 NCI, Leidos, Ellumen

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions software/nbia-download-manager/resources/Oauth2Client.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#--------OAuth2.0 Client Configuration---------
scope=
scope=openid
grant_type=password
client_id=
client_id=nbia-stage
client_secret=
access_token=
#------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ else if (os.toLowerCase().contains("linux"))
fileName = args[i + 1];
++i;
}
if (args[i].toLowerCase().equals("--agree-to-license")) {
dr.skipLicense = true;
}
if (args[i].equals("-u") || args[i].equals("-U")) {
userName = args[i + 1];
++i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
import java.util.logging.Handler;
import java.util.logging.Level;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JOptionPane;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -115,6 +118,7 @@ public class DataRetrieverCLI {
public final java.util.logging.Logger logger = Logger.getGlobal();
private String setProperty;
private String duaText = null;
public boolean skipLicense = false;
/**
* @param args
*/
Expand All @@ -125,11 +129,14 @@ public static void main(String[] args) {
String downloadDir = null; // The directory that the user want to put the downloaded data
// BasicConfigurator.configure();
DataRetrieverCLI dr = new DataRetrieverCLI();
dr.skipLicense = false;

if (args != null && (args.length > 0)) {
for (int i = 0; i < args.length; ++i) {
if (args[i].equals("-c") || args[i].equals("-C") || args[i].equals("--cli") || args[i].equals("--CLI"))
fileName = args[i + 1];
if (args[i].toLowerCase().equals("--agree-to-license"))
dr.skipLicense = true;
if (args[i].equals("-u") || args[i].equals("-U"))
userName = args[i + 1];
if (args[i].equals("-p") || args[i].equals("-P"))
Expand Down Expand Up @@ -380,9 +387,11 @@ public void performDownload(String downloadDir, String fileName, String userName
// DataRetriever cmdDR = new DataRetriever();
loadManifestFile(fileName);

String text = getUserAgreementTxt();
if (text != null && !text.isEmpty()) {
retrieveUsersAns(text);
if (!skipLicense) {
String text = getUserAgreementTxt();
if (text != null && !text.isEmpty()) {
retrieveUsersAns(text);
}
}


Expand Down Expand Up @@ -522,14 +531,19 @@ private String getAccessToken(String userName, String passWord) {
oauthDetails.setPassword(passWord);
oauthDetails.setAuthenticationServerUrl(
serverUrl.replaceFirst("nbia-download/servlet/DownloadServlet", "nbia-api/oauth/token"));

String accessToken = null;

if (oauthDetails.isAccessTokenRequest()) {
// Generate new Access token
// accessToken = OAuthUtils.getAccessToken(oauthDetails);
//


Map<String, String> map = oauthUtil.getAccessToken(oauthDetails);
refreshToken = map.get(OAuthConstants.REFRESH_TOKEN);


accessToken = map.get(OAuthConstants.ACCESS_TOKEN);
// System.out.println("accessToken=" + accessToken);
if (OAuthUtils.isValid(accessToken)) {
Expand All @@ -553,7 +567,7 @@ private String renewAccessToken() {
// Generate the OAuthDetails bean from the config properties file
OAuth2Details oauthDetails = oauthUtil.createOAuthDetails(config);
oauthDetails.setAuthenticationServerUrl(
serverUrl.replaceFirst("nbia-download/servlet/DownloadServlet", "nbia-api/oauth/token"));
serverUrl.replaceFirst("nbia-download/servlet/DownloadServlet", "nbia-api/oauth/token/"));
newToken = oauthUtil.refreshAccessToken(oauthDetails, refreshToken);
logger.fine("get renewed access token =" + newToken);
return newToken;
Expand Down Expand Up @@ -668,7 +682,22 @@ else if(code == 204) {
output = br.readLine(); // data

if (output != null) {
metaData = output.split(",");
List<String> metaDataList = new ArrayList<>();
Pattern pattern = Pattern.compile("\"([^\"]*)\"|(?<=,|^)([^,]*)(?=,|$)");
Matcher matcher = pattern.matcher(output);

while (matcher.find()) {
if (matcher.group(1) != null) {
metaDataList.add(matcher.group(1));
} else {
metaDataList.add(matcher.group(2));
}
}

// Convert the List to a String array
metaData = metaDataList.toArray(new String[0]);

//metaData = output.split(",");
} else
logger.severe(
"Error in getting map for SOPClassName. Ask Admin to check if the server has the property file in place.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,35 @@ public Map<String, String> getAccessToken(OAuth2Details oauthDetails) {

parametersBody.add(new BasicNameValuePair(OAuthConstants.CLIENT_SECRET, clientSecret));


if (isValid(scope)) {
parametersBody.add(new BasicNameValuePair(OAuthConstants.SCOPE, scope));
}

ArrayList<NameValuePair> parameters;

parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("grant_type", "password"));
parameters.add(new BasicNameValuePair("client_id", "clientId"));
parameters.add(new BasicNameValuePair("username", oauthDetails.getUsername()));
parameters.add(new BasicNameValuePair("password", oauthDetails.getPassword()));
parameters.add(new BasicNameValuePair("client_secret", clientSecret));
parameters.add(new BasicNameValuePair("scope", "openid"));


DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = null;

try {
post.addHeader("content-type", "application/x-www-form-urlencoded");
StringEntity params = new StringEntity(
"username=" + oauthDetails.getUsername() + "&password=" + oauthDetails.getPassword()
+ "&client_id=nbiaRestAPIClient&client_secret=ItsBetweenUAndMe&grant_type=password");
post.setEntity(params);
//StringEntity params = new StringEntity(
// "username=" + oauthDetails.getUsername() + "&password=" + oauthDetails.getPassword()
// + "&client_id=nbiaRestAPIClient&client_secret=ItsBetweenUAndMe&grant_type=password");
//post.setEntity(params);
post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));

response = client.execute(post);
int code = response.getStatusLine().getStatusCode();
// logger.fine("HTTP response code is " + code);
if (code == OAuthConstants.HTTP_UNAUTHORIZED) {
logger.fine("Authorization server expects Basic authentication. ");
// Add Basic Authorization header
Expand Down

0 comments on commit 2ed739c

Please sign in to comment.