Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
22f30bb1
Commit
22f30bb1
authored
Nov 20, 2018
by
Viacheslav Pavlov
Committed by
Matija Obreza
Nov 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Institute editing
- added API endpoint for updating of institute data - unit test
parent
35949951
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
2 deletions
+131
-2
src/main/java/org/genesys2/server/api/v1/InstituteController.java
.../java/org/genesys2/server/api/v1/InstituteController.java
+14
-1
src/main/java/org/genesys2/server/service/InstituteService.java
...in/java/org/genesys2/server/service/InstituteService.java
+1
-1
src/main/java/org/genesys2/server/service/impl/InstituteServiceImpl.java
...rg/genesys2/server/service/impl/InstituteServiceImpl.java
+23
-0
src/test/java/org/genesys/test/server/api/v1/InstituteControllerTest.java
...g/genesys/test/server/api/v1/InstituteControllerTest.java
+93
-0
No files found.
src/main/java/org/genesys2/server/api/v1/InstituteController.java
View file @
22f30bb1
...
...
@@ -112,7 +112,13 @@ public class InstituteController {
return
new
FilteredPage
<>(
filterInfo
.
filterCode
,
filterInfo
.
filter
,
instituteService
.
list
(
filterInfo
.
filter
,
page
.
toPageRequest
(
100
,
Sort
.
Direction
.
ASC
,
"id"
)));
}
@GetMapping
(
value
=
"/{code:[A-Z]+[0-9]+}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@JsonView
({
JsonViews
.
Protected
.
class
})
@GetMapping
(
value
=
"/{code:[A-Z]+[0-9]+}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
FaoInstitute
get
(
@PathVariable
(
value
=
"code"
)
String
code
){
return
instituteService
.
findInstitute
(
code
);
}
@GetMapping
(
value
=
"/{code:[A-Z]+[0-9]+}/details"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
InstituteDetails
details
(
@PathVariable
(
value
=
"code"
)
String
code
)
{
FaoInstitute
faoInstitute
=
instituteService
.
getInstitute
(
code
);
...
...
@@ -136,6 +142,13 @@ public class InstituteController {
return
details
;
}
@JsonView
({
JsonViews
.
Protected
.
class
})
@PostMapping
(
value
=
"/{code:[A-Z]+[0-9]+}/update"
)
public
FaoInstitute
update
(
@PathVariable
(
value
=
"code"
)
String
code
,
@RequestBody
FaoInstitute
institute
)
{
return
instituteService
.
update
(
code
,
institute
);
}
private
Map
<
String
,
ElasticsearchService
.
TermResult
>
getOverviewData
(
AccessionFilter
byInstituteFilter
)
{
String
[]
terms
=
new
String
[]
{
"crop.shortName"
,
"cropName"
,
"taxonomy.genus"
,
"taxonomy.genusSpecies"
};
...
...
src/main/java/org/genesys2/server/service/InstituteService.java
View file @
22f30bb1
...
...
@@ -22,7 +22,6 @@ import java.util.Locale;
import
java.util.Map
;
import
org.genesys.catalog.model.vocab.VocabularyTerm
;
import
org.genesys2.server.api.Pagination
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.service.filter.InstituteFilter
;
...
...
@@ -51,6 +50,7 @@ public interface InstituteService {
Page
<
FaoInstitute
>
listActive
(
Pageable
pageable
);
FaoInstitute
update
(
String
code
,
FaoInstitute
institute
);
List
<
FaoInstitute
>
update
(
Collection
<
FaoInstitute
>
institutes
);
void
updateAbout
(
FaoInstitute
faoInstitute
,
String
body
,
String
summary
,
Locale
locale
)
throws
CRMException
;
...
...
src/main/java/org/genesys2/server/service/impl/InstituteServiceImpl.java
View file @
22f30bb1
...
...
@@ -97,6 +97,18 @@ public class InstituteServiceImpl implements InstituteService {
return
instituteRepository
.
listAllActive
(
pageable
);
}
@Override
@Transactional
public
FaoInstitute
update
(
String
code
,
FaoInstitute
institute
)
{
FaoInstitute
target
=
findInstitute
(
code
);
copyValues
(
target
,
institute
);
instituteSettingRepository
.
save
(
target
.
getSettings
().
values
());
return
instituteRepository
.
save
(
target
);
}
@Override
public
Page
<
FaoInstitute
>
listPGRInstitutes
(
Pageable
pageable
)
{
return
instituteRepository
.
listPGRInstitutes
(
pageable
);
...
...
@@ -330,4 +342,15 @@ public class InstituteServiceImpl implements InstituteService {
Page
<
FaoInstitute
>
res
=
instituteRepository
.
findAll
(
page
);
return
res
.
map
(
inst
->
toVocabularyTerm
(
inst
));
}
private
void
copyValues
(
FaoInstitute
target
,
FaoInstitute
source
)
{
target
.
setAllowMaterialRequests
(
source
.
isAllowMaterialRequests
());
target
.
setUniqueAcceNumbs
(
source
.
isUniqueAcceNumbs
());
target
.
setCodeSGSV
(
source
.
getCodeSGSV
());
if
(
source
.
getSettings
()
!=
null
)
{
target
.
getSettings
().
putAll
(
source
.
getSettings
());
}
}
}
src/test/java/org/genesys/test/server/api/v1/InstituteControllerTest.java
0 → 100644
View file @
22f30bb1
package
org.genesys.test.server.api.v1
;
import
org.genesys.test.base.AbstractApiTest
;
import
org.genesys2.server.api.v1.InstituteController
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.model.impl.FaoInstituteSetting
;
import
org.genesys2.server.persistence.FaoInstituteRepository
;
import
org.genesys2.server.persistence.FaoInstituteSettingRepository
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
hamcrest
.
Matchers
.
hasKey
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
public
class
InstituteControllerTest
extends
AbstractApiTest
{
@Autowired
private
FaoInstituteRepository
instituteRepository
;
@Autowired
private
FaoInstituteSettingRepository
instituteSettingRepository
;
private
static
FaoInstitute
institute
;
@Transactional
@Before
@Override
public
void
beforeTest
()
throws
Exception
{
super
.
beforeTest
();
institute
=
setupInstitute
(
"XXX01"
,
"Test fullInstitute"
,
"TI"
,
"test@example.com"
,
"governmental"
);
}
@Transactional
@After
@Override
public
void
cleanup
()
throws
Exception
{
instituteSettingRepository
.
deleteAll
();
instituteRepository
.
deleteAll
();
super
.
cleanup
();
}
@Test
public
void
testUpdateInstitute
()
throws
Exception
{
Map
<
String
,
FaoInstituteSetting
>
instituteSettings
=
new
HashMap
<>();
FaoInstituteSetting
gaTracker
=
new
FaoInstituteSetting
(
institute
);
gaTracker
.
setSetting
(
"googleAnalytics.tracker"
);
gaTracker
.
setValue
(
"test ga"
);
instituteSettings
.
put
(
"googleAnalytics.tracker"
,
gaTracker
);
FaoInstituteSetting
mailTo
=
new
FaoInstituteSetting
(
institute
);
mailTo
.
setSetting
(
"requests.mailto"
);
mailTo
.
setValue
(
"test mail"
);
instituteSettings
.
put
(
"requests.mailto"
,
mailTo
);
institute
.
setSettings
(
instituteSettings
);
mockMvc
.
perform
(
post
(
InstituteController
.
API_BASE
.
concat
(
"/"
).
concat
(
institute
.
getCode
()).
concat
(
"/update"
))
.
content
(
objectMapper
.
writeValueAsString
(
institute
))
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
// .andDo(MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andExpect
(
jsonPath
(
"$.code"
,
is
(
institute
.
getCode
())))
.
andExpect
(
jsonPath
(
"$.settings"
,
is
(
notNullValue
())))
.
andExpect
(
jsonPath
(
"$.settings"
,
hasKey
(
"requests.mailto"
)))
.
andExpect
(
jsonPath
(
"$.settings"
,
hasKey
(
"googleAnalytics.tracker"
)));
}
private
FaoInstitute
setupInstitute
(
String
instCode
,
String
fullName
,
String
acronym
,
String
email
,
String
type
)
{
FaoInstitute
institute
=
new
FaoInstitute
();
institute
.
setCode
(
instCode
);
institute
.
setFullName
(
fullName
);
institute
.
setAcronym
(
acronym
);
institute
.
setEmail
(
email
);
institute
.
setType
(
type
);
return
instituteRepository
.
save
(
institute
);
}
}
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