Commit 264f5b2b authored by Matija Obreza's avatar Matija Obreza

Renamed Organization to PGRFANetwork

- Service renames, method renames
parent 7bebb5b1
......@@ -38,16 +38,16 @@ public interface ServiceEndpoints {
/* =============== Service endpoint /organizations =============== */
/* =============================================================== */
// Lists all Traits associated with Organization $O
// Lists all Traits associated with Network $O
String ORGANIZATION_TRAITS = "/organizations/{organizationId}/traits";
// Lists all DataSets associated with Organization $O
// Lists all DataSets associated with Network $O
String ORGANIZATION_DATA_SETS = "/organizations/{organizationId}/datasets";
// List all Licenses associated with Organization $O
// List all Licenses associated with Network $O
String ORGANIZATION_LICENSES = "/organizations/{organizationId}/licenses";
// Issue a request for current User to join Organization $O
// Issue a request for current User to join Network $O
String JOIN_ORGANIZATION = "/organizations/{organizationId}/join";
/* =============================================================== */
......
......@@ -30,9 +30,9 @@ import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.impl.PGRFANetwork;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.PGRFANetworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
......@@ -61,7 +61,7 @@ public class OrganizationController extends ApiBaseController {
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/org";
@Autowired
private OrganizationService organizationService;
private PGRFANetworkService networkService;
/**
* List organizations
......@@ -73,8 +73,8 @@ public class OrganizationController extends ApiBaseController {
*/
@RequestMapping(value = "", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
List<Organization> listOrganizations(@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
return organizationService.list(new PageRequest(page - 1, 50)).getContent();
List<PGRFANetwork> listOrganizations(@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
return networkService.list(new PageRequest(page - 1, 50)).getContent();
}
/**
......@@ -85,19 +85,19 @@ public class OrganizationController extends ApiBaseController {
*/
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Organization updateOrganization(@RequestBody Organization organizationJson) throws ValidationException {
PGRFANetwork updateOrganization(@RequestBody PGRFANetwork organizationJson) throws ValidationException {
final Validator validator = new Validator();
final List<ConstraintViolation> violations = validator.validate(organizationJson);
if (violations.size() > 0) {
// TODO We could do better messages on validation error
throw new ModelValidationException("Validation failed", violations);
}
Organization organization = organizationService.getOrganization(organizationJson.getSlug());
PGRFANetwork network = networkService.getNetwork(organizationJson.getSlug());
if (organization == null) {
organization = organizationService.create(organizationJson.getSlug(), organizationJson.getTitle());
if (network == null) {
network = networkService.create(organizationJson.getSlug(), organizationJson.getTitle());
}
return organizationService.update(organization.getId(), organization.getSlug(), organizationJson.getTitle());
return networkService.update(network.getId(), network.getSlug(), organizationJson.getTitle());
}
/**
......@@ -108,8 +108,8 @@ public class OrganizationController extends ApiBaseController {
*/
@RequestMapping(value = "/{shortName}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Organization getOrganization(@PathVariable("shortName") String shortName) throws AuthorizationException {
return organizationService.getOrganization(shortName);
PGRFANetwork getOrganization(@PathVariable("shortName") String shortName) throws AuthorizationException {
return networkService.getNetwork(shortName);
}
/**
......@@ -121,8 +121,8 @@ public class OrganizationController extends ApiBaseController {
@RequestMapping(value = "/{shortName}/blurp/{language}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
String getBlurp(@PathVariable("shortName") String shortName, @PathVariable("language") String language) throws AuthorizationException {
Organization org = organizationService.getOrganization(shortName);
Article article = organizationService.getBlurb(org, new Locale(language));
PGRFANetwork org = networkService.getNetwork(shortName);
Article article = networkService.getBlurb(org, new Locale(language));
return article == null ? null : article.getBody();
}
......@@ -136,8 +136,8 @@ public class OrganizationController extends ApiBaseController {
@RequestMapping(value = "/{shortName}/blurp", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Article updateBlurp(@PathVariable("shortName") String shortName, @RequestBody OrganizationBlurpJson blurp) throws AuthorizationException, CRMException {
Organization org = organizationService.getOrganization(shortName);
return organizationService.updateAbout(org, blurp.blurp, blurp.summary, blurp.getLocale());
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.updateAbout(org, blurp.blurp, blurp.summary, blurp.getLocale());
}
/**
......@@ -148,8 +148,8 @@ public class OrganizationController extends ApiBaseController {
*/
@RequestMapping(value = "/{shortName}", method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Organization deleteOrganization(@PathVariable("shortName") String shortName) throws AuthorizationException {
return organizationService.deleteOrganization(organizationService.getOrganization(shortName));
PGRFANetwork deleteOrganization(@PathVariable("shortName") String shortName) throws AuthorizationException {
return networkService.delete(networkService.getNetwork(shortName));
}
/**
......@@ -162,14 +162,14 @@ public class OrganizationController extends ApiBaseController {
public @ResponseBody
Set<String> getOrganizationMembers(@PathVariable("shortName") String shortName) throws AuthorizationException {
Set<String> instCodes = new HashSet<String>();
for (FaoInstitute inst : organizationService.getOrganizationInstitutes(organizationService.getOrganization(shortName))) {
for (FaoInstitute inst : networkService.getInstitutes(networkService.getNetwork(shortName))) {
instCodes.add(inst.getCode());
}
return instCodes;
}
/**
* Add Institutes to Organization
* Add Institutes to Network
*
* @return
* @throws IOException
......@@ -177,19 +177,19 @@ public class OrganizationController extends ApiBaseController {
*/
@RequestMapping(value = "/{slug}/add-institutes", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Organization addOrganizationInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) throws JsonProcessingException,
PGRFANetwork addOrganizationInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) throws JsonProcessingException,
IOException {
// TODO Check user's permissions to update this organization.
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
final PGRFANetwork network = networkService.getNetwork(slug);
if (network == null) {
throw new NotFoundElement();
}
return organizationService.addOrganizationInstitutes(organization, instituteList);
return networkService.addInstitutes(network, instituteList);
}
/**
* Set Institutes of Organization
* Set Institutes of Network
*
* @return
* @throws IOException
......@@ -197,15 +197,15 @@ public class OrganizationController extends ApiBaseController {
*/
@RequestMapping(value = "/{slug}/set-institutes", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Organization setOrganizationInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) throws JsonProcessingException,
PGRFANetwork setOrganizationInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) throws JsonProcessingException,
IOException {
// TODO Check user's permissions to update this organization.
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
final PGRFANetwork network = networkService.getNetwork(slug);
if (network == null) {
throw new NotFoundElement();
}
return organizationService.setOrganizationInstitutes(organization, instituteList);
return networkService.setInstitutes(network, instituteList);
}
public static class OrganizationBlurpJson {
......
......@@ -21,9 +21,9 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.impl.PGRFANetwork;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.PGRFANetworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -55,7 +55,7 @@ public class NetworkController extends ApiBaseController {
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/network";
@Autowired
private OrganizationService organizationService;
private PGRFANetworkService networkService;
/**
* List organizations
......@@ -63,8 +63,8 @@ public class NetworkController extends ApiBaseController {
* @return
*/
@GetMapping(value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Organization> listNetworks(@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
return organizationService.list(new PageRequest(page - 1, 50)).getContent();
public List<PGRFANetwork> listNetworks(@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
return networkService.list(new PageRequest(page - 1, 50)).getContent();
}
/**
......@@ -73,13 +73,13 @@ public class NetworkController extends ApiBaseController {
* @return
*/
@PostMapping(value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
public Organization updateNetwork(@RequestBody Organization organizationJson) {
Organization organization = organizationService.getOrganization(organizationJson.getSlug());
public PGRFANetwork updateNetwork(@RequestBody PGRFANetwork organizationJson) {
PGRFANetwork network = networkService.getNetwork(organizationJson.getSlug());
if (organization == null) {
return organizationService.create(organizationJson.getSlug(), organizationJson.getTitle());
if (network == null) {
return networkService.create(organizationJson.getSlug(), organizationJson.getTitle());
}
return organizationService.update(organization.getId(), organization.getSlug(), organizationJson.getTitle());
return networkService.update(network.getId(), network.getSlug(), organizationJson.getTitle());
}
/**
......@@ -88,11 +88,11 @@ public class NetworkController extends ApiBaseController {
* @return
*/
@GetMapping(value = "/{shortName}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Organization getNetwork(@PathVariable("shortName") String shortName) {
Organization organization = organizationService.getOrganization(shortName);
if (organization == null)
throw new NotFoundElement("Organization not found");
return organization;
public PGRFANetwork getNetwork(@PathVariable("shortName") String shortName) {
PGRFANetwork network = networkService.getNetwork(shortName);
if (network == null)
throw new NotFoundElement("Network not found");
return network;
}
/**
......@@ -102,11 +102,11 @@ public class NetworkController extends ApiBaseController {
*/
@GetMapping(value = "/{shortName}/details", produces = { MediaType.APPLICATION_JSON_VALUE })
public NetworkDetails getNetworkDetails(@PathVariable("shortName") String shortName, @RequestParam(value = "language", defaultValue = "en") String language) {
Organization organization = organizationService.getOrganization(shortName);
Page<FaoInstitute> members = organizationService.getOrganizationInstitutes(organization, new PageRequest(0, 50));
Article blurb = organizationService.getBlurb(organization, new Locale(language));
PGRFANetwork network = networkService.getNetwork(shortName);
Page<FaoInstitute> members = networkService.getInstitutes(network, new PageRequest(0, 50));
Article blurb = networkService.getBlurb(network, new Locale(language));
return NetworkDetails.from(organization, blurb, members);
return NetworkDetails.from(network, blurb, members);
}
/**
......@@ -116,8 +116,8 @@ public class NetworkController extends ApiBaseController {
*/
@GetMapping(value = "/{shortName}/blurb/{language}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Article getBlurb(@PathVariable("shortName") String shortName, @PathVariable("language") String language) {
Organization org = organizationService.getOrganization(shortName);
return organizationService.getBlurb(org, new Locale(language));
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.getBlurb(org, new Locale(language));
}
/**
......@@ -126,8 +126,8 @@ public class NetworkController extends ApiBaseController {
*/
@PutMapping(value = "/{shortName}/blurb", produces = { MediaType.APPLICATION_JSON_VALUE })
public Article updateBlurb(@PathVariable("shortName") String shortName, @RequestBody Article blurb) throws CRMException {
Organization org = organizationService.getOrganization(shortName);
return organizationService.updateAbout(org, blurb.getBody(), blurb.getSummary(), blurb.getLang() == null ? Locale.ENGLISH : new Locale(blurb.getLang()));
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.updateAbout(org, blurb.getBody(), blurb.getSummary(), blurb.getLang() == null ? Locale.ENGLISH : new Locale(blurb.getLang()));
}
/**
......@@ -136,8 +136,8 @@ public class NetworkController extends ApiBaseController {
* @return
*/
@DeleteMapping(value = "/{shortName}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Organization deleteNetwork(@PathVariable("shortName") String shortName) {
return organizationService.deleteOrganization(organizationService.getOrganization(shortName));
public PGRFANetwork deleteNetwork(@PathVariable("shortName") String shortName) {
return networkService.delete(networkService.getNetwork(shortName));
}
/**
......@@ -147,8 +147,8 @@ public class NetworkController extends ApiBaseController {
*/
@GetMapping(value = "/{shortName}/institutes/codes", produces = { MediaType.APPLICATION_JSON_VALUE })
public Set<String> getNetworkInstitutesCodes(@PathVariable("shortName") String shortName) {
Organization org = organizationService.getOrganization(shortName);
return organizationService.getOrganizationInstitutes(org).stream().map(FaoInstitute::getCode).collect(Collectors.toSet());
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.getInstitutes(org).stream().map(FaoInstitute::getCode).collect(Collectors.toSet());
}
/**
......@@ -158,49 +158,49 @@ public class NetworkController extends ApiBaseController {
*/
@GetMapping(value = "/{shortName}/institutes", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<FaoInstitute> getNetworkInstitutes(@PathVariable("shortName") String shortName, @RequestParam Integer page) {
Organization org = organizationService.getOrganization(shortName);
return organizationService.getOrganizationInstitutes(org, new PageRequest(page, 50));
PGRFANetwork org = networkService.getNetwork(shortName);
return networkService.getInstitutes(org, new PageRequest(page, 50));
}
/**
* Add Institutes to Organization
* Add Institutes to Network
*
* @return
*/
@RequestMapping(value = "/{slug}/add-institutes", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Organization addNetworkInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) {
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
throw new NotFoundElement("Organization cannot be found");
public PGRFANetwork addNetworkInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) {
final PGRFANetwork network = networkService.getNetwork(slug);
if (network == null) {
throw new NotFoundElement("Network cannot be found");
}
return organizationService.addOrganizationInstitutes(organization, instituteList);
return networkService.addInstitutes(network, instituteList);
}
/**
* Set Institutes of Organization
* Set Institutes of Network
*
* @return
*/
@RequestMapping(value = "/{slug}/set-institutes", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Organization setNetworkInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) {
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
public PGRFANetwork setNetworkInstitutes(@PathVariable(value = "slug") String slug, @RequestBody List<String> instituteList) {
final PGRFANetwork network = networkService.getNetwork(slug);
if (network == null) {
throw new NotFoundElement();
}
return organizationService.setOrganizationInstitutes(organization, instituteList);
return networkService.setInstitutes(network, instituteList);
}
public static class NetworkDetails {
public Organization network;
public PGRFANetwork network;
public Article blurb;
public Page<FaoInstitute> institutes;
public static NetworkDetails from(Organization organization, Article blurb, Page<FaoInstitute> institutes) {
public static NetworkDetails from(PGRFANetwork network, Article blurb, Page<FaoInstitute> institutes) {
NetworkDetails details = new NetworkDetails();
details.network = organization;
details.network = network;
details.blurb = blurb;
details.institutes = institutes;
......
......@@ -18,7 +18,7 @@ import org.genesys2.server.model.genesys.AccessionList;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.SvalbardDeposit;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.impl.PGRFANetwork;
import org.genesys2.server.service.IndexAliasConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -474,19 +474,19 @@ public class AccessionDetails {
this.historic = historic;
}
public void networks(List<Organization> organizations) {
if (organizations == null || organizations.isEmpty())
public void networks(List<PGRFANetwork> networks) {
if (networks == null || networks.isEmpty())
return;
Set<String> networks = new HashSet<String>();
for (Organization org : organizations) {
networks.add(org.getSlug());
Set<String> nets = new HashSet<String>();
for (PGRFANetwork org : networks) {
nets.add(org.getSlug());
}
if (institute == null)
institute = new Institute();
institute.setNetworks(networks);
institute.setNetworks(nets);
}
public String getAcceUrl() {
......
......@@ -134,7 +134,7 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
@JsonIdentityReference(alwaysAsId = true)
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
@JsonProperty(access = Access.READ_ONLY)
private List<Organization> networks;
private List<PGRFANetwork> networks;
@ManyToOne(cascade = {})
......@@ -332,11 +332,11 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
this.codeSGSV = codeSGSV;
}
public List<Organization> getNetworks() {
public List<PGRFANetwork> getNetworks() {
return networks;
}
public void setNetworks(List<Organization> networks) {
public void setNetworks(List<PGRFANetwork> networks) {
this.networks = networks;
}
......
......@@ -38,7 +38,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "organization")
public class Organization extends AuditedVersionedModel {
public class PGRFANetwork extends AuditedVersionedModel {
private static final long serialVersionUID = 2710908645431936666L;
......
......@@ -29,7 +29,7 @@ import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.PGRFANetworkService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.servlet.filter.LocaleURLFilter;
......@@ -64,7 +64,7 @@ public class HtmlController extends BaseController {
private StatisticsService statisticsService;
@Autowired
private OrganizationService organizationService;
private PGRFANetworkService networkService;
@Autowired
private DatasetService datasetService;
......@@ -129,7 +129,7 @@ public class HtmlController extends BaseController {
model.addAttribute("lastDatasetsUpdates", datasetService.lastPublished());
printSplit("lastDatasetsUpdates", stopWatch);
model.addAttribute("organizations", organizationService.list(new PageRequest(0, 5)));
model.addAttribute("organizations", networkService.list(new PageRequest(0, 5)));
printSplit("organizations", stopWatch);
return "/index";
......
......@@ -27,12 +27,12 @@ import javax.servlet.http.HttpServletRequest;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.impl.PGRFANetwork;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.PGRFANetworkService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
......@@ -52,7 +52,7 @@ import org.springframework.web.bind.annotation.RequestParam;
public class OrganizationController extends BaseController {
@Autowired
private OrganizationService organizationService;
private PGRFANetworkService networkService;
@Autowired
private ContentService contentService;
......@@ -65,18 +65,18 @@ public class OrganizationController extends BaseController {
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("pagedData", organizationService.list(new PageRequest(page - 1, 50, new Sort("title"))));
model.addAttribute("pagedData", networkService.list(new PageRequest(page - 1, 50, new Sort("title"))));
return "/organization/index";
}
@RequestMapping("/{slug}")
public String view(ModelMap model, @PathVariable(value = "slug") String slug) {
LOG.debug("Viewing organization {}", slug);
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
final PGRFANetwork network = networkService.getNetwork(slug);
if (network == null) {
throw new NotFoundElement();
}
final List<FaoInstitute> members = organizationService.getOrganizationInstitutes(organization);
final List<FaoInstitute> members = networkService.getInstitutes(network);
LOG.debug("Has: {}", members.size());
......@@ -90,11 +90,11 @@ public class OrganizationController extends BaseController {
}
});
model.addAttribute("organization", organization);
model.addAttribute("organization", network);
model.addAttribute("members", members);
model.addAttribute("blurp", contentService.getArticle(organization, "blurp", getLocale()));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(organization));
model.addAttribute("blurp", contentService.getArticle(network, "blurp", getLocale()));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(network));
return "/organization/details";
}
......@@ -105,9 +105,9 @@ public class OrganizationController extends BaseController {
try {
view(model, slug);
} catch (final NotFoundElement e) {
final Organization organization = new Organization();
organization.setSlug(slug);
model.addAttribute("organization", organization);
final PGRFANetwork network = new PGRFANetwork();
network.setSlug(slug);
model.addAttribute("organization", network);
}
return "/organization/edit";
}
......@@ -137,43 +137,43 @@ public class OrganizationController extends BaseController {
@RequestParam("title") String title, @RequestParam("blurp") String blurp, @RequestParam(value = "summary", required = false) String summary) throws CRMException {
LOG.debug("Updating organization {}", slug);
Organization organization = organizationService.getOrganization(slug);
PGRFANetwork network = networkService.getNetwork(slug);
if (organization == null) {
organization = organizationService.create(newSlug, title);
if (network == null) {
network = networkService.create(newSlug, title);
} else {
organization = organizationService.update(organization.getId(), newSlug, title);
network = networkService.update(network.getId(), newSlug, title);
}
organizationService.updateAbout(organization, blurp, summary, getLocale());
networkService.updateAbout(network, blurp, summary, getLocale());
return "redirect:/org/" + organization.getSlug();
return "redirect:/org/" + network.getSlug();
}
@RequestMapping("/{orgSlug}/data")
public String viewData(ModelMap model, @PathVariable(value = "orgSlug") String orgSlug,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
LOG.debug("Viewing organization {}", orgSlug);
final Organization organization = organizationService.getOrganization(orgSlug);
if (organization == null) {
final PGRFANetwork network = networkService.getNetwork(orgSlug);
if (network == null) {
throw new NotFoundElement();
}
model.addAttribute("filter", "{\"" + FilterConstants.INSTITUTE_NETWORK + "\":[\"" + organization.getSlug() + "\"]}");
model.addAttribute("filter", "{\"" + FilterConstants.INSTITUTE_NETWORK + "\":[\"" + network.getSlug() + "\"]}");
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{orgSlug}/overview")
public String overview(HttpServletRequest request, @PathVariable(value = "orgSlug") String orgSlug) throws UnsupportedEncodingException {
final Organization organization = organizationService.getOrganization(orgSlug);
if (organization == null) {
final PGRFANetwork network = networkService.getNetwork(orgSlug);
if (network == null) {
throw new NotFoundElement();
}
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTITUTE_NETWORK).addFilterValue(
new FilterHandler.LiteralValueFilter(organization.getSlug())));
new FilterHandler.LiteralValueFilter(network.getSlug())));
return "forward:/explore/overview?filter=" + URLEncoder.encode(appliedFilters.toString(), "UTF8");
}
......
......@@ -58,7 +58,7 @@ import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.PGRFANetworkService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter;
......@@ -109,7 +109,7 @@ public class WiewsController extends BaseController {
private InstituteService instituteService;
@Autowired
private OrganizationService organizationService;
private PGRFANetworkService networkService;
@Autowired
private GenesysService genesysService;
......@@ -175,7 +175,7 @@ public class WiewsController extends BaseController {
throw new NotFoundElement();
}
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("organizations", organizationService.getOrganizations(faoInstitute));
model.addAttribute("organizations", networkService.getNetworksFor(faoInstitute));
LOG.trace("organizations after {}ms", stopWatch.getTime());
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
LOG.trace("blurp after {}ms", stopWatch.getTime());
......
......@@ -19,18 +19,18 @@ package org.genesys2.server.persistence;
import java.util.List;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.impl.PGRFANetwork;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface OrganizationRepository extends JpaRepository<Organization, Long> {
public interface PGRFANetworkRepository extends JpaRepository<PGRFANetwork, Long> {
Organization findBySlug(String slug);
PGRFANetwork findBySlug(String slug);
@Query("select o.members from Organization o where o = ?1 order by code")
List<FaoInstitute> findInstitutesByOrganization(Organization organization);
@Query("select o.members from PGRFANetwork o where o = ?1 order by code")
List<FaoInstitute> findInstitutesByNetwork(PGRFANetwork network);
@Query("select distinct o from Organization o join o.members m where m = ?1")
List<Organization> getOrganizations(FaoInstitute faoInstitute);
@Query("select distinct o from PGRFANetwork o join o.members m where m = ?1")
List<PGRFANetwork> getNetworks(FaoInstitute faoInstitute);