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
91a3eb88
Commit
91a3eb88
authored
Jan 10, 2014
by
Matija Obreza
Browse files
Added FaoInstituteSetting entity, accessible as Map through
faoInstitute.settings[setting.key]
parent
506749e6
Changes
11
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/impl/FaoInstitute.java
View file @
91a3eb88
...
...
@@ -17,11 +17,15 @@
package
org.genesys2.server.model.impl
;
import
java.text.MessageFormat
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.MapKey
;
import
javax.persistence.OneToMany
;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
...
...
@@ -50,27 +54,32 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
@Column
(
unique
=
true
,
nullable
=
false
,
length
=
8
)
@Field
(
store
=
Store
.
NO
)
private
String
code
;
@Column
(
length
=
300
)
@Field
(
name
=
"title"
,
store
=
Store
.
YES
)
private
String
fullName
;
@Column
(
length
=
11
)
private
String
type
;
@Column
(
length
=
300
)
private
String
url
;
@Column
(
length
=
300
)
private
String
email
;
@Column
(
length
=
50
)
private
String
acronym
;
@ManyToOne
(
cascade
=
{},
optional
=
true
)
@JoinColumn
(
name
=
"countryId"
)
private
Country
country
;
@OneToMany
(
cascade
=
{})
@JoinColumn
(
referencedColumnName
=
"code"
,
name
=
"instCode"
)
@MapKey
(
name
=
"setting"
)
private
Map
<
String
,
FaoInstituteSetting
>
settings
=
new
HashMap
<
String
,
FaoInstituteSetting
>();
private
long
accessionCount
;
private
boolean
pgrActivity
;
private
boolean
maintainsCollection
;
...
...
@@ -81,7 +90,6 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
public
FaoInstitute
()
{
}
public
String
getCode
()
{
return
this
.
code
;
}
...
...
@@ -193,4 +201,12 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
public
void
setAltitude
(
Double
altitude
)
{
this
.
altitude
=
altitude
;
}
public
Map
<
String
,
FaoInstituteSetting
>
getSettings
()
{
return
settings
;
}
public
void
setSettings
(
Map
<
String
,
FaoInstituteSetting
>
settings
)
{
this
.
settings
=
settings
;
}
}
src/main/java/org/genesys2/server/model/impl/FaoInstituteSetting.java
0 → 100644
View file @
91a3eb88
package
org.genesys2.server.model.impl
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Lob
;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
import
org.genesys2.server.model.VersionedAuditedModel
;
/**
* Extra configuration for {@link FaoInstitute}
*/
@Entity
@Table
(
name
=
"faoinstitutesetting"
,
uniqueConstraints
=
@UniqueConstraint
(
columnNames
=
{
"instCode"
,
"setting"
}))
public
class
FaoInstituteSetting
extends
VersionedAuditedModel
{
@Column
(
length
=
7
,
nullable
=
false
)
private
String
instCode
;
@Column
(
length
=
64
)
private
String
setting
;
@Lob
private
String
value
;
public
FaoInstituteSetting
()
{
}
public
FaoInstituteSetting
(
FaoInstitute
faoInstitute
)
{
this
.
instCode
=
faoInstitute
.
getCode
();
}
public
String
getInstCode
()
{
return
instCode
;
}
public
void
setInstCode
(
String
instCode
)
{
this
.
instCode
=
instCode
;
}
public
String
getSetting
()
{
return
setting
;
}
public
void
setSetting
(
String
setting
)
{
this
.
setting
=
setting
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
}
src/main/java/org/genesys2/server/persistence/domain/FaoInstituteSettingRepository.java
0 → 100644
View file @
91a3eb88
/**
* 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.persistence.domain
;
import
org.genesys2.server.model.impl.FaoInstituteSetting
;
import
org.springframework.data.jpa.repository.JpaRepository
;
public
interface
FaoInstituteSettingRepository
extends
JpaRepository
<
FaoInstituteSetting
,
Long
>
{
FaoInstituteSetting
findByInstCodeAndSetting
(
String
instCode
,
String
setting
);
}
src/main/java/org/genesys2/server/service/InstituteService.java
View file @
91a3eb88
...
...
@@ -19,6 +19,7 @@ package org.genesys2.server.service;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.FaoInstitute
;
...
...
@@ -52,5 +53,6 @@ public interface InstituteService {
List
<
Organization
>
getOrganizations
(
FaoInstitute
faoInstitute
);
void
updateSettings
(
FaoInstitute
faoInstitute
,
Map
<
String
,
String
>
settings
);
}
src/main/java/org/genesys2/server/service/impl/InstituteServiceImpl.java
View file @
91a3eb88
...
...
@@ -20,15 +20,19 @@ import java.util.ArrayList;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.apache.commons.collections.ListUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.model.impl.FaoInstituteSetting
;
import
org.genesys2.server.model.impl.Organization
;
import
org.genesys2.server.persistence.domain.CountryRepository
;
import
org.genesys2.server.persistence.domain.FaoInstituteRepository
;
import
org.genesys2.server.persistence.domain.FaoInstituteSettingRepository
;
import
org.genesys2.server.persistence.domain.GenesysLowlevelRepository
;
import
org.genesys2.server.persistence.domain.OrganizationRepository
;
import
org.genesys2.server.service.ContentService
;
...
...
@@ -56,6 +60,9 @@ public class InstituteServiceImpl implements InstituteService {
@Autowired
private
FaoInstituteRepository
instituteRepository
;
@Autowired
private
FaoInstituteSettingRepository
instituteSettingRepository
;
@Autowired
private
CountryRepository
countryRepository
;
...
...
@@ -80,7 +87,10 @@ public class InstituteServiceImpl implements InstituteService {
@Override
public
FaoInstitute
getInstitute
(
String
wiewsCode
)
{
return
instituteRepository
.
findByCode
(
wiewsCode
);
FaoInstitute
inst
=
instituteRepository
.
findByCode
(
wiewsCode
);
if
(
inst
!=
null
)
inst
.
getSettings
().
size
();
return
inst
;
}
@Override
...
...
@@ -108,12 +118,39 @@ public class InstituteServiceImpl implements InstituteService {
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR')
or hasPermission(#faoInstitute, 'WRITE')
"
)
@Transactional
(
readOnly
=
false
)
public
void
updateBlurp
(
FaoInstitute
faoInstitute
,
String
blurp
,
Locale
locale
)
{
contentService
.
updateArticle
(
faoInstitute
,
"blurp"
,
null
,
blurp
,
locale
);
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'WRITE')"
)
@Transactional
(
readOnly
=
false
)
public
void
updateSettings
(
FaoInstitute
faoInstitute
,
Map
<
String
,
String
>
settings
)
{
List
<
FaoInstituteSetting
>
toSave
=
new
ArrayList
<
FaoInstituteSetting
>();
List
<
FaoInstituteSetting
>
toRemove
=
new
ArrayList
<
FaoInstituteSetting
>();
for
(
String
key
:
settings
.
keySet
())
{
String
settingValue
=
StringUtils
.
defaultIfBlank
(
settings
.
get
(
key
),
null
);
FaoInstituteSetting
setting
=
instituteSettingRepository
.
findByInstCodeAndSetting
(
faoInstitute
.
getCode
(),
key
);
if
(
setting
==
null
&&
settingValue
!=
null
)
{
setting
=
new
FaoInstituteSetting
(
faoInstitute
);
setting
.
setSetting
(
key
);
setting
.
setValue
(
settingValue
);
toSave
.
add
(
setting
);
}
else
if
(
setting
!=
null
)
{
setting
.
setValue
(
settingValue
);
if
(
settingValue
==
null
)
toRemove
.
add
(
setting
);
else
toSave
.
add
(
setting
);
}
}
instituteSettingRepository
.
save
(
toSave
);
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@Transactional
(
readOnly
=
false
)
...
...
@@ -127,4 +164,5 @@ public class InstituteServiceImpl implements InstituteService {
throw
new
NullPointerException
(
"faoInstitute"
);
return
organizationRepository
.
getOrganizations
(
faoInstitute
);
}
}
src/main/java/org/genesys2/server/servlet/controller/AccessionController.java
View file @
91a3eb88
...
...
@@ -66,6 +66,7 @@ public class AccessionController extends BaseController {
throw
new
ResourceNotFoundException
();
}
model
.
addAttribute
(
"accession"
,
accession
);
model
.
addAttribute
(
"faoInstitute"
,
instituteService
.
getInstitute
(
accession
.
getInstituteCode
()));
model
.
addAttribute
(
"accessionNames"
,
genesysService
.
listAccessionNames
(
accession
));
model
.
addAttribute
(
"accessionExchange"
,
genesysService
.
listAccessionExchange
(
accession
));
model
.
addAttribute
(
"accessionCollect"
,
genesysService
.
listAccessionCollect
(
accession
));
...
...
src/main/java/org/genesys2/server/servlet/controller/WiewsController.java
View file @
91a3eb88
...
...
@@ -17,6 +17,7 @@
package
org.genesys2.server.servlet.controller
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.genesys.Taxonomy
;
...
...
@@ -113,7 +114,8 @@ public class WiewsController extends BaseController {
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@RequestMapping
(
"/{wiewsCode}/update"
)
public
String
update
(
ModelMap
model
,
@PathVariable
(
value
=
"wiewsCode"
)
String
wiewsCode
,
@RequestParam
(
"blurp"
)
String
blurp
)
{
public
String
update
(
ModelMap
model
,
@PathVariable
(
value
=
"wiewsCode"
)
String
wiewsCode
,
@RequestParam
(
"blurp"
)
String
blurp
,
@RequestParam
(
"gaTracker"
)
String
gaTracker
)
{
_logger
.
debug
(
"Updating institite "
+
wiewsCode
);
FaoInstitute
faoInstitute
=
instituteService
.
getInstitute
(
wiewsCode
);
if
(
faoInstitute
==
null
)
{
...
...
@@ -121,6 +123,9 @@ public class WiewsController extends BaseController {
}
instituteService
.
updateBlurp
(
faoInstitute
,
blurp
,
getLocale
());
Map
<
String
,
String
>
settings
=
new
HashMap
<
String
,
String
>();
settings
.
put
(
"googleAnalytics.tracker"
,
gaTracker
);
instituteService
.
updateSettings
(
faoInstitute
,
settings
);
return
"redirect:/wiews/"
+
wiewsCode
;
}
...
...
@@ -180,4 +185,5 @@ public class WiewsController extends BaseController {
return
"/accession/data"
;
}
}
src/main/resources/content/language.properties
View file @
91a3eb88
...
...
@@ -336,3 +336,6 @@ acl.permission.2=Write
acl.permission.4
=
Create
acl.permission.8
=
Delete
acl.permission.16
=
Manage
ga.tracker-code
=
GA Tracker Code
src/main/webapp/WEB-INF/jsp/accession/details.jsp
View file @
91a3eb88
...
...
@@ -274,9 +274,9 @@
});
</c:if>
<%-- //
FIXME Testing GA for IRRI
--%>
<c:if
test=
"
${
accession
.
instituteCode
==
'PHL001'
}
"
>
_pageTrackers
=
[
"
UA-45878088-1
"
];
<%-- //
institute GA
--%>
<c:if
test=
"
${
faoInstitute
.
settings
[
'googleAnalytics.tracker'
]
ne
null
}
"
>
_pageTrackers
=
[
"
${faoInstitute.settings['googleAnalytics.tracker'].value}
"
];
</c:if>
_pageDim
=
{
institute
:
'
${accession.instituteCode}
'
,
genus
:
'
${accession.taxonomy.genus}
'
};
</script>
...
...
src/main/webapp/WEB-INF/jsp/wiews/details.jsp
View file @
91a3eb88
...
...
@@ -13,10 +13,6 @@
<small><c:out
value=
"
${
faoInstitute
.
code
}
"
/></small>
</h1>
<security:authorize
access=
"hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')"
>
<a
href=
"
<c:url
value=
"/acl/${faoInstitute.class.name}/${faoInstitute.id}/permissions"
><c:param
name=
"back"
>
/wiews/${faoInstitute.code.toLowerCase()}
</c:param></c:url>
"
class=
"btn btn-default"
>
<spring:message
code=
"edit-acl"
/></a>
</security:authorize>
<c:if
test=
"
${
countByInstitute
eq
0
}
"
>
<div
class=
"alert alert-info"
>
<spring:message
code=
"faoInstitute.no-accessions-registered"
/>
...
...
@@ -31,7 +27,8 @@
</div>
<div
class=
""
>
<security:authorize
access=
"hasRole('ADMINISTRATOR')"
>
<security:authorize
access=
"hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')"
>
<a
href=
"
<c:url
value=
"/acl/${faoInstitute.class.name}/${faoInstitute.id}/permissions"
><c:param
name=
"back"
>
/wiews/${faoInstitute.code.toLowerCase()}
</c:param></c:url>
"
class=
"close"
>
<spring:message
code=
"edit-acl"
/></a>
<a
href=
"
<c:url
value=
"/wiews/${faoInstitute.code.toLowerCase()}/edit"
/>
"
class=
"close"
>
<spring:message
code=
"edit"
/>
</a>
...
...
@@ -129,22 +126,21 @@
</div>
<c:if
test=
"
${
faoInstitute
.
latitude
ne
null
}
"
>
<script
type=
"text/javascript"
>
jQuery
(
document
).
ready
(
function
()
{
<c:if
test=
"
${
faoInstitute
.
latitude
ne
null
}
"
>
var
map
=
GoogleMaps
.
map
(
"
${pageContext.response.locale.language}
"
,
$
(
"
#map
"
),
{
maxZoom
:
6
,
/* WIEWS does not provide enough detail */
center
:
new
GoogleMaps
.
LatLng
(
$
{
faoInstitute
.
latitude
},
$
{
faoInstitute
.
longitude
}),
markerTitle
:
"
<spring:escapeBody
javaScriptEscape=
"true"
>
${faoInstitute.fullName}
</spring:escapeBody>
"
});
</c:if>
});
<%-- //
FIXME Testing GA for IRRI
--%>
<c:if
test=
"
${
faoInstitute
.
code
==
'PHL001'
}
"
>
_pageTrackers
=
[
"
UA-45878088-1
"
];
<%-- //
institute GA
--%>
<c:if
test=
"
${
faoInstitute
.
settings
[
'googleAnalytics.tracker'
]
ne
null
}
"
>
_pageTrackers
=
[
"
${faoInstitute.settings['googleAnalytics.tracker'].value}
"
];
</c:if>
_pageDim
=
{
institute
:
'
${faoInstitute.code}
'
};
</script>
</c:if>
</body>
</html>
\ No newline at end of file
src/main/webapp/WEB-INF/jsp/wiews/edit.jsp
View file @
91a3eb88
...
...
@@ -14,17 +14,24 @@
<small><c:out
value=
"
${
faoInstitute
.
code
}
"
/></small>
</h1>
<form
role=
"form"
class=
""
action=
"
<c:url
value=
"/wiews/${faoInstitute.code.toLowerCase()}/update"
/>
"
method=
"post"
>
<form
role=
"form"
class=
"
form-horizontal
"
action=
"
<c:url
value=
"/wiews/${faoInstitute.code.toLowerCase()}/update"
/>
"
method=
"post"
>
<div
class=
"form-group"
>
<label
for=
"blurp-body"
class=
"control-label"
><spring:message
code=
"blurp.blurp-body"
/></label>
<div
class=
"controls"
>
<label
for=
"blurp-body"
class=
"
col-lg-12
control-label"
><spring:message
code=
"blurp.blurp-body"
/></label>
<div
class=
"controls
col-lg-12
"
>
<textarea
id=
"blurp-body"
name=
"blurp"
class=
"span9 required html-editor"
>
<c:out
value=
"
${
blurp
.
body
}
"
/>
</textarea>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"col-lg-2 control-label"
><spring:message
code=
"ga.tracker-code"
/></label>
<div
class=
"controls col-lg-3"
>
<input
type=
"text"
name=
"gaTracker"
class=
"form-control required"
value=
"${faoInstitute.settings['googleAnalytics.tracker'].value}"
/>
</div>
</div>
<input
type=
"submit"
value=
"
<spring:message
code=
"
blurp.update-blurp
"
/>
"
class=
"btn btn-primary"
/>
<a
href=
"
<c:url
value=
"/wiews/${faoInstitute.code.toLowerCase()}"
/>
"
class=
"btn btn-default"
>
<spring:message
code=
"cancel"
/>
<input
type=
"submit"
value=
"
<spring:message
code=
"
save
"
/>
"
class=
"btn btn-primary"
/>
<a
href=
"
<c:url
value=
"/wiews/${faoInstitute.code.toLowerCase()}"
/>
"
class=
"btn btn-default"
>
<spring:message
code=
"cancel"
/>
</a>
</form>
...
...
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