Commit 77071c61 authored by Matija Obreza's avatar Matija Obreza
Browse files

Added (organization|institute|country)/edit pages

parent 63848b3c
......@@ -49,10 +49,6 @@ public class Organization extends BusinessModel {
@Field(name = "body", store = Store.NO)
private String title;
@Lob
@Field(name = "text", store = Store.NO)
private String description;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = FaoInstitute.class)
@JoinTable(name = "organizationinstitute", joinColumns = @JoinColumn(name = "organizationId"), inverseJoinColumns = @JoinColumn(name = "instituteId"))
private List<FaoInstitute> members = new ArrayList<FaoInstitute>();
......@@ -72,14 +68,6 @@ public class Organization extends BusinessModel {
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<FaoInstitute> getMembers() {
return members;
......
......@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import org.genesys2.server.model.impl.Country;
......@@ -40,4 +41,6 @@ public interface GeoService {
List<Country> listAll();
void updateBlurp(Country country, String blurp, Locale locale);
}
......@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -44,5 +45,9 @@ public interface InstituteService {
void update(Collection<FaoInstitute> institutes);
void updateBlurp(FaoInstitute faoInstitute, String blurp, Locale locale);
void updateCountryRefs();
}
......@@ -14,9 +14,10 @@
* limitations under the License.
**/
package org.genesys2.server.service;
import java.util.Locale;
import org.genesys2.server.model.impl.Organization;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -27,4 +28,17 @@ public interface OrganizationService {
Organization getOrganization(String slug);
void updateBlurp(Organization organization, String blurp, Locale locale);
Organization update(long id, String newSlug, String title);
/**
* Create a new organization
*
* @param newSlug
* @param title
* @return
*/
Organization create(String slug, String title);
}
......@@ -148,7 +148,7 @@ public class ContentServiceImpl implements ContentService {
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Article updateArticle(Class<?> clazz, Long id, String slug, String title, String body, Locale locale) {
Article article = getArticle(clazz, id, slug, locale);
if (article == null || article.getLang() != locale.getLanguage()) {
if (article == null || ! article.getLang().equals(locale.getLanguage())) {
article = new Article();
article.setClassPk(ensureClassPK(clazz));
article.setTargetId(id);
......
......@@ -63,6 +63,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -275,8 +276,10 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
@Override
public Page<Accession> listAccessionsByOrganization(Organization organization, Pageable pageable) {
if (organization.getMembers() == null || organization.getMembers().size() == 0) {
return new LucenePage<Accession>(0, 0);
}
return accessionRepository.findByInstitute(organization.getMembers(), pageable);
}
@Override
......@@ -310,12 +313,14 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateAccessionCountryRefs() {
genesysLowlevelRepository.updateCountryRefs();
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateAccessionInstitueRefs() {
genesysLowlevelRepository.updateFaoInstituteRefs();
......@@ -332,6 +337,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void saveSvalbards(List<SvalbardData> svalbards) {
svalbardRepository.save(svalbards);
......
......@@ -18,6 +18,7 @@ package org.genesys2.server.service.impl;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
......@@ -27,9 +28,11 @@ import org.genesys2.geo.sources.DavrosCountrySource;
import org.genesys2.geo.sources.GeoNamesCountrySource;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.persistence.domain.CountryRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.GeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -41,6 +44,10 @@ public class GeoServiceImpl implements GeoService {
@Autowired
CountryRepository countryRepository;
@Autowired
ContentService contentService;
@Override
public List<Country> listAll() {
return countryRepository.findAll(new Sort("name", "current"));
......@@ -184,4 +191,12 @@ public class GeoServiceImpl implements GeoService {
}
}
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateBlurp(Country country, String blurp, Locale locale) {
contentService.updateArticle(country, "blurp", null, blurp, locale);
}
}
......@@ -19,6 +19,7 @@ package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.logging.Log;
......@@ -27,6 +28,8 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.domain.CountryRepository;
import org.genesys2.server.persistence.domain.FaoInstituteRepository;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.InstituteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -34,6 +37,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -48,10 +52,16 @@ public class InstituteServiceImpl implements InstituteService {
private static final List<FaoInstitute> EMPTY_LIST = ListUtils.unmodifiableList(new ArrayList<FaoInstitute>());
@Autowired
FaoInstituteRepository instituteRepository;
private FaoInstituteRepository instituteRepository;
@Autowired
CountryRepository countryRepository;
private CountryRepository countryRepository;
@Autowired
private ContentService contentService;
@Autowired
private GenesysLowlevelRepository genesysLowlevelRepository;
@Override
public Page<FaoInstitute> list(Pageable pageable) {
......@@ -92,4 +102,17 @@ public class InstituteServiceImpl implements InstituteService {
instituteRepository.save(institutes);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateBlurp(FaoInstitute faoInstitute, String blurp, Locale locale) {
contentService.updateArticle(faoInstitute, "blurp", null, blurp, locale);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateCountryRefs() {
genesysLowlevelRepository.updateFaoInstituteCountries();
}
}
......@@ -16,15 +16,19 @@
package org.genesys2.server.service.impl;
import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.persistence.domain.FaoInstituteRepository;
import org.genesys2.server.persistence.domain.OrganizationRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -34,19 +38,53 @@ public class OrganizationServiceImpl implements OrganizationService {
public static final Log LOG = LogFactory.getLog(OrganizationServiceImpl.class);
@Autowired
FaoInstituteRepository instituteRepository;
private FaoInstituteRepository instituteRepository;
@Autowired
private OrganizationRepository organizationRepository;
@Autowired
OrganizationRepository organizationRepository;
private ContentService contentService;
@Override
public Organization getOrganization(String slug) {
return organizationRepository.findBySlug(slug);
}
@Override
public Page<Organization> list(Pageable pageable) {
return organizationRepository.findAll(pageable);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateBlurp(Organization organization, String blurp, Locale locale) {
contentService.updateArticle(organization, "blurp", null, blurp, locale);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public Organization update(long id, String newSlug, String title) {
Organization organization = organizationRepository.findOne(id);
organization.setSlug(newSlug);
organization.setTitle(title);
organizationRepository.save(organization);
return organization;
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public Organization create(String slug, String title) {
Organization organization = new Organization();
organization.setSlug(slug);
organization.setTitle(title);
organizationRepository.save(organization);
return organization;
}
}
......@@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.LuceneIndexer;
import org.genesys2.server.service.impl.ContentSanitizer;
import org.genesys2.server.service.impl.InstituteUpdater;
......@@ -59,6 +60,9 @@ public class AdminController {
@Autowired
ContentSanitizer contentSanitizer;
@Autowired
private InstituteService instituteService;
@RequestMapping("/")
public String root() {
return "/admin/index";
......@@ -101,7 +105,13 @@ public class AdminController {
genesysService.updateAccessionCountryRefs();
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/updateInstituteCountryRefs")
public String updateInstituteCountryRefs() {
instituteService.updateCountryRefs();
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/updateAccessionInstituteRefs")
public String updateAccessionInstituteRefs() {
genesysService.updateAccessionInstitueRefs();
......
......@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -81,6 +82,28 @@ public class CountryController extends BaseController {
return "/country/details";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/{country}/edit")
public String edit(ModelMap model, @PathVariable(value = "country") String countryStr) {
view(model, countryStr);
return "/country/edit";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/{country}/update")
public String update(ModelMap model, @PathVariable(value = "country") String countryStr, @RequestParam("blurp") String blurp) {
_logger.debug("Editing country " + countryStr);
Country country = geoService.getCountry(countryStr);
if (country == null) {
throw new ResourceNotFoundException();
}
geoService.updateBlurp(country, blurp, getLocale());
return "redirect:/geo/" + country.getCode3().toLowerCase();
}
@RequestMapping("/{country}/data")
public String viewData(ModelMap model, @PathVariable(value = "country") String countryStr,
......
......@@ -30,11 +30,13 @@ import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@Scope("request")
@RequestMapping("/org")
......@@ -54,7 +56,7 @@ public class OrganizationController extends BaseController {
@Autowired
private ContentService contentService;
@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"))));
......@@ -73,13 +75,48 @@ public class OrganizationController extends BaseController {
model.addAttribute("blurp", contentService.getArticle(organization, "blurp", getLocale()));
// model.addAttribute("countByInstitute", genesysService.countByInstitute(faoInstitute));
// model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute));
// model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute));
// model.addAttribute("countByInstitute",
// genesysService.countByInstitute(faoInstitute));
// model.addAttribute("statisticsGenus",
// genesysService.statisticsGenusByInstitute(faoInstitute));
// model.addAttribute("statisticsTaxonomy",
// genesysService.statisticsTaxonomyByInstitute(faoInstitute));
return "/organization/details";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/{slug}/edit")
public String edit(ModelMap model, @PathVariable(value = "slug") String slug) {
try {
view(model, slug);
} catch (ResourceNotFoundException e) {
Organization organization = new Organization();
organization.setSlug(slug);
model.addAttribute("organization", organization);
}
return "/organization/edit";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "/{slug}/update")
public String update(ModelMap model, @PathVariable(value = "slug") String slug, @RequestParam(value = "slug") String newSlug,
@RequestParam("title") String title, @RequestParam("blurp") String blurp) {
_logger.debug("Updating organization " + slug);
Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
organization = organizationService.create(newSlug, title);
} else {
organization = organizationService.update(organization.getId(), newSlug, title);
}
organizationService.updateBlurp(organization, blurp, getLocale());
return "redirect:/org/" + organization.getSlug();
}
@RequestMapping("/{wiewsCode}/data")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String slug,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
......@@ -31,6 +31,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -56,7 +57,6 @@ public class WiewsController extends BaseController {
@Autowired
private ContentService contentService;
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......@@ -81,7 +81,7 @@ public class WiewsController extends BaseController {
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
model.addAttribute("countByInstitute", genesysService.countByInstitute(faoInstitute));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute, new PageRequest(0, 30)));
......@@ -89,6 +89,27 @@ public class WiewsController extends BaseController {
return "/wiews/details";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/{wiewsCode}/edit")
public String edit(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode) {
view(model, wiewsCode);
return "/wiews/edit";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String blurp) {
_logger.debug("Updating institite " + wiewsCode);
FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
instituteService.updateBlurp(faoInstitute, blurp, getLocale());
return "redirect:/wiews/" + wiewsCode;
}
@RequestMapping("/{wiewsCode}/data")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
......@@ -45,9 +45,10 @@ sample.message.id=ID
sample.message.name=Name
sample.message.description=Description
sample.message.actions=Actions
sample.message.add=Add
sample.message.edit=Edit
sample.message.save=Save
add=Add
edit=Edit
save=Save
cancel=Cancel
sample.message.delete=Delete
#JS messages
......@@ -218,6 +219,8 @@ trait-list=Descriptors
organization.page.list.title=Organizations
organization.page.profile.title=Organization {0}
organization.slug=Organization acronym
organization.title=Full organization name
filter.organization=Organization
......
......@@ -45,9 +45,10 @@ sample.message.password=Geslo
sample.message.name=Ime
sample.message.description=Opis
# sample.message.actions=Actions
sample.message.add=Dodaj
sample.message.edit=Uredi
sample.message.save=Shrani
add=Dodaj
edit=Uredi
save=Shrani
cancel=Prekli\u010Di
sample.message.delete=Odstrani
#JS messages
......@@ -98,7 +99,7 @@ user.pulldown.logout=Odjava
activity.recent-activity=Aktualno
country.page.profile.title=Profil države\: {0}
country.page.profile.title=Profil dr\u00C5\u00BEave\: {0}
country.page.list.title=Seznam držav
country.page.not-current=To je zgodovinski zapis.
country.page.faoInstitutes={0} organizacij registriranih v WIEWS
......
......@@ -13,30 +13,34 @@
</h1>
<form method="post" action="<c:url value="/admin/refreshWiews" />">
<input type="submit" value="Refresh WIEWS data" />
<input type="submit" class="btn btn-default" value="Refresh WIEWS data" />
</form>
<form method="post" action="<c:url value="/admin/updateSGSV" />">
<input type="submit" value="Update SGSV" />
<input type="submit" class="btn btn-default" value="Update SGSV" />
</form>
<form method="post" action="<c:url value="/admin/importSGSV" />">
<input type="submit" value="Import SGSV" />
<input type="submit" class="btn btn-default" value="Import SGSV" />
</form>
<form method="post" action="<c:url value="/admin/refreshCountries" />">
<input type="submit" value="Refresh country data" />
<input type="submit" class="btn btn-default" value="Refresh country data" />