Skip to content

Commit

Permalink
Merge branch '2023.06.x' into revert-995-issues/MIR-1304-remove_valid…
Browse files Browse the repository at this point in the history
…ation_until_validation_frequency_improved
  • Loading branch information
Antoniafriedrich authored Oct 7, 2024
2 parents 43e9eda + afcb647 commit 5a3fcdd
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 73 deletions.
35 changes: 15 additions & 20 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,21 @@ function migrateC3P0toHikari {
}


function setOrAddProperty() {
KEY=$1
VALUE=$2

if [ -z "$VALUE" ]; then
# remove property
sed -ri "/$KEY/d" "${MYCORE_PROPERTIES}"
return
elif [ -z "$KEY" ]; then
echo "No Key given. Skip setting property."
return
fi

if grep -q "$KEY=" "${MYCORE_PROPERTIES}" ; then
ESCAPED_KEY=$(echo "${KEY}" | sed 's/\//\\\//g')
ESCAPED_VALUE=$(echo "${VALUE}" | sed 's/\//\\\//g')
sed -ri "s/#*($ESCAPED_KEY=).+/\1$ESCAPED_VALUE/" "${MYCORE_PROPERTIES}"
else
echo "$KEY=$VALUE">>"${MYCORE_PROPERTIES}"
fi
function migrateJavaxPropertiesToJakarta() {
if grep -q "javax.persistence" "${PERSISTENCE_XML}"; then
echo "Migrate properties in persistence.xml from javax to jakarta"
sed -ri "s/(<property name=\")javax.persistence(.*\" value=\".*\" \/>)/\1jakarta.persistence\2/" "${PERSISTENCE_XML}"
fi
if grep -q "xmlns.jcp.org" "${PERSISTENCE_XML}"; then
echo "Migrate xmlns in persistence.xml from jcp.org to jakarta.ee"
sed -ri "s/xmlns=\".+persistence\"/xmlns=\"https:\/\/jakarta.ee\/xml\/ns\/persistence\"/" "${PERSISTENCE_XML}"
echo "Migrate schemaLocation in persistence.xml from jcp.org to jakarta.ee"
sed -ri "s/(xsi:schemaLocation=\").*jcp.org.*(\")/\1https:\/\/jakarta.ee\/xml\/ns\/persistence https:\/\/jakarta.ee\/xml\/ns\/persistence\/persistence_3_0.xsd\2/" "${PERSISTENCE_XML}"
fi
if grep -q "version=\"2" "${PERSISTENCE_XML}"; then
echo "Migrate version in persistence.xml from 2.* to 3.0"
sed -ri "s/version=\"2.*\"/version=\"3.0\"/" "${PERSISTENCE_XML}"
fi
}

function setDockerValues() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package org.mycore.mir.migration;

import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.servlet.ServletContext;
import org.mycore.backend.jpa.MCREntityManagerProvider;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.events.MCRStartupHandler.AutoExecutable;
import org.mycore.services.queuedjob.MCRJob;
import org.mycore.services.queuedjob.MCRJobQueue;
import org.mycore.services.queuedjob.MCRJobQueueManager;
import org.mycore.services.queuedjob.MCRJobStatus;
import org.mycore.services.queuedjob.MCRJob_;
import org.mycore.util.concurrent.MCRTransactionableRunnable;

import java.util.ArrayList;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

/**
* Class creates {@link MCRJob} in {@link MCRJobQueue} that migrates all static history content.
*
* @author shermann (Silvio Hermann)
* */
*/
public class MIRMigrateStaticHistoryContent implements AutoExecutable {

private static final Logger LOGGER = LogManager.getLogger();

static final Path STATIC_HISTORY_PATH = Path.of(
MCRConfiguration2.getStringOrThrow("MCR.Object.Static.Content.Default.Path"), "mir-history");

@Override
public String getName() {
return MIRMigrateStaticHistoryContent.class.getName();
Expand All @@ -38,7 +42,11 @@ public int getPriority() {
@Override
public void startUp(ServletContext servletContext) {
MCRTransactionableRunnable runnable = new MCRTransactionableRunnable(() -> {
if (!alreadyDone()) {
if (Files.notExists(STATIC_HISTORY_PATH)) {
LOGGER.info("No static content exists, nothing to do.");
} else if (alreadyDone()) {
LOGGER.info("Static content migration already scheduled, nothing to do.");
} else if (!alreadyDone()) {
MCRJobQueueManager
.getInstance()
.getJobQueue(MIRMigrateStaticHistoryContentJobAction.class)
Expand All @@ -49,18 +57,11 @@ public void startUp(ServletContext servletContext) {
}

private boolean alreadyDone() {
EntityManager manager = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder builder = manager.getCriteriaBuilder();
CriteriaQuery<MCRJob> criteria = builder.createQuery(MCRJob.class);
Root<MCRJob> root = criteria.from(MCRJob.class);

List<Predicate> predicates = new ArrayList<Predicate>();
predicates.add(builder.equal(root.get(MCRJob_.action), MIRMigrateStaticHistoryContentJobAction.class));
predicates.add(builder.equal(root.get(MCRJob_.status), MCRJobStatus.FINISHED));

criteria.where(predicates.toArray(new Predicate[] {}));
List<MCRJob> resultList = manager.createQuery(criteria).getResultList();

return resultList.size() > 0;
return MCRJobQueueManager
.getInstance()
.getJobDAO()
.getJobCount(MIRMigrateStaticHistoryContentJobAction.class, Collections.emptyMap(),
List.of(MCRJobStatus.FINISHED)) > 0;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.mycore.mir.migration;

import static org.mycore.mir.migration.MIRMigrateStaticHistoryContent.STATIC_HISTORY_PATH;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom2.Document;
import org.jdom2.input.SAXBuilder;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.metadata.MCRMetadataManager;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.services.queuedjob.MCRJob;
import org.mycore.services.queuedjob.MCRJobAction;
import org.mycore.services.queuedjob.staticcontent.MCRJobStaticContentGenerator;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitResult;
Expand All @@ -21,31 +21,27 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.ExecutionException;


/**
* Class converts all static history content on start up automatically.
*
* @author shermann (Silvio Hermann)
* */
public class MIRMigrateStaticHistoryContentJobAction extends MCRJobAction {
private Path staticHistoryPath;
private Logger logger;

private static final Logger LOGGER = LogManager.getLogger();

public MIRMigrateStaticHistoryContentJobAction(MCRJob job) {
super(job);
logger = LogManager.getLogger(MIRMigrateStaticHistoryContentJobAction.class);

staticHistoryPath = Path.of(
MCRConfiguration2.getStringOrThrow("MCR.Object.Static.Content.Default.Path") + File.separator
+ "mir-history");
}

@Override
public void execute() throws ExecutionException {
try {
SAXBuilder builder = new SAXBuilder();
Files.walkFileTree(staticHistoryPath, new SimpleFileVisitor<Path>() {
Files.walkFileTree(STATIC_HISTORY_PATH, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
String filename = file.getFileName().toString();
String id = filename.substring(0, filename.lastIndexOf('.'));

Expand All @@ -56,19 +52,19 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
try (InputStream is = Files.newInputStream(file)) {
Document history = builder.build(is);
if ("table".equals(history.getRootElement().getName())) {
logger.info("Migrating static history for object {}", id);
LOGGER.info("Migrating static history for object {}", id);
MCRJobStaticContentGenerator generator = new MCRJobStaticContentGenerator(
"mir-history");
generator.generate(MCRMetadataManager.retrieveMCRObject(MCRObjectID.getInstance(id)));
}
} catch (Exception e) {
logger.error("Could not migrate static mcr-history for file {}", file.getFileName(), e);
LOGGER.error("Could not migrate static mcr-history for file {}", file.getFileName(), e);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
logger.error("Error occurred during migration of static history content", e);
LOGGER.error("Error occurred during migration of static history content", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,9 @@
</div>
<div class="col-md-8 text-right mt-2 mt-md-0">
<button id="modalFrame-cancel" type="button" class="btn btn-danger mr-0 ml-1" data-dismiss="modal"></button>
<button id="modalFrame-send" type="button" class="btn btn-primary mr-0 ml-1"></button>
<button id="modalFrame-send" type="button" class="btn btn-primary mr-0 ml-1">
<xed:output i18n="button.select"/>
</button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ $(document).ready(function() {
var input = button.next().next("input");
var sortType = "";
let fq = button.data("fq");
//if no id is given set fq empty
if(fq == "-id:") {
fq = "";
}

//load genre classification
loadGenres(initContent);
Expand All @@ -99,7 +103,7 @@ $(document).ready(function() {
function initBody() {
$("#modalFrame-title").text(button.val());
$("#modalFrame-cancel").text($("button[name='_xed_submit_cancel']").text());
$("#modalFrame-send").text("Auswählen").attr("disabled", "").removeAttr("style");
$("#modalFrame-send").attr("disabled", "").removeAttr("style");
// TODO: check if you can remove HTML from js code (e.g. by a js template)
$("#modalFrame-body").append("<div id='main_left_content' class='list-group col-md-4' />");
$("#modalFrame-body").append("<div id='main_right_content' class='list-group col-md-8' />");
Expand All @@ -108,9 +112,14 @@ $(document).ready(function() {
$("#main_right_content").css("padding-left", "10px");
//create pagination
$("#modalFrame-body").append("<div class='col-12 mt-2'><nav style='clear: both'><ul class='modal-frame-pagination pagination justify-content-center'><li id='first' class='page-item previous disabled'><a href='#' class='page-link' data='0'>First</a></li><li id='previous' class='page-item previous disabled'><a href='#' class='page-link'>Previous</a></li><li class='page-item next disabled'><a href='#' class='page-link'>Next</a></li></ul></nav></div>");
$(".already-linked").after("<div class='col-md-4 type-select'><select class='form-control'><option value=''>Ohne Eingrenzung nach Typ:</option></select></div>");

if($(".type-select").length == 0) {
$(".already-linked").after("<div class='col-md-4 type-select'><select class='form-control'><option value=''>Ohne Eingrenzung nach Typ:</option></select></div>");
}

$("li a").css("cursor", "pointer");
$("#modal-searchInput").removeAttr("hidden");
$("#modal-searchInput button span").removeAttr("style");
$("#modal-searchInput > input").attr("autocomplete", "off");
$("#modalFrame").modal("show");
}
Expand Down Expand Up @@ -289,7 +298,7 @@ $(document).ready(function() {
dataType = "xml";
break;
case "select":
url = "servlets/solr/select?fq=" + fq + "q=" + qry + "&fq=objectType%3A\"mods\"&start=0&rows=10&XSL.Style=xml";
url = "servlets/solr/select?fq=" + fq + "&q=" + qry + "&fq=objectType%3A\"mods\"&start=0&rows=10&XSL.Style=xml";
dataType = "xml";
break;
case "receive":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ button.loading = Lade...
button.save = Speichern
button.saveandredirect = Speichern und hochladen...
button.search = Suchen...
button.select = Ausw\u00E4hlen
button.selectPerson = Person ausw\u00E4hlen

component.mods.metaData.dictionary.identifier.hdl = Handle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ button.loading = Loading...
button.save = Save
button.saveandredirect = Save and upload ...
button.search = Search...
button.select = Select
button.selectPerson = Select person

component.mods.metaData.dictionary.identifier.hdl = Handle
Expand Down
3 changes: 3 additions & 0 deletions mir-module/src/main/resources/config/mir/mycore.properties
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ MIR.Layout.Display.Div=mir-edit,mir-abstract-badges
#MIR.Layout.Display.Panel.Icon.mir-admindata=fas fa-info-circle
#MIR.Layout.Display.Panel.Icon.mir-citation=fas fa-quote-right

# Provide a classification for resolving the human-readable names of the abstract type
MIR.Layout.Abstract.Type.Classification=

MIR.NotFullAccessInfo.Genres=
MIR.Viewer.DisableDerivateType=thumbnail
##############################################################################
Expand Down
38 changes: 27 additions & 11 deletions mir-module/src/main/resources/xsl/metadata/mir-abstract.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<xsl:import href="xslImport:modsmeta:metadata/mir-abstract.xsl" />
<xsl:include href="resource:xsl/mir-utils.xsl" />

<xsl:param name="MIR.Layout.Abstract.Type.Classification"/>
<xsl:variable name="objectID" select="/mycoreobject/@ID" />
<xsl:variable name="modsPart" select="concat('mods.part.', $objectID)" />
<xsl:variable name="nbsp" select="'&#xa0;'"/>
Expand Down Expand Up @@ -217,12 +217,29 @@

<xsl:choose>
<xsl:when test="count($abstracts/mods:abstract) &gt; 1">
<xsl:variable name="has-abstract-in-current-lang" select="$abstracts/mods:abstract[@xml:lang=$CurrentLang]"/>
<xsl:variable name="first-abstract-in-current-lang-node" select="$abstracts/mods:abstract[@xml:lang=$CurrentLang][1]"/>
<xsl:variable name="first-abstract-in-current-lang-position">
<xsl:for-each select="$abstracts/mods:abstract">
<xsl:sort select="@type"/>
<xsl:sort select="@xml:lang"/>

<xsl:if test=".= $first-abstract-in-current-lang-node">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>

<div id="mir-abstract-tabs">
<ul class="nav nav-tabs justify-content-end" role="tablist">
<xsl:for-each select="$abstracts/mods:abstract">
<xsl:sort select="@type"/>
<xsl:sort select="@xml:lang"/>

<xsl:variable name="tabName">
<xsl:choose>
<xsl:when test="@type and $MIR.Layout.Abstract.Type.Classification">
<xsl:value-of select="mcrxsl:getDisplayName($MIR.Layout.Abstract.Type.Classification, @type)"/>
</xsl:when>
<xsl:when test="@xml:lang">
<xsl:value-of
select="document(concat('classification:metadata:0:children:rfc5646:',./@xml:lang))//category/label[@xml:lang=$CurrentLang]/@text" />
Expand All @@ -236,13 +253,11 @@
<li class="nav-item">
<a class="nav-link" href="#tab{position()}" role="tab" data-toggle="tab">
<xsl:choose>
<xsl:when test="$has-abstract-in-current-lang">
<xsl:if test="./@xml:lang=$CurrentLang">
<xsl:attribute name="class">active nav-link</xsl:attribute>
</xsl:if>
<xsl:when test="$first-abstract-in-current-lang-position = position()">
<xsl:attribute name="class">active nav-link</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position()=1">
<xsl:if test="position() = 1 and not($first-abstract-in-current-lang-position &gt;0)">
<xsl:attribute name="class">active nav-link</xsl:attribute>
</xsl:if>
</xsl:otherwise>
Expand All @@ -255,20 +270,21 @@
</ul>
<div class="tab-content">
<xsl:for-each select="$abstracts/mods:abstract">
<xsl:sort select="@type"/>
<xsl:sort select="@xml:lang"/>

<div class="tab-pane ellipsis ellipsis-text" role="tabpanel" id="tab{position()}">
<xsl:if test="@xml:lang">
<xsl:attribute name="lang">
<xsl:value-of select="@xml:lang" />
</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="$has-abstract-in-current-lang">
<xsl:if test="./@xml:lang=$CurrentLang">
<xsl:when test="$first-abstract-in-current-lang-position = position()">
<xsl:attribute name="class">tab-pane ellipsis ellipsis-text active</xsl:attribute>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position()=1">
<xsl:if test="position() = 1 and not($first-abstract-in-current-lang-position &gt;0)">
<xsl:attribute name="class">tab-pane ellipsis ellipsis-text active</xsl:attribute>
</xsl:if>
</xsl:otherwise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<xsl:text>:</xsl:text>
</td>
<td class="metavalue">
<xsl:variable name="verinfo" select="document(concat('versioninfo:',mycoreobject/@ID))"/>
<xsl:variable name="verinfo" select="document(concat('notnull:staticcontent:mir-history:', mycoreobject/@ID))"/>
<xsl:variable name="revision">
<xsl:call-template name="UrlGetParam">
<xsl:with-param name="url" select="$RequestURL"/>
Expand Down

0 comments on commit 5a3fcdd

Please sign in to comment.