Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ipmworks_backend
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ipmworks
ipmworks_backend
Commits
d480b325
Commit
d480b325
authored
Apr 30, 2024
by
Danijela Boberic Krsticev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some minor changes
parent
184f79bf
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
121 deletions
+116
-121
src/main/java/ipm/ipmworks/control/AdminResourceController.java
+11
-0
src/main/java/ipm/ipmworks/control/ResourceController.java
+60
-118
src/main/java/ipm/ipmworks/model/Comment.java
+11
-0
src/main/java/ipm/ipmworks/model/Resource.java
+13
-3
src/main/java/ipm/ipmworks/service/EmailService.java
+21
-0
No files found.
src/main/java/ipm/ipmworks/control/AdminResourceController.java
View file @
d480b325
...
...
@@ -35,6 +35,17 @@ public class AdminResourceController {
if
(
resource
.
isPresent
()){
Resource
r
=
resource
.
get
();
r
.
setApproved
(
true
);
r
.
setHide
(
false
);
resourceRepository
.
save
(
r
);
}
}
@GetMapping
(
"/archive/{id}"
)
public
void
archiveResource
(
@PathVariable
(
"id"
)
String
idResource
){
Optional
<
Resource
>
resource
=
resourceRepository
.
findById
(
idResource
);
if
(
resource
.
isPresent
()){
Resource
r
=
resource
.
get
();
r
.
setApproved
(
false
);
r
.
setHide
(
true
);
resourceRepository
.
save
(
r
);
}
}
...
...
src/main/java/ipm/ipmworks/control/ResourceController.java
View file @
d480b325
...
...
@@ -5,18 +5,14 @@ import com.mongodb.client.gridfs.GridFSFindIterable;
import
com.mongodb.client.gridfs.model.GridFSFile
;
import
ipm.ipmworks.model.*
;
import
ipm.ipmworks.repository.*
;
import
ipm.ipmworks.service.EmailService
;
import
ipm.ipmworks.service.FileService
;
import
net.sf.jasperreports.engine.*
;
import
net.sf.jasperreports.engine.data.JRAbstractBeanDataSource
;
import
net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
;
import
net.sf.jasperreports.engine.export.JRPdfExporter
;
import
net.sf.jasperreports.engine.export.JRXlsExporter
;
import
net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer
;
import
net.sf.jasperreports.engine.util.JRSwapFile
;
import
net.sf.jasperreports.export.SimpleExporterInput
;
import
net.sf.jasperreports.export.SimpleOutputStreamExporterOutput
;
import
net.sf.jasperreports.export.SimplePdfReportConfiguration
;
import
net.sf.jasperreports.export.SimpleXlsReportConfiguration
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -73,7 +69,8 @@ public class ResourceController {
@Autowired
FileService
fileService
;
@Autowired
EmailService
emailService
;
@Autowired
@Qualifier
(
"ipmDecisionRest"
)
...
...
@@ -105,6 +102,7 @@ public class ResourceController {
@RequestMapping
(
value
=
"/saveResource"
,
method
=
RequestMethod
.
POST
)
public
Resource
saveResource
(
@RequestBody
Resource
r
){
r
.
setHide
(
false
);
Resource
res
=
rr
.
save
(
r
);
return
res
;
}
...
...
@@ -130,7 +128,10 @@ public class ResourceController {
if
(
title
!=
null
&&
!
title
.
isEmpty
())
{
Resource
r
=
new
Resource
();
r
.
setExternal
(
true
);
r
.
getLinks
().
add
(
"https://orgprints.org/"
);
Link
link
=
new
Link
();
link
.
setName
(
"orgprint"
);
link
.
setUrl
(
"https://orgprints.org/"
);
r
.
getLinks
().
add
(
link
);
r
.
setCanEdit
(
false
);
r
.
setProject
(
"Organic Eprints"
);
if
(
title
!=
null
)
{
...
...
@@ -162,7 +163,10 @@ public class ResourceController {
if
((
List
<
String
>)
map
.
get
(
"documents"
)
!=
null
)
{
List
<
LinkedHashMap
>
documents
=
(
List
<
LinkedHashMap
>)
map
.
get
(
"documents"
);
for
(
LinkedHashMap
doc
:
documents
)
{
r
.
getLinks
().
add
((
String
)
doc
.
get
(
"uri"
));
Link
link1
=
new
Link
();
link1
.
setName
((
String
)
doc
.
get
(
"uri"
));
link1
.
setUrl
((
String
)
doc
.
get
(
"uri"
));
r
.
getLinks
().
add
(
link1
);
}
}
...
...
@@ -177,10 +181,14 @@ public class ResourceController {
return
null
;
}
}
private
Resource
createResourceFromIPMDecisions
(
LinkedHashMap
map
){
private
Resource
createResourceFromIPMDecisions
(
LinkedHashMap
map
,
List
<
String
>
acceptLanguage
){
Resource
r
=
new
Resource
();
r
.
setExternal
(
true
);
r
.
getLinks
().
add
(
"https://platform.ipmdecisions.net/"
);
Link
link
=
new
Link
();
link
.
setName
(
"https://platform.ipmdecisions.net/"
);
link
.
setUrl
(
"https://platform.ipmdecisions.net/"
);
r
.
getLinks
().
add
(
link
);
r
.
setCanEdit
(
false
);
if
((
String
)
map
.
get
(
"resourceName"
)!=
null
){
r
.
setResourceName
((
String
)
map
.
get
(
"resourceName"
));
...
...
@@ -228,6 +236,12 @@ public class ResourceController {
}
if
((
List
<
String
>)
map
.
get
(
"languages"
)!=
null
){
List
<
String
>
languages
=(
List
<
String
>)
map
.
get
(
"languages"
);
if
(
acceptLanguage
!=
null
)
{
if
(
Collections
.
disjoint
(
languages
,
acceptLanguage
))
{
return
null
;
}
}
if
(
languages
.
size
()
>
1
){
Language
temp
=
new
Language
(
String
.
join
(
", "
,
languages
));
r
.
setLanguage
(
temp
);
...
...
@@ -280,7 +294,7 @@ public class ResourceController {
ResponseEntity
<
LinkedHashMap
>
map
=
ipmDecisionRest
.
exchange
(
"/search/"
+
idRes
,
HttpMethod
.
GET
,
entity
,
LinkedHashMap
.
class
);
return
createResourceFromIPMDecisions
(
map
.
getBody
());
return
createResourceFromIPMDecisions
(
map
.
getBody
()
,
null
);
}
}
else
{
List
<
Map
>
files
=
getResourceFiles
(
idResource
);
...
...
@@ -350,12 +364,10 @@ public class ResourceController {
imageName
=
"smartprotect"
;
}
else
if
(
resource
.
getProject
()!=
null
&&
resource
.
getProject
().
equals
(
"Endure"
)){
imageName
=
"endure"
;
}
else
if
(
resource
.
getSectors
()
!=
null
&&
resource
.
getSectors
().
size
()
>
2
)
{
}
else
if
(
resource
.
getSectors
()
!=
null
&&
resource
.
getSectors
().
size
()
>
1
)
{
imageName
=
"multi"
;
}
else
if
(
resource
.
getSectors
()
!=
null
&&
resource
.
getSectors
().
size
()
==
1
)
{
imageName
=
resource
.
getSectors
().
get
(
0
).
getSectorIcon
();
}
else
if
(
resource
.
getSectors
()
!=
null
&&
resource
.
getSectors
().
size
()
==
2
)
{
imageName
=
resource
.
getSectors
().
get
(
0
).
getSectorIcon
()+
"_"
+
resource
.
getSectors
().
get
(
1
).
getSectorIcon
();
}
else
{
imageName
=
"multi"
;
...
...
@@ -385,106 +397,6 @@ public class ResourceController {
}
}
/* @GetMapping("/image/{idResource}")
@ResponseBody
public ResponseEntity<InputStreamResource> getImage(@PathVariable("idResource") String idResource) {
Optional<Resource> res = rr.findById(idResource);
String regionImage = "images/regions/Default.png";
String sectorImage = "images/sectors/multi.jpg";
String languageImage = "images/languages/english.png";
Resource resource=null;
if (res.isPresent()) {
resource = res.get();
}else if (idResource.startsWith("adas")) { //ovo je resurs iz IPM Decision
String idRes = idResource.replaceFirst("_",";");
LinkedHashMap map = ipmDecisionRest.getForObject("/search/"+idRes, LinkedHashMap.class);
resource = createResourceFromIPMDecisions(map);
}else { //eprint baza
if (idResource.length() > 7){
String idRes = idResource.substring(7);
List<LinkedHashMap> map = organicKnowledgeRest.getForObject(searchByTitle + idRes , List.class);
if (map != null && !map.isEmpty()) {
resource = createResourceFromOrganicKnowledge(map.get(0));
}
}
}
List<Sector> sectors = resource.getSectors();
List<Region> regions = resource.getRegions();
Language language = resource.getLanguage();
String icon1 = null, icon2 = null, icon3 = null, icon4 = null, icon5 = null;
if (sectors != null && sectors.size()==1) {
sectorImage = "images/sectors/" + sectors.get(0).getSectorIcon();
}else if (sectors != null && sectors.size()>1){
sectorImage = "images/sectors/multi/" + sectors.get(0).getSectorIcon();
if(sectors.size()>=1){
icon1 = "images/icons/"+sectors.get(0).getSectorIcon();
}
if(sectors.size()>=2){
icon2 = "images/icons/"+sectors.get(1).getSectorIcon();
}
if(sectors.size()>=3){
icon3 = "images/icons/"+sectors.get(2).getSectorIcon();
}
if(sectors.size()>=4){
icon4 = "images/icons/"+sectors.get(3).getSectorIcon();
}
if(sectors.size()>=5){
icon5 = "images/icons/"+sectors.get(4).getSectorIcon();
}
}
if (language != null) {
languageImage = "images/languages/" + language.getName().toLowerCase()+".png";
}
if (regions != null && !regions.isEmpty()){
Region r = regionRepository.findByName(regions.get(0).getName());
if (r == null){
regionImage = "images/regions/Default.png";
}else{
regionImage = "images/regions/"+regions.get(0).getName().replaceFirst(" ","_")+".png";
}
}
try {
GridFsResource gridFSFileImage = fileService.getResourceImage(idResource,"image");
GridFsResource gridFSFileLogo = fileService.getResourceImage(idResource,"logo");
InputStream logo = null;
if (gridFSFileLogo != null){
logo = gridFSFileLogo.getInputStream();
}else{
if (resource.getProject().equals("Smart Protect")) {
logo = fileService.getResourceImage("smartprotect", "logo").getInputStream();
}else if (resource.getProject().equals("Organic Eprints")) {
logo = fileService.getResourceImage("organiceprint", "logo").getInputStream();
}else if (resource.getProject().equals("IPM Decisions")) {
logo = fileService.getResourceImage("6239f180051d511bc931ea30", "logo").getInputStream();
}
}
Image generatedImg = null;
if (gridFSFileImage != null) {
generatedImg = generateImage(sectorImage,gridFSFileImage.getInputStream(), regionImage, logo, languageImage,icon1,icon2,icon3,icon4,icon5);
} else {
generatedImg = generateImage(sectorImage, null, regionImage, logo, languageImage,icon1,icon2,icon3,icon4,icon5);
}
InputStream is = createInputStream(generatedImg);
if(is !=null){
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(MediaType.IMAGE_JPEG_VALUE))
.contentType(MediaType.parseMediaType(MediaType.IMAGE_PNG_VALUE))
.body(new InputStreamResource(is));
}else{
return ResponseEntity.internalServerError().build();
}
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.internalServerError().build();
}
}*/
private
InputStream
createInputStream
(
Image
generatedImg
){
try
{
ByteArrayOutputStream
compressed
=
new
ByteArrayOutputStream
();
...
...
@@ -646,7 +558,7 @@ public class ResourceController {
List
<
ResourceType
>
resourceTypes
=
searchModel
.
getResourceType
();
List
<
Crop
>
crops
=
searchModel
.
getCrop
();
List
<
Pest
>
pests
=
searchModel
.
getPest
();
//
List<Language> languages = searchModel.getLanguage();
List
<
Language
>
languages
=
searchModel
.
getLanguage
();
List
<
Region
>
regions
=
searchModel
.
getRegion
();
Project
project
=
searchModel
.
getProject
();
String
title
=
searchModel
.
getTitle
();
...
...
@@ -701,6 +613,7 @@ public class ResourceController {
private
List
<
Resource
>
searchIPMDecision
(
SearchModel
searchModel
)
throws
Exception
{
List
<
Resource
>
resourceList
=
new
ArrayList
<>();
String
acceptLanguage
=
null
;
List
<
String
>
acceptedLang
=
null
;
IpmDecisionModel
model
=
new
IpmDecisionModel
();
if
(
searchModel
.
getPest
()!=
null
&&
!
searchModel
.
getPest
().
isEmpty
()){
for
(
Pest
p:
searchModel
.
getPest
())
{
...
...
@@ -719,6 +632,7 @@ public class ResourceController {
languages
.
add
(
l
.
getCode
());
}
acceptLanguage
=
String
.
join
(
","
,
languages
);
acceptedLang
=
searchModel
.
getLanguage
().
stream
().
map
(
l
->
l
.
getName
()).
collect
(
Collectors
.
toList
());
}
if
(
searchModel
.
getRegion
()!=
null
&&
!
searchModel
.
getRegion
().
isEmpty
()){
for
(
Region
r:
searchModel
.
getRegion
()){
...
...
@@ -732,10 +646,12 @@ public class ResourceController {
HttpEntity
entity
=
new
HttpEntity
(
model
,
headers
);
ResponseEntity
<
List
>
result
=
ipmDecisionRest
.
postForEntity
(
"/search"
,
entity
,
List
.
class
);
for
(
LinkedHashMap
map
:
(
List
<
LinkedHashMap
>)
result
.
getBody
())
{
Resource
r
=
createResourceFromIPMDecisions
(
map
);
Resource
r
=
createResourceFromIPMDecisions
(
map
,
acceptedLang
);
if
(
r
!=
null
)
{
resourceList
.
add
(
r
);
}
}
else
{
}
}
/*else{
ResourceType type = resourceTypeRepository.findByName("IPM Decisions Model");
if ((searchModel.getProject()!=null && searchModel.getProject().getName().equals("IPM Decisions")) || (searchModel.getResourceType() !=null && searchModel.isIPMDecision() )) {
HttpHeaders headers = new HttpHeaders();
...
...
@@ -747,7 +663,7 @@ public class ResourceController {
resourceList.add(r);
}
}
}
}
*/
return
resourceList
;
}
...
...
@@ -877,6 +793,8 @@ public class ResourceController {
if
(!
andCriteria
.
isEmpty
()){
Criteria
c
=
new
Criteria
().
where
(
"approved"
).
is
(
true
);
andCriteria
.
add
(
c
);
Criteria
c1
=
new
Criteria
().
where
(
"hide"
).
is
(
false
);
andCriteria
.
add
(
c1
);
current
=
current
.
andOperator
(
andCriteria
);
query
.
addCriteria
(
current
);
List
<
Resource
>
ipmWorksResult
=
mongoTemplate
.
find
(
query
,
Resource
.
class
);
...
...
@@ -927,4 +845,28 @@ public class ResourceController {
e
.
printStackTrace
();
}
}
@PostMapping
(
"comment/{idResource}"
)
public
void
commentResource
(
@RequestBody
Comment
comment
,
@PathVariable
(
"idResource"
)
String
idResource
){
StringBuilder
body
=
new
StringBuilder
();
String
resourceLink
=
"https://ipmworks.net/toolbox/en/#/resource/"
+
idResource
;
body
.
append
(
"You have a new comment regarding resource "
+
resourceLink
);
body
.
append
(
"\n"
);
body
.
append
(
"\n"
);
body
.
append
(
"-----------------------"
);
body
.
append
(
"\n"
);
body
.
append
(
comment
.
getText
());
body
.
append
(
"\n"
);
body
.
append
(
"-----------------------"
);
body
.
append
(
"\n"
);
if
(!
comment
.
getCommenterEmail
().
isEmpty
())
{
body
.
append
(
"You can reply on this comment using email left by commenter: "
+
comment
.
getCommenterEmail
());
}
body
.
append
(
"\n"
);
body
.
append
(
"\n"
);
body
.
append
(
"Best regards\n"
);
body
.
append
(
"IPMWorks toolbox team"
);
emailService
.
sendEmail
(
"IPMWORKS-WP4@inrae.fr"
,
"New resource comment"
,
body
.
toString
());
}
}
src/main/java/ipm/ipmworks/model/Comment.java
0 → 100644
View file @
d480b325
package
ipm
.
ipmworks
.
model
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
Comment
{
private
String
text
;
private
String
commenterEmail
;
}
src/main/java/ipm/ipmworks/model/Resource.java
View file @
d480b325
package
ipm
.
ipmworks
.
model
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Transient
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -29,7 +38,8 @@ public class Resource {
private
String
contactPhone
;
private
String
contactAddress
;
private
List
<
String
>
links
=
new
ArrayList
<
String
>();
private
List
<
Link
>
links
=
new
ArrayList
<
Link
>();
private
String
youtube
;
private
List
<
Map
>
files
=
new
ArrayList
();
private
String
project
;
private
String
projectWeb
;
...
...
@@ -42,9 +52,9 @@ public class Resource {
private
User
approvedBy
;
private
List
<
Pest
>
pests
=
new
ArrayList
<
Pest
>();
private
List
<
Crop
>
crops
=
new
ArrayList
<
Crop
>();
private
List
<
User
>
likes
=
new
ArrayList
<
User
>();
private
Date
creationDate
;
private
LocalDateTime
creationDate
;
private
boolean
approved
;
private
boolean
canEdit
;
private
boolean
external
;
private
boolean
hide
;
}
src/main/java/ipm/ipmworks/service/EmailService.java
0 → 100644
View file @
d480b325
package
ipm
.
ipmworks
.
service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.mail.SimpleMailMessage
;
import
org.springframework.mail.javamail.JavaMailSender
;
import
org.springframework.stereotype.Service
;
@Service
public
class
EmailService
{
@Autowired
private
JavaMailSender
javaMailSender
;
public
void
sendEmail
(
String
receiver
,
String
subject
,
String
body
)
{
SimpleMailMessage
msg
=
new
SimpleMailMessage
();
msg
.
setTo
(
receiver
);
msg
.
setSubject
(
subject
);
msg
.
setText
(
body
);
javaMailSender
.
send
(
msg
);
}
}
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