Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
AoU-Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AoU
AoU-Backend
Merge requests
!669
refactor: solidify sitemap controller
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
refactor: solidify sitemap controller
HCA-solidifySiteMap
into
master
Overview
0
Commits
5
Pipelines
0
Changes
8
Merged
Hugues.Cazeaux
requested to merge
HCA-solidifySiteMap
into
master
2 years ago
Overview
0
Commits
5
Pipelines
0
Changes
8
Expand
0
0
Merge request reports
Compare
master
version 3
cd3edcb5
2 years ago
version 2
a8784bc7
2 years ago
version 1
e98d2074
2 years ago
master (base)
and
latest version
latest version
687913dc
5 commits,
2 years ago
version 3
cd3edcb5
4 commits,
2 years ago
version 2
a8784bc7
4 commits,
2 years ago
version 1
e98d2074
3 commits,
2 years ago
8 files
+
28
−
224
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
AoU-Access/src/main/java/ch/unige/aou/controller/SitemapController.java
+
27
−
62
Options
package
ch.unige.aou.controller
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
ch.unige.solidify.config.SolidifyProperties
;
import
ch.unige.solidify.controller.SolidifySitemapController
;
import
ch.unige.solidify.rest.FacetPage
;
import
ch.unige.solidify.rest.SearchCondition
;
import
ch.unige.solidify.security.EveryonePermissions
;
import
ch.unige.solidify.service.IndexResourceService
;
import
ch.unige.aou.AouConstants
;
import
ch.unige.aou.config.AouProperties
;
import
ch.unige.aou.model.index.PublicationIndexEntry
;
import
ch.unige.aou.model.sitemap.Sitemap
;
import
ch.unige.aou.model.sitemap.SitemapIndex
;
import
ch.unige.aou.model.sitemap.XmlUrl
;
import
ch.unige.aou.model.sitemap.XmlUrlSet
;
import
ch.unige.aou.rest.AouActionName
;
@RestController
@ConditionalOnBean
(
AccessController
.
class
)
public
class
SitemapController
{
public
class
SitemapController
extends
SolidifySitemapController
{
public
static
final
int
SIZE_SITEMAP
=
100
;
private
final
String
homepage
;
private
final
String
indexName
;
private
final
IndexResourceService
<
String
,
PublicationIndexEntry
>
indexResourceService
;
public
SitemapController
(
AouProperties
aouProperties
,
IndexResourceService
<
String
,
PublicationIndexEntry
>
indexResourceService
)
{
this
.
homepage
=
aouProperties
.
getParameters
().
getHomepage
();
public
SitemapController
(
SolidifyProperties
config
,
AouProperties
aouProperties
,
IndexResourceService
<
String
,
PublicationIndexEntry
>
indexResourceService
)
{
super
(
config
,
aouProperties
.
getParameters
().
getHomepage
());
this
.
indexName
=
aouProperties
.
getIndexing
().
getPublishedPublicationsIndexName
();
this
.
indexResourceService
=
indexResourceService
;
}
@EveryonePermissions
@GetMapping
(
value
=
AouActionName
.
SITEMAP
,
produces
=
MediaType
.
APPLICATION_XML_VALUE
)
public
SitemapIndex
getSiteMapIndex
()
{
SitemapIndex
sitemapIndex
=
new
SitemapIndex
();
// Get total of archives stocked in ES
long
total
=
this
.
getTotalArchives
();
for
(
int
i
=
0
;
i
<
total
;
i
=
i
+
SIZE_SITEMAP
)
{
this
.
createSitemap
(
sitemapIndex
,
"/sitemap.xml?from="
+
i
);
}
return
sitemapIndex
;
}
@EveryonePermissions
@GetMapping
(
value
=
AouActionName
.
SITEMAP
,
params
=
"from"
,
produces
=
MediaType
.
APPLICATION_XML_VALUE
)
public
XmlUrlSet
getByArchiveId
(
@RequestParam
(
name
=
"from"
)
String
from
)
{
XmlUrlSet
xmlUrlSet
=
new
XmlUrlSet
();
List
<
PublicationIndexEntry
>
archives
=
this
.
getArchivesFrom
(
Integer
.
parseInt
(
from
));
for
(
int
i
=
0
;
i
<
archives
.
size
();
i
++)
{
this
.
createXmlUrl
(
xmlUrlSet
,
"/"
+
archives
.
get
(
i
).
getArchiveId
(),
"never"
,
XmlUrl
.
Priority
.
HIGH
);
}
return
xmlUrlSet
;
}
private
void
createXmlUrl
(
XmlUrlSet
xmlUrlSet
,
String
link
,
String
changeFrec
,
XmlUrl
.
Priority
priority
)
{
xmlUrlSet
.
addUrl
(
new
XmlUrl
(
this
.
homepage
+
link
,
changeFrec
,
priority
));
}
private
void
createSitemap
(
SitemapIndex
sitemapIndex
,
String
link
)
{
sitemapIndex
.
addSitemap
(
new
Sitemap
(
this
.
homepage
+
link
));
}
public
long
getTotalArchives
()
{
@Override
protected
long
getItemsTotal
()
{
Pageable
pageable
=
PageRequest
.
of
(
0
,
1
);
FacetPage
<
PublicationIndexEntry
>
result
s
=
this
.
get
Result
s
(
pageable
);
return
result
s
.
getTotalElements
();
FacetPage
<
PublicationIndexEntry
>
result
=
this
.
get
Publication
s
(
pageable
);
return
result
.
getTotalElements
();
}
public
List
<
PublicationIndexEntry
>
getArchivesFrom
(
int
from
)
{
int
page
;
@Override
protected
List
<
String
>
getItemsFrom
(
int
from
)
{
int
page
=
0
;
if
(
from
>
0
)
{
page
=
from
/
SIZE_SITEMAP
;
}
else
{
page
=
0
;
page
=
from
/
this
.
getPageSize
();
}
Pageable
pageable
=
PageRequest
.
of
(
page
,
SIZE_SITEMAP
,
Sort
.
by
(
AouConstants
.
INDEX_FIELD_ARCHIVE_ID_INT
));
FacetPage
<
PublicationIndexEntry
>
results
=
this
.
getResults
(
pageable
);
return
results
.
getContent
();
Pageable
pageable
=
PageRequest
.
of
(
page
,
this
.
getPageSize
(),
Sort
.
by
(
AouConstants
.
INDEX_FIELD_ARCHIVE_ID_INT
));
FacetPage
<
PublicationIndexEntry
>
result
=
this
.
getPublications
(
pageable
);
return
result
.
stream
().
map
(
PublicationIndexEntry:
:
getArchiveId
).
collect
(
Collectors
.
toList
());
}
@Override
protected
List
<
String
>
getExtraUrls
()
{
return
Collections
.
emptyList
();
}
p
ublic
FacetPage
<
PublicationIndexEntry
>
get
Result
s
(
Pageable
pageable
)
{
p
rivate
FacetPage
<
PublicationIndexEntry
>
get
Publication
s
(
Pageable
pageable
)
{
List
<
SearchCondition
>
searchConditionList
=
new
ArrayList
<>();
return
this
.
indexResourceService
.
search
(
this
.
indexName
,
searchConditionList
,
null
,
pageable
);
}
Loading