Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
trismegisto-services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mauro Paolo Josue Zuñiga Mallqui
trismegisto-services
Commits
1cf76e1d
Commit
1cf76e1d
authored
Dec 26, 2023
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] FILES ADDED 26122023
parent
f2133fbf
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
373 additions
and
17 deletions
+373
-17
pom.xml
pom.xml
+18
-3
AppApi.java
src/main/java/web/multitask/app/api/AppApi.java
+2
-2
EmailApi.java
src/main/java/web/multitask/app/api/EmailApi.java
+48
-0
JWTApi.java
src/main/java/web/multitask/app/api/JWTApi.java
+2
-4
DotEnvConfig.java
src/main/java/web/multitask/app/config/DotEnvConfig.java
+17
-0
EmailConfig.java
src/main/java/web/multitask/app/config/EmailConfig.java
+43
-0
FilterConfig.java
src/main/java/web/multitask/app/config/FilterConfig.java
+1
-1
SecurityConfig.java
src/main/java/web/multitask/app/config/SecurityConfig.java
+5
-6
WebSocketConfig.java
src/main/java/web/multitask/app/config/WebSocketConfig.java
+3
-0
JwtTokenFilter.java
src/main/java/web/multitask/app/filter/JwtTokenFilter.java
+3
-1
EmailRequest.java
src/main/java/web/multitask/app/model/EmailRequest.java
+19
-0
EmailService.java
src/main/java/web/multitask/app/service/EmailService.java
+157
-0
DotEnvUtil.java
src/main/java/web/multitask/app/utils/DotEnvUtil.java
+55
-0
No files found.
pom.xml
View file @
1cf76e1d
...
...
@@ -49,7 +49,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- JPA -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
...
...
@@ -59,6 +58,7 @@
<groupId>
com.mysql
</groupId>
<artifactId>
mysql-connector-j
</artifactId>
<scope>
runtime
</scope>
<version>
8.2.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -73,7 +73,7 @@
<dependency>
<groupId>
org.json
</groupId>
<artifactId>
json
</artifactId>
<version>
2023
0618
</version>
<version>
2023
1013
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -107,7 +107,22 @@
<version>
0.11.2
</version>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
io.github.cdimascio
</groupId>
<artifactId>
java-dotenv
</artifactId>
<version>
5.2.2
</version>
</dependency>
<dependency>
<groupId>
javax.mail
</groupId>
<artifactId>
mail
</artifactId>
<version>
1.5.0-b01
</version>
<type>
jar
</type>
</dependency>
<dependency>
<groupId>
com.sun.mail
</groupId>
<artifactId>
javax.mail
</artifactId>
<version>
1.6.0
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/web/multitask/app/api/AppApi.java
View file @
1cf76e1d
...
...
@@ -19,7 +19,7 @@ public class AppApi {
this
.
userRepo
=
userRepo
;
}
@PostMapping
(
"/procedure"
)
@PostMapping
(
"/pr
ivate/pr
ocedure"
)
public
String
callProcedure
(
@RequestBody
String
body
)
{
JSONObject
json
=
new
JSONObject
(
body
);
if
(
json
.
has
(
"procedure"
))
{
...
...
@@ -35,7 +35,7 @@ public class AppApi {
}
}
@GetMapping
(
"/users"
)
@GetMapping
(
"/
private/
users"
)
public
String
getUsers
(){
return
new
JSONObject
().
put
(
"data"
,
userRepo
.
findAll
()).
put
(
"message"
,
"Success"
).
put
(
"status"
,
true
).
toString
();
}
...
...
src/main/java/web/multitask/app/api/EmailApi.java
0 → 100644
View file @
1cf76e1d
package
web
.
multitask
.
app
.
api
;
import
javax.mail.internet.MimeMessage
;
import
org.json.JSONObject
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RestController
;
import
web.multitask.app.model.EmailRequest
;
import
web.multitask.app.service.EmailService
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@RestController
@RequestMapping
(
"/email"
)
public
class
EmailApi
{
private
final
EmailService
emailService
;
public
EmailApi
(
EmailService
emailService
)
{
this
.
emailService
=
emailService
;
}
@RequestMapping
(
path
=
"/public/simple"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
MediaType
.
MULTIPART_FORM_DATA_VALUE
})
public
String
simple
(
@ModelAttribute
EmailRequest
request
)
{
try
{
MimeMessage
message
=
emailService
.
simpleMessage
(
request
);
JSONObject
response
=
emailService
.
send
(
message
);
return
response
.
toString
();
}
catch
(
Exception
e
)
{
return
new
JSONObject
().
put
(
"message"
,
e
.
getMessage
()).
put
(
"status"
,
false
).
toString
();
}
}
@RequestMapping
(
path
=
"/private/full"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
MediaType
.
MULTIPART_FORM_DATA_VALUE
})
public
String
full
(
@ModelAttribute
EmailRequest
request
)
{
try
{
MimeMessage
message
=
emailService
.
htmlMessage
(
request
);
JSONObject
response
=
emailService
.
send
(
message
);
return
response
.
toString
();
}
catch
(
Exception
e
)
{
return
new
JSONObject
().
put
(
"message"
,
e
.
getMessage
()).
put
(
"status"
,
false
).
toString
();
}
}
}
\ No newline at end of file
src/main/java/web/multitask/app/api/J
wt
Api.java
→
src/main/java/web/multitask/app/api/J
WT
Api.java
View file @
1cf76e1d
...
...
@@ -17,11 +17,11 @@ import org.springframework.web.bind.annotation.RequestBody;
@RestController
@RequestMapping
(
"/token"
)
@CrossOrigin
class
J
wt
Api
{
class
J
WT
Api
{
private
final
JwtTokenUtil
jwtTokenUtil
;
private
final
UserRespository
userRepo
;
public
J
wt
Api
(
JwtTokenUtil
jwtTokenUtil
,
UserRespository
userRepo
)
{
public
J
WT
Api
(
JwtTokenUtil
jwtTokenUtil
,
UserRespository
userRepo
)
{
this
.
jwtTokenUtil
=
jwtTokenUtil
;
this
.
userRepo
=
userRepo
;
}
...
...
@@ -48,5 +48,4 @@ class JwtApi {
}
}
}
\ No newline at end of file
src/main/java/web/multitask/app/config/DotEnvConfig.java
0 → 100644
View file @
1cf76e1d
package
web
.
multitask
.
app
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
io.github.cdimascio.dotenv.Dotenv
;
import
web.multitask.app.utils.DotEnvUtil
;
@Configuration
public
class
DotEnvConfig
{
@Bean
Dotenv
getDotEnvPath
()
{
return
Dotenv
.
configure
().
directory
(
DotEnvUtil
.
getDotEnvPath
(
"fullservice"
)).
load
();
}
}
src/main/java/web/multitask/app/config/EmailConfig.java
0 → 100644
View file @
1cf76e1d
package
web
.
multitask
.
app
.
config
;
import
java.util.Properties
;
import
javax.mail.Session
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
io.github.cdimascio.dotenv.Dotenv
;
@Configuration
public
class
EmailConfig
{
Dotenv
dotenv
;
public
EmailConfig
(
Dotenv
dotenv
)
{
this
.
dotenv
=
dotenv
;
}
@Bean
public
Session
setSession
()
{
Properties
properties
=
new
Properties
();
String
enabled
=
dotenv
.
get
(
"EMAIL_STARTTLS_ENABLE"
);
String
email
=
dotenv
.
get
(
"EMAIL_CORREO"
);
String
password
=
dotenv
.
get
(
"EMAIL_PASSWORD"
);
String
port
=
dotenv
.
get
(
"EMAIL_PORT"
);
String
host
=
dotenv
.
get
(
"EMAIL_HOST"
);
properties
.
put
(
"mail.smtp.host"
,
host
);
properties
.
put
(
"mail.smtp.starttls.enable"
,
enabled
);
properties
.
put
(
"mail.smtp.port"
,
port
);
properties
.
put
(
"mail.smtp.mail.sender"
,
email
);
properties
.
put
(
"mail.smtp.password"
,
password
);
properties
.
put
(
"mail.smtp.user"
,
email
);
properties
.
put
(
"mail.smtp.auth"
,
enabled
);
properties
.
put
(
"mail.smtp.ssl.trust"
,
"smtp.gmail.com"
);
properties
.
put
(
"mail.smtp.socketFactory.port"
,
port
);
properties
.
put
(
"mail.smtp.socketFactory.class"
,
"javax.net.ssl.SSLSocketFactory"
);
properties
.
put
(
"mail.smtp.ssl.protocols"
,
"TLSv1.2"
);
return
Session
.
getDefaultInstance
(
properties
);
}
}
src/main/java/web/multitask/app/config/FilterConfig.java
View file @
1cf76e1d
...
...
@@ -9,7 +9,7 @@ import web.multitask.app.filter.JwtTokenFilter;
public
class
FilterConfig
{
@Bean
public
FilterRegistrationBean
<
JwtTokenFilter
>
filterRegistrationBean
()
{
FilterRegistrationBean
<
JwtTokenFilter
>
filterRegistrationBean
()
{
FilterRegistrationBean
<
JwtTokenFilter
>
registrationBean
=
new
FilterRegistrationBean
<>();
registrationBean
.
setFilter
(
new
JwtTokenFilter
());
registrationBean
.
addUrlPatterns
(
"/**"
);
...
...
src/main/java/web/multitask/app/config/SecurityConfig.java
View file @
1cf76e1d
...
...
@@ -16,7 +16,6 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
web.multitask.app.filter.JwtTokenFilter
;
import
web.multitask.app.repository.UserRespository
;
import
web.multitask.app.utils.JwtTokenUtil
;
...
...
@@ -34,7 +33,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean
public
AuthenticationManager
authenticationManager
(
AuthenticationConfiguration
authenticationConfiguration
)
AuthenticationManager
authenticationManager
(
AuthenticationConfiguration
authenticationConfiguration
)
throws
Exception
{
return
authenticationConfiguration
.
getAuthenticationManager
();
}
...
...
@@ -50,10 +49,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
authorizeHttpRequests
(
authorizeRequests
->
authorizeRequests
.
antMatchers
(
"/security/**"
).
hasAnyAuthority
(
"ADMIN"
)
.
antMatchers
(
"/api/**"
).
hasAnyAuthority
(
"ADMIN"
,
"USER"
)
//
.antMatchers("/api/**").hasAnyAuthority("ADMIN", "USER")
.
antMatchers
(
"/token/**"
).
permitAll
()
.
antMatchers
(
"/private/*
*"
).
hasAnyAuthority
(
"ADMIN"
,
"USER"
)
.
antMatchers
(
"/public/*
*"
).
permitAll
()
.
regexMatchers
(
".*/private/.
*"
).
hasAnyAuthority
(
"ADMIN"
,
"USER"
)
.
regexMatchers
(
".*/public/.
*"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
GET
,
"/**"
).
permitAll
()
.
anyRequest
()
.
authenticated
());
...
...
@@ -66,7 +65,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean
public
CorsFilter
corsFilter
()
{
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
setAllowCredentials
(
true
);
...
...
src/main/java/web/multitask/app/config/WebSocketConfig.java
View file @
1cf76e1d
...
...
@@ -9,6 +9,7 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo
@Configuration
@EnableWebSocketMessageBroker
public
class
WebSocketConfig
implements
WebSocketMessageBrokerConfigurer
{
@Override
public
void
configureMessageBroker
(
MessageBrokerRegistry
registry
)
{
registry
.
enableSimpleBroker
(
"/topic"
);
...
...
@@ -19,4 +20,5 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public
void
registerStompEndpoints
(
StompEndpointRegistry
registry
)
{
registry
.
addEndpoint
(
"websocket"
).
setAllowedOrigins
(
"*"
);
}
}
\ No newline at end of file
src/main/java/web/multitask/app/filter/JwtTokenFilter.java
View file @
1cf76e1d
...
...
@@ -5,6 +5,7 @@ import javax.servlet.ServletException;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.jetbrains.annotations.NotNull
;
import
org.json.JSONObject
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpHeaders
;
...
...
@@ -36,7 +37,7 @@ public class JwtTokenFilter extends OncePerRequestFilter {
}
@Override
protected
void
doFilterInternal
(
HttpServletRequest
request
,
HttpServletResponse
response
,
FilterChain
chain
)
protected
void
doFilterInternal
(
HttpServletRequest
request
,
@NotNull
HttpServletResponse
response
,
@NotNull
FilterChain
chain
)
throws
ServletException
,
IOException
,
java
.
io
.
IOException
{
final
String
header
=
request
.
getHeader
(
HttpHeaders
.
AUTHORIZATION
);
...
...
@@ -47,6 +48,7 @@ public class JwtTokenFilter extends OncePerRequestFilter {
token
=
null
;
}
if
(
token
==
null
||
token
.
isEmpty
())
{
SecurityContextHolder
.
getContext
().
setAuthentication
(
null
);
chain
.
doFilter
(
request
,
response
);
}
else
{
if
(
jwtTokenUtil
.
validateToken
(
token
))
{
...
...
src/main/java/web/multitask/app/model/EmailRequest.java
0 → 100644
View file @
1cf76e1d
package
web
.
multitask
.
app
.
model
;
import
org.springframework.web.multipart.MultipartFile
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
@Getter
@Setter
@NoArgsConstructor
public
class
EmailRequest
{
private
String
to
;
private
String
cc
;
private
String
bcc
;
private
String
subject
;
private
String
body
;
private
MultipartFile
[]
files
;
}
src/main/java/web/multitask/app/service/EmailService.java
0 → 100644
View file @
1cf76e1d
package
web
.
multitask
.
app
.
service
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Objects
;
import
java.util.Properties
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
javax.activation.DataHandler
;
import
javax.activation.FileDataSource
;
import
javax.mail.BodyPart
;
import
javax.mail.MessagingException
;
import
javax.mail.Multipart
;
import
javax.mail.Session
;
import
javax.mail.Transport
;
import
javax.mail.internet.AddressException
;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.MimeBodyPart
;
import
javax.mail.internet.MimeMessage
;
import
javax.mail.internet.MimeMultipart
;
import
org.json.JSONObject
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
io.github.cdimascio.dotenv.Dotenv
;
import
web.multitask.app.model.EmailRequest
;
@Service
public
class
EmailService
{
Dotenv
dotenv
;
Session
session
;
public
EmailService
(
Dotenv
dotenv
,
Session
session
)
{
this
.
dotenv
=
dotenv
;
this
.
session
=
session
;
}
public
MimeMessage
htmlMessage
(
EmailRequest
request
)
throws
UnsupportedEncodingException
{
try
{
String
email
=
dotenv
.
get
(
"EMAIL_CORREO"
);
MimeMessage
message
=
new
MimeMessage
(
session
);
message
.
setFrom
(
new
InternetAddress
(
email
,
"FULLSERVICE APPLICATION"
));
message
.
setSender
(
new
InternetAddress
(
email
,
"FULLSERVICE APPLICATION"
));
message
.
setRecipients
(
MimeMessage
.
RecipientType
.
TO
,
buildRecipients
(
new
JSONObject
().
put
(
"to"
,
request
.
getTo
()),
"to"
));
if
(
request
.
getCc
()
!=
null
)
{
message
.
setRecipients
(
MimeMessage
.
RecipientType
.
CC
,
buildRecipients
(
new
JSONObject
().
put
(
"cc"
,
request
.
getCc
()),
"cc"
));
}
if
(
request
.
getBcc
()
!=
null
)
{
message
.
setRecipients
(
MimeMessage
.
RecipientType
.
BCC
,
buildRecipients
(
new
JSONObject
().
put
(
"bcc"
,
request
.
getBcc
()),
"bcc"
));
}
message
.
setSubject
(
request
.
getSubject
());
MimeBodyPart
texto
=
new
MimeBodyPart
();
texto
.
setContent
(
request
.
getBody
(),
"text/html; charset=utf-8"
);
MimeMultipart
multiParte
=
new
MimeMultipart
();
multiParte
.
addBodyPart
(
texto
);
try
{
String
file_folder
=
dotenv
.
get
(
"FILE_FOLDER"
);
MultipartFile
[]
files
=
request
.
getFiles
();
for
(
MultipartFile
file
:
files
)
{
BodyPart
adjunto
=
new
MimeBodyPart
();
String
fileName
=
file
.
getOriginalFilename
();
convertByteArrayToFile
(
file
.
getBytes
(),
fileName
,
file_folder
);
FileDataSource
fds
=
new
FileDataSource
(
file_folder
+
"/"
+
fileName
);
adjunto
.
setDataHandler
(
new
DataHandler
(
fds
));
adjunto
.
setFileName
(
fds
.
getName
());
multiParte
.
addBodyPart
(
adjunto
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
message
.
setContent
(
multiParte
);
return
message
;
}
catch
(
MessagingException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
return
null
;
}
}
public
void
convertByteArrayToFile
(
byte
[]
byteArray
,
String
fileName
,
String
file_folder
){
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
file_folder
+
"/"
+
fileName
))
{
fos
.
write
(
byteArray
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
e
.
getMessage
());
}
}
public
void
deleteAllFiles
(
String
file_folder
){
File
file
=
new
File
(
file_folder
);
if
(
file
.
exists
()){
File
[]
files
=
file
.
listFiles
();
for
(
File
f:
files
){
f
.
delete
();
}
}
}
public
MimeMessage
simpleMessage
(
EmailRequest
request
)
throws
UnsupportedEncodingException
{
try
{
MimeMessage
message
=
new
MimeMessage
(
session
);
String
email
=
dotenv
.
get
(
"EMAIL_CORREO"
);
message
.
setFrom
(
new
InternetAddress
(
email
,
"FULLSERVICE APPLICATION"
));
message
.
setSender
(
new
InternetAddress
(
email
,
"FULLSERVICE APPLICATION"
));
message
.
setRecipients
(
MimeMessage
.
RecipientType
.
TO
,
buildRecipients
(
new
JSONObject
().
put
(
"to"
,
request
.
getTo
()),
"to"
));
message
.
setSubject
(
request
.
getSubject
());
message
.
setText
(
request
.
getBody
());
return
message
;
}
catch
(
MessagingException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
public
JSONObject
send
(
MimeMessage
message
)
{
try
{
Transport
t
=
session
.
getTransport
(
"smtp"
);
String
email
=
dotenv
.
get
(
"EMAIL_CORREO"
);
String
password
=
dotenv
.
get
(
"EMAIL_PASSWORD"
);
t
.
connect
(
email
,
password
);
t
.
sendMessage
(
message
,
message
.
getAllRecipients
());
t
.
close
();
deleteAllFiles
(
dotenv
.
get
(
"FILE_FOLDER"
));
return
new
JSONObject
().
put
(
"message"
,
"OK"
).
put
(
"status"
,
true
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
return
new
JSONObject
().
put
(
"message"
,
e
.
getMessage
()).
put
(
"status"
,
false
);
}
}
public
InternetAddress
[]
buildRecipients
(
JSONObject
json
,
String
type
)
{
String
[]
recipients
=
json
.
optString
(
type
).
split
(
","
);
InternetAddress
[]
addresses
=
new
InternetAddress
[
recipients
.
length
];
Stream
.
of
(
recipients
).
map
(
recipient
->
{
try
{
return
new
InternetAddress
(
recipient
);
}
catch
(
AddressException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
()).
toArray
(
addresses
);
return
addresses
;
}
}
src/main/java/web/multitask/app/utils/DotEnvUtil.java
0 → 100644
View file @
1cf76e1d
package
web
.
multitask
.
app
.
utils
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
public
class
DotEnvUtil
{
static
String
detectedOS
;
public
enum
OSType
{
Windows
,
MacOS
,
Linux
,
Other
};
public
static
String
getOperatingSystemType
()
{
return
detectedOS
!=
null
?
detectedOS
:
(
detectedOS
=
getOSFromSystemProperty
());
}
private
static
String
getOSFromSystemProperty
()
{
String
OS
=
System
.
getProperty
(
"os.name"
,
"generic"
).
toLowerCase
(
Locale
.
ENGLISH
);
if
(
OS
.
contains
(
"mac"
)
||
OS
.
contains
(
"darwin"
))
return
"MacOS"
;
if
(
OS
.
contains
(
"win"
))
return
"Windows"
;
if
(
OS
.
contains
(
"nux"
))
return
"Linux"
;
return
"Other"
;
}
private
static
final
Map
<
String
,
String
>
OS_PATH_MAP
=
new
HashMap
<>();
static
{
OS_PATH_MAP
.
put
(
"MacOS"
,
"/opt/dotenv/"
);
OS_PATH_MAP
.
put
(
"Linux"
,
"/opt/dotenv/"
);
OS_PATH_MAP
.
put
(
"Windows"
,
"abcdefghijklmnopqrstuvwxyz"
);
}
public
static
String
getDotEnvPath
(
String
projectName
)
{
String
detectedOs
=
DotEnvUtil
.
getOperatingSystemType
();
return
OS_PATH_MAP
.
getOrDefault
(
detectedOs
,
""
)
+
(
detectedOs
.
equals
(
"Windows"
)
?
getWindowsPath
(
projectName
)
:
projectName
);
}
private
static
String
getWindowsPath
(
String
projectName
)
{
return
OS_PATH_MAP
.
get
(
"Windows"
)
.
chars
()
.
mapToObj
(
letter
->
"/"
+
(
char
)
letter
+
":/dotenv/"
+
projectName
)
.
filter
(
path
->
new
File
(
path
).
exists
())
.
findFirst
()
.
orElse
(
""
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment