Commit 4fdff271 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Merge branch '462-remove-website-controllers-and-jsps' into 'master'

Resolve "Remove website controllers and JSPs"

Closes #462

See merge request genesys-pgr/genesys-server!444
parents ac2121b4 a7417a09
......@@ -78,24 +78,6 @@ module.exports = function(grunt) {
cwd : 'node_modules/notosans-fontface/fonts/',
src : '*',
dest : '<%= app.dist1 %>/styles/fonts'
}, {
// tinyMCE
expand : true,
cwd : 'node_modules/tinymce/skins',
src : [ '**' ],
dest : '<%= app.dist1 %>/js/skins'
}, {
// leaflet
expand : true,
cwd : 'node_modules/leaflet/dist/',
src : [ 'leaflet.css', 'images/*.png' ],
dest : '<%= app.dist1 %>/styles'
}, {
// simplecolorpicker
expand : true,
cwd : 'node_modules/jquery-simplecolorpicker/',
src : [ 'jquery.simplecolorpicker.css', 'jquery.simplecolorpicker-regularfont.css' ],
dest : '<%= app.dist1 %>/styles'
}, {
expand : true,
cwd : 'node_modules/jquery-ui-dist/',
......@@ -103,13 +85,6 @@ module.exports = function(grunt) {
dest : '<%= app.dist1 %>/styles'
} ]
}
// styles : {
// expand : true,
// cwd : '<%= app.source %>/styles',
// dest : '.tmp/styles/',
// src : '{,*/}*.css'
// }
},
// Make sure code styles are up to par and there are no obvious mistakes
......@@ -133,21 +108,8 @@ module.exports = function(grunt) {
dist1 : {
src : [
'node_modules/jquery/dist/jquery.js',
'node_modules/jquery-flot/jquery.flot.js',
'node_modules/jquery-flot/jquery.flot.pie.js',
'node_modules/jquery-flot/jquery.flot.fillbetween.js',
'node_modules/jquery-simplecolorpicker/jquery.simplecolorpicker.js',
'node_modules/tinymce/tinymce.js',
'node_modules/tinymce/tinymce.jquery.js',
'node_modules/tinymce/themes/modern/theme.js',
'node_modules/tinymce/plugins/link/plugin.js',
'node_modules/tinymce/plugins/autolink/plugin.js',
'node_modules/tinymce/plugins/code/plugin.js',
'node_modules/leaflet/dist/leaflet.js',
'node_modules/leaflet.locationfilter/src/locationfilter.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
'node_modules/jquery-ui-dist/jquery-ui.js',
'node_modules/jstree/dist/jstree.js',
'node_modules/modernizr/bin/modernizr.js',
'node_modules/form-serializer/jquery.serialize-object.js'
],
......@@ -157,18 +119,9 @@ module.exports = function(grunt) {
src : [
'<%= app.source1 %>/js/prologue.js',
'<%= app.source1 %>/js/crophub.js',
'<%= app.source1 %>/js/browse.js',
'<%= app.source1 %>/js/epilogue.js'
],
dest : '<%= app.dist1 %>/js/genesys.js'
},
world1 : {
src : [
'node_modules/highmaps-release/highmaps.src.js',
'node_modules/highcharts/lib/modules/data.src.js',
'<%= app.source1 %>/js/world.js'
],
dest : '<%= app.dist1 %>/js/genesyshighcharts.js'
}
},
......@@ -196,18 +149,12 @@ module.exports = function(grunt) {
'<%= app.dist1 %>/styles/other.min.css' : [
'<%= app.dist1 %>/styles/jquery-ui.css',
'<%= app.dist1 %>/styles/forza.css',
'<%= app.dist1 %>/styles/leaflet.css',
'<%= app.dist1 %>/styles/jquery.simplecolorpicker.css',
'<%= app.dist1 %>/styles/jquery.simplecolorpicker-regularfont.css'
],
'<%= app.dist1 %>/styles/genesys.min.css' : [ '<%= app.dist1 %>/styles/genesys.css' ],
'<%= app.dist1 %>/styles/all.min.css' : [
'<%= app.dist1 %>/styles/bootstrap.css',
'<%= app.dist1 %>/styles/jquery-ui.css',
'<%= app.dist1 %>/styles/forza.css',
'<%= app.dist1 %>/styles/leaflet.css',
'<%= app.dist1 %>/styles/jquery.simplecolorpicker.css',
'<%= app.dist1 %>/styles/jquery.simplecolorpicker-regularfont.css',
'<%= app.dist1 %>/styles/genesys.css'
]
}
......@@ -251,7 +198,7 @@ module.exports = function(grunt) {
},
js1 : {
files : [ 'src/main/sourceapp/1/{,*/}*.js' ],
tasks : [ 'newer:jshint:dist1', 'concat:world1', 'concat:app1' ],
tasks : [ 'newer:jshint:dist1', 'concat:app1' ],
options : {
livereload : true
}
......@@ -265,7 +212,6 @@ module.exports = function(grunt) {
{ src : [ '<%= app.dist1 %>/js/libraries.min.js'], dest : '<%= app.dist1 %>/js/libraries.min.' + buildNumber + '.js' },
{ src : [ '<%= app.dist1 %>/js/libraries.js'], dest : '<%= app.dist1 %>/js/libraries.' + buildNumber + '.js' },
{ src : [ '<%= app.dist1 %>/js/genesys.js'], dest : '<%= app.dist1 %>/js/genesys.' + buildNumber + '.js' },
{ src : [ '<%= app.dist1 %>/js/genesyshighcharts.min.js'], dest : '<%= app.dist1 %>/js/genesyshighcharts.min.' + buildNumber + '.js' },
{ src : [ '<%= app.dist1 %>/styles/bootstrap.css'], dest : '<%= app.dist1 %>/styles/bootstrap.' + buildNumber + '.css' },
{ src : [ '<%= app.dist1 %>/styles/bootstrap.min.css'], dest : '<%= app.dist1 %>/styles/bootstrap.min.' + buildNumber + '.css' },
......@@ -283,7 +229,7 @@ module.exports = function(grunt) {
// grunt.loadNpmTasks('grunt-contrib-watch');
// grunt.loadNpmTasks('grunt-newer');
grunt.registerTask('build1', [ 'newer:jshint:dist1', 'compass:dist1', 'copy:dist1', 'concat:dist1', 'concat:world1', 'concat:app1', 'autoprefixer:dist1', 'uglify:dist1', 'cssmin:dist1' ]);
grunt.registerTask('build1', [ 'newer:jshint:dist1', 'compass:dist1', 'copy:dist1', 'concat:dist1', 'concat:app1', 'autoprefixer:dist1', 'uglify:dist1', 'cssmin:dist1' ]);
// grunt.registerTask('js', [ 'jshint:all', 'copy:dist', 'concat',
// 'autoprefixer', 'uglify:dist' ]);
// grunt.registerTask('css', [ 'compass:dist', 'copy:dist', 'concat',
......
......@@ -1384,16 +1384,6 @@
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"highcharts": {
"version": "4.1.10",
"resolved": "https://registry.npmjs.org/highcharts/-/highcharts-4.1.10.tgz",
"integrity": "sha1-6TgCiIp76RHRI+2VO+CqqTl/0ew="
},
"highmaps-release": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/highmaps-release/-/highmaps-release-1.1.10.tgz",
"integrity": "sha1-6oDB29dOe0Z292LNVfAfl1LHwf8="
},
"hooker": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz",
......@@ -1566,16 +1556,6 @@
"resolved": "https://registry.npmjs.org/jquery/-/jquery-2.1.4.tgz",
"integrity": "sha1-IoveaYoMYUMdwmMKahVPFYkNIxc="
},
"jquery-flot": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/jquery-flot/-/jquery-flot-0.8.3.tgz",
"integrity": "sha1-onOs9D8TGQ9ueHAYae4kv+8Swio="
},
"jquery-simplecolorpicker": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/jquery-simplecolorpicker/-/jquery-simplecolorpicker-0.3.1.tgz",
"integrity": "sha1-T2vv04CrBUcPWF1UguUYBVbkYOs="
},
"jquery-ui-dist": {
"version": "1.12.1",
"resolved": "https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.12.1.tgz",
......@@ -1654,16 +1634,6 @@
"invert-kv": "^1.0.0"
}
},
"leaflet": {
"version": "0.7.7",
"resolved": "https://registry.npmjs.org/leaflet/-/leaflet-0.7.7.tgz",
"integrity": "sha1-HjUrpU5j0HZFH6NjyQCJDLLPde4="
},
"leaflet.locationfilter": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/leaflet.locationfilter/-/leaflet.locationfilter-0.1.0.tgz",
"integrity": "sha1-nqiQKVNkJhwKUvMcj34satVHOP4="
},
"livereload-js": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/livereload-js/-/livereload-js-2.3.0.tgz",
......@@ -2618,11 +2588,6 @@
}
}
},
"tinymce": {
"version": "4.1.10",
"resolved": "https://registry.npmjs.org/tinymce/-/tinymce-4.1.10.tgz",
"integrity": "sha1-XozIu2+9/+igw4eQb/RB96t49aA="
},
"tmp": {
"version": "0.0.28",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.28.tgz",
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.mvc;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
@Controller
@RequestMapping("/acn")
public class AccessionController extends BaseController {
public static final UUID WORLDCLIM_DATASET_UUID = UUID.fromString("BC84433B-A626-4BDF-97D3-DB36D79499C6");
@Autowired
private InstituteService instituteService;
@Autowired
private GenesysService genesysService;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private DownloadService downloadService;
@Autowired
private AccessionService accessionService;
@Value("${base.url}")
private String baseUrl;
@RequestMapping(value = "/id/{accessionId}", produces = {MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody
AccessionDetails viewJson(ModelMap model, @PathVariable(value = "accessionId") long accessionId) {
AccessionDetails ad = genesysService.getAccessionDetails(accessionId);
if (ad == null) {
throw new NotFoundElement();
}
return ad;
}
@RequestMapping(value = "/id/{accessionId}")
public ModelAndView view(ModelMap model, @PathVariable(value = "accessionId") long accessionId) {
LOG.debug("Viewing ACN {}", accessionId);
final Accession accession = genesysService.getAccession(accessionId);
if (accession == null) {
throw new NotFoundElement();
}
RedirectView rv = new RedirectView();
rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
if (StringUtils.isNotEmpty(accession.getDoi())) {
rv.setUrl("/" + accession.getDoi());
} else {
rv.setUrl("/a/" + accession.getUuid().toString());
}
return new ModelAndView(rv);
}
@RequestMapping("/{holdingInstitute}/{genus}/{accessionName:.+}")
public String viewInstituteAccession(ModelMap model, @PathVariable(value = "holdingInstitute") String holdingInstitute,
@PathVariable(value = "genus") String genus, @PathVariable(value = "accessionName") String accessionName) {
LOG.debug("Viewing ACN {}", accessionName);
final FaoInstitute faoInstitute = instituteService.getInstitute(holdingInstitute);
if (faoInstitute == null) {
throw new NotFoundElement();
}
try {
final String doi = null;
final Accession accession = genesysService.getAccession(holdingInstitute, doi, accessionName, genus);
if (accession == null) {
throw new NotFoundElement();
} else {
return "redirect:/a/" + accession.getUuid();
}
} catch (NonUniqueAccessionException e) {
return "redirect:/acn/" + holdingInstitute + "/" + accessionName;
}
}
@RequestMapping("/{holdingInstitute}/{accessionName:.+}")
public String viewInstituteAccession(ModelMap model, @PathVariable(value = "holdingInstitute") String holdingInstitute,
@PathVariable(value = "accessionName") String accessionName) {
LOG.debug("Viewing ACN {}", accessionName);
final FaoInstitute faoInstitute = instituteService.findInstitute(holdingInstitute);
if (faoInstitute == null) {
throw new NotFoundElement();
}
final List<Accession> accessions = genesysService.listAccessions(faoInstitute, accessionName);
if (accessions.size() == 0) {
throw new NotFoundElement();
}
if (accessions.size() == 1) {
return "redirect:/a/" + accessions.get(0).getUuid();
}
model.addAttribute("faoInstitute", faoInstitute);
// This expects a List<>
model.addAttribute("accessions", accessions);
return "/accession/resolve";
}
@GetMapping(value = "/{uuid:\\w{8}\\-\\w{4}.+}")
public ModelAndView viewAccessionByUUID(final ModelMap model, @PathVariable("uuid") final UUID uuid) {
final Accession accession = accessionService.getByUuid(uuid);
if (accession == null) {
throw new NotFoundElement();
}
RedirectView rv = new RedirectView();
rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
if (StringUtils.isNotEmpty(accession.getDoi())) {
rv.setUrl("/" + accession.getDoi());
} else {
rv.setUrl("/a/" + accession.getUuid().toString());
}
return new ModelAndView(rv);
}
/**
* View by Taxonomy
*
* @param model
* @param genus
* @param page
* @return
*/
@RequestMapping("/t/{genus}")
public String viewDataByGenus(ModelMap model, @PathVariable(value = "genus") String genus,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
// Taxonomy
final Taxonomy2 taxonomy = taxonomyService.get(genus);
if (taxonomy == null) {
throw new NotFoundElement("No taxonomy with genus=" + genus);
}
model.addAttribute("filter", "{\"" + FilterConstants.TAXONOMY_GENUS + "\":[\"" + taxonomy.getGenus() + "\"]}");
model.addAttribute("page", page);
return "redirect:/explore";
}
/**
* View by Taxonomy
*
* @param model
* @param genus
* @param species
* @param page
* @return
*/
@RequestMapping("/t/{genus}/{species:.+}")
public String viewDataByGenusSpecies(ModelMap model, @PathVariable(value = "genus") String genus, @PathVariable(value = "species") String species,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
// Taxonomy
final Taxonomy2 taxonomy = taxonomyService.get(genus, species);
if (taxonomy == null) {
throw new NotFoundElement("No taxonomy with genus=" + genus);
}
model.addAttribute("filter", "{\"" + FilterConstants.TAXONOMY_GENUS + "\":[\"" + taxonomy.getGenus() + "\"], \"" + FilterConstants.TAXONOMY_SPECIES
+ "\":[\"" + taxonomy.getSpecies() + "\"]}");
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/updates")
public String updateStats(ModelMap model) {
model.addAttribute("updates", genesysService.getLastUpdatedStatistics());
return "/accession/updates";
}
@RequestMapping(value = "/updates/download", method = RequestMethod.POST)
public void downloadCSV(final HttpServletResponse response) throws IOException {
response.setContentType("text/csv;charset=UTF-16LE");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"last-updates-of-passport-data.csv\""));
response.flushBuffer();
// Write CSV to the stream.
final OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(), "UTF-16LE");
final List<Object[]> lastUpdatedStatistics = genesysService.getLastUpdatedStatistics();
try {
downloadService.writeCsvLastUpdated(lastUpdatedStatistics, osw);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
}
}
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.mvc;
import org.genesys.blocks.security.model.AclObjectIdentity;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys2.server.model.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
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("/acl")
@PreAuthorize("isAuthenticated()")
public class AclEditController extends BaseController {
@Autowired
private CustomAclService aclService;
@RequestMapping("/{clazz}/{id}/permissions")
public String permissions(ModelMap model, @PathVariable(value = "clazz") String className, @PathVariable("id") long id,
@RequestParam(value = "back", required = false) String backUrl) {
final AclObjectIdentity objectIdentity = aclService.ensureObjectIdentity(id, className);
model.addAttribute("aclObjectIdentity", objectIdentity);
if (objectIdentity != null) {
model.addAttribute("aclPermissions", aclService.getAvailablePermissions(className));
}
model.addAttribute("aclSids", aclService.getSids(id, className));
// Map<AclSid, Map<Permission, Boolean>>
model.addAttribute("sidPermissions", aclService.getPermissions(id, className));
model.addAttribute("backUrl", backUrl);
model.addAttribute("roles", UserRole.values());
return "/acl/editor";
}
}
/*
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.server.mvc;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ClimateDataService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteFilesService;
import org.genesys2.server.service.TraitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.context.SecurityContextHolder;
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.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
/**
* Handles accession display on `/a/...` URL prefix using UUID
*/
@Controller
@RequestMapping("/a")
public class AcnController extends BaseController {
@Autowired
private GenesysService genesysService;