Commit f9d5681e authored by Matija Obreza's avatar Matija Obreza

Merge branch '359-upgrade-to-data-provider' into 'master'

Resolve "Upgrade to Data Provider"

Closes #359

See merge request genesys-pgr/genesys-server!260
parents 0f6e1048 8d8cca09
......@@ -24,10 +24,12 @@ import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.elasticsearch.annotations.Document;
import javax.persistence.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -78,10 +80,9 @@ public class Partner extends UuidModel implements SelfCleaning, AclAwareModel {
private Set<URL> urls;
/// FAO WIEWS codes associated with this partner
@ElementCollection
@CollectionTable(name = "partner_wiews", joinColumns = @JoinColumn(name = "partnerId"))
@Column(name = "wiews")
private Set<String> wiewsCodes;
@JsonIgnore
@OneToMany(mappedBy = "owner", fetch = FetchType.LAZY)
private List<FaoInstitute> institutes;
@ElementCollection
@CollectionTable(name = "partner_country", joinColumns = @JoinColumn(name = "partnerId"), uniqueConstraints = { @UniqueConstraint(columnNames = { "partnerId", "code" }) })
......@@ -121,7 +122,7 @@ public class Partner extends UuidModel implements SelfCleaning, AclAwareModel {
* @param partner the partner
*/
public Partner(final Partner partner) {
this(partner.getShortName(), partner.getName(), partner.getUrls(), partner.getWiewsCodes(), partner.getDescriptors(), partner.getVocabularies(), partner
this(partner.getShortName(), partner.getName(), partner.getUrls(), partner.getInstitutes(), partner.getDescriptors(), partner.getVocabularies(), partner
.getDescriptorList());
}
......@@ -131,20 +132,20 @@ public class Partner extends UuidModel implements SelfCleaning, AclAwareModel {
* @param shortName the short name
* @param name the name
* @param urls the urls
* @param wiewsCodes the wiews codes
* @param institutes the institutes
* @param descriptors the descriptors
* @param vocabularies the vocabularies
* @param descriptorList the descriptor list
*/
public Partner(final String shortName, final String name, final Set<URL> urls, final Set<String> wiewsCodes, final List<Descriptor> descriptors,
public Partner(final String shortName, final String name, final Set<URL> urls, final List<FaoInstitute> institutes, final List<Descriptor> descriptors,
final List<ControlledVocabulary> vocabularies, final List<DescriptorList> descriptorList) {
this.shortName = shortName;
this.name = name;
if (urls != null) {
this.urls = new HashSet<>(urls);
}
if (wiewsCodes != null) {
this.wiewsCodes = new HashSet<>(wiewsCodes);
if (institutes != null) {
this.institutes = new ArrayList<>(institutes);
}
this.descriptors = descriptors;
this.vocabularies = vocabularies;
......@@ -223,22 +224,12 @@ public class Partner extends UuidModel implements SelfCleaning, AclAwareModel {
this.urls = urls;
}
/**
* Gets the wiews codes.
*
* @return the wiewsCodes
*/
public Set<String> getWiewsCodes() {
return wiewsCodes;
public List<FaoInstitute> getInstitutes() {
return institutes;
}
/**
* Sets the wiews codes.
*
* @param wiewsCodes the wiewsCodes to set
*/
public void setWiewsCodes(final Set<String> wiewsCodes) {
this.wiewsCodes = wiewsCodes;
public void setInstitutes(List<FaoInstitute> institutes) {
this.institutes = institutes;
}
/**
......
......@@ -70,7 +70,7 @@ public class PartnerFilter extends UuidModelFilter<PartnerFilter, Partner> {
and.and(description.buildQuery(partnerPath.description));
}
if (CollectionUtils.isNotEmpty(wiewsCodes)) {
and.and(partnerPath.wiewsCodes.any().in(wiewsCodes));
and.and(partnerPath.institutes.any().code.in(wiewsCodes));
}
return and;
}
......
......@@ -17,9 +17,12 @@ package org.genesys.catalog.service;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.filter.InstituteFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.Set;
import java.util.UUID;
/**
......@@ -61,6 +64,14 @@ public interface PartnerService {
*/
Partner loadPartner(UUID uuid);
/**
* Load partners institutes by uuid of partner.
*
* @param uuid uuid of partner
* @return partners institutes
*/
Page<FaoInstitute> loadPartnerInstitutes(UUID uuid, InstituteFilter filter, Pageable page);
/**
* Load partner.
*
......@@ -96,6 +107,25 @@ public interface PartnerService {
*/
Page<Partner> listPartners(PartnerFilter partnerFilter, Pageable page);
/**
* Adds the institutes to partner
*
* @param partner the partner
* @param instituteCodes the institute codes
* @return the partner
*/
Partner addInstitutes(Partner partner, Set<String> instituteCodes);
/**
* Removes the institutes from partner
*
* @param partner the partner
* @param instituteCodes the institute codes
* @return the partner
*/
Partner removeInstitutes(Partner partner, Set<String> instituteCodes);
/**
* Method for copy values of source to target.
*
......
......@@ -17,15 +17,24 @@ package org.genesys.catalog.service.impl;
import static org.genesys.catalog.model.QPartner.partner;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.UUID;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.QFaoInstitute;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.filter.InstituteFilter;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -55,9 +64,15 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
@Autowired
private PartnerRepository partnerRepository;
@Autowired
private FaoInstituteRepository instituteRepository;
@Autowired
private SecurityUtils securityUtils;
@Autowired
private CustomAclService aclService;
@Value("${partner.primary.uuid}")
private UUID primaryPartnerUuid;
......@@ -163,14 +178,52 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
}
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Partner addInstitutes(Partner partner, Set<String> instituteCodes) {
final Partner savedPartner = loadPartner(partner.getUuid());
List<FaoInstitute> institutes = instituteRepository.findAllByCodes(instituteCodes);
institutes.forEach((inst) -> inst.setOwner(savedPartner));
institutes.forEach((institute -> aclService.createOrUpdatePermissions(institute)));
savedPartner.getInstitutes().addAll(institutes);
return lazyLoad(partnerRepository.save(savedPartner));
}
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Partner removeInstitutes(Partner partner, Set<String> instituteCodes) {
partner = loadPartner(partner.getUuid());
List<FaoInstitute> institutesToRemove = instituteRepository.findAllByCodes(instituteCodes);
institutesToRemove.forEach((institute -> institute.setOwner(null)));
institutesToRemove.forEach((institute -> aclService.createOrUpdatePermissions(institute)));
instituteRepository.save(institutesToRemove);
partner.getInstitutes().removeAll(institutesToRemove);
return lazyLoad(partnerRepository.save(partner));
}
/**
* {@inheritDoc}
*/
@Override
public Partner loadPartner(final UUID uuid) {
return lazyLoad(partnerRepository.findByUuid(uuid));
Partner partner = partnerRepository.findByUuid(uuid);
if (partner == null) {
throw new NotFoundElement("No partner with uuid=" + uuid);
}
return lazyLoad(partner);
}
@Override
public Page<FaoInstitute> loadPartnerInstitutes(UUID uuid, InstituteFilter filter, Pageable page) {
return instituteRepository.findAll(QFaoInstitute.faoInstitute.owner.uuid.eq(uuid).and(filter.buildQuery()), page);
}
/**
* {@inheritDoc}
*/
......@@ -197,9 +250,9 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
target.getUrls().addAll(source.getUrls());
}
target.setWiewsCodes(new HashSet<>());
if (source.getWiewsCodes() != null) {
target.getWiewsCodes().addAll(source.getWiewsCodes());
target.setInstitutes(new ArrayList<>());
if (source.getInstitutes() != null) {
target.getInstitutes().addAll(source.getInstitutes());
}
target.setCountryCodes(new HashSet<>());
......@@ -236,8 +289,8 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
if (partner.getUrls() != null) {
partner.getUrls().size();
}
if (partner.getWiewsCodes() != null) {
partner.getWiewsCodes().size();
if (partner.getInstitutes() != null) {
partner.getInstitutes().size();
}
if (partner.getCountryCodes() != null) {
partner.getCountryCodes().size();
......
......@@ -17,6 +17,7 @@
package org.genesys2.server.api.v1;
import java.io.IOException;
import java.util.Set;
import java.util.UUID;
import io.swagger.annotations.Api;
......@@ -29,6 +30,8 @@ import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.filter.InstituteFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -109,6 +112,36 @@ public class PartnerController {
return partnerService.updatePartner(source);
}
/**
* Adds the institutes to the Partner with provided uuid. Existing
* {@link FaoInstitute#owner} is force-set to this partner.
*
* @param uuid the uuid
* @param instituteCodes the institute codes
* @return the partner
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/addInstitutes/{UUID}")
public Partner addInstitutes(@PathVariable("UUID") UUID uuid, @RequestBody Set<String> instituteCodes) {
Partner partner = partnerService.loadPartner(uuid);
return partnerService.addInstitutes(partner, instituteCodes);
}
/**
* Removes the institutes from the Partner with provided uuid. Effectively this
* sets {@link FaoInstitute#owner} to null.
*
* @param uuid the uuid
* @param instituteCodes the institute codes
* @return the partner
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/removeInstitutes/{UUID}")
public Partner removeInstitutes(@PathVariable("UUID") UUID uuid, @RequestBody Set<String> instituteCodes) {
Partner partner = partnerService.loadPartner(uuid);
return partnerService.removeInstitutes(partner, instituteCodes);
}
/**
* List partners.
*
......@@ -131,6 +164,18 @@ public class PartnerController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, partnerService.listPartners(filterInfo.filter, page.toPageRequest(100)));
}
/**
* Gets partners institutes.
*
* @param uuid the uuid
* @return the partner
*/
@PostMapping(value = "/{UUID}/institutes")
public Page<FaoInstitute> listInstitutes(@PathVariable("UUID") final UUID uuid,
@RequestBody(required = false) InstituteFilter filter, Pagination page) {
return partnerService.loadPartnerInstitutes(uuid, filter, page.toPageRequest(100));
}
/**
* My partners.
*
......
......@@ -64,7 +64,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@MapsId
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, optional = false, orphanRemoval = false)
@JoinColumn(name = "id")
@JsonUnwrapped
@JsonUnwrapped
@Field(type=FieldType.Auto)
private AccessionId accessionId;
......
......@@ -25,24 +25,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.*;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.EntityId;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.model.Partner;
import org.genesys.custom.elasticsearch.IgnoreField;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.springframework.data.elasticsearch.annotations.Field;
......@@ -118,6 +108,12 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private List<Organization> networks;
@ManyToOne(cascade = {})
@JoinColumn(name = "partnerId")
@JsonView({ JsonViews.Public.class })
private Partner owner;
private long accessionCount;
private boolean pgrActivity;
private boolean maintainsCollection;
......@@ -132,6 +128,12 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
@Column(name = "pdciHistogram")
private String pdciHistogram;
@Override
public AclAwareModel aclParentObject(){
return this.owner;
}
public FaoInstitute() {
}
......@@ -340,6 +342,14 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
this.pdciHistogram = pdciHistogram;
}
public Partner getOwner() {
return owner;
}
public void setOwner(Partner owner) {
this.owner = owner;
}
public PDCIStatistics getStatisticsPDCI() {
if (this.pdciMin == null || this.pdciMax == null || this.pdciAvg == null) {
return null;
......
......@@ -4468,6 +4468,56 @@ databaseChangeLog:
referencedColumnNames: id
- changeSet:
id: 1539274052727-1
author: vpavlov
comment: partnerId to faoinstitute
changes:
- addColumn:
columns:
- column:
name: partnerId
type: bigint(20)
tableName: faoinstitute
- changeSet:
id: 1539274052727-2
author: vpavlov
comment: added foreign key faoinstitute(partnerId)-partner(id)
changes:
- addForeignKeyConstraint:
baseColumnNames: partnerId
baseTableName: faoinstitute
constraintName: FK_103537ceb0f6f88fee69bbf23
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: partner
- changeSet:
id: 1539274052727-3
author: vpavlov
comment: Migrate data from partner_wiews to faoinstitute (partnerId)
changes:
- sql:
sql: >-
update faoinstitute f
inner join partner_wiews pw on
f.code = pw.wiews
set f.partnerId = pw.partnerId;
- changeSet:
id: 1539274052727-4
author: vpavlov
comment: drop partner_wiews
changes:
- dropTable:
tableName: partner_wiews
# ENABLE AFTER SOME TIME
# - changeSet:
# id: 1537463144763-folder
......
......@@ -17,6 +17,7 @@ package org.genesys.test.base;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
......@@ -121,7 +122,7 @@ public abstract class AbstractApiTest extends AbstractTest {
partner.setActive(isActive);
partner.setShortName(shortName);
partner.setUuid(uuid);
partner.setWiewsCodes(new HashSet<>());
partner.setInstitutes(new ArrayList<>());
partner.setUrls(new HashSet<>());
return partnerRepository.save(partner);
}
......
......@@ -17,6 +17,7 @@ package org.genesys.test.catalog.services;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
......@@ -85,6 +86,12 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Autowired
protected PartnerRepository partnerRepository;
@Autowired
protected InstituteService instituteService;
@Autowired
protected FaoInstituteRepository instituteRepository;
@Autowired
protected DescriptorListService descriptorListService;
......@@ -109,18 +116,12 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Autowired
protected ShortFilterRepository shortFilterRepository;
@Autowired
private InstituteService instituteService;
@Autowired
private AccessionUploader accessionUploader;
@Autowired
protected AccessionRepository accessionRepository;
@Autowired
protected FaoInstituteRepository instituteRepository;
protected Partner partner;
protected Partner partner2;
......@@ -128,11 +129,11 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Override
public void cleanup() throws Exception {
partnerRepository.deleteAll();
accessionRepository.deleteAll();
instituteRepository.deleteAll();
partner = setupPartner(PARTNER_1, PARTNER_ACRONYM_1, Sets.newHashSet(URL_1));
partner2 = setupPartner(PARTNER_2, PARTNER_ACRONYM_2, Sets.newHashSet(URL_1));
accessionRepository.deleteAll();
instituteRepository.deleteAll();
super.cleanup();
}
......@@ -141,10 +142,20 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
inputP.setName(name);
inputP.setShortName(shortName);
inputP.setUrls(urls);
inputP.setWiewsCodes(Sets.newHashSet(wiewsCodes));
List<FaoInstitute> institutes = new ArrayList<>();
for (String code: wiewsCodes ) {
institutes.add(setupInstitute(code));
}
inputP.setInstitutes(institutes);
return partnerService.createPartner(inputP);
}
protected FaoInstitute setupInstitute(final String code){
final FaoInstitute inputI = new FaoInstitute();
inputI.setCode(code);
return instituteRepository.save(inputI);
}
protected DescriptorList setupDescriptorList(final String title, final String version, final String description) {
final DescriptorList descriptorList = new DescriptorList();
descriptorList.setOwner(partner);
......
......@@ -21,10 +21,13 @@ import static org.junit.Assert.assertThat;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.UUID;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.RandomStringUtils;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys2.server.model.impl.FaoInstitute;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
......@@ -81,7 +84,7 @@ public class PartnerServiceTest extends CatalogServiceTest {
input.setName(PARTNER_1);
input.setShortName(PARTNER_ACRONYM_1);
input.setUrls(Sets.newHashSet(new URL(URL_1), new URL(URL_2)));
input.setWiewsCodes(Sets.newHashSet("XXX001", "XXX002", "YYY003"));
input.setInstitutes(Lists.newArrayList(setupInstitute("XXX001"), setupInstitute("XXX002"),setupInstitute("YYY003")));
final String description = RandomStringUtils.randomAlphanumeric(60, 100);
input.setDescription(description);
input.setEmail(EMAIL_1);
......@@ -93,8 +96,8 @@ public class PartnerServiceTest extends CatalogServiceTest {
assertThat(result.getId(), not(nullValue()));
assertThat(result.getUrls(), hasSize(2));
assertThat(result.getUrls(), containsInAnyOrder(new URL(URL_1), new URL(URL_2)));
assertThat(result.getWiewsCodes(), hasSize(3));
assertThat(result.getWiewsCodes(), containsInAnyOrder("XXX001", "XXX002", "YYY003"));
assertThat(result.getInstitutes(), hasSize(3));
assertThat(result.getInstitutes().stream().map(FaoInstitute::getCode).collect(Collectors.toList()), containsInAnyOrder("XXX001", "XXX002", "YYY003"));
assertThat(result.getDescription(), is(description));
assertThat(result.getEmail(), is(EMAIL_1));
assertThat(result.getAddress(), is(ADDRESS_1));
......@@ -158,7 +161,7 @@ public class PartnerServiceTest extends CatalogServiceTest {
result.setName(PARTNER_2);
result.setShortName(PARTNER_ACRONYM_2);
result.getUrls().add(new URL(URL_1));
result.setWiewsCodes(Sets.newHashSet("XXX001", "XXX002", "YYY003"));
result.setInstitutes(Lists.newArrayList(setupInstitute("XXX001"), setupInstitute("XXX002"),setupInstitute("YYY003")));
final String description = RandomStringUtils.random(100);
result.setDescription(description);
result.setEmail(EMAIL_2);
......@@ -170,7 +173,7 @@ public class PartnerServiceTest extends CatalogServiceTest {
assertThat(result.getShortName(), is(PARTNER_ACRONYM_2));
assertThat(result.getUrls(), hasSize(1));
assertThat(result.getUrls(), containsInAnyOrder(new URL(URL_1)));
assertThat(result.getWiewsCodes(), containsInAnyOrder("XXX001", "XXX002", "YYY003"));
assertThat(result.getInstitutes().stream().map(FaoInstitute::getCode).collect(Collectors.toList()), containsInAnyOrder("XXX001", "XXX002", "YYY003"));
assertThat(result.getDescription(), is(description));
assertThat(result.getEmail(), is(EMAIL_2));
assertThat(result.getAddress(), is(ADDRESS_2));
......
......@@ -23,16 +23,21 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys2.server.api.v1.PartnerController;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.test.base.AbstractApiTest;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,6 +62,9 @@ public class PartnerControllerTest extends AbstractApiTest {
@Autowired
private PartnerRepository partnerRepository;
@Autowired
private FaoInstituteRepository instituteRepository;
private MockMvc mockMvc;
......@@ -71,6 +79,7 @@ public class PartnerControllerTest extends AbstractApiTest {
@After
@Override
public void cleanup() throws Exception {
instituteRepository.deleteAll();
partnerRepository.deleteAll();
super.cleanup();
}
......@@ -262,12 +271,91 @@ public class PartnerControllerTest extends AbstractApiTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(partner.getUuid().toString())))
.andExpect(jsonPath("$.wiewsCodes", containsInAnyOrder(partner.getWiewsCodes().toArray())))
.andExpect(jsonPath("$.urls", containsInAnyOrder(partner.getUrls().stream().map(url -> url.toString()).collect(Collectors.toSet()).toArray())))
.andExpect(jsonPath("$.urls", containsInAnyOrder(partner.getUrls().stream().map(URL::toString).distinct().toArray())))
.andDo(document("partner-get"));
/*@formatter:on*/
}
@Test
public void listPartnerInstitutesTest() throws Exception {
final Partner partner = partnerRepository.save(setPartner("Partner one", true, "Partner one", UUID.randomUUID()));
List<FaoInstitute> instituteList = Lists.newArrayList(setupInstitute("PAR001"), setupInstitute("PAR002"));
instituteList.forEach((institute -> institute.setOwner(partner)));
instituteRepository.save(instituteList);
/*@formatter:off*/
this.mockMvc
.perform(RestDocumentationRequestBuilders.post(PartnerController.CONTROLLER_URL.concat("/{UUID}/institutes"), partner.getUuid())
.content("{}").contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.content", not(nullValue())))
.andExpect(jsonPath("$.content", hasSize(2)))
.andExpect(jsonPath("$.content[0].code", isOneOf(instituteList.stream().map(FaoInstitute::getCode).toArray())))
.andExpect(jsonPath("$.content[0].owner.uuid", is(partner.getUuid().toString())))
.andExpect(jsonPath("$.content[1].code", isOneOf(instituteList.stream().map(FaoInstitute::getCode).toArray())))
.andExpect(jsonPath("$.content[1].owner", is(partner.getUuid().toString())));
/*@formatter:on*/
}
@Test
@WithMockUser(username = "user",