Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
5834281c
Commit
5834281c
authored
Oct 10, 2017
by
Andrey Lugovskiy
Committed by
Matija Obreza
Oct 23, 2017
Browse files
Download repository metadata for an institute
- metadata files info - Update WiewsController - download files metadata
parent
1d509486
Changes
23
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
5834281c
...
...
@@ -792,7 +792,7 @@
</attributes>
</configuration>
</plugin>
<!--
<plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
license-maven-plugin
</artifactId>
<version>
1.9
</version>
...
...
@@ -815,7 +815,7 @@
<configuration>
<sortArtifactByName>
true
</sortArtifactByName>
</configuration>
</plugin>
-->
</plugin>
<plugin>
<groupId>
org.liquibase
</groupId>
<artifactId>
liquibase-maven-plugin
</artifactId>
...
...
src/main/java/org/genesys2/server/service/GenesysService.java
View file @
5834281c
...
...
@@ -55,6 +55,8 @@ import org.genesys2.server.service.impl.NonUniqueAccessionException;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
javax.servlet.http.HttpServletResponse
;
public
interface
GenesysService
{
/**
...
...
@@ -290,4 +292,12 @@ public interface GenesysService {
Page
<
AccessionDetails
>
listAccessionsDetails
(
Collection
<
Long
>
accessionIds
,
Pageable
page
);
/**
* Method for download files metadata
* @param response response
* @param repositoryPath repository path
* @throws IOException
*/
void
downloadFilesMetadata
(
HttpServletResponse
response
,
String
repositoryPath
)
throws
IOException
;
}
src/main/java/org/genesys2/server/service/impl/FilesMetadataInfo.java
0 → 100644
View file @
5834281c
package
org.genesys2.server.service.impl
;
import
org.genesys.filerepository.model.RepositoryFile
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
/**
* @author Andrey Lugovskoy.
*/
@Service
(
"filesMetadataInfo"
)
public
class
FilesMetadataInfo
extends
MetadataInfo
<
RepositoryFile
>
{
@Value
(
"#{'${files.metadata.fields}'.split(',')}"
)
private
List
<
String
>
filesMetadataHeader
;
@Override
public
void
downloadMetadata
(
List
<
RepositoryFile
>
entities
,
HttpServletResponse
response
,
char
separator
,
char
quoteChar
,
char
escapeChar
,
String
lineEnd
)
throws
IOException
{
super
.
downloadMetadata
(
filesMetadataHeader
,
entities
,
response
,
separator
,
quoteChar
,
escapeChar
,
lineEnd
);
}
}
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
5834281c
...
...
@@ -16,37 +16,16 @@
package
org.genesys2.server.service.impl
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
javax.persistence.EntityManager
;
import
com.opencsv.CSVWriter
;
import
com.opencsv.ResultSetHelper
;
import
com.opencsv.ResultSetHelperService
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.Predicate
;
import
org.apache.commons.lang.StringUtils
;
import
org.genesys.blocks.security.SecurityContextUtil
;
import
org.genesys.blocks.security.service.CustomAclService
;
import
org.genesys.filerepository.model.RepositoryFile
;
import
org.genesys.filerepository.service.RepositoryService
;
import
org.genesys2.server.model.elastic.AccessionDetails
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.genesys.AccessionAlias
;
...
...
@@ -127,6 +106,28 @@ import org.springframework.transaction.annotation.Isolation;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.EntityManager
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
@Service
@Transactional
(
readOnly
=
true
)
public
class
GenesysServiceImpl
implements
GenesysService
,
DatasetService
{
...
...
@@ -200,6 +201,12 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Autowired
private
GenesysFilterService
filterService
;
@Autowired
(
required
=
false
)
private
RepositoryService
repositoryService
;
@Autowired
(
required
=
false
)
private
FilesMetadataInfo
filesMetadataInfo
;
private
List
<
String
>
availableDisplayColumns
;
private
List
<
String
>
defaultDisplayColumns
;
...
...
@@ -290,7 +297,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public
Page
<
AccessionDetails
>
listAccessionsDetails
(
Collection
<
Long
>
accessionIds
,
Pageable
pageable
)
{
if
(!
accessionIds
.
isEmpty
())
{
Page
<
Accession
>
data
=
accessionRepository
.
findById
(
accessionIds
,
pageable
);
return
new
PageImpl
<
AccessionDetails
>(
getAccessionDetails
(
data
.
getContent
().
stream
().
map
(
a
->
a
.
getId
()).
collect
(
Collectors
.
toList
())),
pageable
,
data
.
getTotalElements
());
return
new
PageImpl
<
AccessionDetails
>(
getAccessionDetails
(
data
.
getContent
().
stream
().
map
(
a
->
a
.
getId
()).
collect
(
Collectors
.
toList
())),
pageable
,
data
.
getTotalElements
());
}
else
{
return
null
;
}
...
...
@@ -299,7 +307,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public
Accession
getAccession
(
AccessionIdentifier3
aid3
)
throws
NonUniqueAccessionException
{
try
{
Accession
accession
=
accessionRepository
.
findOne
(
instituteRepository
.
findByCode
(
aid3
.
getHoldingInstitute
()),
aid3
.
getDoi
(),
aid3
.
getAccessionNumber
(),
aid3
.
getGenus
());
Accession
accession
=
accessionRepository
.
findOne
(
instituteRepository
.
findByCode
(
aid3
.
getHoldingInstitute
()),
aid3
.
getDoi
(),
aid3
.
getAccessionNumber
(),
aid3
.
getGenus
());
return
lazyLoadAccession
(
accession
);
}
catch
(
IncorrectResultSizeDataAccessException
e
)
{
LOG
.
error
(
"Duplicate accession name instCode={} acceNumb={} genus={}"
,
aid3
.
getHoldingInstitute
(),
aid3
.
getAccessionNumber
(),
aid3
.
getGenus
());
...
...
@@ -881,10 +890,10 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
* Update {@link SvalbardDeposit} data and link with Genesys accessions. The
* primary key for {@link SvalbardDeposit} is the <code>sgsv_id</code> as
* provided by NordGen.
*
*
* Any existing SGSV records are first deleted. Inserted and linked with
* accessions in this method.
*
*
* @param svalbardDeposits
* @return
*/
...
...
@@ -1901,4 +1910,17 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public
List
<
Object
[]>
getLastUpdatedStatistics
(
FaoInstitute
faoInstitute
)
{
return
accessionRepository
.
lastUpdatedStatistics
(
faoInstitute
);
}
/**
* {@inheritDoc}
*
* @param response
*/
@Override
public
void
downloadFilesMetadata
(
HttpServletResponse
response
,
String
repositoryPath
)
throws
IOException
{
List
<
RepositoryFile
>
files
=
repositoryService
.
getFiles
(
repositoryPath
);
filesMetadataInfo
.
downloadMetadata
(
files
,
response
,
' '
,
'"'
,
'\\'
,
"\r\n"
);
}
}
src/main/java/org/genesys2/server/service/impl/MetadataInfo.java
0 → 100644
View file @
5834281c
package
org.genesys2.server.service.impl
;
import
com.opencsv.CSVWriter
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author Andrey Lugovskoy.
*/
public
abstract
class
MetadataInfo
<
T
>
{
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
MetadataInfo
.
class
);
public
abstract
void
downloadMetadata
(
List
<
T
>
entities
,
HttpServletResponse
response
,
char
separator
,
char
quoteChar
,
char
escapeChar
,
String
lineEnd
)
throws
IOException
;
public
void
downloadMetadata
(
List
<
String
>
filesMetadataFields
,
List
<
T
>
entities
,
HttpServletResponse
response
,
char
separator
,
char
quoteChar
,
char
escapeChar
,
String
lineEnd
)
throws
IOException
{
try
(
CSVWriter
writer
=
new
CSVWriter
(
new
BufferedWriter
(
new
OutputStreamWriter
(
response
.
getOutputStream
())),
separator
,
quoteChar
,
escapeChar
,
lineEnd
))
{
writer
.
writeNext
(
filesMetadataFields
.
toArray
(
ArrayUtils
.
EMPTY_STRING_ARRAY
));
entities
.
stream
().
forEach
(
element
->
{
List
<
Object
>
values
=
new
ArrayList
<>();
Class
<?>
aClass
=
element
.
getClass
();
filesMetadataFields
.
stream
().
forEach
(
fieldName
->
{
Field
field
;
Object
value
=
" "
;
try
{
field
=
aClass
.
getField
(
fieldName
);
value
=
field
.
get
(
element
);
}
catch
(
NoSuchFieldException
e
)
{
try
{
field
=
aClass
.
getSuperclass
().
getDeclaredField
(
fieldName
);
field
.
setAccessible
(
true
);
value
=
field
.
get
(
element
);
value
=
value
==
null
?
" "
:
value
;
}
catch
(
NoSuchFieldException
|
IllegalAccessException
e1
)
{
LOG
.
error
(
"Error getting value from field in "
+
element
.
getClass
().
getName
());
}
}
catch
(
IllegalAccessException
e
)
{
LOG
.
error
(
"Error getting value from field in "
+
element
.
getClass
().
getName
());
}
values
.
add
(
value
);
});
String
[]
stockArr
=
new
String
[
values
.
size
()];
stockArr
=
values
.
toArray
(
stockArr
);
writer
.
writeNext
(
stockArr
);
});
writer
.
flush
();
}
}
}
src/main/java/org/genesys2/server/servlet/controller/WiewsController.java
View file @
5834281c
...
...
@@ -16,22 +16,6 @@
package
org.genesys2.server.servlet.controller
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.genesys.filerepository.InvalidRepositoryFileDataException
;
import
org.genesys.filerepository.InvalidRepositoryPathException
;
import
org.genesys.filerepository.NoSuchRepositoryFileException
;
...
...
@@ -82,6 +66,21 @@ import org.springframework.web.servlet.HandlerMapping;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
org.springframework.web.util.UriUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
@Controller
@Scope
(
"request"
)
@RequestMapping
(
"/wiews"
)
...
...
@@ -506,8 +505,6 @@ public class WiewsController extends BaseController {
public
String
uploadFile
(
@RequestParam
MultipartFile
file
,
@PathVariable
String
wiewsCode
,
@RequestParam
String
repositoryPath
,
RedirectAttributes
redirectAttributes
)
throws
IOException
{
//check user permissions
instituteService
.
getInstituteForEdit
(
wiewsCode
);
final
String
mimeType
=
file
.
getContentType
();
try
{
...
...
@@ -610,7 +607,6 @@ public class WiewsController extends BaseController {
model
.
addAttribute
(
"thumbnailFormat"
,
"200x200"
);
model
.
addAttribute
(
"imageGallery"
,
imageGallery
);
model
.
addAttribute
(
"wiewsCode"
,
wiewsCode
);
model
.
addAttribute
(
"gallerySubPath"
,
gallerySubPath
);
return
MANAGE_FILES_JSP_PATH
+
"/gallery/details"
;
}
...
...
@@ -644,19 +640,30 @@ public class WiewsController extends BaseController {
}
redirectAttributes
.
addFlashAttribute
(
"successMessage"
,
"repository.gallery.successfully-updated"
);
return
"redirect:/wiews/"
+
wiewsCode
+
"/files/gallery"
;
return
"redirect:/wiews/"
+
wiewsCode
+
"/files/gallery"
;
}
@PostMapping
(
value
=
"{wiewsCode}/files/gallery/delete"
)
public
String
deleteFile
(
@RequestParam
String
galleryPath
,
RedirectAttributes
redirectAttributes
,
@PathVariable
(
"wiewsCode"
)
String
wiewsCode
)
throws
InvalidRepositoryPathException
{
public
String
deleteFile
(
@RequestParam
String
galleryPath
,
RedirectAttributes
redirectAttributes
,
@PathVariable
(
"wiewsCode"
)
String
wiewsCode
)
throws
InvalidRepositoryPathException
{
//check user permissions
instituteService
.
getInstituteForEdit
(
wiewsCode
);
ImageGallery
imageGallery
=
imageGalleryService
.
loadImageGallery
(
galleryPath
);
ImageGallery
imageGallery
=
imageGalleryService
.
loadImageGallery
(
galleryPath
);
imageGalleryService
.
removeGallery
(
imageGallery
);
redirectAttributes
.
addFlashAttribute
(
"successMessage"
,
"repository.gallery.removed"
);
return
"redirect:/wiews/"
+
wiewsCode
+
"/files/gallery"
;
return
"redirect:/wiews/"
+
wiewsCode
+
"/files/gallery"
;
}
@RequestMapping
(
value
=
"{wiewsCode}/files/download/metadata"
)
public
void
downloadMetadata
(
@PathVariable
(
"wiewsCode"
)
String
wiewsCode
,
HttpServletResponse
response
)
throws
IOException
{
final
String
repositoryPath
=
"/wiews/"
+
wiewsCode
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
wiewsCode
+
"_files_metadata.csv "
);
genesysService
.
downloadFilesMetadata
(
response
,
repositoryPath
);
}
@InitBinder
...
...
src/main/java/org/genesys2/spring/config/ApplicationConfig.java
View file @
5834281c
...
...
@@ -63,6 +63,7 @@ public class ApplicationConfig {
final
List
<
Resource
>
locations
=
new
ArrayList
<>();
locations
.
add
(
new
ClassPathResource
(
"application.properties"
));
locations
.
add
(
new
ClassPathResource
(
"files-metadata.properties"
));
locations
.
add
(
new
ClassPathResource
(
"genesys.properties"
));
final
String
extraConfigFile
=
System
.
getenv
(
"config.file"
);
...
...
src/main/resources/application.properties
View file @
5834281c
...
...
@@ -43,14 +43,6 @@ base.cookie-http-only=true
# robots.txt
robots.allow
=
false
db.url
=
jdbc:mysql://localhost/genesys?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
db.driverClassName
=
com.mysql.jdbc.Driver
db.username
=
root
db.password
=
db.showSql
=
false
db.hbm2ddl
=
false
hibernate.dialect
=
org.hibernate.dialect.MySQL5InnoDBDialect
google.api.key
=
AIzaSyBEvPuc8j5ps5GDQ3tdnTJaffKhfOdxFVc
google.url.shortener
=
https://www.googleapis.com/urlshortener/v1/url
news.menu.abbreviate.length
=
22
...
...
src/main/resources/content/language.properties
View file @
5834281c
...
...
@@ -866,6 +866,7 @@ repository.file.dateSubmitted=Date of submission
repository.file.lastModifiedDate
=
Last modified date
file.upload-file
=
Upload file
file.download-metadata
=
Download metadata
file.upload-file.help
=
Select file for upload from local computer
file.manage-files
=
Manage files
...
...
src/main/resources/content/language_ar.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=البحث في جينيسيس
welcome.networks
=
الشبكات
geo.country
=
الدولة:
file.download-metadata
=
تنزيل البيانات الوصفية
file.download-metadata
=
تنزيل البيانات الوصفية
article.is.template
=
هو القالب:
src/main/resources/content/language_de.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=Genesys durchsuchen
welcome.networks
=
Netzwerke
geo.country
=
Land:
file.download-metadata
=
Metadaten herunterladen
file.download-metadata
=
Metadaten herunterladen
article.is.template
=
Ist Vorlage:
src/main/resources/content/language_en.properties
View file @
5834281c
...
...
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
file.download-metadata
=
Download metadata
src/main/resources/content/language_es.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=Buscar en Genesys
welcome.networks
=
Redes
geo.country
=
País:
file.download-metadata
=
Descargar metadatos
file.download-metadata
=
Descargar metadatos
article.is.template
=
Es plantilla:
src/main/resources/content/language_fa.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=جستجو در Genesys
welcome.networks
=
شبکهها
geo.country
=
کشور:
file.download-metadata
=
دانلود ابرداده
file.download-metadata
=
دانلود ابرداده
article.is.template
=
الگو است:
src/main/resources/content/language_fr.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=Recherche sur Genesys
welcome.networks
=
Réseaux
geo.country
=
Pays :
file.download-metadata
=
Télécharger les métadonnées
file.download-metadata
=
Télécharger les métadonnées
article.is.template
=
Est-ce que le modèle:
src/main/resources/content/language_pt.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=Pesquisar no Genesys
welcome.networks
=
Redes
geo.country
=
País:
file.download-metadata
=
Baixar metadados
file.download-metadata
=
Baixar metadados
article.is.template
=
É modelo:
src/main/resources/content/language_ru.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=Поиск по Genesys
welcome.networks
=
Сети
geo.country
=
Страна:
file.download-metadata
=
Загрузить метаданные
file.download-metadata
=
Загрузить метаданные
article.is.template
=
Шаблон:
src/main/resources/content/language_zh.properties
View file @
5834281c
...
...
@@ -858,4 +858,6 @@ welcome.search-genesys=搜索Genesys
welcome.networks
=
网站
geo.country
=
国家/地区:
file.download-metadata
=
下載元數據
file.download-metadata
=
下載元數據
article.is.template
=
是模板
src/main/resources/files-metadata.properties
0 → 100644
View file @
5834281c
files.metadata.fields
=
originalFilename,extension,title,subject,description,creator,created,license,contentType
src/main/webapp/WEB-INF/jsp/wiews/files/index.jsp
View file @
5834281c
...
...
@@ -82,6 +82,13 @@
</tbody>
</table>
<form
style=
"padding-bottom: 5px;"
action=
"
<c:url
value=
"/wiews/${wiewsCode}/files/download/metadata"
><c:param
name=
"
${
_csrf
.
parameterName
}
"
value=
"
${
_csrf
.
token
}
"
/></c:url>
"
method=
"post"
enctype=
"multipart/form-data"
class=
""
>
<input
type=
"hidden"
name=
"wiewsCode"
value=
"${wiewsCode}"
/>
<input
type=
"hidden"
name=
"repositoryPath"
value=
"${currentPath}"
/>
<button
type=
"submit"
class=
"btn btn-primary"
><spring:message
code=
"file.download-metadata"
/></button>
</form>
<form
action=
"
<c:url
value=
"/wiews/${wiewsCode}/upload-file"
><c:param
name=
"
${
_csrf
.
parameterName
}
"
value=
"
${
_csrf
.
token
}
"
/></c:url>
"
method=
"post"
enctype=
"multipart/form-data"
class=
""
>
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment