Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
annawolf committed Feb 27, 2025
2 parents 8e02162 + 05094f5 commit f36ec9f
Show file tree
Hide file tree
Showing 23 changed files with 453 additions and 334 deletions.
4 changes: 2 additions & 2 deletions goobi-viewer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<reflections.version>0.10.2</reflections.version>
<rome.version>2.1.0</rome.version>
<spring.version>6.2.3</spring.version>
<slf4j.version>2.0.16</slf4j.version>
<slf4j.version>2.0.17</slf4j.version>
<solr.version>9.8.0</solr.version>
<swagger.version>2.2.28</swagger.version>
<tomcat.version>10.1.31</tomcat.version>
Expand Down Expand Up @@ -1187,7 +1187,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.21.2</version>
<version>10.21.3</version>
</dependency>
</dependencies>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public String getBookmarkListAsRSS(
throws DAOException, IOException, RestApiException, ContentLibException {
BookmarkList list = getBookmarkList(id);
String query = list.generateSolrQueryForItems();
return RSSFeed.createRssFeed(language, maxHits, null, query, null, servletRequest, null, true);
return RSSFeed.createRssFeedString(language, maxHits, null, query, null, servletRequest, null, true);
}

@GET
Expand Down Expand Up @@ -409,6 +409,6 @@ public String getSharedBookmarkListAsRSS(
throws DAOException, RestApiException, ContentLibException {
BookmarkList list = getSharedBookmarkListByKey(key);
String query = list.generateSolrQueryForItems();
return RSSFeed.createRssFeed(language, maxHits, null, query, null, servletRequest, null, true);
return RSSFeed.createRssFeedString(language, maxHits, null, query, null, servletRequest, null, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getRssFeed(
@QueryParam("sortDescending") Boolean sortDescending)
throws ContentLibException {

return RSSFeed.createRssFeed(language, maxHits, subtheme, query, facets, servletRequest, sortField, sortDescending == null || sortDescending);
return RSSFeed.createRssFeedString(language, maxHits, subtheme, query, facets, servletRequest, sortField, sortDescending == null || sortDescending);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public boolean update(IDAO dao, CMSTemplateManager templateManager) throws DAOEx
}

}

dao.executeUpdate("RENAME TABLE roles TO user_roles");
return true;
}

return true;
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
import java.sql.SQLException;
import java.util.Objects;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import io.goobi.viewer.controller.StringConstants;
import io.goobi.viewer.dao.IDAO;
import io.goobi.viewer.exceptions.DAOException;
import io.goobi.viewer.model.cms.pages.CMSTemplateManager;

public class TranslationUpdate implements IModelUpdate {

private static final Logger logger = LogManager.getLogger(TranslationUpdate.class);

private static final String[] TABLES = { "cs_campaign_translations", "cms_geomap_translation", "terms_of_use_translations", "translations" };

/** {@inheritDoc} */
Expand All @@ -42,6 +47,7 @@ public boolean update(IDAO dao, CMSTemplateManager templateManager) throws DAOEx
if (dao.tableExists(table)) {
boolean newColumnHasEntries = dao.getNativeQueryResults("SELECT translation_value FROM " + table).stream().anyMatch(Objects::nonNull);
if (!newColumnHasEntries) {
logger.debug("Updating table: {}", table);
dao.executeUpdate(StringConstants.SQL_ALTER_TABLE + table + " DROP translation_value;");
try {
dao.executeUpdate(StringConstants.SQL_ALTER_TABLE + table + " RENAME COLUMN value TO translation_value");
Expand All @@ -54,12 +60,11 @@ public boolean update(IDAO dao, CMSTemplateManager templateManager) throws DAOEx
if (!dao.columnsExists("cms_pages", "page_template_id")) {
dao.executeUpdate(StringConstants.SQL_ALTER_TABLE + table + " ADD COLUMN page_template_id varchar(255);");
}

return true;
}

}
}

return true;
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public class UserUpdate implements IModelUpdate {
@Override
@SuppressWarnings("unchecked")
public boolean update(IDAO dao, CMSTemplateManager templateManager) throws DAOException, SQLException {
boolean ret = false;

// Update table name
if (dao.tableExists("users")) {

// Delete new table with anonymous use, if already created by EclipseLink
if (dao.tableExists(TABLE_NAME_CURRENT)) {
boolean newTableEmpty = dao.getNativeQueryResults("SELECT * FROM " + TABLE_NAME_CURRENT).size() <= 1;
Expand All @@ -52,8 +54,9 @@ public boolean update(IDAO dao, CMSTemplateManager templateManager) throws DAOEx
}

}

dao.executeUpdate("RENAME TABLE users TO " + TABLE_NAME_CURRENT);
ret = true;
}

if (dao.columnsExists(TABLE_NAME_CURRENT, "use_gravatar")) {
Expand All @@ -62,9 +65,10 @@ public boolean update(IDAO dao, CMSTemplateManager templateManager) throws DAOEx
dao.executeUpdate("UPDATE " + TABLE_NAME_CURRENT + " SET avatar_type='GRAVATAR' WHERE " + TABLE_NAME_CURRENT + ".user_id=" + userId);
}
dao.executeUpdate(StringConstants.SQL_ALTER_TABLE + TABLE_NAME_CURRENT + " DROP COLUMN use_gravatar");
ret = true;
}

return true;
return ret;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public List<ArchiveResource> getFilteredDatabases() {
} else {
try {
if (AccessConditionUtils
.checkAccessPermissionByIdentifierAndLogId(resource.getResourceId(), null, IPrivilegeHolder.PRIV_LIST,
.checkAccessPermissionByIdentifierAndLogId(resource.getResourceId(), null, IPrivilegeHolder.PRIV_ARCHIVE_DISPLAY_NODE,
BeanUtils.getRequest())
.isGranted()) {
ret.add(resource);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* This file is part of the Goobi viewer - a content presentation and management
* application for digitized objects.
*
* Visit these websites for more information.
* - http://www.intranda.com
* - http://digiverso.com
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.goobi.viewer.managedbeans;

import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.rometools.rome.feed.synd.SyndEntry;

import de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException;
import io.goobi.viewer.controller.DataManager;
import io.goobi.viewer.exceptions.DAOException;
import io.goobi.viewer.exceptions.IndexUnreachableException;
import io.goobi.viewer.exceptions.PresentationException;
import io.goobi.viewer.exceptions.ViewerConfigurationException;
import io.goobi.viewer.managedbeans.utils.BeanUtils;
import io.goobi.viewer.model.rss.Channel;
import io.goobi.viewer.model.rss.RSSFeed;
import io.goobi.viewer.model.search.SearchAggregationType;
import io.goobi.viewer.model.search.SearchFacets;
import io.goobi.viewer.model.search.SearchHelper;
import io.goobi.viewer.servlets.utils.ServletUtils;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;

@Named("rssBean")
@RequestScoped
public class RSSBean {

private static final Logger logger = LogManager.getLogger(RSSBean.class);

/**
*
* @param maxHits
* @param query
* @param sortField
* @param sortDescending
* @return List<SyndEntry>
*/
public List<SyndEntry> getRssFeed(Integer maxHits, String query, String sortField, Boolean sortDescending) {
try {
return RSSFeed.createRssFeed(null, maxHits, null, query, null, BeanUtils.getRequest(), sortField,
sortDescending == null || sortDescending).getEntries();

} catch (PresentationException | IndexUnreachableException | ViewerConfigurationException | DAOException e) {
logger.error(e.getMessage());
}

return Collections.emptyList();
}

/**
*
* @param maxHits
* @param query
* @param sortField
* @param sortDescending
* @return {@link Channel}
*/
public Channel getRssFeedChannel(Integer maxHits, String query, String sortField, Boolean sortDescending) {
try {
return RSSFeed.createRssResponse(null, maxHits, null, query, null, BeanUtils.getRequest(), sortField,
sortDescending == null || sortDescending);

} catch (ContentLibException e) {
logger.error(e.getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public boolean isAccessAllowed() {

try {
boolean ret = AccessConditionUtils
.checkAccessPermissionByIdentifierAndLogId(topstructPi, logId, IPrivilegeHolder.PRIV_LIST, BeanUtils.getRequest())
.checkAccessPermissionByIdentifierAndLogId(topstructPi, logId, IPrivilegeHolder.PRIV_ARCHIVE_DISPLAY_NODE, BeanUtils.getRequest())
.isGranted();
if (!ret) {
logger.trace("Access denied to {}", label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static SyndFeed createRss(String rootPath, String query, List<String> fil
List<SyndEntry> entries = new ArrayList<>();

String sortOrder = sortDescending ? "desc" : "asc";
logger.trace("RSS query: {}", query);
SolrDocumentList docs = DataManager.getInstance()
.getSearchIndex()
.search(query, 0, maxItems,
Expand Down Expand Up @@ -732,33 +733,57 @@ public static Channel createRssResponse(final String language, final Integer max
* @return RSS feed as {@link String}
* @throws ContentLibException
*/
public static String createRssFeed(final String language, final Integer maxHits, String subtheme, final String query, String facets,
public static String createRssFeedString(final String language, final Integer maxHits, String subtheme, final String query, String facets,
HttpServletRequest servletRequest, String sortField, boolean sortDescending)
throws ContentLibException {
try {
String q = createQuery(query, null, subtheme, servletRequest, false);
if (StringUtils.isNotBlank(q)) {
q = SearchHelper.buildFinalQuery(q, false, servletRequest, SearchAggregationType.AGGREGATE_TO_TOPSTRUCT);
}

// Optional faceting
List<String> filterQueries = null;
if (StringUtils.isNotBlank(facets)) {
SearchFacets searchFacets = new SearchFacets();
searchFacets.setActiveFacetString(facets);
filterQueries = searchFacets.generateFacetFilterQueries(true);
}

SyndFeedOutput output = new SyndFeedOutput();
return output
.outputString(RSSFeed.createRss(ServletUtils.getServletPathWithHostAsUrlFromRequest(servletRequest), q, filterQueries,
language != null ? language : servletRequest.getLocale().getLanguage(),
maxHits != null ? maxHits : DataManager.getInstance().getConfiguration().getRssFeedItems(), sortField, sortDescending));
.outputString(createRssFeed(language, maxHits, subtheme, query, facets, servletRequest, sortField, sortDescending));

} catch (PresentationException | IndexUnreachableException | ViewerConfigurationException | DAOException | FeedException e) {
throw new ContentLibException(e.toString());
}
}

/**
*
* @param language
* @param maxHits
* @param subtheme
* @param query
* @param facets
* @param servletRequest
* @param sortField
* @param sortDescending
* @return {@link SyndFeed}
* @throws PresentationException
* @throws IndexUnreachableException
* @throws ViewerConfigurationException
* @throws DAOException
*/
public static SyndFeed createRssFeed(final String language, final Integer maxHits, String subtheme, final String query, String facets,
HttpServletRequest servletRequest, String sortField, boolean sortDescending)
throws PresentationException, IndexUnreachableException, ViewerConfigurationException, DAOException {
String q = createQuery(query, null, subtheme, servletRequest, false);
if (StringUtils.isNotBlank(q)) {
q = SearchHelper.buildFinalQuery(q, false, servletRequest, SearchAggregationType.AGGREGATE_TO_TOPSTRUCT);
}

// Optional faceting
List<String> filterQueries = null;
if (StringUtils.isNotBlank(facets)) {
SearchFacets searchFacets = new SearchFacets();
searchFacets.setActiveFacetString(facets);
filterQueries = searchFacets.generateFacetFilterQueries(true);
}

return RSSFeed.createRss(ServletUtils.getServletPathWithHostAsUrlFromRequest(servletRequest), q, filterQueries,
language != null ? language : servletRequest.getLocale().getLanguage(),
maxHits != null ? maxHits : DataManager.getInstance().getConfiguration().getRssFeedItems(), sortField, sortDescending);

}

/**
*
* @param query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected AbstractPrivilegeHolder() {
protected static final String[] PRIVS_RECORD =
{ PRIV_LIST, PRIV_VIEW_THUMBNAILS, PRIV_VIEW_IMAGES, PRIV_VIEW_VIDEO, PRIV_VIEW_AUDIO, PRIV_VIEW_FULLTEXT, PRIV_VIEW_METADATA,
PRIV_ZOOM_IMAGES, PRIV_DOWNLOAD_IMAGES, PRIV_DOWNLOAD_ORIGINAL_CONTENT, PRIV_DOWNLOAD_PAGE_PDF, PRIV_DOWNLOAD_PDF,
PRIV_DOWNLOAD_METADATA, PRIV_GENERATE_IIIF_MANIFEST, PRIV_VIEW_UGC, PRIV_DOWNLOAD_BORN_DIGITAL_FILES };
PRIV_DOWNLOAD_METADATA, PRIV_GENERATE_IIIF_MANIFEST, PRIV_VIEW_UGC, PRIV_DOWNLOAD_BORN_DIGITAL_FILES, PRIV_ARCHIVE_DISPLAY_NODE };

/** Constant array containing all constants for CMS privileges. */
protected static final String[] PRIVS_CMS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public interface IPrivilegeHolder {
public static final String PREFIX_TICKET = "TICKET_";
/** Constant <code>PREFIX_PRIV="PRIV_"</code> */
public static final String PREFIX_PRIV = "PRIV_";

/** Constant <code>PRIV_ARCHIVE_DISPLAY_NODE="PRIV_ARCHIVE_DISPLAY_NODE"</code> */
public static final String PRIV_ARCHIVE_DISPLAY_NODE = "ARCHIVE_DISPLAY_NODE";
/** Constant <code>PRIV_LIST="LIST"</code> */
public static final String PRIV_LIST = "LIST";
/** Constant <code>PRIV_VIEW_IMAGES="VIEW_IMAGES"</code> */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,17 @@ public static boolean isImageOrPdfDownloadAllowed(String mimeTypeName) {

return mimeType.isImageOrPdfDownloadAllowed();
}

public static String getSpecificMimeType(String mimeType) {
if (StringUtils.isBlank(mimeType)) {
return "";
}

String useName = mimeType;
if (useName.contains("/")) {
return useName.substring(useName.indexOf("/") + 1);
} else {
return "";
}
}
}
Loading

0 comments on commit f36ec9f

Please sign in to comment.