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
9ec93f17
Commit
9ec93f17
authored
Nov 03, 2015
by
Matija Obreza
Browse files
Accession lists: shared and used on Project pages
parent
5efb2162
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/json/UserAccessionList.java
View file @
9ec93f17
...
...
@@ -27,6 +27,7 @@ public class UserAccessionList implements Serializable {
public
UUID
uuid
;
public
String
title
;
public
String
description
;
public
boolean
shared
;
public
static
UserAccessionList
from
(
AccessionList
ual
)
{
UserAccessionList
ul
=
new
UserAccessionList
();
...
...
@@ -34,6 +35,7 @@ public class UserAccessionList implements Serializable {
ul
.
uuid
=
ual
.
getUuid
();
ul
.
title
=
ual
.
getTitle
();
ul
.
description
=
ual
.
getDescription
();
ul
.
shared
=
ual
.
isShared
();
return
ul
;
}
...
...
@@ -52,4 +54,8 @@ public class UserAccessionList implements Serializable {
public
UUID
getUuid
()
{
return
uuid
;
}
public
boolean
getShared
()
{
return
shared
;
}
}
src/main/java/org/genesys2/server/persistence/domain/AccessionListCustomRepository.java
View file @
9ec93f17
...
...
@@ -16,10 +16,14 @@
package
org.genesys2.server.persistence.domain
;
import
java.util.Collection
;
import
org.genesys2.server.model.impl.AccessionList
;
import
org.genesys2.server.service.impl.FilterHandler.AppliedFilters
;
public
interface
AccessionListCustomRepository
{
int
addAll
(
AccessionList
loaded
,
Collection
<
Long
>
accessionIds
);
int
addAll
(
AccessionList
loaded
,
AppliedFilters
filters
);
...
...
src/main/java/org/genesys2/server/persistence/domain/AccessionListRepositoryCustomImpl.java
View file @
9ec93f17
...
...
@@ -16,6 +16,8 @@
package
org.genesys2.server.persistence.domain
;
import
java.util.Collection
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.Query
;
...
...
@@ -29,7 +31,6 @@ import org.genesys2.server.service.impl.DirectMysqlQuery.MethodResolver;
import
org.genesys2.server.service.impl.FilterHandler.AppliedFilters
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Repository
;
@Repository
...
...
@@ -39,12 +40,21 @@ public class AccessionListRepositoryCustomImpl implements AccessionListCustomRep
@PersistenceContext
private
EntityManager
entityManager
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
MethodRepository
methodRepository
;
@Override
public
int
addAll
(
AccessionList
accessionList
,
Collection
<
Long
>
accessionIds
)
{
Query
q
=
entityManager
.
createNativeQuery
(
"insert ignore into accelistitems (listid, acceid) values (?1, ?2)"
);
q
.
setParameter
(
1
,
accessionList
);
int
count
=
0
;
for
(
Long
acceId
:
accessionIds
)
{
q
.
setParameter
(
2
,
acceId
);
count
+=
q
.
executeUpdate
();
}
return
count
;
}
@Override
public
int
addAll
(
AccessionList
list
,
AppliedFilters
filter
)
{
final
DirectMysqlQuery
directQuery
=
new
DirectMysqlQuery
(
"accession"
,
"a"
);
...
...
@@ -58,10 +68,10 @@ public class AccessionListRepositoryCustomImpl implements AccessionListCustomRep
Query
q
=
entityManager
.
createNativeQuery
(
"insert ignore into accelistitems (listid, acceid) ("
+
directQuery
.
getQuery
(
"?, a.id"
)
+
")"
);
q
.
setParameter
(
1
,
list
.
getId
());
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Updating list: "
+
list
.
getUuid
()
+
" id="
+
list
.
getId
());
int
param
=
2
;
for
(
Object
pv
:
directQuery
.
getParameters
())
{
q
.
setParameter
(
param
++,
pv
);
...
...
src/main/java/org/genesys2/server/service/AccessionListService.java
View file @
9ec93f17
...
...
@@ -37,19 +37,23 @@ public interface AccessionListService {
List
<
AccessionList
>
getMyLists
();
Set
<
Long
>
getAccessionIds
(
AccessionList
loaded
);
Set
<
Long
>
getAccessionIds
(
AccessionList
accessionList
);
AccessionList
getList
(
UUID
uuid
);
List
<
AccessionList
>
getLists
(
List
<
UUID
>
uuid
);
void
removeAll
(
AccessionList
accessionList
);
void
addToList
(
AccessionList
list
,
AccessionData
accession
);
void
addToList
(
AccessionList
acceList
,
Collection
<
Long
>
accessionIds
);
void
addToList
(
AccessionList
accessionList
,
Collection
<
Long
>
accessionIds
);
void
addToList
(
AccessionList
accessionList
,
AppliedFilters
filters
);
void
setList
(
AccessionList
accessionList
,
Collection
<
Long
>
accessionIds
);
void
addToList
(
AccessionList
loaded
,
AppliedFilters
filters
);
int
sizeOf
(
AccessionList
accessionList
);
int
sizeOf
(
AccessionList
loaded
);
}
\ No newline at end of file
src/main/java/org/genesys2/server/service/impl/AccessionListServiceImpl.java
View file @
9ec93f17
...
...
@@ -22,16 +22,16 @@ import java.util.Set;
import
java.util.UUID
;
import
org.apache.commons.collections.ListUtils
;
import
org.apache.commons.lang.ArrayUtils
;
import
org.apache.log4j.Logger
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.genesys.AccessionData
;
import
org.genesys2.server.model.impl.AccessionList
;
import
org.genesys2.server.model.impl.User
;
import
org.genesys2.server.persistence.domain.AccessionListRepository
;
import
org.genesys2.server.service.AccessionListService
;
import
org.genesys2.server.service.FilterConstants
;
import
org.genesys2.server.service.impl.FilterHandler.AppliedFilter
;
import
org.genesys2.server.service.impl.FilterHandler.AppliedFilters
;
import
org.genesys2.server.service.
impl.FilterHandler.LiteralValueFil
ter
;
import
org.genesys2.server.service.
worker.ElasticUpda
ter
;
import
org.genesys2.spring.SecurityContextUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PostAuthorize
;
...
...
@@ -48,6 +48,9 @@ public class AccessionListServiceImpl implements AccessionListService {
@Autowired
AccessionListRepository
accessionListRepository
;
@Autowired
ElasticUpdater
elasticUpdater
;
@Override
@PostAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(returnObject, 'READ')"
)
public
AccessionList
getList
(
Long
id
)
{
...
...
@@ -91,6 +94,9 @@ public class AccessionListServiceImpl implements AccessionListService {
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')"
)
@Transactional
public
void
removeAll
(
AccessionList
accessionList
)
{
// Re-index
elasticUpdater
.
updateAll
(
Accession
.
class
,
accessionListRepository
.
getAccessionIds
(
accessionList
).
toArray
(
ArrayUtils
.
EMPTY_LONG_OBJECT_ARRAY
));
accessionListRepository
.
removeAll
(
accessionList
);
}
...
...
@@ -98,6 +104,9 @@ public class AccessionListServiceImpl implements AccessionListService {
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')"
)
@Transactional
public
void
addToList
(
AccessionList
list
,
AccessionData
accession
)
{
// Re-index
elasticUpdater
.
update
(
Accession
.
class
,
accession
.
getId
());
accessionListRepository
.
addOne
(
list
,
accession
.
getAccessionId
());
}
...
...
@@ -107,27 +116,44 @@ public class AccessionListServiceImpl implements AccessionListService {
public
void
addToList
(
AccessionList
acceList
,
Collection
<
Long
>
accessionIds
)
{
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Adding a bunch "
+
accessionIds
.
size
());
AppliedFilters
filters
=
new
AppliedFilters
();
filters
.
add
(
new
AppliedFilter
().
setFilterName
(
FilterConstants
.
ID
).
addFilterValues
(
LiteralValueFilter
.
class
,
accessionIds
));
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Ready with query :-)"
);
accessionListRepository
.
addAll
(
acceList
,
filters
);
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Bhwaha"
);
accessionListRepository
.
addAll
(
acceList
,
accessionIds
);
// Re-index
elasticUpdater
.
updateAll
(
Accession
.
class
,
accessionIds
.
toArray
(
ArrayUtils
.
EMPTY_LONG_OBJECT_ARRAY
));
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')"
)
@Transactional
public
void
addToList
(
AccessionList
loaded
,
AppliedFilters
filters
)
{
accessionListRepository
.
addAll
(
loaded
,
filters
);
public
void
setList
(
AccessionList
accessionList
,
Collection
<
Long
>
accessionIds
)
{
// Re-index
elasticUpdater
.
updateAll
(
Accession
.
class
,
accessionListRepository
.
getAccessionIds
(
accessionList
).
toArray
(
ArrayUtils
.
EMPTY_LONG_OBJECT_ARRAY
));
accessionListRepository
.
removeAll
(
accessionList
);
accessionListRepository
.
addAll
(
accessionList
,
accessionIds
);
// Re-index
elasticUpdater
.
updateAll
(
Accession
.
class
,
accessionIds
.
toArray
(
ArrayUtils
.
EMPTY_LONG_OBJECT_ARRAY
));
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')"
)
@Transactional
public
void
addToList
(
AccessionList
accessionList
,
AppliedFilters
filters
)
{
accessionListRepository
.
addAll
(
accessionList
,
filters
);
// Re-index
elasticUpdater
.
updateAll
(
Accession
.
class
,
accessionListRepository
.
getAccessionIds
(
accessionList
).
toArray
(
ArrayUtils
.
EMPTY_LONG_OBJECT_ARRAY
));
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'DELETE')"
)
@Transactional
public
void
delete
(
AccessionList
accessionList
)
{
// Re-index
elasticUpdater
.
updateAll
(
Accession
.
class
,
accessionListRepository
.
getAccessionIds
(
accessionList
).
toArray
(
ArrayUtils
.
EMPTY_LONG_OBJECT_ARRAY
));
accessionListRepository
.
delete
(
accessionList
);
}
...
...
src/main/java/org/genesys2/server/servlet/controller/SelectionController.java
View file @
9ec93f17
...
...
@@ -110,7 +110,9 @@ public class SelectionController extends BaseController {
// If I have permissions to manage list:
if
(
permissionEvaluator
.
hasPermission
(
SecurityContextHolder
.
getContext
().
getAuthentication
(),
list
,
"WRITE"
))
{
_logger
.
info
(
"User has WRITE parmission on AccessionList"
);
if
(
_logger
.
isDebugEnabled
())
{
_logger
.
debug
(
"User has WRITE parmission on AccessionList"
);
}
selectionBean
.
setUserAccessionList
(
UserAccessionList
.
from
(
list
));
}
}
...
...
@@ -299,21 +301,22 @@ public class SelectionController extends BaseController {
@RequestMapping
(
value
=
"/userList"
,
params
=
{
"save"
},
method
=
RequestMethod
.
POST
)
@PreAuthorize
(
"isAuthenticated()"
)
public
String
saveAccessionList
(
@RequestParam
String
title
,
@RequestParam
String
description
,
RedirectAttributes
redirectAttrs
)
{
public
String
saveAccessionList
(
@RequestParam
String
title
,
@RequestParam
String
description
,
@RequestParam
(
defaultValue
=
"false"
)
boolean
shared
,
RedirectAttributes
redirectAttrs
)
{
AccessionList
accessionList
=
new
AccessionList
();
return
saveOrUpdateList
(
title
,
description
,
redirectAttrs
,
accessionList
);
return
saveOrUpdateList
(
title
,
description
,
shared
,
redirectAttrs
,
accessionList
);
}
@RequestMapping
(
value
=
"/userList"
,
params
=
{
"update"
,
"uuid"
},
method
=
RequestMethod
.
POST
)
@PreAuthorize
(
"isAuthenticated()"
)
public
String
updateAccessionList
(
@RequestParam
(
value
=
"uuid"
)
UUID
uuid
,
@RequestParam
String
title
,
@RequestParam
String
description
,
RedirectAttributes
redirectAttrs
)
{
@RequestParam
(
defaultValue
=
"false"
)
boolean
shared
,
RedirectAttributes
redirectAttrs
)
{
AccessionList
accessionList
=
accessionListService
.
getList
(
uuid
);
return
saveOrUpdateList
(
title
,
description
,
redirectAttrs
,
accessionList
);
return
saveOrUpdateList
(
title
,
description
,
shared
,
redirectAttrs
,
accessionList
);
}
/**
...
...
@@ -326,13 +329,13 @@ public class SelectionController extends BaseController {
* @param accessionList
* @return
*/
private
String
saveOrUpdateList
(
String
title
,
String
description
,
RedirectAttributes
redirectAttrs
,
AccessionList
accessionList
)
{
private
String
saveOrUpdateList
(
String
title
,
String
description
,
boolean
shared
,
RedirectAttributes
redirectAttrs
,
AccessionList
accessionList
)
{
accessionList
.
setDescription
(
description
);
accessionList
.
setTitle
(
title
);
accessionList
.
setShared
(
shared
);
accessionListService
.
save
(
accessionList
);
accessionListService
.
removeAll
(
accessionList
);
accessionListService
.
addToList
(
accessionList
,
selectionBean
.
copy
());
accessionListService
.
setList
(
accessionList
,
selectionBean
.
copy
());
selectionBean
.
setUserAccessionList
(
UserAccessionList
.
from
(
accessionList
));
redirectAttrs
.
addFlashAttribute
(
"resultFromSave"
,
"user.accession.list.saved-updated"
);
...
...
src/main/resources/content/language.properties
View file @
9ec93f17
...
...
@@ -734,6 +734,7 @@ userlist.description=List description
userlist.disconnect
=
Disconnect list
userlist.update-list
=
Save updated list
userlist.make-new-list
=
Create new list
userlist.shared
=
Allow others to access the list
region.page.list.title
=
FAO Geographical regions
region.page.list.intro
=
FAO Geographical regions lists below allow you to access the data about accessions collected or maintained in the region.
...
...
src/main/webapp/WEB-INF/jsp/selection/index.jsp
View file @
9ec93f17
...
...
@@ -160,6 +160,11 @@
<input
id=
"accessionListTitle"
type=
"text"
name=
"title"
class=
"form-control"
value=
"${selection.userAccessionList.title}"
/>
</div>
<div
class=
"form-group"
>
<input
type=
"checkbox"
id=
"accessionListShared"
name=
"shared"
value=
"true"
${
selection.userAccessionList.shared
?
"
checked
"
:
""}
/>
<label
for=
"accessionListShared"
><spring:message
code=
"userlist.shared"
/></label>
</div>
<div
class=
"form-group"
>
<label
for=
"accessionListDescr"
><spring:message
code=
"userlist.description"
/></label>
<textarea
name=
"description"
rows=
"3"
id=
"accessionListDescr"
...
...
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