From 4f8cdeede6851188def8254993bfb862d30aabe6 Mon Sep 17 00:00:00 2001 From: Thomas Scheffler Date: Thu, 9 Jan 2025 14:12:15 +0100 Subject: [PATCH] Update mir 2024 (#283) * update to MyCoRe/MIR 2024.06.x * fixes along the way and delete IdentifierExtractorEventHandler --- pom.xml | 2 +- ...ntifierExtractorDefaultPrefixProvider.java | 36 -- .../IdentifierExtractorEventHandler.java | 317 ------------------ .../IdentifierExtractorPrefixProvider.java | 35 -- .../de/urmel_dl/dbt/events/package-info.java | 27 -- .../dbt/opc/datamodel/Catalogues.java | 34 +- .../dbt/rc/commandline/RCCommands.java | 2 +- .../de/urmel_dl/dbt/rc/datamodel/Period.java | 163 +++++---- .../urmel_dl/dbt/rc/datamodel/RCCalendar.java | 61 ++-- .../dbt/rc/persistency/SlotManager.java | 106 ++---- .../dbt/rc/resolver/PeriodResolver.java | 14 +- .../dbt/rc/servlets/SlotListServlet.java | 2 +- .../de/urmel_dl/dbt/utils/EntityFactory.java | 55 +-- .../DBTViewerConfigurationStrategy.java | 6 +- .../META-INF/resources/scss/dbt/_rc.scss | 4 +- .../resources/config/dbt/mycore.properties | 3 +- src/main/resources/rccalendar.xml | 6 +- src/main/resources/xsl/rc/periods2options.xsl | 6 +- .../TestIdentifierExtractorEventHandler.java | 76 ----- .../java/de/urmel_dl/dbt/rc/TestPeriod.java | 80 ++--- .../de/urmel_dl/dbt/rc/TestRCCalendar.java | 32 +- 21 files changed, 240 insertions(+), 827 deletions(-) delete mode 100644 src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorDefaultPrefixProvider.java delete mode 100644 src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorEventHandler.java delete mode 100644 src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorPrefixProvider.java delete mode 100644 src/main/java/de/urmel_dl/dbt/events/package-info.java delete mode 100644 src/test/java/de/urmel_dl/dbt/events/TestIdentifierExtractorEventHandler.java diff --git a/pom.xml b/pom.xml index 1438ec19..46f2abb9 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ true ${java.target.version} ${project.build.directory}/media - 2023.06.3-SNAPSHOT + 2024.06.1-SNAPSHOT v16.19.1 6.14.18 ${project.build.directory}/rcclient diff --git a/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorDefaultPrefixProvider.java b/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorDefaultPrefixProvider.java deleted file mode 100644 index 9873b2ce..00000000 --- a/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorDefaultPrefixProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Digitale Bibliothek Thüringen repository software. - * Copyright (c) 2000 - 2016 - * See and - * - * 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 3 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 . - */ -package de.urmel_dl.dbt.events; - -import org.mycore.mods.MCRMODSWrapper; - -/** - * @author Ren\u00E9 Adler (eagle) - * - */ -public class IdentifierExtractorDefaultPrefixProvider implements IdentifierExtractorPrefixProvider { - - /* (non-Javadoc) - * @see de.urmel_dl.dbt.events.IdentifierExtractorPrefixProvider#getPrefix(org.mycore.mods.MCRMODSWrapper) - */ - @Override - public String getPrefix(MCRMODSWrapper mods) { - return "gvk"; - } - -} diff --git a/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorEventHandler.java b/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorEventHandler.java deleted file mode 100644 index 43dfc0a6..00000000 --- a/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorEventHandler.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * This file is part of the Digitale Bibliothek Thüringen repository software. - * Copyright (c) 2000 - 2016 - * See and - * - * 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 3 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 . - */ -package de.urmel_dl.dbt.events; - -import java.text.MessageFormat; -import java.text.Normalizer; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.jdom2.Element; -import org.jdom2.filter.Filters; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; -import org.jdom2.xpath.XPathExpression; -import org.jdom2.xpath.XPathFactory; -import org.mycore.common.MCRConstants; -import org.mycore.common.config.MCRConfiguration2; -import org.mycore.common.events.MCREvent; -import org.mycore.common.events.MCREventHandlerBase; -import org.mycore.datamodel.metadata.MCRObject; -import org.mycore.mods.MCRMODSWrapper; - -import de.urmel_dl.dbt.opc.OPCConnector; -import de.urmel_dl.dbt.opc.datamodel.pica.PPField; -import de.urmel_dl.dbt.opc.datamodel.pica.PPSubField; -import de.urmel_dl.dbt.opc.datamodel.pica.Record; -import de.urmel_dl.dbt.opc.datamodel.pica.Result; - -/** - * @author Ren\u00E9 Adler (eagle) - * - */ -public class IdentifierExtractorEventHandler extends MCREventHandlerBase { - - private static final Logger LOGGER = LogManager.getLogger(IdentifierExtractorEventHandler.class); - - private static final IdentifierExtractorPrefixProvider PREFIX_SINGELTON = MCRConfiguration2 - . getInstanceOf("MIR.IdentifierExtractor.Prefix.Class") - .orElseGet(IdentifierExtractorDefaultPrefixProvider::new); - - private static final String URI_SYNTAX = "http://uri.gbv.de/document/{0}:ppn:{1}"; - - private static final String QUERY_FILTER = "[-+]"; - - /* (non-Javadoc) - * @see org.mycore.common.events.MCREventHandlerBase#handleObjectCreated(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject) - */ - @Override - synchronized protected void handleObjectCreated(MCREvent evt, MCRObject obj) { - if (!obj.getId().getTypeId().equals("mods")) { - return; - } - - MCRMODSWrapper mods = new MCRMODSWrapper(obj); - - try { - final String prefix = PREFIX_SINGELTON.getPrefix(mods); - - if (mods.getElements("mods:identifier[@type='uri']").stream() - .noneMatch(e -> e.getText() - .contains(new MessageFormat(URI_SYNTAX, Locale.ROOT).format(new Object[] { prefix, "" })))) { - final OPCConnector opc = new OPCConnector(); - opc.setMaxHits(50); - - final List titleInfos = mods.getElements("mods:titleInfo"); - titleInfos.parallelStream().forEach(titleInfo -> { - try { - final String query = buildQuery(titleInfo); - final Result result = opc.search(query); - - if (result.getRecords().isEmpty()) { - LOGGER.info("Nothing was found for title " + query); - } else { - result.getRecords().parallelStream().map(record -> { - record.load(true); - return record; - }).filter(record -> Optional.ofNullable(record.getFieldByTag("002@")) - .map(f -> f.getSubfieldByCode("0")).map(sf -> sf.getContent().startsWith("O")) - .orElse(false) && matchTitle(titleInfo, record) - && matchPersons(mods.getElements("mods:name[@type='personal']"), record, opc)) - .findFirst() - .ifPresent(record -> { - LOGGER.info("Found PPN " + record.getPPN()); - - final Element mId = mods.addElement("identifier"); - mId.setAttribute("type", "uri"); - mId.addContent(new MessageFormat(URI_SYNTAX, Locale.ROOT) - .format(new Object[] { prefix, record.getPPN() })); - - final List persons = mods.getElements("mods:name[@type='personal']"); - persons.parallelStream() - .filter(person -> buildXPath("mods:nameIdentifier[@type='gnd']") - .evaluateFirst(person) == null) - .forEach(person -> { - final String gnd = extractPersonIdentifier("gnd", - buildXPath("mods:displayForm").evaluateFirst(person), record, opc); - if (gnd != null) { - final Element mNId = new Element("nameIdentifier", - MCRConstants.MODS_NAMESPACE); - mNId.setAttribute("type", "gnd"); - mNId.addContent(gnd); - person.addContent(mNId); - } - }); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(new XMLOutputter(Format.getPrettyFormat()) - .outputString(obj.createXML())); - } - }); - } - } catch (ExecutionException e1) { - LOGGER.error("Error on extract identifiers for object " + obj, e1); - } - }); - } - } catch (Exception e) { - LOGGER.error("Error on extract identifiers for object " + obj, e); - } - } - - /* (non-Javadoc) - * @see org.mycore.common.events.MCREventHandlerBase#handleObjectUpdated(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject) - */ - @Override - synchronized protected void handleObjectUpdated(MCREvent evt, MCRObject obj) { - handleObjectCreated(evt, obj); - } - - /* (non-Javadoc) - * @see org.mycore.common.events.MCREventHandlerBase#handleObjectRepaired(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject) - */ - @Override - synchronized protected void handleObjectRepaired(MCREvent evt, MCRObject obj) { - handleObjectCreated(evt, obj); - } - - /* (non-Javadoc) - * @see org.mycore.common.events.MCREventHandlerBase#handleObjectIndex(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject) - */ - @Override - synchronized protected void handleObjectIndex(MCREvent evt, MCRObject obj) { - handleObjectCreated(evt, obj); - } - - private XPathExpression buildXPath(String xPath) { - return XPathFactory.instance().compile(xPath, Filters.element(), null, MCRConstants.MODS_NAMESPACE, - MCRConstants.XLINK_NAMESPACE); - } - - private String buildQuery(final Element titleInfo) { - final StringBuffer sb = new StringBuffer(); - - final Element title = buildXPath("mods:title").evaluateFirst(titleInfo); - final Element subTitle = buildXPath("mods:subTitle").evaluateFirst(titleInfo); - - if (title != null && title.getTextNormalize().length() > 3) { - sb.append("tit " + title.getTextNormalize().replaceAll(QUERY_FILTER, "")); - } - if (subTitle != null) { - if (sb.length() > 0) { - sb.append(" or "); - } - sb.append("tit " + subTitle.getTextNormalize().replaceAll(QUERY_FILTER, "")); - } - - return sb.toString(); - } - - private boolean matchTitle(final Element titleInfo, final Record record) { - if (titleInfo != null && record != null) { - final List titFields = record.getFieldsByTag("021A"); - if (!titFields.isEmpty()) { - final StringBuffer sb = new StringBuffer(); - - final Element title = buildXPath("mods:title").evaluateFirst(titleInfo); - final Element subTitle = buildXPath("mods:subTitle").evaluateFirst(titleInfo); - - if (title != null && title.getTextNormalize().length() > 3) { - sb.append(title.getTextNormalize()); - } - if (subTitle != null) { - if (sb.length() > 0) { - sb.append(" "); - } - sb.append(subTitle.getTextNormalize()); - } - - for (final PPField titField : titFields) { - int confidence = partsCompare(sb.toString(), - Arrays.stream("a,d".split(",")).map(s -> titField.getSubfieldByCode(s)) - .filter(sc -> sc != null).map(sc -> sc.getContent()) - .collect(Collectors.joining(", "))); - if (confidence > 75) { - LOGGER.info( - "Title \"" + sb.toString() + "\" matches with a confidence of " + confidence + "%."); - return true; - } - } - } - } - - return false; - } - - private boolean matchPerson(final Element displayForm, final Record record, - final OPCConnector opc) { - if (displayForm != null && record != null) { - List nameFields = Arrays.stream("028A,028B,028C,028D,028E,028F,028G,028H,028L,028M".split(",")) - .map(tag -> record.getFieldsByTag(tag)).flatMap(l -> l.stream()).collect(Collectors.toList()); - - for (final PPField f : nameFields) { - int confidence = partsCompare(displayForm.getTextTrim(), - Arrays.stream("d,a,c".split(",")).map(s -> f.getSubfieldByCode(s)).filter(sc -> sc != null) - .map(sc -> sc.getContent()).collect(Collectors.joining(", "))); - - if (confidence > 50) { - LOGGER.info("Person \"" + displayForm.getTextTrim() + "\" matches with a confidence of " - + confidence + "%."); - - return true; - } - } - } - - return false; - } - - private boolean matchPersons(final List persons, final Record record, - final OPCConnector opc) { - long numMatching = persons.parallelStream().map(person -> matchPerson( - buildXPath("mods:displayForm").evaluateFirst(person), record, opc)).count(); - - return Math.round(100 / persons.size() * numMatching) > 75; - } - - private String extractPersonIdentifier(final String idType, final Element displayForm, final Record record, - final OPCConnector opc) { - if (displayForm != null && record != null) { - List nameFields = Arrays.stream("028A,028B,028C,028D,028E,028F,028G,028H,028L,028M".split(",")) - .map(tag -> record.getFieldsByTag(tag)).flatMap(l -> l.stream()).collect(Collectors.toList()); - - for (final PPField f : nameFields) { - int confidence = partsCompare(displayForm.getTextTrim(), - Arrays.stream("d,a,c".split(",")).map(s -> f.getSubfieldByCode(s)).filter(sc -> sc != null) - .map(sc -> sc.getContent()).collect(Collectors.joining(", "))); - - if (confidence > 50) { - final Optional idn = Optional.ofNullable(f.getSubfieldByCode("9")); - if (idn.isPresent()) { - final String id = getIdentifier(idType, opc, idn.get().getContent()); - if (id != null) { - LOGGER.info("Found " + idType + " " + id + " for person \"" + displayForm.getTextTrim() - + "\"."); - return id; - } - } - } - } - } - - return null; - } - - private String getIdentifier(final String idType, final OPCConnector opc, final String idn) { - try { - final Record record = opc.getRecord(idn); - List ids = Stream.of(record.getFieldsByTag("007K"), record.getFieldsByTag("007N")) - .flatMap(l -> l.stream()) - .filter(f -> f.getSubfieldByCode("a").getContent().equalsIgnoreCase(idType)) - .map(f -> f.getSubfieldByCode("0").getContent()).collect(Collectors.toList()); - - return ids.isEmpty() ? null : ids.get(0); - } catch (Exception e) { - LOGGER.error("Couldn't read record for idn " + idn, e); - return null; - } - } - - private static String normalizeAccents(final String str) { - return Normalizer.normalize(str, Normalizer.Form.NFD).replaceAll("\\p{M}|´", ""); - } - - private static int partsCompare(final String n1, final String n2) { - List n1Parts = Arrays.stream(n1.split("[,\\s:]")).filter(s -> !s.isEmpty()) - .map(s -> s.toLowerCase(Locale.ROOT)) - .map(IdentifierExtractorEventHandler::normalizeAccents).collect(Collectors.toList()); - List n2Parts = Arrays.stream(n2.split("[,\\s:]")).filter(s -> !s.isEmpty()) - .map(s -> s.toLowerCase(Locale.ROOT)) - .map(IdentifierExtractorEventHandler::normalizeAccents).collect(Collectors.toList()); - - return Math.round(100 / (n1Parts.size() > n2Parts.size() ? n1Parts.size() : n2Parts.size()) - * n1Parts.stream().filter(s -> n2Parts.contains(s)).count()); - } -} diff --git a/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorPrefixProvider.java b/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorPrefixProvider.java deleted file mode 100644 index 84fdddbd..00000000 --- a/src/main/java/de/urmel_dl/dbt/events/IdentifierExtractorPrefixProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Digitale Bibliothek Thüringen repository software. - * Copyright (c) 2000 - 2016 - * See and - * - * 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 3 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 . - */ -package de.urmel_dl.dbt.events; - -import org.mycore.mods.MCRMODSWrapper; - -/** - * @author Ren\u00E9 Adler (eagle) - * - */ -interface IdentifierExtractorPrefixProvider { - - /** - * Returns the catalog prefix for given MODS document. - * - * @param mods the MODS document - * @return the Prefix - */ - public String getPrefix(MCRMODSWrapper mods); -} diff --git a/src/main/java/de/urmel_dl/dbt/events/package-info.java b/src/main/java/de/urmel_dl/dbt/events/package-info.java deleted file mode 100644 index 665b9c27..00000000 --- a/src/main/java/de/urmel_dl/dbt/events/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * $Id$ - * $Revision$ $Date$ - * - * This file is part of *** M y C o R e *** - * See http://www.mycore.de/ for details. - * - * This program is free software; you can use it, redistribute it - * and / or modify it under the terms of the GNU General Public License - * (GPL) 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, in a file called gpl.txt or license.txt. - * If not, write to the Free Software Foundation Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA - */ -/** - * @author Ren\u00E9 Adler (eagle) - * - */ -package de.urmel_dl.dbt.events; \ No newline at end of file diff --git a/src/main/java/de/urmel_dl/dbt/opc/datamodel/Catalogues.java b/src/main/java/de/urmel_dl/dbt/opc/datamodel/Catalogues.java index 553d6f3a..fae01c54 100644 --- a/src/main/java/de/urmel_dl/dbt/opc/datamodel/Catalogues.java +++ b/src/main/java/de/urmel_dl/dbt/opc/datamodel/Catalogues.java @@ -23,11 +23,6 @@ import java.util.ArrayList; import java.util.List; -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jdom2.Document; @@ -35,13 +30,19 @@ import org.mycore.common.MCRException; import org.mycore.common.config.MCRConfiguration2; import org.mycore.common.config.MCRConfigurationDir; +import org.mycore.resource.MCRResourcePath; +import org.mycore.resource.MCRResourceResolver; import de.urmel_dl.dbt.utils.EntityFactory; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; /** * The Class Catalogues. * - * @author Ren\u00E9 Adler (eagle) + * @author René Adler (eagle) */ @XmlAccessorType(XmlAccessType.NONE) @XmlRootElement(name = "catalogues") @@ -65,7 +66,7 @@ public static Catalogues instance() { throw new MCRException("Could not find " + getCataloguesConfigResourceName()); } - Document doc = new Document(); + Document doc; final SAXBuilder builder = new SAXBuilder(); try { doc = builder.build(cataloguesConfig); @@ -84,10 +85,12 @@ private static URL getCataloguesConfig() { try { return configFile.toURI().toURL(); } catch (final MalformedURLException e) { - LOGGER.warn("Error while looking for: " + configFile, e); + LOGGER.warn(()->"Error while looking for: " + configFile, e); } } - return MCRConfigurationDir.getConfigResource(getCataloguesConfigResourceName()); + return MCRResourceResolver.instance() + .resolve(MCRResourcePath.ofPath(getCataloguesConfigResourceName())) + .orElse(null); } private static String getCataloguesConfigResourceName() { @@ -95,7 +98,7 @@ private static String getCataloguesConfigResourceName() { } /** - * Returns a list of calagogues. + * Returns a list of catalogues. * * @return the catalogues */ @@ -114,16 +117,7 @@ public void setCatalogues(final List catalogues) { } /** - * Adds a catalog. - * - * @param catalog the catalog to set - */ - public void addCatalog(final Catalog catalog) { - this.catalogues.add(catalog); - } - - /** - * Returns the {@link Catalog#Catalog()} for given Id. + * Returns the {@link Catalog#Catalog()} for given id. * * @param id the catalog identifier * @return the {@link Catalog#Catalog()} diff --git a/src/main/java/de/urmel_dl/dbt/rc/commandline/RCCommands.java b/src/main/java/de/urmel_dl/dbt/rc/commandline/RCCommands.java index 1b716cd7..d66fd2c8 100644 --- a/src/main/java/de/urmel_dl/dbt/rc/commandline/RCCommands.java +++ b/src/main/java/de/urmel_dl/dbt/rc/commandline/RCCommands.java @@ -345,7 +345,7 @@ public static void rcInactivator() throws IOException, MCRAccessException { slot.setStatus(Status.ACTIVE); slot.setValidTo(RCCalendar - .getPeriodBySetable(slot.getLocation().toString(), new Date()) + .getPeriodBySettable(slot.getLocation().toString(), new Date()) .getToDate()); evt = MCREvent.customEvent(SlotManager.SLOT_TYPE, diff --git a/src/main/java/de/urmel_dl/dbt/rc/datamodel/Period.java b/src/main/java/de/urmel_dl/dbt/rc/datamodel/Period.java index ece957c2..188bc414 100644 --- a/src/main/java/de/urmel_dl/dbt/rc/datamodel/Period.java +++ b/src/main/java/de/urmel_dl/dbt/rc/datamodel/Period.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.List; +import de.urmel_dl.dbt.rc.utils.DateUtils; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; @@ -29,15 +30,13 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; -import de.urmel_dl.dbt.rc.utils.DateUtils; - /** - * @author Ren\u00E9 Adler (eagle) + * @author René Adler (eagle) * */ @XmlRootElement(name = "period") @XmlAccessorType(XmlAccessType.NONE) -@XmlType(name = "period", propOrder = { "from", "to", "lectureEnd", "matchingLocation", "setableFrom", "setableTo", +@XmlType(name = "period", propOrder = { "from", "to", "lectureEnd", "matchingLocation", "settableFrom", "settableTo", "labels", "warnings" }) public class Period implements Serializable, Comparable, Cloneable { @@ -53,11 +52,11 @@ public class Period implements Serializable, Comparable, Cloneable { private String fromShort; - private String setableFromShort; + private String settableFromShort; private String toShort; - private String setableToShort; + private String settableToShort; private String lectureEndShort; @@ -81,7 +80,7 @@ public Date getBaseDate() { /** * Set the base date for this {@link Period}. * If {@link #getFrom()} or {@link #getTo()} resp. - * {@link #getSetableFrom()} or {@link #getSetableTo()} + * {@link #getSettableFrom()} or {@link #getSettableTo()} * returns null, the period isn't a valid on. * * @param base the base to set @@ -102,7 +101,7 @@ public void setBaseDate(final Date base) { public void setStartDate(final Date base) { this.baseDate = getPeriodDate(base, fromShort, toShort, false); if (this.baseDate == null) { - this.baseDate = getPeriodDate(base, setableFromShort, setableToShort, true); + this.baseDate = getPeriodDate(base, settableFromShort, settableToShort, true); } } @@ -203,61 +202,61 @@ private void setFromShort(final String fromShort) { } /** - * Returns the setableFrom date as short string or + * Returns the settableFrom date as short string or * if {@link #isFullyQualified()} equals true a fully qualified date string. * - * @return the setableFrom date + * @return the settableFrom date */ - @XmlAttribute(name = "setableFrom") - public String getSetableFrom() { - final Date date = getPeriodDate(getBaseDate(), setableFromShort, setableToShort, false); - return fqDate && date != null ? constructDateString(date) : setableFromShort; + @XmlAttribute(name = "settableFrom") + public String getSettableFrom() { + final Date date = getPeriodDate(getBaseDate(), settableFromShort, settableToShort, false); + return fqDate && date != null ? constructDateString(date) : settableFromShort; } /** - * Returns the setableFrom date as Date. + * Returns the settableFrom date as Date. * * @param base the basis date - * @return the setableFrom date + * @return the settableFrom date */ - public Date getSetableFromDate(final Date base) { - return getPeriodDate(base, setableFromShort, setableToShort, false); + public Date getSettableFromDate(final Date base) { + return getPeriodDate(base, settableFromShort, settableToShort, false); } /** - * Set the setableFrom date by given string. + * Set the settableFrom date by given string. * The input string should be as short format or as fully qualified date string. * - * @param setableFrom the setableFrom date + * @param settableFrom the settableFrom date */ - public void setSetableFrom(final String setableFrom) { - setSetableFromShort(constructShort(setableFrom)); + public void setSettableFrom(final String settableFrom) { + setSettableFromShort(constructShort(settableFrom)); } /** - * Set the setableFrom date by given date. + * Set the settableFrom date by given date. * - * @param setableFrom the setableFrom date + * @param settableFrom the settableFrom date */ - public void setSetableFrom(final Date setableFrom) { - setSetableFromShort(constructShort(setableFrom)); + public void setSettableFrom(final Date settableFrom) { + setSettableFromShort(constructShort(settableFrom)); } /** - * @return the setableFromShort + * @return the settableFromShort */ - protected String getSetableFromShort() { - return setableFromShort; + protected String getSettableFromShort() { + return settableFromShort; } /** - * @param setableFromShort the setableFromShort to set + * @param settableFromShort the settableFromShort to set */ - private void setSetableFromShort(final String setableFromShort) { - if (setableFromShort == null || !setableFromShort.matches(SHORT_FORMAT)) { - throw new IllegalArgumentException("invalid setableFrom format given"); + private void setSettableFromShort(final String settableFromShort) { + if (settableFromShort == null || !settableFromShort.matches(SHORT_FORMAT)) { + throw new IllegalArgumentException("invalid settableFrom format given"); } - this.setableFromShort = setableFromShort; + this.settableFromShort = settableFromShort; } /** @@ -328,85 +327,81 @@ private void setToShort(final String toShort) { } /** - * Returns the setableTo date as Date. + * Returns the settableTo date as Date. * * @param base the basis date - * @return the setableTo date + * @return the settableTo date */ - public Date getSetableToDate(final Date base) { - return getPeriodDate(base, setableFromShort, setableToShort, true); + public Date getSettableToDate(final Date base) { + return getPeriodDate(base, settableFromShort, settableToShort, true); } /** - * Returns the setableTo date as short string or + * Returns the settableTo date as short string or * if {@link #isFullyQualified()} equals true a fully qualified date string. * - * @return the setableTo date + * @return the settableTo date */ - @XmlAttribute(name = "setableTo") - public String getSetableTo() { - final Date date = getPeriodDate(getBaseDate(), setableFromShort, setableToShort, true); - return fqDate && date != null ? constructDateString(date) : setableToShort; + @XmlAttribute(name = "settableTo") + public String getSettableTo() { + final Date date = getPeriodDate(getBaseDate(), settableFromShort, settableToShort, true); + return fqDate && date != null ? constructDateString(date) : settableToShort; } /** - * Set the setableTo date by given string. + * Set the settableTo date by given string. * The input string should be as short format or as fully qualified date string. * - * @param setableTo the setableTo date + * @param settableTo the settableTo date */ - public void setSetableTo(final String setableTo) { - setSetableToShort(constructShort(setableTo)); + public void setSettableTo(final String settableTo) { + setSettableToShort(constructShort(settableTo)); } /** - * Set the setableTo date by given date. + * Set the settableTo date by given date. * - * @param setableTo the setableTo date + * @param settableTo the settableTo date */ - public void setSetableTo(final Date setableTo) { - setSetableToShort(constructShort(setableTo)); + public void setSettableTo(final Date settableTo) { + setSettableToShort(constructShort(settableTo)); } /** - * @return the setableToShort + * @return the settableToShort */ - protected String getSetableToShort() { - return setableToShort; + protected String getSettableToShort() { + return settableToShort; } /** - * @param setableToShort the setableToShort to set + * @param settableToShort the settableToShort to set */ - private void setSetableToShort(final String setableToShort) { - if (setableToShort == null || !setableToShort.matches(SHORT_FORMAT)) { - throw new IllegalArgumentException("invalid setableTo format given"); + private void setSettableToShort(final String settableToShort) { + if (settableToShort == null || !settableToShort.matches(SHORT_FORMAT)) { + throw new IllegalArgumentException("invalid settableTo format given"); } - this.setableToShort = setableToShort; + this.settableToShort = settableToShort; } - @XmlAttribute(name = "setable", required = false) - public boolean isSetable() { + @XmlAttribute(name = "settable", required = false) + public boolean isSettable() { final Date today = new Date(); final Date to = getToDate(); if (to != null && today.after(to)) { return false; } else { - Date setTo = getPeriodDate(getBaseDate(), setableFromShort, setableToShort, true); + Date setTo = getPeriodDate(getBaseDate(), settableFromShort, settableToShort, true); if (setTo == null) - setTo = getPeriodDate(today, setableFromShort, setableToShort, true); + setTo = getPeriodDate(today, settableFromShort, settableToShort, true); - if (setTo == null || today.after(setTo)) { - return false; - } + return setTo != null && !today.after(setTo); } - - return true; } - public boolean isSetable(final Date base) { - return getPeriodDate(base, setableFromShort, setableToShort, false) != null; + public boolean isSettable(final Date base) { + return getPeriodDate(base, settableFromShort, settableToShort, false) != null; } /** @@ -641,9 +636,7 @@ private String constructShort(final String inputStr) { date = DateUtils.parseDate(inputStr); } - if (date != null) { - return constructShort(date); - } + return constructShort(date); } throw new IllegalArgumentException("invalid input string \"" + inputStr + "\""); @@ -789,8 +782,7 @@ private static Date getPeriodDate(final Date base, final String from, final Stri */ @Override public boolean equals(Object obj) { - if (obj instanceof Period) { - Period other = (Period) obj; + if (obj instanceof Period other) { if (!fromShort.equals(other.fromShort) || !toShort.equals(other.toShort)) return false; @@ -818,13 +810,14 @@ public int compareTo(final Period other) { */ @Override public Period clone() throws CloneNotSupportedException { + Period period = (Period) super.clone(); final Period clone = new Period(); clone.baseDate = this.baseDate; clone.fromShort = this.fromShort; clone.toShort = this.toShort; - clone.setableFromShort = this.setableFromShort; - clone.setableToShort = this.setableToShort; + clone.settableFromShort = this.settableFromShort; + clone.settableToShort = this.settableToShort; clone.lectureEndShort = this.lectureEndShort; clone.labels = this.labels; clone.setWarnings(this.warnings); @@ -859,16 +852,16 @@ public String toString() { builder.append(toShort); builder.append(", "); } - if (setableFromShort != null) { - builder.append("setableFromShort="); - builder.append(setableFromShort); - if (setableToShort != null) { + if (settableFromShort != null) { + builder.append("settableFromShort="); + builder.append(settableFromShort); + if (settableToShort != null) { builder.append(", "); } } - if (setableToShort != null) { - builder.append("setableToShort="); - builder.append(setableToShort); + if (settableToShort != null) { + builder.append("settableToShort="); + builder.append(settableToShort); } builder.append("]"); return builder.toString(); diff --git a/src/main/java/de/urmel_dl/dbt/rc/datamodel/RCCalendar.java b/src/main/java/de/urmel_dl/dbt/rc/datamodel/RCCalendar.java index dccb5166..701c9387 100644 --- a/src/main/java/de/urmel_dl/dbt/rc/datamodel/RCCalendar.java +++ b/src/main/java/de/urmel_dl/dbt/rc/datamodel/RCCalendar.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.Serializable; +import java.net.URL; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -28,10 +29,6 @@ import java.util.NoSuchElementException; import java.util.TimeZone; -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; import javax.xml.transform.TransformerException; import org.apache.logging.log4j.LogManager; @@ -40,22 +37,27 @@ import org.jdom2.Element; import org.jdom2.JDOMException; import org.mycore.common.MCRException; -import org.mycore.common.config.MCRConfigurationDir; import org.mycore.common.content.MCRSourceContent; +import org.mycore.resource.MCRResourcePath; +import org.mycore.resource.MCRResourceResolver; import org.xml.sax.SAXException; import de.urmel_dl.dbt.rc.utils.DateUtils; import de.urmel_dl.dbt.utils.EntityFactory; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; /** - * @author Ren\u00E9 Adler (eagle) + * @author René Adler (eagle) * */ @XmlRootElement(name = "calendar") @XmlAccessorType(XmlAccessType.NONE) public final class RCCalendar implements Serializable, Iterable { - protected static final String RESOURCE_URI = "rccalendar.xml"; + private static final String RESOURCE_URI = "rccalendar.xml"; private static final long serialVersionUID = -812825621316872737L; @@ -71,7 +73,7 @@ private RCCalendar() { /** * Returns a {@link RCCalendar} instance. * - * @return a instance of {@link RCCalendar} + * @return an instance of {@link RCCalendar} */ public static RCCalendar instance() { if (singleton == null) { @@ -90,7 +92,11 @@ public static RCCalendar instance() { private static Document getCalendar() throws MCRException, TransformerException, JDOMException, IOException, SAXException { - return MCRSourceContent.getInstance(MCRConfigurationDir.getConfigResource(RESOURCE_URI).toString()).asXML(); + String resourceSystemId = MCRResourceResolver.instance() + .resolve(MCRResourcePath.ofPath(RESOURCE_URI)) + .map(URL::toString) + .orElseThrow(() -> new MCRException("Could not find " + RESOURCE_URI)); + return MCRSourceContent.getInstance(resourceSystemId).asXML(); } /** @@ -124,14 +130,14 @@ public static Period getPeriod(final String areaCode, final Date date) { } } catch (final Throwable e) { // Period is NULL - LOGGER.info("no period given for date " + date); + LOGGER.info(() -> "no period given for date " + date); } return null; } /** - * Returns a list of setable {@link Period} for given areaCode, date and + * Returns a list of settable {@link Period} for given areaCode, date and * numNext (number of next periods). * * @param areaCode specific area code for the period @@ -149,11 +155,11 @@ public static RCCalendar getPeriodList(final String areaCode, final Date date, i * * @param areaCode specific area code for the period * @param date date as starting point which should return period(s) - * @param onlySetable if true only setable periods are listed - * @param numNext number of periods after first setable one + * @param onlySettable if true only settable periods are listed + * @param numNext number of periods after first settable one * @return a list of {@link Period} */ - public static RCCalendar getPeriodList(final String areaCode, final Date date, boolean onlySetable, int numNext) { + public static RCCalendar getPeriodList(final String areaCode, final Date date, boolean onlySettable, int numNext) { try { final Iterable periods = instance().iterable(areaCode); @@ -166,16 +172,16 @@ public static RCCalendar getPeriodList(final String areaCode, final Date date, b while (pos < numNext + 1) { for (Period period : periods) { period.setBaseDate(lastDate); - if (!onlySetable && period.getFromDate(lastDate) == null && period.getToDate(lastDate) == null) { + if (!onlySettable && period.getFromDate(lastDate) == null && period.getToDate(lastDate) == null) { continue; } - if (pos < numNext + 1 && ((period.isSetable(lastDate) && onlySetable) || (!onlySetable && (period - .isSetable(lastDate) + if (pos < numNext + 1 && ((period.isSettable(lastDate) && onlySettable) || (!onlySettable && (period + .isSettable(lastDate) || (period.getFromDate(lastDate) != null && period.getToDate(lastDate) != null))))) { final Period p = period.clone(); - if (onlySetable) { + if (onlySettable) { p.setStartDate(lastDate); } @@ -188,9 +194,9 @@ public static RCCalendar getPeriodList(final String areaCode, final Date date, b lastDate = nextDay.getTime(); - boolean setAble = p.isSetable(); + boolean setAble = p.isSettable(); - if (setAble && onlySetable || !onlySetable) { + if (setAble || !onlySettable) { calendar.periods.add(p); } @@ -204,7 +210,7 @@ public static RCCalendar getPeriodList(final String areaCode, final Date date, b return calendar; } catch (final Throwable e) { // Period is NULL - LOGGER.info("no periods given for date " + date); + LOGGER.info(() -> "no periods given for date " + date); } return null; @@ -212,7 +218,7 @@ public static RCCalendar getPeriodList(final String areaCode, final Date date, b /** * Tries to obtain a {@link Period}, which was defined inside RC periods, by - * calculating setableFrom and setableTo dates with the use of target date. + * calculating settableFrom and settableTo dates with the use of target date. * * @param areaCode * specific area code for the period @@ -221,10 +227,10 @@ public static RCCalendar getPeriodList(final String areaCode, final Date date, b * @return the targeting {@link Period} if one could be calculated, * null otherwise */ - public static Period getPeriodBySetable(final String areaCode, final Date date) { + public static Period getPeriodBySettable(final String areaCode, final Date date) { try { for (Period period : instance().iterable(areaCode)) { - if (period.getSetableFromDate(date) != null && period.getSetableToDate(date) != null) { + if (period.getSettableFromDate(date) != null && period.getSettableToDate(date) != null) { final Period p = period.clone(); p.setStartDate(date); p.setFullyQualified(true); @@ -233,7 +239,7 @@ public static Period getPeriodBySetable(final String areaCode, final Date date) } } catch (final Throwable e) { // Period is NULL - LOGGER.info("no period given for date " + date); + LOGGER.info(() -> "no period given for date " + date); } return null; @@ -242,6 +248,7 @@ public static Period getPeriodBySetable(final String areaCode, final Date date) /** * @param periods the periods to set */ + @SuppressWarnings("unused") protected void setPeriods(final List periods) { this.periods = periods; } @@ -263,8 +270,8 @@ public Iterator iterator() { * @see java.lang.Iterable#iterator() */ public Iterator iterator(final String areaCode) { - return new Iterator() { - Iterator it = periods.iterator(); + return new Iterator<>() { + final Iterator it = periods.iterator(); Period next = null; diff --git a/src/main/java/de/urmel_dl/dbt/rc/persistency/SlotManager.java b/src/main/java/de/urmel_dl/dbt/rc/persistency/SlotManager.java index 1bf38828..0fde9241 100644 --- a/src/main/java/de/urmel_dl/dbt/rc/persistency/SlotManager.java +++ b/src/main/java/de/urmel_dl/dbt/rc/persistency/SlotManager.java @@ -37,7 +37,6 @@ import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocumentList; -import org.jdom2.Element; import org.jdom2.JDOMException; import org.mycore.access.MCRAccessException; import org.mycore.access.MCRAccessManager; @@ -46,10 +45,8 @@ import org.mycore.common.MCRPersistenceException; import org.mycore.common.MCRSessionMgr; import org.mycore.common.MCRUserInformation; -import org.mycore.common.config.MCRConfiguration2; import org.mycore.common.content.MCRContent; import org.mycore.datamodel.classifications2.MCRCategoryID; -import org.mycore.datamodel.classifications2.impl.MCRCategoryDAOImpl; import org.mycore.datamodel.common.MCRAbstractMetadataVersion; import org.mycore.datamodel.common.MCRActiveLinkException; import org.mycore.datamodel.common.MCRCreatorCache; @@ -61,7 +58,7 @@ import org.mycore.mcr.acl.accesskey.MCRAccessKeyUtils; import org.mycore.mir.authorization.accesskeys.MIRAccessKeyManager; import org.mycore.mir.authorization.accesskeys.backend.MIRAccessKeyPair; -import org.mycore.solr.MCRSolrClientFactory; +import org.mycore.solr.MCRSolrCoreManager; import org.mycore.solr.MCRSolrUtils; import org.mycore.user2.MCRUser; import org.mycore.user2.MCRUserAttribute; @@ -76,7 +73,6 @@ import de.urmel_dl.dbt.rc.datamodel.slot.SlotList; import de.urmel_dl.dbt.rc.datamodel.slot.entries.FileEntry; import de.urmel_dl.dbt.rc.utils.SlotWrapper; -import de.urmel_dl.dbt.utils.EntityFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.TypedQuery; import jakarta.persistence.criteria.CriteriaBuilder; @@ -96,10 +92,6 @@ public final class SlotManager { public static final String POOLPRIVILEGE_CREATE_SLOT = "create-slot"; - public static final String ADMIN_GROUP = MCRConfiguration2.getStringOrThrow("DBT.RC.Administrator.GroupName"); - - public static final String EDITOR_GROUP = MCRConfiguration2.getStringOrThrow("DBT.RC.Editor.GroupName"); - public static final String PROJECT_ID = "rc"; public static final String SLOT_TYPE = "slot"; @@ -114,9 +106,9 @@ public final class SlotManager { private static final Logger LOGGER = LogManager.getLogger(); - private static SlotManager singelton; + private static volatile SlotManager singleton; - private SlotList slotList; + private final SlotList slotList; private SlotManager() { slotList = new SlotList(); @@ -124,22 +116,26 @@ private SlotManager() { } /** - * Returns a instance of the {@link SlotManager}. + * Returns an instance of the {@link SlotManager}. * * @return the SlotManager */ public static SlotManager instance() { - if (singelton == null) { - singelton = new SlotManager(); + if (singleton == null) { + synchronized (SlotManager.class) { + if (singleton == null) { + singleton = new SlotManager(); + } + } } - return singelton; + return singleton; } public static String buildKey() { - final StringBuffer buf = new StringBuffer(); - buf.append(Long.toString(System.nanoTime(), 36)); - return buf.reverse().toString(); + final StringBuilder sb = new StringBuilder(); + sb.append(Long.toString(System.nanoTime(), 36)); + return sb.reverse().toString(); } /** @@ -174,14 +170,9 @@ public static boolean checkPermission(final MCRObjectID objId, final String perm public static boolean checkPermission(final String objId, final String permission) { if (permission.equals(MCRAccessManager.PERMISSION_READ) || permission.equals(MCRAccessManager.PERMISSION_WRITE)) { - if (hasAdminPermission() || hasEditorPermission() || isOwner(objId)) { - return true; - } - } else if (permission.equals(MCRAccessManager.PERMISSION_DELETE) && hasAdminPermission()) { - return true; - } - - return false; + return hasAdminPermission() || hasEditorPermission() || isOwner(objId); + } else + return permission.equals(MCRAccessManager.PERMISSION_DELETE) && hasAdminPermission(); } /** @@ -231,12 +222,12 @@ public static boolean isOwner(final String objId, final MCRUserInformation user) } public static void setOwner(final String objId) - throws MCRPersistenceException, MCRActiveLinkException, MCRAccessException { + throws MCRPersistenceException, MCRAccessException { setOwner(objId, MCRSessionMgr.getCurrentSession().getUserInformation()); } public static void setOwner(final String objId, final MCRUserInformation user) - throws MCRPersistenceException, MCRActiveLinkException, MCRAccessException { + throws MCRPersistenceException, MCRAccessException { final MCRObject obj = MCRMetadataManager.retrieveMCRObject(MCRObjectID.getInstance(objId)); final MCRObjectService os = obj.getService(); @@ -248,50 +239,6 @@ public static void setOwner(final String objId, final MCRUserInformation user) MCRCreatorCache.invalidate(objId); } - /** - * Checks if given access key was previously used on slot. - * - * @param nodes the slot element - * @return true if key is matching - */ - public static boolean isMatchPreviousAccessKeys(List nodes) { - if (nodes != null && !nodes.isEmpty()) { - final Slot slot = new EntityFactory<>(Slot.class).fromElement(nodes.get(0)); - final Slot cSlot = SlotManager.instance().getSlotById(slot.getSlotId()); - - final MIRAccessKeyPair accKP = MIRAccessKeyManager.getKeyPair(cSlot.getMCRObjectID()); - - return accKP != null - && (accKP.getReadKey().equals(slot.getReadKey()) || accKP.getWriteKey().equals(slot.getWriteKey())); - } - return false; - } - - /** - * Checks if given slot location and new number is free. - * - * @param nodes the location element - * @return true if slot number is free - */ - public static boolean isFreeId(List nodes) { - if (nodes != null && !nodes.isEmpty()) { - final Element xml = nodes.get(0); - final Element location = xml.getChild("location"); - final String locId = location != null ? location.getAttributeValue("id") : null; - final String newId = location != null ? location.getAttributeValue("newId") : null; - - if (locId != null && newId != null) { - final Slot slot = new EntityFactory<>(Slot.class).fromElement(xml); - final MCRCategoryID locCat = new MCRCategoryDAOImpl() - .getCategory(new MCRCategoryID(Slot.CLASSIF_ROOT_LOCATION, locId), 0).getId(); - int id = Integer.parseInt(newId); - - return slot.getLocation().equals(locCat) && slot.getId() == id || instance().isFreeId(locCat, id); - } - } - return false; - } - public static boolean isActive(String slotId) { return Optional.ofNullable(instance().getSlotById(slotId)).map(Slot::isActive).orElse(false); } @@ -299,9 +246,6 @@ public static boolean isActive(String slotId) { /** * Check if given entry is supported by {@link MediaService}. * - * @param slotId - * @param entryId - * @return */ @SuppressWarnings("unchecked") public static boolean isStreamingSupported(String slotId, String entryId) { @@ -346,7 +290,7 @@ public synchronized void loadList() { slotList.addSlot(slot); } } catch (final Exception e) { - LOGGER.error("Error on loading " + objId + "!", e); + LOGGER.error(() -> "Error on loading " + objId + "!", e); } }); } @@ -452,7 +396,7 @@ public synchronized boolean isFreeId(final MCRCategoryID rcLocation, int id) { * Returns the current SVN revision of an {@link Slot}. * * @param slot the {@link Slot} - * @return an number or null on Exception + * @return a number or null on Exception */ public synchronized Long getLastRevision(final Slot slot) { try { @@ -469,7 +413,7 @@ public synchronized Long getLastRevision(final Slot slot) { } } - private Predicate> filterFileEntry = (se) -> se.getEntry() instanceof FileEntry; + private final Predicate> filterFileEntry = (se) -> se.getEntry() instanceof FileEntry; /** * Saves or updates the metadata of given {@link Slot}. @@ -537,8 +481,8 @@ public void removeDeletedFileEntries(Slot slotBefore, Slot slot) { if (slotBefore != null && slotBefore.getEntries() != null) { slotBefore.getEntries().stream().filter(filterFileEntry) .filter(se -> Optional.ofNullable(slot).map(Slot::getEntries) - .map(nse -> !nse.stream().filter(filterFileEntry) - .anyMatch(e -> e.getId().equals(se.getId()))) + .map(nse -> nse.stream().filter(filterFileEntry) + .noneMatch(e -> e.getId().equals(se.getId()))) .orElse(true)) .peek(e -> LOGGER.info("remove {}", e)) .forEach(se -> FileEntryManager.delete(slotBefore, (SlotEntry) se)); @@ -639,7 +583,7 @@ public SlotList getSlotList() { */ public SlotList getFilteredSlotList(final String search, final String filter, Integer start, Integer rows, final List sortClauses) throws SolrServerException, IOException { - final SolrClient client = MCRSolrClientFactory.getMainSolrClient(); + final SolrClient client = MCRSolrCoreManager.getMainSolrClient(); final SolrQuery query = new SolrQuery(); final String searchStr = "(slotId:%filter%) OR (slot.title:%filter%) OR (slot.lecturer:%filter%) OR (slot.location:%filter%) OR (slot.validTo:%filter%)" diff --git a/src/main/java/de/urmel_dl/dbt/rc/resolver/PeriodResolver.java b/src/main/java/de/urmel_dl/dbt/rc/resolver/PeriodResolver.java index 3f1a739f..63813f2d 100644 --- a/src/main/java/de/urmel_dl/dbt/rc/resolver/PeriodResolver.java +++ b/src/main/java/de/urmel_dl/dbt/rc/resolver/PeriodResolver.java @@ -44,10 +44,10 @@ *
    *
  • period:areacode=areaCode[&date={now|31.12.2011}] get (set able) period for given date
  • *
  • period:areacode=areaCode[&date={now|31.12.2011}][&fq=true] get (fq = full qualified) period for given date
  • - *
  • period:areacode=areaCode[&date={now|31.12.2011}][&list=true][&onlySetable=true][&numnext=1] get periods (+ next) for given date
  • + *
  • period:areacode=areaCode[&date={now|31.12.2011}][&list=true][&onlySettable=true][&numnext=1] get periods (+ next) for given date
  • *
* - * @author Ren\u00E9 Adler (eagle) + * @author René Adler (eagle) * */ public class PeriodResolver implements URIResolver { @@ -72,9 +72,9 @@ public Source resolve(final String href, final String base) throws TransformerEx final String areaCode = params.get("areacode"); final String dateStr = params.get("date") != null ? params.get("date") : "now"; - boolean fq = params.get("fq") != null ? Boolean.parseBoolean(params.get("fq")) : false; - boolean list = params.get("list") != null ? Boolean.parseBoolean(params.get("list")) : false; - boolean onlySetable = params.get("onlySetable") != null ? Boolean.parseBoolean(params.get("onlySetable")) + boolean fq = params.get("fq") != null && Boolean.parseBoolean(params.get("fq")); + boolean list = params.get("list") != null && Boolean.parseBoolean(params.get("list")); + boolean onlySettable = params.get("onlySettable") != null ? Boolean.parseBoolean(params.get("onlySettable")) : true; int numNext = params.get("numnext") != null ? Integer.parseInt(params.get("numnext")) : 1; @@ -89,10 +89,10 @@ public Source resolve(final String href, final String base) throws TransformerEx if (!list) { final Period period = fq ? RCCalendar.getPeriod(areaCode, date) - : RCCalendar.getPeriodBySetable(areaCode, date); + : RCCalendar.getPeriodBySettable(areaCode, date); return new JDOMSource(new EntityFactory<>(period).toDocument()); } else { - final RCCalendar calendar = RCCalendar.getPeriodList(areaCode, date, onlySetable, numNext); + final RCCalendar calendar = RCCalendar.getPeriodList(areaCode, date, onlySettable, numNext); return new JDOMSource(new EntityFactory<>(calendar).toDocument()); } } catch (final Exception ex) { diff --git a/src/main/java/de/urmel_dl/dbt/rc/servlets/SlotListServlet.java b/src/main/java/de/urmel_dl/dbt/rc/servlets/SlotListServlet.java index fd31f299..940278c6 100644 --- a/src/main/java/de/urmel_dl/dbt/rc/servlets/SlotListServlet.java +++ b/src/main/java/de/urmel_dl/dbt/rc/servlets/SlotListServlet.java @@ -142,7 +142,7 @@ public void doGetPost(final MCRServletJob job) throws Exception { } else if ("reactivateComplete".equals(action)) { evt = MCREvent.customEvent(SlotManager.SLOT_TYPE, SlotManager.REACTIVATE_EVENT); slot.setValidTo( - RCCalendar.getPeriodBySetable(slot.getLocation().toString(), new Date()).getToDate()); + RCCalendar.getPeriodBySettable(slot.getLocation().toString(), new Date()).getToDate()); } else { evt = MCREvent.customEvent(SlotManager.SLOT_TYPE, MCREvent.EventType.UPDATE); } diff --git a/src/main/java/de/urmel_dl/dbt/utils/EntityFactory.java b/src/main/java/de/urmel_dl/dbt/utils/EntityFactory.java index b824ae18..c7c7e70a 100644 --- a/src/main/java/de/urmel_dl/dbt/utils/EntityFactory.java +++ b/src/main/java/de/urmel_dl/dbt/utils/EntityFactory.java @@ -26,7 +26,6 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -72,7 +71,7 @@ *
* Examples: *

- * Marshalling a entity to output: + * Marshalling an entity to output: *

*
*
@@ -90,7 +89,7 @@
  * 
*
* - * @author Ren\u00E9 Adler (eagle) + * @author René Adler (eagle) * @param the generic type */ public class EntityFactory { @@ -118,7 +117,7 @@ public class EntityFactory { private T entity; - private BiConsumer, Object> marshal = (marshallerCaller, output) -> { + private final BiConsumer, Object> marshal = (marshallerCaller, output) -> { Marshaller marshaller; try { marshaller = marshallerCaller.call(); @@ -142,7 +141,7 @@ public class EntityFactory { } }; - private BiFunction, Object, T> unmarshal = (unmarshallerCaller, input) -> { + private final BiFunction, Object, T> unmarshal = (unmarshallerCaller, input) -> { Unmarshaller unmarshaller; try { unmarshaller = unmarshallerCaller.call(); @@ -166,7 +165,7 @@ public class EntityFactory { } }; - private BiFunction, Object, T> jsonUnmarshal = (unmarshallerCaller, input) -> { + private final BiFunction, Object, T> jsonUnmarshal = (unmarshallerCaller, input) -> { Unmarshaller unmarshaller; try { unmarshaller = unmarshallerCaller.call(); @@ -224,29 +223,6 @@ public boolean canHandle() { .anyMatch(p -> entityType.getPackage().getName().contains(p) || entityType.getName().contains(p))); } - /** - * Marshals a entity with specified marshal function. - * - * @param the return type - * @param f the f - * @return the return type - */ - public R marshal(Function f) { - return f.apply(entity); - } - - /** - * Unmarshals a entity with specified unmarshal function. - * - * @param the source type - * @param s the source - * @param f the unmarshal function - * @return the entity class - */ - public T unmarshal(S s, Function f) { - return f.apply(s); - } - /** * Marshals the entity to JSON. * @@ -354,15 +330,6 @@ public T fromDocument(Document doc) { return unmarshal.apply(() -> unmarshaller(Optional.empty()), source.getInputSource()); } - /** - * Marshals the entity to {@link Element}. - * - * @return the {@link Element} - */ - public Element toElement() { - return toDocument().getRootElement().clone(); - } - /** * Unmarshals the {@link Element} to entity. * @@ -374,7 +341,7 @@ public T fromElement(Element elm) { } /** - * Returns the marshaled entity. By default outputs entity as XML. + * Returns the marshaled entity. By default, outputs entity as XML. * * @param mediaType the optional mediaType * @return the marshaled entity @@ -388,7 +355,7 @@ public String marshalByMediaType(Optional mediaType) { } /** - * Returns the unmarshaled entity. + * Returns the unmarshalled entity. * * @param source the source * @param mediaType the mediaType @@ -443,7 +410,7 @@ private Unmarshaller unmarshaller(Optional> extraProperties) thro }); return unmarshaller; - }; + } private Optional findMethod(Class cls, String name, Class... parameterTypes) { return Arrays.stream(cls.getMethods()).filter(m -> name.equals(m.getName())).filter(m -> { @@ -489,13 +456,13 @@ private Source toSource(Object input) { CONFIG_PREFIX + entityType.getName() + "." + propType); return MCRConfiguration2.getPropertiesMap().entrySet().stream() - .filter(e -> propNames.stream().anyMatch(n -> e.getKey().startsWith(n))).sorted(Comparator.comparing( - Entry::getKey, (k1, k2) -> { + .filter(e -> propNames.stream().anyMatch(n -> e.getKey().startsWith(n))).sorted( + Entry.comparingByKey((k1, k2) -> { String fpn = keyFunc.apply(k1); if (fpn.equals(keyFunc.apply(k2))) { int pi1 = propNames.indexOf(k1.replace(fpn, "")); int pi2 = propNames.indexOf(k2.replace(fpn, "")); - return pi1 == pi2 ? 0 : pi1 < pi2 ? -1 : 1; + return Integer.compare(pi1, pi2); } return k1.compareTo(k2); })) diff --git a/src/main/java/de/urmel_dl/dbt/viewer/DBTViewerConfigurationStrategy.java b/src/main/java/de/urmel_dl/dbt/viewer/DBTViewerConfigurationStrategy.java index 95dd4c71..c6659b10 100644 --- a/src/main/java/de/urmel_dl/dbt/viewer/DBTViewerConfigurationStrategy.java +++ b/src/main/java/de/urmel_dl/dbt/viewer/DBTViewerConfigurationStrategy.java @@ -17,13 +17,13 @@ */ package de.urmel_dl.dbt.viewer; -import jakarta.servlet.http.HttpServletRequest; - import org.mycore.common.xml.MCRXMLFunctions; import org.mycore.frontend.MCRFrontendUtil; import org.mycore.viewer.configuration.MCRViewerConfiguration; import org.mycore.viewer.configuration.MCRViewerDefaultConfigurationStrategy; +import jakarta.servlet.http.HttpServletRequest; + /** * Provides Bootstrap JavaScript and CSS in DBT colors */ @@ -43,7 +43,7 @@ public MCRViewerConfiguration get(HttpServletRequest request) { } else { // Default JS viewerConfiguration - .addScript(baseURL + "assets/bootstrap/js/bootstrap.min.js"); + .addScript(baseURL + "assets/bootstrap/js/bootstrap.min.js", false); } } return viewerConfiguration; diff --git a/src/main/resources/META-INF/resources/scss/dbt/_rc.scss b/src/main/resources/META-INF/resources/scss/dbt/_rc.scss index 94ab8b7c..9bcba39e 100644 --- a/src/main/resources/META-INF/resources/scss/dbt/_rc.scss +++ b/src/main/resources/META-INF/resources/scss/dbt/_rc.scss @@ -105,7 +105,7 @@ body.dragging * { cursor: move ! important; } -#validTo>option.not-setable { +#validTo>option.not-settable { color: $danger; } @@ -179,4 +179,4 @@ body.dragging * { .slot-pending-validating>td:first-child { @include status-gradient (#ebf1f6, #abd3ee, #89c3eb, #d5ebfb); } -} \ No newline at end of file +} diff --git a/src/main/resources/config/dbt/mycore.properties b/src/main/resources/config/dbt/mycore.properties index a9bbf4f3..05e6267e 100644 --- a/src/main/resources/config/dbt/mycore.properties +++ b/src/main/resources/config/dbt/mycore.properties @@ -154,7 +154,6 @@ MCR.Hibernate.Mappings=%MCR.Hibernate.Mappings%,org.mycore.services.queuedjob.MC MCR.EventHandler.MCRDerivate.010.Class=org.mycore.datamodel.metadata.MCRDerivateDefaultClassEventHandler -MCR.EventHandler.MCRObject.016dbt.Class=de.urmel_dl.dbt.events.IdentifierExtractorEventHandler # can be used to persist transient user (shibboleth or ...) MCR.EventHandler.MCRObject.110dbt.Class=org.mycore.user2.events.MCRPersistTransientUserEventHandler @@ -356,7 +355,7 @@ MCR.Sword.Collection.MyWorkspace.DefaultDeepGreen = org.mycore.mir.sword2.MIRDee MCR.Sword.DefaultDeepGreen.Transformer = deepgreenjats2mods MCR.Sword.DefaultDeepGreen.State = imported #used org.mycore.access.strategies.MCRCreatorRuleStrategy: -MCR.Access.Strategy.SubmittedCategory=%MCR.Access.Strategy.SubmittedCategory%,state:%MCR.Sword.DefaultDeepGreen.State% +MCR.Access.Strategy.SubmittedCategories=%MCR.Access.Strategy.SubmittedCategories%,state:%MCR.Sword.DefaultDeepGreen.State% MCR.ContentTransformer.deepgreenjats2mods.Class=org.mycore.common.content.transformer.MCRXSLTransformer MCR.ContentTransformer.deepgreenjats2mods.TransformerFactoryClass=net.sf.saxon.TransformerFactoryImpl diff --git a/src/main/resources/rccalendar.xml b/src/main/resources/rccalendar.xml index 1187474c..985122ff 100644 --- a/src/main/resources/rccalendar.xml +++ b/src/main/resources/rccalendar.xml @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/src/main/resources/xsl/rc/periods2options.xsl b/src/main/resources/xsl/rc/periods2options.xsl index 582839c8..a6a893db 100644 --- a/src/main/resources/xsl/rc/periods2options.xsl +++ b/src/main/resources/xsl/rc/periods2options.xsl @@ -16,9 +16,9 @@ - \ No newline at end of file + diff --git a/src/test/java/de/urmel_dl/dbt/events/TestIdentifierExtractorEventHandler.java b/src/test/java/de/urmel_dl/dbt/events/TestIdentifierExtractorEventHandler.java deleted file mode 100644 index 3eeac470..00000000 --- a/src/test/java/de/urmel_dl/dbt/events/TestIdentifierExtractorEventHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the Digitale Bibliothek Thüringen - * Copyright (C) 2000-2018 - * See and - * - * 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 3 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 . - */ -package de.urmel_dl.dbt.events; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Optional; - -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; -import org.junit.Test; -import org.mycore.common.MCRTestCase; -import org.mycore.common.content.MCRStreamContent; -import org.mycore.common.events.MCREvent; -import org.mycore.datamodel.metadata.MCRObject; -import org.mycore.mods.MCRMODSWrapper; - -/** - * @author René Adler (eagle) - * - */ -public class TestIdentifierExtractorEventHandler extends MCRTestCase { - - @Test - public void testIdentfierExtract() throws IOException, JDOMException { - for (String wantedPPN : Arrays.asList("101233726X", "1012341062", "502025298", "39170155X")) { - MCRStreamContent sc = new MCRStreamContent( - getClass().getClassLoader().getResourceAsStream("mods_id_extract_" + wantedPPN + ".xml")); - MCRObject obj = new MCRObject(sc.asByteArray(), false); - - assertNotNull(obj); - - MCREvent evt = new MCREvent(MCREvent.ObjectType.OBJECT, MCREvent.EventType.CREATE); - evt.put(MCREvent.OBJECT_KEY, obj); - - IdentifierExtractorEventHandler eh = new IdentifierExtractorEventHandler(); - eh.doHandleEvent(evt); - - new XMLOutputter(Format.getPrettyFormat()).output(obj.createXML(), System.out); - - MCRMODSWrapper mods = new MCRMODSWrapper(obj); - Optional ppnURI = mods.getElements("mods:identifier[@type='uri']").stream() - .map(Element::getTextTrim) - .filter(textTrim -> textTrim.contains("gvk:ppn")).findFirst(); - - assertTrue("we should have a ppn URI", ppnURI.isPresent()); - - String ppn = ppnURI.map(uri -> uri.substring(uri.indexOf("ppn:") + 4)).orElse(null); - - assertEquals("should match", wantedPPN, ppn); - } - } - -} diff --git a/src/test/java/de/urmel_dl/dbt/rc/TestPeriod.java b/src/test/java/de/urmel_dl/dbt/rc/TestPeriod.java index 90e88aa3..bb090000 100644 --- a/src/test/java/de/urmel_dl/dbt/rc/TestPeriod.java +++ b/src/test/java/de/urmel_dl/dbt/rc/TestPeriod.java @@ -51,11 +51,11 @@ public void testPeriod() throws IOException { assertEquals("01.10.", period.getFrom()); assertEquals("31.03.", period.getTo()); - period.setSetableFrom("21.07."); - period.setSetableTo("02.02."); + period.setSettableFrom("21.07."); + period.setSettableTo("02.02."); - assertEquals("21.07.", period.getSetableFrom()); - assertEquals("02.02.", period.getSetableTo()); + assertEquals("21.07.", period.getSettableFrom()); + assertEquals("02.02.", period.getSettableTo()); period.setLectureEnd("02.03."); assertEquals("02.03.", period.getLectureEnd()); @@ -78,11 +78,11 @@ public void testPeriodFQFromAfterTo() throws IOException { assertEquals("01.10." + year, period.getFrom()); assertEquals("31.03." + (year + 1), period.getTo()); - period.setSetableFrom("21.07."); - period.setSetableTo("02.02."); + period.setSettableFrom("21.07."); + period.setSettableTo("02.02."); - assertEquals("21.07." + year, period.getSetableFrom()); - assertEquals("02.02." + (year + 1), period.getSetableTo()); + assertEquals("21.07." + year, period.getSettableFrom()); + assertEquals("02.02." + (year + 1), period.getSettableTo()); period.setLectureEnd("02.03."); assertEquals("02.03." + (year + 1), period.getLectureEnd()); @@ -105,11 +105,11 @@ public void testPeriodFQToAfterFrom() throws IOException { assertEquals("01.04." + year, period.getFrom()); assertEquals("30.09." + year, period.getTo()); - period.setSetableFrom("03.02."); - period.setSetableTo("20.07."); + period.setSettableFrom("03.02."); + period.setSettableTo("20.07."); - assertEquals("03.02." + year, period.getSetableFrom()); - assertEquals("20.07." + year, period.getSetableTo()); + assertEquals("03.02." + year, period.getSettableFrom()); + assertEquals("20.07." + year, period.getSettableTo()); period.setLectureEnd("03.08."); assertEquals("03.08." + year, period.getLectureEnd()); @@ -163,52 +163,52 @@ public void testPeriodToLong() throws IOException { public void testPeriodSetableFromShort() throws IOException { Period period = new Period(); - period.setSetableFrom("01.10."); - period.setSetableTo("02.10."); - assertEquals("01.10.", period.getSetableFrom()); + period.setSettableFrom("01.10."); + period.setSettableTo("02.10."); + assertEquals("01.10.", period.getSettableFrom()); - period.setSetableFrom("01.12."); - period.setSetableTo("02.12."); - assertEquals("01.12.", period.getSetableFrom()); + period.setSettableFrom("01.12."); + period.setSettableTo("02.12."); + assertEquals("01.12.", period.getSettableFrom()); } @Test public void testPeriodSetableFromLong() throws IOException { Period period = new Period(); - period.setSetableFrom("01.10.2014"); - period.setSetableTo("02.10.2014"); - assertEquals("01.10.", period.getSetableFrom()); + period.setSettableFrom("01.10.2014"); + period.setSettableTo("02.10.2014"); + assertEquals("01.10.", period.getSettableFrom()); - period.setSetableFrom("01.12.2014"); - period.setSetableTo("02.12.2014"); - assertEquals("01.12.", period.getSetableFrom()); + period.setSettableFrom("01.12.2014"); + period.setSettableTo("02.12.2014"); + assertEquals("01.12.", period.getSettableFrom()); } @Test public void testPeriodSetableToShort() throws IOException { Period period = new Period(); - period.setSetableFrom("01.10."); - period.setSetableTo("02.10."); - assertEquals("02.10.", period.getSetableTo()); + period.setSettableFrom("01.10."); + period.setSettableTo("02.10."); + assertEquals("02.10.", period.getSettableTo()); - period.setSetableFrom("30.11."); - period.setSetableTo("01.12."); - assertEquals("01.12.", period.getSetableTo()); + period.setSettableFrom("30.11."); + period.setSettableTo("01.12."); + assertEquals("01.12.", period.getSettableTo()); } @Test public void testPeriodSetableToLong() throws IOException { Period period = new Period(); - period.setSetableFrom("01.10.2014"); - period.setSetableTo("01.10.2014"); - assertEquals("01.10.", period.getSetableTo()); + period.setSettableFrom("01.10.2014"); + period.setSettableTo("01.10.2014"); + assertEquals("01.10.", period.getSettableTo()); - period.setSetableFrom("30.11.2014"); - period.setSetableTo("01.12.2014"); - assertEquals("01.12.", period.getSetableTo()); + period.setSettableFrom("30.11.2014"); + period.setSettableTo("01.12.2014"); + assertEquals("01.12.", period.getSettableTo()); } @Test @@ -241,8 +241,8 @@ public void testPeriodTransform() throws IOException { period.setFrom("01.10."); period.setTo("31.03."); - period.setSetableFrom("21.07."); - period.setSetableTo("02.02."); + period.setSettableFrom("21.07."); + period.setSettableTo("02.02."); period.setLectureEnd("02.03."); @@ -267,8 +267,8 @@ public void testPeriodFQTransform() throws IOException { period.setFrom("01.10."); period.setTo("31.03."); - period.setSetableFrom("21.07."); - period.setSetableTo("02.02."); + period.setSettableFrom("21.07."); + period.setSettableTo("02.02."); period.setLectureEnd("02.03."); diff --git a/src/test/java/de/urmel_dl/dbt/rc/TestRCCalendar.java b/src/test/java/de/urmel_dl/dbt/rc/TestRCCalendar.java index a518ac0d..a666d66b 100644 --- a/src/test/java/de/urmel_dl/dbt/rc/TestRCCalendar.java +++ b/src/test/java/de/urmel_dl/dbt/rc/TestRCCalendar.java @@ -42,7 +42,7 @@ /** * Test Case for RCCalendar. * - * @author Ren\u00E9 Adler (eagle) + * @author René Adler (eagle) */ public class TestRCCalendar extends MCRTestCase { @@ -76,8 +76,8 @@ public void testRCCalendarGetPeriod() throws IOException { } @Test - public void testRCCalendarGetSetable() throws IOException { - Period period = RCCalendar.getPeriodBySetable("2700", new Date()); + public void testRCCalendarGetSettable() throws IOException { + Period period = RCCalendar.getPeriodBySettable("2700", new Date()); assertNotNull(period); Document p = new EntityFactory<>(period).toDocument(); @@ -97,27 +97,27 @@ public void testPeriodResolverList() throws IOException { Element input = MCRURIResolver.instance().resolve("period:areacode=0&date=now&list=true"); new XMLOutputter(Format.getPrettyFormat()).output(input, System.out); - assertTrue(Boolean.parseBoolean(input.getChildren("period").get(0).getAttributeValue("setable"))); + assertTrue(Boolean.parseBoolean(input.getChildren("period").getFirst().getAttributeValue("settable"))); } @Test public void testPeriodResolverListAll() throws IOException { Element input = MCRURIResolver.instance() - .resolve("period:areacode=0&date=31.03.2015&onlySetable=false&list=true"); + .resolve("period:areacode=0&date=31.03.2015&onlySettable=false&list=true"); new XMLOutputter(Format.getPrettyFormat()).output(input, System.out); - assertFalse(Boolean.parseBoolean(input.getChildren("period").get(0).getAttributeValue("setable"))); + assertFalse(Boolean.parseBoolean(input.getChildren("period").getFirst().getAttributeValue("settable"))); } @Test public void testPeriodResolverListFirstSemester() throws IOException, ParseException, CloneNotSupportedException { RCCalendar calendar = RCCalendar.instance(); - Period p = calendar.getPeriods().get(0).clone(); + Period p = calendar.getPeriods().getFirst().clone(); p.setStartDate(new Date()); p.setFullyQualified(true); Element input = MCRURIResolver.instance() - .resolve("period:areacode=0&date=" + p.getSetableFrom() + "&list=true"); + .resolve("period:areacode=0&date=" + p.getSettableFrom() + "&list=true"); new XMLOutputter(Format.getPrettyFormat()).output(input, System.out); assertEquals(2, input.getChildren("period").size()); @@ -131,10 +131,10 @@ public void testPeriodResolverListSecondSemester() throws IOException, ParseExce p.setFullyQualified(true); Element input = MCRURIResolver.instance() - .resolve("period:areacode=0&date=" + p.getSetableFrom() + "&list=true"); + .resolve("period:areacode=0&date=" + p.getSettableFrom() + "&list=true"); new XMLOutputter(Format.getPrettyFormat()).output(input, System.out); - assertTrue(Boolean.parseBoolean(input.getChildren("period").get(0).getAttributeValue("setable"))); + assertTrue(Boolean.parseBoolean(input.getChildren("period").getFirst().getAttributeValue("settable"))); assertEquals(2, input.getChildren("period").size()); } @@ -149,17 +149,17 @@ public void testPeriodResolverListMore() throws IOException { @Test public void testPeriodResolverListMoreAll() throws IOException { Element input = MCRURIResolver.instance() - .resolve("period:areacode=0&date=30.09.2014&list=true&onlySetable=false&numnext=1"); + .resolve("period:areacode=0&date=30.09.2014&list=true&onlySettable=false&numnext=1"); new XMLOutputter(Format.getPrettyFormat()).output(input, System.out); - assertFalse(Boolean.parseBoolean(input.getChildren("period").get(0).getAttributeValue("setable"))); + assertFalse(Boolean.parseBoolean(input.getChildren("period").getFirst().getAttributeValue("settable"))); - int numSetable = 0; + int numbSettable = 0; for (Element child : input.getChildren("period")) { - if (Boolean.parseBoolean(child.getAttributeValue("setable"))) { - numSetable++; + if (Boolean.parseBoolean(child.getAttributeValue("settable"))) { + numbSettable++; } } - assertEquals(2, numSetable); + assertEquals(2, numbSettable); } }