Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
b70f588c
Commit
b70f588c
authored
Jan 28, 2014
by
Matija Obreza
Browse files
Request handling service
parent
73668f45
Changes
10
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
b70f588c
...
...
@@ -438,7 +438,12 @@
<artifactId>
google-api-client
</artifactId>
<version>
1.17.0-rc
</version>
</dependency>
</dependencies>
<dependency>
<groupId>
org.apache.velocity
</groupId>
<artifactId>
velocity
</artifactId>
<version>
1.7
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/org/genesys2/server/service/ContentService.java
View file @
b70f588c
...
...
@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.genesys2.server.model.EntityId
;
import
org.genesys2.server.model.impl.ActivityPost
;
...
...
@@ -99,4 +100,6 @@ public interface ContentService {
* @return
*/
Locale
getDefaultLocale
();
String
processTemplate
(
String
body
,
Map
<
String
,
Object
>
root
);
}
src/main/java/org/genesys2/server/service/RequestService.java
0 → 100644
View file @
b70f588c
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed 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
*
* http://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.
**/
package
org.genesys2.server.service
;
import
java.util.Set
;
import
org.genesys2.server.service.impl.EasySMTAConnector.EasySMTAUserData
;
public
interface
RequestService
{
void
sendRequest
(
EasySMTAUserData
pid
,
Set
<
Long
>
accessionIds
);
}
src/main/java/org/genesys2/server/service/impl/ContentServiceImpl.java
View file @
b70f588c
...
...
@@ -16,12 +16,17 @@
package
org.genesys2.server.service.impl
;
import
java.io.StringWriter
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.velocity.VelocityContext
;
import
org.apache.velocity.app.Velocity
;
import
org.genesys2.server.model.EntityId
;
import
org.genesys2.server.model.impl.ActivityPost
;
import
org.genesys2.server.model.impl.Article
;
...
...
@@ -114,8 +119,14 @@ public class ContentServiceImpl implements ContentService {
article
.
setSlug
(
slug
);
article
.
setTitle
(
htmlSanitizer
.
sanitize
(
title
));
article
.
setBody
(
htmlSanitizer
.
sanitize
(
body
));
// FIXME TODO Find a better way to distinguish between Velocity
// templates and general articles
if
(
StringUtils
.
contains
(
body
,
"VELOCITY"
))
{
article
.
setBody
(
body
);
}
else
{
article
.
setBody
(
htmlSanitizer
.
sanitize
(
body
));
}
articleRepository
.
save
(
article
);
return
article
;
...
...
@@ -244,4 +255,21 @@ public class ContentServiceImpl implements ContentService {
public
void
deleteActivityPost
(
long
id
)
{
postRepository
.
delete
(
id
);
}
@Override
public
String
processTemplate
(
String
templateStr
,
Map
<
String
,
Object
>
root
)
{
VelocityContext
context
=
new
VelocityContext
();
for
(
String
key
:
root
.
keySet
())
{
context
.
put
(
key
,
root
.
get
(
key
));
}
StringWriter
swOut
=
new
StringWriter
();
/**
* Merge data and template
*/
Velocity
.
evaluate
(
context
,
swOut
,
"log tag name"
,
templateStr
);
System
.
out
.
println
(
swOut
);
return
swOut
.
toString
();
}
}
src/main/java/org/genesys2/server/service/impl/RequestServiceImpl.java
0 → 100644
View file @
b70f588c
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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
*
* http://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.
**/
package
org.genesys2.server.service.impl
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.impl.Article
;
import
org.genesys2.server.service.ContentService
;
import
org.genesys2.server.service.EMailService
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.service.RequestService
;
import
org.genesys2.server.service.impl.EasySMTAConnector.EasySMTAUserData
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.stereotype.Service
;
@Service
public
class
RequestServiceImpl
implements
RequestService
{
private
static
final
Log
LOG
=
LogFactory
.
getLog
(
EMailVerificationServiceImpl
.
class
);
@Autowired
private
EMailService
emailService
;
@Autowired
private
ContentService
contentService
;
@Autowired
private
GenesysService
genesysService
;
@Value
(
"${base.url}"
)
private
String
baseUrl
;
@Value
(
"${mail.requests.to}"
)
private
String
requestsEmail
;
@Override
public
void
sendRequest
(
EasySMTAUserData
pid
,
Set
<
Long
>
accessionIds
)
{
Article
article
=
contentService
.
getGlobalArticle
(
"smtp.material-request"
,
Locale
.
ENGLISH
);
String
mailSubject
=
article
.
getTitle
();
Page
<
Accession
>
accessions
=
genesysService
.
listAccessions
(
accessionIds
,
new
PageRequest
(
0
,
Integer
.
MAX_VALUE
));
// Create the root hash
Map
<
String
,
Object
>
root
=
new
HashMap
<
String
,
Object
>();
root
.
put
(
"baseUrl"
,
baseUrl
);
root
.
put
(
"pid"
,
pid
);
root
.
put
(
"accessions"
,
accessions
.
getContent
());
String
mailBody
=
contentService
.
processTemplate
(
article
.
getBody
(),
root
);
LOG
.
info
(
">>>"
+
mailBody
);
emailService
.
sendMail
(
requestsEmail
,
null
,
mailSubject
,
mailBody
);
}
}
src/main/java/org/genesys2/server/servlet/controller/RequestController.java
View file @
b70f588c
...
...
@@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletRequest;
import
org.apache.commons.lang.StringUtils
;
import
org.genesys2.server.service.ContentService
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.service.RequestService
;
import
org.genesys2.server.service.impl.EasySMTAConnector
;
import
org.genesys2.server.service.impl.EasySMTAConnector.EasySMTAUserData
;
import
org.genesys2.util.ReCaptchaUtil
;
...
...
@@ -63,6 +64,9 @@ public class RequestController extends BaseController {
@Value
(
"${captcha.publicKey}"
)
private
String
captchaPublicKey
;
@Autowired
private
RequestService
requestService
;
/**
* Give information about the request process
*
...
...
@@ -112,8 +116,7 @@ public class RequestController extends BaseController {
}
else
{
// TODO send email to registered email address, wait for response
_logger
.
info
(
"Send email to: "
+
pid
);
requestService
.
sendRequest
(
pid
,
selectionBean
.
copy
());
}
// Whatever the response is, we render the same message
...
...
src/main/resources/default-content/smtp.material-request
0 → 100644
View file @
b70f588c
{
"en": {
"title": "Verify your email address",
"body": "<h2><small>genesys-pgr.org</small>\n<br/>Request for Material</h2><p></p><p>Thanks,<br/ >Genesys team</p>"
}
}
\ No newline at end of file
src/main/resources/spring/spring.properties
View file @
b70f588c
...
...
@@ -56,7 +56,8 @@ auto.createContent=false
mail.host
=
localhost
mail.port
=
25
mail.user.from
=
test@example.com
mail.user.from
=
test@localhost
mail.requests.to
=
test@localhost
mail.user.password
=
mail.user.name
=
...
...
src/main/webapp/WEB-INF/jsp/content/article-edit.jsp
View file @
b70f588c
...
...
@@ -30,9 +30,7 @@
<div
class=
"form-group"
>
<label
for=
"article-body"
class=
"control-label"
><spring:message
code=
"article.body"
/></label>
<div
class=
"controls"
>
<textarea
id=
"article-body"
name=
"body"
class=
"span9 required form-control html-editor"
>
<c:out
value=
"
${
article
.
body
}
"
escapeXml=
"false"
/>
</textarea>
<textarea
id=
"article-body"
name=
"body"
class=
"span9 required form-control html-editor"
><c:out
value=
"
${
article
.
body
}
"
escapeXml=
"false"
/></textarea>
</div>
</div>
...
...
@@ -44,14 +42,17 @@
<script
type=
"text/javascript"
src=
"/html/js/tinymce/tinymce.min.js"
></script>
<script
type=
"text/javascript"
>
jQuery
(
document
).
ready
(
function
()
{
tinyMCE
.
init
({
selector
:
"
.html-editor
"
,
menubar
:
false
,
statusbar
:
false
,
height
:
200
,
plugins
:
"
link autolink
"
,
directionality
:
document
.
dir
});
if
(
window
.
location
.
hash
==
'
#raw
'
)
{
}
else
{
tinyMCE
.
init
({
selector
:
"
.html-editor
"
,
menubar
:
false
,
statusbar
:
false
,
height
:
200
,
plugins
:
"
link autolink code
"
,
directionality
:
document
.
dir
});
}
});
</script>
</content>
...
...
src/main/webapp/WEB-INF/jsp/content/article.jsp
View file @
b70f588c
...
...
@@ -22,6 +22,9 @@
<a
href=
"
<c:url
value=
"/content/${article.slug}/edit"
/>
"
class=
"close"
>
<spring:message
code=
"edit"
/>
</a>
<a
href=
"
<c:url
value=
"/content/${article.slug}/edit#raw"
/>
"
class=
"close"
>
<spring:message
code=
"edit"
/>
</a>
</security:authorize>
<c:out
value=
"
${
article
.
body
}
"
escapeXml=
"false"
/>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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