commit c3d2b804e3f25079c05ab611612f416f6197e959 Author: tacehex Date: Mon Jul 1 15:07:24 2024 +0300 add - перенос из hg в git diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..891233f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +### IntelliJ IDEA ### +.idea +.mvn +/HELP.md diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..af91474 --- /dev/null +++ b/README.MD @@ -0,0 +1,55 @@ +# Инвентаризация (ESPD) + +Кроссплатформенное приложение для инвентаризации. + +> Использованные библиотеки/фреймворки: +> - [JavaFX](https://openjfx.io) - фреймворк для создания UI-приложений +> - [oshi](https://github.com/oshi/oshi) - получение информации об аппаратной и системной части компьютера. +> - [JSpeedTest](https://github.com/bertrandmartel/speed-test-lib) - замеры скорости интернета + +> Для запуска приложения потребуется установить **JDK 17 или выше**. Скачать +> можно [здесь](https://www.oracle.com/java/technologies/downloads/). + +> Для формирования приложения воспользуйтесь командой `mvn clean package` + +## Содержание формы + +- **Код учреждения** (int) - вводится пользователем; +- **Наименование ОО** (string) - после нахождения в БД при помощи кода ОО автоматически заполняется; +- **Номер здания** (int) - выбирается элемент в списке; +- **Адрес** (string) - отображается после выбора элемента в списке номеров зданий; +- **Помещение** (string) - выбирается элемент в списке; +- **Label с GIF** - показ того, что сейчас происходит в форме +- **Отправить** - активируется при наличии всех заполненных полей; +- **Статус необходимости обновить приложение**. + +> ### После нажатия кнопки "сохранить" собирается следующее +> - данные из полей в форме; +> - конфигурация компьютера с учетом списка выше; +> - Замеры скорости интернета +>> При каких-либо ошибках `output.log` отправляется на сервер. + +> ### Перед закрытием приложения +> - **Дата начала работы (datetime)** - выводится после открытия приложения; +> - **Дата окончания работы (datetime)** - высчитывается перед закрытием приложения. + +### Список отправляемой конфигурации при успешном заполнении формы и нажатии "Отправить" + +- **Операционная система** (справочник) - Windows, Linux или MACos; +- **Версия операционной системы** (string) - 11.2, 18.03 и т.д. +- **Устройство** (справочник) - ноутбук или ПК; +- **Модель процессора** (string) - Название модели процессора; +- **Частота процессора** (float) - измеряется в ГГц; +- **Объем ОЗУ** (float) - 0.5, если 512МБ, 16 - если 16ГБ; +- **Диски** (список): + - **Тип диска** - SSD / HDD / Nvm.2 (_справочник_) + - **Модель диска** - название модели диска; +- **Скорость интернета** (String) - в какой форме? + +> Нужно учесть пару моментов при реализации: +> 1. защиту от **посторонних пользователей**; +> 2. автоматический запуск приложения **при запуске ОС**; +> 3. автоматическое заполнение поля окончания работы и сохранение **при выключении компьютера**; +> 4. как будет обновляться приложение - **вручную ссылкой с проверкой актуальности версии или автоматическое обновление + приложения**; +> 5. Попробовать вложить JDK в проект для избежания лишних установок для пользователя. \ No newline at end of file diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..66df285 --- /dev/null +++ b/mvnw @@ -0,0 +1,308 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# https://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.2.0 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "$(uname)" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then + if $darwin ; then + javaHome="$(dirname "\"$javaExecutable\"")" + javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" + else + javaExecutable="$(readlink -f "\"$javaExecutable\"")" + fi + javaHome="$(dirname "\"$javaExecutable\"")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=$(cd "$wdir/.." || exit 1; pwd) + fi + # end of workaround + done + printf '%s' "$(cd "$basedir" || exit 1; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; + esac + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget > /dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..95ba6f5 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,205 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..684e737 --- /dev/null +++ b/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.1.5 + + + ru.integrics + espd-client + 1.0.0 + espd + espd-client-new + + 17 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-web + 6.1.3 + + + org.openjfx + javafx-controls + 17 + + + org.openjfx + javafx-fxml + 17 + + + org.openjfx + javafx-graphics + 17 + win + + + org.openjfx + javafx-graphics + 17 + linux + + + org.openjfx + javafx-graphics + 17 + mac + + + com.github.oshi + oshi-core + 6.4.11 + + + + fr.bmartel + jspeedtest + 1.32.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.16.1 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + + diff --git a/src/main/java/espd/EspdClientApplication.java b/src/main/java/espd/EspdClientApplication.java new file mode 100644 index 0000000..b92047a --- /dev/null +++ b/src/main/java/espd/EspdClientApplication.java @@ -0,0 +1,11 @@ +package espd; + +import javafx.application.Application; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class EspdClientApplication { + public static void main(String[] args) { + Application.launch(JavaFxApplication.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/espd/JavaFxApplication.java b/src/main/java/espd/JavaFxApplication.java new file mode 100644 index 0000000..d63765f --- /dev/null +++ b/src/main/java/espd/JavaFxApplication.java @@ -0,0 +1,51 @@ +package espd; + +import javafx.application.Application; +import javafx.application.HostServices; +import javafx.application.Platform; +import javafx.stage.Stage; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.GenericApplicationContext; + +public class JavaFxApplication extends Application { + private ConfigurableApplicationContext context; + + @Override + public void init() { + + ApplicationContextInitializer initializer = applicationContext -> { + applicationContext.registerBean(Application.class, () -> JavaFxApplication.this); + applicationContext.registerBean(Parameters.class, this::getParameters); + applicationContext.registerBean(HostServices.class, this::getHostServices); + }; + + this.context = new SpringApplicationBuilder().sources(EspdClientApplication.class).initializers(initializer).run(getParameters().getRaw().toArray(new String[0])); + + context.getBean(HostServices.class); + } + + @Override + public void start(Stage stage) { + this.context.publishEvent(new StageReadyEvent(stage)); + } + + @Override + public void stop() { + this.context.close(); + Platform.exit(); + } +} + +class StageReadyEvent extends ApplicationEvent { + + Stage getStage() { + return (Stage) getSource(); + } + + public StageReadyEvent(Stage source) { + super(source); + } +} diff --git a/src/main/java/espd/StageListener.java b/src/main/java/espd/StageListener.java new file mode 100644 index 0000000..eb3b17b --- /dev/null +++ b/src/main/java/espd/StageListener.java @@ -0,0 +1,51 @@ +package espd; + +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.stage.Stage; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URL; +import java.util.Objects; + +@Component +public class StageListener implements ApplicationListener { + + private final String applicationTitle; + private final Resource fxml; + private final ApplicationContext context; + + public StageListener(@Value("${spring.application.ui.title}") String applicationTitle, @Value("classpath:/ui.fxml") Resource resource, ApplicationContext context) { + this.applicationTitle = applicationTitle; + this.fxml = resource; + this.context = context; + } + + @Override + public void onApplicationEvent(StageReadyEvent event) { + try { + URL url = this.fxml.getURL(); + FXMLLoader loader = new FXMLLoader(url); + loader.setControllerFactory(context::getBean); + + Parent root = loader.load(); + Scene scene = new Scene(root, 400, 580); + Stage stage = event.getStage(); + + stage.setResizable(false); + stage.getIcons().add(new Image(Objects.requireNonNull(StageListener.class.getResourceAsStream("/img/icon.png")))); + stage.setScene(scene); + stage.setTitle(this.applicationTitle); + stage.show(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/espd/controllers/HttpController.java b/src/main/java/espd/controllers/HttpController.java new file mode 100644 index 0000000..db559ea --- /dev/null +++ b/src/main/java/espd/controllers/HttpController.java @@ -0,0 +1,65 @@ +package espd.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import espd.jsonObj.FullConfig; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +@Log4j2 +@Controller +public class HttpController { + + private static final HttpClient client = HttpClient.newHttpClient(); + private static String apiUrl; + + @Value("${spring.application.api.url}") + public void setApiUrl(String apiUrl) { + HttpController.apiUrl = apiUrl; + } + + public static String makeGetRequest(String path) throws IOException, InterruptedException { + String fullUrl = apiUrl + path; + + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(fullUrl)) + .GET() + .build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + return getResponseBody(response, fullUrl); + } + + public static String makePostRequest(String path, FullConfig config) throws IOException, InterruptedException { + + String fullUrl = apiUrl + path; + + ObjectMapper objectMapper = new ObjectMapper(); + String requestBody = objectMapper.writeValueAsString(config); + + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(fullUrl)) + .POST(HttpRequest.BodyPublishers.ofString(requestBody)) + .header("Content-Type", "application/json") + .build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());; + return getResponseBody(response, fullUrl); + } + + public static String getResponseBody(HttpResponse response, String url) { + if (response.statusCode() == 200) { + return response.body(); + } else { + log.atError().log("Ошибка получения ответа по адресу: {}", url); + } + + return null; + } +} \ No newline at end of file diff --git a/src/main/java/espd/controllers/JsonController.java b/src/main/java/espd/controllers/JsonController.java new file mode 100644 index 0000000..4506a8a --- /dev/null +++ b/src/main/java/espd/controllers/JsonController.java @@ -0,0 +1,45 @@ +package espd.controllers; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import espd.jsonObj.School; +import org.springframework.stereotype.Controller; + +import java.util.HashMap; +import java.util.Map; + +@Controller +public class JsonController { + private final ObjectMapper objectMapper = new ObjectMapper(); + private final Map data = new HashMap<>(); + + public void addData(String key, Object value) { + data.put(key, value); + } + + public void addNestedData(String parentKey, String childKey, Object childValue) { + if (data.containsKey(parentKey)) { + Map nestedData = (Map) data.get(parentKey); + nestedData.put(childKey, childValue); + } else { + Map nestedData = new HashMap<>(); + nestedData.put(childKey, childValue); + data.put(parentKey, nestedData); + } + } + + public Map createDiskData(String type, String size) { + Map diskData = new HashMap<>(); + diskData.put("type", type); + diskData.put("size", size); + return diskData; + } + + public String toJson() throws JsonProcessingException { + return objectMapper.writeValueAsString(data); + } + + public School fromJson(String jsonString) throws JsonProcessingException { + return objectMapper.readValue(jsonString, School.class); + } +} diff --git a/src/main/java/espd/controllers/UiController.java b/src/main/java/espd/controllers/UiController.java new file mode 100644 index 0000000..1c32666 --- /dev/null +++ b/src/main/java/espd/controllers/UiController.java @@ -0,0 +1,206 @@ +package espd.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import espd.itemsFxml.BuildingItem; +import espd.itemsFxml.DeviceTypeItem; +import espd.itemsFxml.RoomItem; +import espd.jsonObj.*; +import espd.utils.Fxml; +import espd.utils.SystemInfoProvider; +import javafx.application.HostServices; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import org.springframework.stereotype.Controller; + +import java.io.IOException; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; + + +@Controller +public class UiController { + + private boolean needUpdate = false; // TODO: исправить, когда можно будет отслеживать обновления + private LocalDate dateStart; // дата запуска приложения + private final HostServices hostServices; + @FXML + private TextField textFieldCodeEdu; // текстовое поле кода организации + @FXML + private TextField textFieldNameEdu; // поле наименования образовательной организации + @FXML + private ComboBox comboBoxBuilding; // список номеров здания + @FXML + private TextField textFieldAddress; // текстовое поле адреса + @FXML + private ComboBox comboBoxRoom; // список помещений + @FXML + private ComboBox comboBoxDeviceType; // список устройств + @FXML + private Hyperlink linkNewVersion; // кнопка ссылки на скачивание новой версии + @FXML + private Label labelSearch; // текст статуса выполнения + @FXML + private Button buttonSubmit; // кнопка отправки данных + + private final ObjectMapper objectMapper = new ObjectMapper(); + + UiController(HostServices hostServices) { + this.hostServices = hostServices; + } + + @FXML + public void initialize() { + // Заполнение типов устройства + Map enRuDeviceTypeMap = new HashMap<>(); + + enRuDeviceTypeMap.put("Laptop", "Ноутбук"); + enRuDeviceTypeMap.put("PC", "ПК"); + enRuDeviceTypeMap.put("Tablet", "Планшет"); + + for (Map.Entry entry : enRuDeviceTypeMap.entrySet()) { + comboBoxDeviceType.getItems().add(new DeviceTypeItem(entry.getKey(), entry.getValue())); + } + + // Проверка новой версии + this.dateStart = SystemInfoProvider.getCurrentDateAndTime(); + + if (needUpdate) { + linkNewVersion.setText("Доступна новая версия"); + } else { + linkNewVersion.getStyleClass().add("not-link"); + linkNewVersion.setText("Установлена актуальная версия приложения"); + } + } + + /** + * Обработка кнопки кода образовательной организации при нажатии + */ + @FXML + private void handleCodeEduButtonClick() throws IOException, InterruptedException { + String codeEdu = textFieldCodeEdu.getText().replaceAll(" ", ""); + textFieldCodeEdu.setText(codeEdu); + + Fxml.deactivateAndClearInput(textFieldNameEdu); + Fxml.deactivateAndClearComboBox(comboBoxBuilding); + Fxml.deactivateAndClearInput(textFieldAddress); + Fxml.deactivateAndClearComboBox(comboBoxRoom); + Fxml.deactivateComboBox(comboBoxDeviceType); + + Fxml.activateOrDeactivateButton(buttonSubmit, false); + + // проверка на пустоту и наличие других символов, кроме чисел + if (codeEdu.isEmpty()) { + Fxml.showOrHideMessage(labelSearch, false, true, "Заполните код ОО и запустите проверку"); + } else if (!codeEdu.matches("\\d+")) { + Fxml.showOrHideMessage(labelSearch, false, true,"Код ОО должен состоять только из чисел"); + } else { + Fxml.showOrHideMessage(labelSearch, true, false, null); + + School school = objectMapper.readValue(HttpController.makeGetRequest("school=" + codeEdu), School.class); + textFieldNameEdu.setText(school.getShortAddress()); + + // Получаем информацию о зданиях + Map buildings = school.getBuildings(); + + if (buildings != null) { + buildings.values().forEach(building -> comboBoxBuilding.getItems().add(new BuildingItem( + building.getActualAddress(), + building.getName(), + building.getSysGuid() + ))); + + Fxml.openComboBox(comboBoxBuilding); + Fxml.showOrHideMessage(labelSearch, false, false, "Выберите наименование здания"); + } else { + Fxml.showOrHideMessage(labelSearch, false, true, "Список зданий отсутствует. Заполните данные для отображения"); + } + } + } + + /** + * Обработка событий списка наименований здания + */ + @FXML + private void handleItemsComboBoxBuildingClick() throws IOException, InterruptedException { + BuildingItem selectedValue = comboBoxBuilding.getValue(); + + Fxml.deactivateAndClearInput(textFieldAddress); + Fxml.deactivateAndClearComboBox(comboBoxRoom); + Fxml.deactivateComboBox(comboBoxDeviceType); + + Fxml.showOrHideMessage(labelSearch, true, false, null); + Fxml.activateOrDeactivateButton(buttonSubmit, false); + + Map rooms = objectMapper.readValue(HttpController.makeGetRequest("rooms=" + selectedValue.sysGuid()), Rooms.class).getRooms(); + + if (rooms != null) { + textFieldAddress.setText(selectedValue.shortAddress()); + rooms.values().forEach(roomInfo -> comboBoxRoom.getItems().add(new RoomItem(roomInfo.getNumber(), roomInfo.getSysGuid()))); + + Fxml.openComboBox(comboBoxRoom); + Fxml.showOrHideMessage(labelSearch, false, false, "Выберите помещение"); + } else { + Fxml.showOrHideMessage(labelSearch, false, true, "Список помещений отсутствует. Заполните данные для отображения"); + } + } + + /** + * Обработка событий списка номеров помещений + */ + @FXML + private void handleItemsComboBoxRoomClick() { + Fxml.openComboBox(comboBoxDeviceType); + Fxml.showOrHideMessage(labelSearch, false, false, "Выберите тип устройства"); + Fxml.activateOrDeactivateButton(buttonSubmit, false); + } + + @FXML + private void handleItemsComboBoxDeviceTypeClick() { + Fxml.activateOrDeactivateButton(buttonSubmit, true); + Fxml.showOrHideMessage(labelSearch, false, false, "Форма готова к отправке"); + } + + @FXML + private void handleSubmitClick() throws IOException, InterruptedException { + if (Fxml.buttonHasClassActive(buttonSubmit)) { + FullConfig config = getFullConfig(); + Status status = objectMapper.readValue(HttpController.makePostRequest("configs", config), Status.class); + + Fxml.showOrHideMessage(labelSearch, false, status.getStatus() != 200, status.getStatusMsg()); + } + } + + private FullConfig getFullConfig() { + String osName = SystemInfoProvider.getPlatformName(); + Map ipMacAddressMap = SystemInfoProvider.getIpAndMacAddress(osName); + Map capacityMap = SystemInfoProvider.getHddAndSsdCapacity(); + // TODO: добавить измерение интернета + + return new FullConfig( + comboBoxRoom.getValue().sysGuid(), + comboBoxDeviceType.getValue().deviceTypeEn(), + SystemInfoProvider.getProcessorName(), + SystemInfoProvider.getProcessorMaxFrequencyInMHz(), + SystemInfoProvider.getAmountGbRam(osName), + osName, + SystemInfoProvider.getPlatformVersion(), + capacityMap.get("hdd"), + capacityMap.get("ssd"), + ipMacAddressMap.get("ipAddress"), + ipMacAddressMap.get("macAddress"), + null, + null + ); + } + + /** + * Обработка ссылки обновления + */ + @FXML + private void openInBrowser() { + if (needUpdate) { + hostServices.showDocument("https://www.google.com"); // TODO: установить другую ссылку + } + } +} diff --git a/src/main/java/espd/itemsFxml/BuildingItem.java b/src/main/java/espd/itemsFxml/BuildingItem.java new file mode 100644 index 0000000..9c6f5c7 --- /dev/null +++ b/src/main/java/espd/itemsFxml/BuildingItem.java @@ -0,0 +1,9 @@ +package espd.itemsFxml; + +public record BuildingItem(String shortAddress, String name, String sysGuid) { + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/espd/itemsFxml/DeviceTypeItem.java b/src/main/java/espd/itemsFxml/DeviceTypeItem.java new file mode 100644 index 0000000..417ba50 --- /dev/null +++ b/src/main/java/espd/itemsFxml/DeviceTypeItem.java @@ -0,0 +1,8 @@ +package espd.itemsFxml; + +public record DeviceTypeItem(String deviceTypeEn, String deviceTypeRu) { + @Override + public String toString() { + return deviceTypeRu; + } +} diff --git a/src/main/java/espd/itemsFxml/RoomItem.java b/src/main/java/espd/itemsFxml/RoomItem.java new file mode 100644 index 0000000..90e7a00 --- /dev/null +++ b/src/main/java/espd/itemsFxml/RoomItem.java @@ -0,0 +1,9 @@ +package espd.itemsFxml; + +public record RoomItem(Integer roomNumber, String sysGuid) { + + @Override + public String toString() { + return String.valueOf(roomNumber); + } +} diff --git a/src/main/java/espd/jsonObj/Building.java b/src/main/java/espd/jsonObj/Building.java new file mode 100644 index 0000000..858cebe --- /dev/null +++ b/src/main/java/espd/jsonObj/Building.java @@ -0,0 +1,12 @@ +package espd.jsonObj; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Building { + private String actualAddress; + private String name; + private String sysGuid; +} diff --git a/src/main/java/espd/jsonObj/FullConfig.java b/src/main/java/espd/jsonObj/FullConfig.java new file mode 100644 index 0000000..487acf3 --- /dev/null +++ b/src/main/java/espd/jsonObj/FullConfig.java @@ -0,0 +1,24 @@ +package espd.jsonObj; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class FullConfig { + private String sysGuidRoom; + private String deviceType; + private String cpuModel; + private Integer cpuFrequency; + private Integer ramSize; + private String osName; + private String osVersion; + private Integer hddCapacity; + private Integer ssdCapacity; + private String ipAddress; + private String macAddress; + private String uploadSpeed; + private String downloadSpeed; +} diff --git a/src/main/java/espd/jsonObj/Room.java b/src/main/java/espd/jsonObj/Room.java new file mode 100644 index 0000000..f63f1df --- /dev/null +++ b/src/main/java/espd/jsonObj/Room.java @@ -0,0 +1,11 @@ +package espd.jsonObj; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Room { + private Integer number; + private String sysGuid; +} diff --git a/src/main/java/espd/jsonObj/Rooms.java b/src/main/java/espd/jsonObj/Rooms.java new file mode 100644 index 0000000..84df107 --- /dev/null +++ b/src/main/java/espd/jsonObj/Rooms.java @@ -0,0 +1,13 @@ +package espd.jsonObj; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; + +@Setter +@Getter +public class Rooms { + private Map rooms; + private String error; +} diff --git a/src/main/java/espd/jsonObj/School.java b/src/main/java/espd/jsonObj/School.java new file mode 100644 index 0000000..3af2fe0 --- /dev/null +++ b/src/main/java/espd/jsonObj/School.java @@ -0,0 +1,14 @@ +package espd.jsonObj; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; + +@Getter +@Setter +public class School { + private String shortAddress; + private Map buildings; + private String error; +} diff --git a/src/main/java/espd/jsonObj/Status.java b/src/main/java/espd/jsonObj/Status.java new file mode 100644 index 0000000..6aec335 --- /dev/null +++ b/src/main/java/espd/jsonObj/Status.java @@ -0,0 +1,19 @@ +package espd.jsonObj; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Status { + private Integer status; + private String statusMsg; + + @JsonCreator + public Status(@JsonProperty("status") Integer status, @JsonProperty("statusMsg") String statusMsg) { + this.status = status; + this.statusMsg = statusMsg; + } +} diff --git a/src/main/java/espd/utils/DiskDrive.java b/src/main/java/espd/utils/DiskDrive.java new file mode 100644 index 0000000..c1dbacd --- /dev/null +++ b/src/main/java/espd/utils/DiskDrive.java @@ -0,0 +1,65 @@ +package espd.utils; + +import lombok.Getter; +import oshi.hardware.HWDiskStore; + +import java.util.Arrays; + +@Getter +public class DiskDrive { + HWDiskStore diskStore; + public DiskDrive(HWDiskStore store) { + this.diskStore = store; + } + + public int getDiskDriveSizeGb() { + return findNextValueSizeGb(bytesToGB(diskStore.getSize())); + } + + public DiskType getDiskType() { + String diskStoreModel = diskStore.getModel().trim().toLowerCase(); + + if (diskStoreModel.contains("nvme")) { + return DiskType.NVMe; + } else if (diskStoreModel.contains("ssd")) { + return DiskType.SSD; + } else if (diskStoreModel.contains("hdd")) { + return DiskType.HDD; + } else if (diskStoreModel.contains("накопители") || diskStoreModel.contains("drive")) { + return DiskType.UNDEFINED; + } else { + return null; + } + } + + private int bytesToGB(long bytes) { + return (int) (bytes / (1024 * 1024 * 1024)); + } + + /** + * Получение размера производителя на этикетке + * @param actualSize фактический размер, взятый из системы + * @return размер с этикетки + */ + private int findNextValueSizeGb(int actualSize) { + return Arrays.stream(new int[]{32, 64, 128, 256, 512, 1024, 2048, 4096}) + .filter(size -> actualSize < size) + .findFirst() + .orElse(actualSize); + } + + @Getter + public enum DiskType { + HDD("HDD"), + SSD("SSD"), + NVMe("NVMe"), + UNDEFINED("Undefined"); + + private final String typeName; + + DiskType(String typeName) { + this.typeName = typeName; + } + + } +} diff --git a/src/main/java/espd/utils/Fxml.java b/src/main/java/espd/utils/Fxml.java new file mode 100644 index 0000000..c3471dc --- /dev/null +++ b/src/main/java/espd/utils/Fxml.java @@ -0,0 +1,54 @@ +package espd.utils; + +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +public abstract class Fxml { + public static boolean buttonHasClassActive(Button button) { + return button.getStyleClass().contains("active"); + } + + public static void activateOrDeactivateButton(Button button, boolean isActivate) { + if (isActivate) { + button.getStyleClass().add("active"); + } else { + button.getStyleClass().remove("active"); + } + } + + public static void showOrHideMessage(Label label, boolean isHide, boolean isRed, String message) { + if (isHide && !label.getStyleClass().contains("hide")) { + label.getStyleClass().add("hide"); + } else { + label.getStyleClass().remove("hide"); + } + + if (isRed && !label.getStyleClass().contains("red")) { + label.getStyleClass().add("red"); + } else { + label.getStyleClass().remove("red"); + } + + label.setText(message); + } + + public static void deactivateComboBox(ComboBox comboBox) { + comboBox.setDisable(true); + } + + public static void deactivateAndClearComboBox(ComboBox comboBox) { + comboBox.getItems().clear(); + comboBox.setDisable(true); + } + + public static void deactivateAndClearInput(TextField field) { + field.setText(""); + field.setDisable(true); + } + + public static void openComboBox(ComboBox comboBox) { + comboBox.setDisable(false); + } +} diff --git a/src/main/java/espd/utils/SpeedTest.java b/src/main/java/espd/utils/SpeedTest.java new file mode 100644 index 0000000..a457147 --- /dev/null +++ b/src/main/java/espd/utils/SpeedTest.java @@ -0,0 +1,37 @@ +package espd.utils; + +import fr.bmartel.speedtest.SpeedTestReport; +import fr.bmartel.speedtest.SpeedTestSocket; +import fr.bmartel.speedtest.inter.ISpeedTestListener; +import fr.bmartel.speedtest.model.SpeedTestError; + +import java.math.BigDecimal; + +public class SpeedTest { + static SpeedTestSocket socket = new SpeedTestSocket(); + + public static void checkSpeedTest() { + socket.addSpeedTestListener(new ISpeedTestListener() { + @Override + public void onCompletion(SpeedTestReport report) { + BigDecimal speed = report.getTransferRateBit(); + BigDecimal speedMbps = speed.divide(new BigDecimal(1000000)); + + System.out.println("Speed: " + speedMbps + " mbps"); + } + + @Override + public void onProgress(float percent, SpeedTestReport report) { + System.out.println(percent + "%"); + } + + @Override + public void onError(SpeedTestError speedTestError, String s) { + System.out.println(s); + } + }); + +// socket.startDownload("https://github.com/obsidianmd/obsidian-releases/releases/download/v1.5.3/Obsidian.1.5.3.exe"); +// socket.startUpload("http://ipv4.ikoula.testdebit.info/", 1000000); + } +} diff --git a/src/main/java/espd/utils/SystemInfoProvider.java b/src/main/java/espd/utils/SystemInfoProvider.java new file mode 100644 index 0000000..70dbf41 --- /dev/null +++ b/src/main/java/espd/utils/SystemInfoProvider.java @@ -0,0 +1,168 @@ +package espd.utils; + +import lombok.Getter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.converter.json.GsonBuilderUtils; +import org.springframework.util.StringUtils; +import oshi.SystemInfo; +import oshi.hardware.HWDiskStore; +import oshi.hardware.NetworkIF; +import oshi.hardware.PhysicalMemory; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.time.LocalDate; +import java.util.*; + +@Getter +public class SystemInfoProvider { + private static final Logger log = LoggerFactory.getLogger(SystemInfoProvider.class); + public static SystemInfo systemInfo = new SystemInfo(); + + public static String getPlatformName() { + return SystemInfo.getCurrentPlatform().getName().trim(); + } + + public static String getPlatformVersion() { + return systemInfo.getOperatingSystem().getVersionInfo().getVersion().trim(); + } + + public static String getProcessorName() { + return systemInfo.getHardware().getProcessor().getProcessorIdentifier().getName().trim(); + } + + public static int getProcessorMaxFrequencyInMHz() { + return (int) (systemInfo.getHardware().getProcessor().getMaxFreq() / 1_000_000); + } + + public static int getAmountGbRam(String osName) { + osName = osName.trim().toLowerCase(); + List physicalMemoryList = systemInfo.getHardware().getMemory().getPhysicalMemory(); + + int result = 0; + + if (!physicalMemoryList.isEmpty()) { + result = (int) (systemInfo.getHardware().getMemory().getPhysicalMemory().stream() + .mapToLong(PhysicalMemory::getCapacity) + .sum() / 1073741824L); + } else { + if (osName.contains("linux")) { + result = getMemoryInfoLinux(); + } + } + + return result; + } + + public static Map getHddAndSsdCapacity() { + Map capacityMap = new HashMap<>(); + + int hddCount = 0; + int ssdCount = 0; + int nvmeCount = 0; + int undefinedCount = 0; + + for (HWDiskStore diskStore : systemInfo.getHardware().getDiskStores()) { + DiskDrive diskDrive = new DiskDrive(diskStore); + int diskSizeGb = diskDrive.getDiskDriveSizeGb(); + + if (diskDrive.getDiskType() == DiskDrive.DiskType.HDD) { + hddCount += diskSizeGb; + } else if (diskDrive.getDiskType() == DiskDrive.DiskType.SSD) { + ssdCount += diskSizeGb; + } else if (diskDrive.getDiskType() == DiskDrive.DiskType.UNDEFINED) { + undefinedCount += diskSizeGb; + } else if (diskDrive.getDiskType() == DiskDrive.DiskType.NVMe) { + nvmeCount += diskSizeGb; + } + } + + capacityMap.put("hdd", hddCount); + capacityMap.put("ssd", ssdCount); + capacityMap.put("undefined", undefinedCount); + capacityMap.put("nvme", nvmeCount); + + System.out.println(capacityMap); + + return capacityMap; + } + + public static Map getIpAndMacAddress(String osName) { + osName = osName.trim().toLowerCase(); + Map ipMacAddressMap = new HashMap<>(); + List networkInterfaces = new ArrayList<>(systemInfo.getHardware().getNetworkIFs()); + + NetworkIF networkIF = null; + + if (osName.contains("linux")) { + for (NetworkIF ni : networkInterfaces) { + if (ni.getName().equalsIgnoreCase("wlp1s0") && ni.getIPv4addr().length != 0) { + networkIF = ni; + } + } + } else { + // Находим wlan соединения. Если таковых нет - берем net соединение + networkIF = networkInterfaces.stream() + .filter(ni -> ni.getName().contains("wlan") && ni.getIPv4addr().length != 0) + .findFirst() + .orElseGet(() -> networkInterfaces.stream() + .filter(ni -> ni.getName().contains("net") && ni.getIPv4addr().length != 0) + .findFirst() + .orElse(null) + ); + } + + // костыль (если совсем ничего не найдено - начинает бегать по всем соединениям) + if (networkIF == null) { + for (NetworkIF ni : networkInterfaces) { + String[] ipAddresses = ni.getIPv4addr(); + String macAddress = ni.getMacaddr(); + + if (ipAddresses.length != 0 && macAddress != null && !macAddress.isEmpty()) { + networkIF = ni; + break; + } + } + } + + if (networkIF != null) { + ipMacAddressMap.put("ipAddress", networkIF.getIPv4addr()[0]); // TODO: Может не существовать адрес, т.е. пустышка. Поправить + ipMacAddressMap.put("macAddress", networkIF.getMacaddr()); + } else { + log.atInfo().log("No network interface found"); + } + + return ipMacAddressMap; + } + + public static LocalDate getCurrentDateAndTime() { + return LocalDate.now(); + } + + private static int getMemoryInfoLinux() { + + int result = 0; + + try { + BufferedReader reader = new BufferedReader(new FileReader("/proc/meminfo")); + String line; + + while ((line = reader.readLine()) != null) { + if (line.startsWith("MemTotal:")) { + String[] parts = line.split("\\s+"); + long totalMemoryKB = Long.parseLong(parts[1]); + result = (int) (totalMemoryKB / (1024 * 1024)); + break; + } + } + + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return result; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..20a42a4 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.application.ui.title = Inventory +spring.application.api.url = http://213.145.5.42:38085/espd/ +#spring.application.api.url = http://localhost:8085/espd/ \ No newline at end of file diff --git a/src/main/resources/fonts/inter-bold.ttf b/src/main/resources/fonts/inter-bold.ttf new file mode 100644 index 0000000..fe23eeb Binary files /dev/null and b/src/main/resources/fonts/inter-bold.ttf differ diff --git a/src/main/resources/fonts/inter-extralight.ttf b/src/main/resources/fonts/inter-extralight.ttf new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/fonts/inter-light.ttf b/src/main/resources/fonts/inter-light.ttf new file mode 100644 index 0000000..71188f5 Binary files /dev/null and b/src/main/resources/fonts/inter-light.ttf differ diff --git a/src/main/resources/fonts/inter-regular.ttf b/src/main/resources/fonts/inter-regular.ttf new file mode 100644 index 0000000..5e4851f Binary files /dev/null and b/src/main/resources/fonts/inter-regular.ttf differ diff --git a/src/main/resources/fonts/inter-semibold.ttf b/src/main/resources/fonts/inter-semibold.ttf new file mode 100644 index 0000000..ecc7041 Binary files /dev/null and b/src/main/resources/fonts/inter-semibold.ttf differ diff --git a/src/main/resources/img/icon.png b/src/main/resources/img/icon.png new file mode 100644 index 0000000..f65ea86 Binary files /dev/null and b/src/main/resources/img/icon.png differ diff --git a/src/main/resources/img/rcit-logo.png b/src/main/resources/img/rcit-logo.png new file mode 100644 index 0000000..767b0f3 Binary files /dev/null and b/src/main/resources/img/rcit-logo.png differ diff --git a/src/main/resources/img/wait.png b/src/main/resources/img/wait.png new file mode 100644 index 0000000..3b2c7ca Binary files /dev/null and b/src/main/resources/img/wait.png differ diff --git a/src/main/resources/logback.spring.xml b/src/main/resources/logback.spring.xml new file mode 100644 index 0000000..162d57f --- /dev/null +++ b/src/main/resources/logback.spring.xml @@ -0,0 +1,26 @@ + + + + + + ${LOG_DIR}/app.log + + %d{dd.MM.yyyy HH:mm:ss.SSS} [%thread{20}] %-5level - %msg%n + + + ${LOG_DIR}/archived/app_%d{dd-MM-yyyy}.log + 100 + 200MB + + + + + %d{dd.MM.yyyy HH:mm:ss.SSS} %magenta([%-20.20thread]) %highlight(%-5level) - %msg%n + + + + + + + + diff --git a/src/main/resources/styles.css b/src/main/resources/styles.css new file mode 100644 index 0000000..f19898b --- /dev/null +++ b/src/main/resources/styles.css @@ -0,0 +1,150 @@ +@keyframes rotateAnimation { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} + +.body { + -fx-padding: 30px; + -fx-background-color: #EAEAEA; +} + +.hide { + -fx-opacity: 0; +} + +.header { + -fx-spacing: 52px; + -fx-alignment: CENTER_LEFT; + -fx-padding: 0 0 30px; +} + +.header__text { + /*-fx-font-family: 'Inter Bold';*/ + -fx-font-weight: 700; + -fx-font-size: 25px; +} + +.subtitle { + -fx-padding: 0 0 10px; +} + +.subtitle__text { + /*-fx-font-family: 'Inter ExtraLight';*/ + font-size: 12px; +} + +.row { + -fx-padding: 0 0 8px; + -fx-alignment: center-right; +} + +.row.center { + -fx-alignment: center; +} + +.row.with-button { + -fx-padding: 0 0 12px; +} + +.row.margin { + -fx-padding: 0 0 15px; +} + +.row__input { + -fx-pref-width: Infinity; + -fx-padding: 10px 10px 10px 20px; + -fx-font-size: 15px; + -fx-border-color: #B8B8B8; +} + +.row__input.right { + -fx-padding: 10px 120px 10px 20px; +} + +.row__link.not-link { + -fx-text-fill: inherit; + -fx-background-color: transparent; + -fx-border-color: transparent; + -fx-border-width: 0; + -fx-padding: 0; + -fx-text-decoration: none; + -fx-underline: false; + -fx-cursor: default; +} + +.row__link.not-link:hover { + -fx-cursor: default; + -fx-underline: false; +} + +.row__input.not-active { + -fx-background-color: #DDDDDD; +} + +.row__combo-box { + -fx-font-size: 15px; + -fx-pref-width: Infinity; + -fx-hgrow: "ALWAYS"; + -fx-padding: 5px 10px; +} + +.row__button { + /*-fx-font-family: "inter-semibold";*/ + -fx-font-size: 12px; + -fx-font-weight: 700; + -fx-padding: 13px; + -fx-text-fill: #FFFFFF; + -fx-background-color: #747474; +} + +.row__button.inline { + -fx-pref-width: Infinity; + -fx-hgrow: "ALWAYS"; +} + +.row__button.inline.submit.active { + -fx-background-color: #56B665; +} + +.row__button.inline.submit.active:hover { + -fx-background-color: #499855; +} + +.row__button.active { + -fx-background-color: #285BBD; +} + +.row__button.active:hover { + -fx-background-color: #224c9e; + -fx-cursor: hand; +} + +.row__text { + /*-fx-font-family: 'Inter Light';*/ + -fx-font-size: 12px; +} + +.status { + -fx-alignment: center; + -fx-padding: 0 0 10px; +} + +.status__icon { + -fx-max-width: 20px; + -fx-max-height: 20px; +} + +.status__text { + -fx-padding: 0 0 13px; + /*-fx-font-family: "Inter SemiBold";*/ + -fx-font-weight: 700; + -fx-font-size: 12px; +} + +.status__text.red { + -fx-text-fill: #d51e1e; +} \ No newline at end of file diff --git a/src/main/resources/ui.fxml b/src/main/resources/ui.fxml new file mode 100644 index 0000000..87a6343 --- /dev/null +++ b/src/main/resources/ui.fxml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + +