Commit 2c03e184 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-554-descriptor-list-descriptor-details' into 'master'

Excluded descriptors[] from JSON response to DescriptorList actions

See merge request genesys-pgr/genesys-server!476
parents cd52dbc0 b384abb4
......@@ -222,9 +222,14 @@ public class DescriptorListServiceImpl implements DescriptorListService {
// append to end
for (final Descriptor descriptor : descriptors) {
LOG.info("Add descriptor uuid={} title={} to descriptionList uuid={} title={}", descriptor.getUuid(), descriptor.getTitle(), descriptorList.getUuid(), descriptorList
.getTitle());
loaded.getDescriptors().add(descriptor);
if (loaded.getDescriptors().contains(descriptor)) {
LOG.info("Not adding existing descriptor uuid={} title={} to descriptionList uuid={} title={}", descriptor.getUuid(), descriptor.getTitle(), descriptorList.getUuid(), descriptorList
.getTitle());
} else {
LOG.info("Add descriptor uuid={} title={} to descriptionList uuid={} title={}", descriptor.getUuid(), descriptor.getTitle(), descriptorList.getUuid(), descriptorList
.getTitle());
loaded.getDescriptors().add(descriptor);
}
}
return lazyLoad(descriptorListRepository.save(loaded));
......
......@@ -190,6 +190,7 @@ public class DescriptorListController {
* @return the descriptor list
*/
@PostMapping(value = "/create")
@JsonView(JsonViews.Public.class)
public DescriptorList createDescriptorList(@RequestBody final DescriptorList source) {
return descriptorListService.createDescriptorList(source);
}
......@@ -201,6 +202,7 @@ public class DescriptorListController {
* @return the descriptor list
*/
@PostMapping(value = "/update")
@JsonView(JsonViews.Public.class)
public DescriptorList updateDescriptorList(@RequestBody final DescriptorList source) {
return descriptorListService.updateDescriptorList(source);
}
......@@ -215,6 +217,7 @@ public class DescriptorListController {
* @throws IOException Signals that an I/O exception has occurred.
*/
@PostMapping(value = "/list")
@JsonView(JsonViews.Public.class)
public FilteredPage<DescriptorList> listDescriptorLists(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorListFilter filter) throws IOException {
......@@ -291,6 +294,7 @@ public class DescriptorListController {
* @throws IOException Signals that an I/O exception has occurred.
*/
@PostMapping(value = "/list-mine")
@JsonView(JsonViews.Public.class)
public FilteredPage<DescriptorList> myDescriptorLists(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorListFilter filter) throws IOException {
......@@ -307,6 +311,7 @@ public class DescriptorListController {
* @return the descriptor list
*/
@PostMapping(value = "/add-descriptors/{uuid},{version}")
@JsonView(JsonViews.Public.class)
public DescriptorList addDescriptor(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version, @RequestBody final List<UUID> descriptorUuids) {
final DescriptorList descriptorList = descriptorListService.loadDescriptorList(uuid, version);
final List<Descriptor> descriptors = descriptorUuids.stream().map(descriptorUuid -> descriptorService.getDescriptor(descriptorUuid)).collect(Collectors.toList());
......@@ -322,6 +327,7 @@ public class DescriptorListController {
* @return the descriptor list
*/
@PostMapping(value = "/remove-descriptors/{uuid},{version}")
@JsonView(JsonViews.Public.class)
public DescriptorList removeDescriptor(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version, @RequestBody final Set<UUID> descriptorUuids) {
final DescriptorList descriptorList = descriptorListService.loadDescriptorList(uuid, version);
final Set<Descriptor> descriptors = descriptorUuids.stream().map(descriptorUuid -> descriptorService.getDescriptor(descriptorUuid)).collect(Collectors.toSet());
......@@ -337,6 +343,7 @@ public class DescriptorListController {
* @return the descriptor list
*/
@PostMapping(value = "/set-descriptors/{uuid},{version}")
@JsonView(JsonViews.Public.class)
public DescriptorList setDescriptor(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version, @RequestBody final List<UUID> descriptorUuids) {
final DescriptorList descriptorList = descriptorListService.loadDescriptorList(uuid, version);
final List<Descriptor> descriptors = descriptorUuids.stream().map(descriptorUuid -> descriptorService.getDescriptor(descriptorUuid)).collect(Collectors.toList());
......@@ -351,6 +358,7 @@ public class DescriptorListController {
* @return published DescriptorList (admin-only)
*/
@RequestMapping(value = "/approve", method = RequestMethod.POST)
@JsonView(JsonViews.Public.class)
public DescriptorList approveDescriptorList(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final DescriptorList descriptorList = descriptorListService.loadDescriptorList(uuid, version);
return descriptorListService.approveDescriptorList(descriptorList);
......@@ -364,6 +372,7 @@ public class DescriptorListController {
* @return descriptorList in review state
*/
@RequestMapping(value = "/for-review", method = RequestMethod.POST)
@JsonView(JsonViews.Public.class)
public DescriptorList reviewDescriptorList(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final DescriptorList descriptorList = descriptorListService.loadDescriptorList(uuid, version);
return descriptorListService.reviewDescriptorList(descriptorList);
......@@ -398,6 +407,7 @@ public class DescriptorListController {
* @return unpublished descriptorList
*/
@RequestMapping(value = "/reject", method = RequestMethod.POST)
@JsonView(JsonViews.Public.class)
public DescriptorList rejectDescriptorList(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final DescriptorList descriptorList = descriptorListService.loadDescriptorList(uuid, version);
return descriptorListService.rejectDescriptorList(descriptorList);
......
......@@ -109,7 +109,7 @@ public class DescriptorListControllerTest extends AbstractApiTest {
@Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void getDescriptorListsWithDescriptorsTest() throws Exception {
public void getDescriptorListsAndDescriptorsTest() throws Exception {
Descriptor descriptor = descriptorService.createDescriptor(setUpDescriptor());
assertThat(descriptorRepository.count(), is(1L));
final MockMultipartFile image = new MockMultipartFile("image", "image.png", "image/png", new byte[1]);
......@@ -132,7 +132,7 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.descriptors").doesNotExist())
.andExpect(jsonPath("$.descriptors").doesNotExist()) // Must not return descriptors
.andDo(document("contract-roles-get"));
mockMvc
......@@ -173,7 +173,9 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(jsonPath("$.title", is(descriptorList.getTitle())))
.andExpect(jsonPath("$.url", is(descriptorList.getUrl())))
.andExpect(jsonPath("$.description", is(descriptorList.getDescription())))
.andExpect(jsonPath("$.versionTag", is(descriptorList.getVersionTag())));
.andExpect(jsonPath("$.versionTag", is(descriptorList.getVersionTag())))
.andExpect(jsonPath("$.descriptors").doesNotExist()) // Must not return descriptors
;
/*@formatter:on */
}
......@@ -221,7 +223,9 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(jsonPath("$.filterCode", not(nullValue())))
.andExpect(jsonPath("$.filter", not(nullValue())))
.andExpect(jsonPath("$.content[0]", not(nullValue())))
.andExpect(jsonPath("$.content[0].uuid", is(descriptorList.getUuid().toString())));
.andExpect(jsonPath("$.content[0].uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.content[0].descriptors").doesNotExist()) // Must not return descriptors
;
/*@formatter:on*/
}
......@@ -274,7 +278,9 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(jsonPath("$.filterCode", is(filterCode)))
.andExpect(jsonPath("$.filter", not(nullValue())))
.andExpect(jsonPath("$.content[0]", not(nullValue())))
.andExpect(jsonPath("$.content[0].uuid", is(descriptorList.getUuid().toString())));
.andExpect(jsonPath("$.content[0].uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.content[0].descriptors").doesNotExist()) // Must not return descriptors
;
/*@formatter:on*/
}
......@@ -294,7 +300,8 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptorList.getUuid().toString())))
.andDo(document("contract-roles-get"));
.andExpect(jsonPath("$.content[0].descriptors").doesNotExist()) // Must not return descriptors
.andDo(document("descriptorList-get"));
/*@formatter:on*/
}
......@@ -345,7 +352,9 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.state", is(PublishState.REVIEWING.name())));
.andExpect(jsonPath("$.state", is(PublishState.REVIEWING.name())))
.andExpect(jsonPath("$.content[0].descriptors").doesNotExist()) // Must not return descriptors
;
/*@formatter:on*/
}
......@@ -365,7 +374,9 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.state", is(PublishState.DRAFT.name())));
.andExpect(jsonPath("$.state", is(PublishState.DRAFT.name())))
.andExpect(jsonPath("$.content[0].descriptors").doesNotExist()) // Must not return descriptors
;
/*@formatter:on*/
}
......@@ -384,7 +395,9 @@ public class DescriptorListControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.state", is(PublishState.PUBLISHED.name())));
.andExpect(jsonPath("$.state", is(PublishState.PUBLISHED.name())))
.andExpect(jsonPath("$.content[0].descriptors").doesNotExist()) // Must not return descriptors
;
/*@formatter:on*/
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment