Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
INB
eTRANSAFE
pretox-rest-api
Commits
95bb807d
Commit
95bb807d
authored
May 31, 2022
by
jcorvi
Browse files
Merge branch 'remove-reports' into 'develop'
remove documents See merge request
!25
parents
a3721a60
c37d4b17
Pipeline
#30683
passed with stage
in 5 minutes and 15 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/es/bsc/inb/ades/rest/api/controllers/DocumentController.java
View file @
95bb807d
package
es.bsc.inb.ades.rest.api.controllers
;
import
java.security.Principal
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -23,6 +27,8 @@ import es.bsc.inb.ades.rest.api.services.DocumentService;
@CrossOrigin
(
origins
=
"*"
)
public
class
DocumentController
{
@Autowired
public
DocumentService
documentService
;
...
...
@@ -69,6 +75,8 @@ public class DocumentController {
documentService
.
moveDocument
(
id
,
status
);
return
"true"
;
}
@RequestMapping
(
"/documents/{id}/setExportSRDomain/{srDomainId}/{export_srDomain}"
)
public
String
setExportFinding
(
@PathVariable
(
value
=
"id"
)
Long
id
,
@PathVariable
(
value
=
"srDomainId"
)
Integer
srDomainId
,
@PathVariable
(
value
=
"export_srDomain"
)
Boolean
export_srDomain
)
{
...
...
@@ -137,10 +145,26 @@ public class DocumentController {
return
new
ResponseEntity
<>(
content
,
head
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"/documents/remove/{id}"
)
public
String
removeDocument
(
@PathVariable
(
"id"
)
long
documentId
){
documentService
.
removeDocument
(
documentId
);
return
"true"
;
}
@RequestMapping
(
value
=
"/documents/restore/{id}"
)
public
String
restoreDocument
(
@PathVariable
(
"id"
)
long
documentId
){
documentService
.
restoreDocument
(
documentId
);
return
"true"
;
}
@RequestMapping
(
"/documents/{id}/tracking"
)
public
DocumentTracking
findTrackings
(
@PathVariable
(
value
=
"id"
)
Long
id
)
{
return
documentService
.
findTrackings
(
id
);
return
documentService
.
findTrackings
(
id
);
}
}
\ No newline at end of file
src/main/java/es/bsc/inb/ades/rest/api/model/Document.java
View file @
95bb807d
...
...
@@ -26,6 +26,8 @@ public class Document{
private
Status
status
;
private
RecordState
recordState
;
public
Document
()
{
super
();
}
...
...
@@ -90,5 +92,14 @@ public class Document{
this
.
fileName
=
fileName
;
}
public
RecordState
getRecordState
()
{
return
recordState
;
}
public
void
setRecordState
(
RecordState
recordState
)
{
this
.
recordState
=
recordState
;
}
}
src/main/java/es/bsc/inb/ades/rest/api/model/RecordState.java
0 → 100644
View file @
95bb807d
package
es.bsc.inb.ades.rest.api.model
;
public
enum
RecordState
{
ACTIVE
,
DELETED
;
}
src/main/java/es/bsc/inb/ades/rest/api/repository/DocumentRepositoryImpl.java
View file @
95bb807d
...
...
@@ -33,6 +33,8 @@ public class DocumentRepositoryImpl implements DocumentRepositoryCustom{
query
.
fields
().
include
(
"name"
);
query
.
fields
().
include
(
"processDate"
);
query
.
fields
().
include
(
"status"
);
query
.
fields
().
include
(
"recordState"
);
query
.
addCriteria
(
Criteria
.
where
(
"recordState"
).
ne
(
"DELETED"
));
//Sort sort = new Sort(Sort.Direction.ASC, "name");
//query.with(sort);
List
<
Document
>
documents
=
mongoTemplate
.
find
(
query
,
Document
.
class
);
...
...
src/main/java/es/bsc/inb/ades/rest/api/security/pkce/SecurityConfig.java
View file @
95bb807d
...
...
@@ -19,6 +19,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
authorizeRequests
()
.
antMatchers
(
HttpMethod
.
GET
,
"/liveness"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
GET
,
"/readiness"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
GET
,
"/documents/restore/*"
).
permitAll
()
.
anyRequest
().
authenticated
()
.
and
()
.
sessionManagement
()
...
...
src/main/java/es/bsc/inb/ades/rest/api/services/DocumentService.java
View file @
95bb807d
...
...
@@ -46,5 +46,9 @@ public interface DocumentService {
Status
moveDocument
(
Long
id
,
Status
status
);
DocumentTracking
findTrackings
(
Long
documentId
);
DocumentTracking
findTrackings
(
Long
documentId
);
void
removeDocument
(
long
documentId
);
void
restoreDocument
(
long
documentId
);
}
src/main/java/es/bsc/inb/ades/rest/api/services/DocumentServiceImpl.java
View file @
95bb807d
package
es.bsc.inb.ades.rest.api.services
;
import
java.nio.charset.Charset
;
import
java.security.Principal
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
;
import
org.springframework.stereotype.Service
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
com.nimbusds.jwt.JWT
;
import
es.bsc.inb.ades.rest.api.model.Action
;
import
es.bsc.inb.ades.rest.api.model.Annotation
;
...
...
@@ -21,6 +29,7 @@ import es.bsc.inb.ades.rest.api.model.Document;
import
es.bsc.inb.ades.rest.api.model.DocumentAnnotations
;
import
es.bsc.inb.ades.rest.api.model.DocumentTracking
;
import
es.bsc.inb.ades.rest.api.model.Finding
;
import
es.bsc.inb.ades.rest.api.model.RecordState
;
import
es.bsc.inb.ades.rest.api.model.SRDomainFinding
;
import
es.bsc.inb.ades.rest.api.model.Status
;
import
es.bsc.inb.ades.rest.api.model.Tracking
;
...
...
@@ -33,7 +42,8 @@ import es.bsc.inb.ades.rest.api.util.Constants;
@Service
public
class
DocumentServiceImpl
implements
DocumentService
{
@Autowired
private
HttpServletRequest
request
;
@Autowired
public
DocumentRepository
documentRepository
;
...
...
@@ -107,7 +117,7 @@ public class DocumentServiceImpl implements DocumentService {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
findingSelected
.
setStatus
(
status
);
documentAnnotationsRepository
.
save
(
documentAnnotations
);
createTracking
(
id
,
"admin"
,
Action
.
ACCEPT
,
findingSelected
.
getTrackingSummary
());
createTracking
(
id
,
Action
.
ACCEPT
,
findingSelected
.
getTrackingSummary
());
return
true
;
}
return
false
;
...
...
@@ -132,7 +142,7 @@ public class DocumentServiceImpl implements DocumentService {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
srDomainFindingelected
.
setStatus
(
status
);
documentAnnotationsRepository
.
save
(
documentAnnotations
);
createTracking
(
id
,
"admin"
,
Action
.
ACCEPT
,
srDomainFindingelected
.
getTrackingSummary
());
createTracking
(
id
,
Action
.
ACCEPT
,
srDomainFindingelected
.
getTrackingSummary
());
return
true
;
}
return
false
;
...
...
@@ -158,7 +168,7 @@ public class DocumentServiceImpl implements DocumentService {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
sRDomainFindingSelected
.
setExport
(
export_srdomainfinding
);
documentAnnotationsRepository
.
save
(
documentAnnotations
);
createTracking
(
id
,
"admin"
,
export_srdomainfinding
?
Action
.
EXPORT_SR_FINDING
:
Action
.
NOT_EXPORT_SR_FINDING
,
sRDomainFindingSelected
.
getTrackingSummary
());
createTracking
(
id
,
export_srdomainfinding
?
Action
.
EXPORT_SR_FINDING
:
Action
.
NOT_EXPORT_SR_FINDING
,
sRDomainFindingSelected
.
getTrackingSummary
());
return
true
;
}
return
false
;
...
...
@@ -976,15 +986,16 @@ public class DocumentServiceImpl implements DocumentService {
documentAnnotation
.
setStatus
(
status
);
documentRepository
.
save
(
document
);
documentAnnotationsRepository
.
save
(
documentAnnotation
);
createTracking
(
id
,
"admin"
,
Action
.
MOVE
,
status
.
toString
());
createTracking
(
id
,
Action
.
MOVE
,
status
.
toString
());
return
status
;
}
private
void
createTracking
(
Long
id
,
String
userName
,
Action
action
,
String
comment
)
{
private
void
createTracking
(
Long
id
,
Action
action
,
String
comment
)
{
DocumentTracking
documentTracking
=
this
.
findDocumentTrackingById
(
id
);
Tracking
tracking
=
new
Tracking
(
userName
,
action
,
comment
);
// Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
// JwtAuthenticationToken token = (JwtAuthenticationToken)principal;
// Tracking tracking = new Tracking (token.getTokenAttributes().get("name").toString(), action, comment);
Tracking
tracking
=
new
Tracking
(
getUserName
(),
action
,
comment
);
documentTracking
.
addTracking
(
tracking
);
documentTrackingRepository
.
save
(
documentTracking
);
}
...
...
@@ -1003,6 +1014,37 @@ public class DocumentServiceImpl implements DocumentService {
return
documentTracking
;
}
@Override
public
void
removeDocument
(
long
documentId
)
{
Document
document
=
this
.
findByDocumentId
(
documentId
);
document
.
setRecordState
(
RecordState
.
DELETED
);
documentRepository
.
save
(
document
);
}
@Override
public
void
restoreDocument
(
long
documentId
)
{
Document
document
=
this
.
findByDocumentId
(
documentId
);
document
.
setRecordState
(
RecordState
.
ACTIVE
);
documentRepository
.
save
(
document
);
}
private
String
getUserName
()
{
Principal
user
=
request
.
getUserPrincipal
();
String
userName
=
""
;
if
(
user
!=
null
&&
user
instanceof
JwtAuthenticationToken
)
{
JwtAuthenticationToken
token
=
(
JwtAuthenticationToken
)
user
;
if
(
token
.
getTokenAttributes
().
get
(
"name"
)!=
null
)
{
userName
=
token
.
getTokenAttributes
().
get
(
"name"
).
toString
();
};
}
return
userName
;
}
public
HttpServletRequest
getRequest
()
{
return
request
;
}
public
void
setRequest
(
HttpServletRequest
request
)
{
this
.
request
=
request
;
}
}
src/main/java/es/bsc/inb/ades/rest/api/services/FileServiceImp.java
View file @
95bb807d
...
...
@@ -18,6 +18,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.MongoDatabase
;
import
es.bsc.inb.ades.rest.api.model.RecordState
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.IOException
;
...
...
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