Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonde committed Sep 10, 2020
2 parents 9c988c4 + 41ec788 commit 622337c
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 88 deletions.
4 changes: 2 additions & 2 deletions goobi-viewer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.goobi.viewer</groupId>
<artifactId>viewer-core</artifactId>
<version>4.10.0</version>
<version>4.11.0-SNAPSHOT</version>
<packaging>jar</packaging>


Expand Down Expand Up @@ -118,7 +118,7 @@
<jstl.version>1.2</jstl.version>
<junit.version>4.13</junit.version>
<mariadb-java-client.version>2.3.0</mariadb-java-client.version>
<mockito.version>3.5.9</mockito.version>
<mockito.version>3.5.10</mockito.version>
<mockserver.version>5.11.1</mockserver.version>
<oauth.version>1.0.2</oauth.version>
<openpdf.version>1.3.20</openpdf.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -53,12 +55,10 @@
import de.intranda.metadata.multilanguage.SimpleMetadataValue;
import de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException;
import de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException;
import de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException;
import io.goobi.viewer.api.rest.AbstractApiUrlManager;
import io.goobi.viewer.api.rest.resourcebuilders.TextResourceBuilder;
import io.goobi.viewer.controller.DataManager;
import io.goobi.viewer.controller.FileTools;
import io.goobi.viewer.exceptions.AccessDeniedException;
import io.goobi.viewer.controller.StringTools;
import io.goobi.viewer.exceptions.DAOException;
import io.goobi.viewer.exceptions.IndexUnreachableException;
import io.goobi.viewer.exceptions.PresentationException;
Expand Down Expand Up @@ -94,7 +94,7 @@ public class SequenceBuilder extends AbstractBuilder {
protected ImageDeliveryBean imageDelivery = BeanUtils.getImageDeliveryBean();
private BuildMode buildMode = BuildMode.IIIF;
private PageType preferredView = PageType.viewObject;

/**
* <p>
* Constructor for SequenceBuilder.
Expand Down Expand Up @@ -197,6 +197,11 @@ public void addSeeAlsos(Canvas canvas, StructElement doc, PhysicalElement page)

if (MimeType.IMAGE.getName().equals(page.getMimeType())) {
String url = imageDelivery.getPdf().getPdfUrl(doc, page);
try {
url = URLEncoder.encode(url, StringTools.DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage());
}
LinkingContent link = new LinkingContent(new URI(url));
link.setFormat(Format.APPLICATION_PDF);
link.setType(DcType.SOFTWARE);
Expand Down Expand Up @@ -394,8 +399,9 @@ public Map<AnnotationType, AnnotationList> addOtherContent(StructElement doc, Ph
String altoText = builder.getAltoDocument(doc.getPi(), altoFilename);
AltoDocument alto = AltoDocument.getDocumentFromString(altoText);
if (alto.getFirstPage() != null && StringUtils.isNotBlank(alto.getFirstPage().getContent())) {
List<IAnnotation> annos = new AltoAnnotationBuilder(urls, "oa").createAnnotations(alto.getFirstPage(), doc.getPi(), page.getOrder(), canvas,
AltoAnnotationBuilder.Granularity.LINE, false);
List<IAnnotation> annos =
new AltoAnnotationBuilder(urls, "oa").createAnnotations(alto.getFirstPage(), doc.getPi(), page.getOrder(), canvas,
AltoAnnotationBuilder.Granularity.LINE, false);
for (IAnnotation annotation : annos) {
annoList.addResource(annotation);
}
Expand All @@ -406,11 +412,11 @@ public Map<AnnotationType, AnnotationList> addOtherContent(StructElement doc, Ph

} else if (StringUtils.isNotBlank(page.getFulltextFileName())) {
try {
OpenAnnotation anno = new OpenAnnotation(URI.create(annoList.getId().toString() + "/text"));
anno.setMotivation(Motivation.PAINTING);
anno.setTarget(createSpecificResource(canvas, 0, 0, canvas.getWidth(), canvas.getHeight()));
String fulltextFilename = Paths.get(page.getFulltextFileName()).getFileName().toString();
String fulltext = builder.getFulltext(doc.getPi(), fulltextFilename);
OpenAnnotation anno = new OpenAnnotation(URI.create(annoList.getId().toString() + "/text"));
anno.setMotivation(Motivation.PAINTING);
anno.setTarget(createSpecificResource(canvas, 0, 0, canvas.getWidth(), canvas.getHeight()));
String fulltextFilename = Paths.get(page.getFulltextFileName()).getFileName().toString();
String fulltext = builder.getFulltext(doc.getPi(), fulltextFilename);
TextualResource body = new TextualResource(fulltext);
anno.setBody(body);
annoList.addResource(anno);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,75 +255,7 @@ public class BrowseElement implements Serializable {
if (this.metadataList != null) {
int length = DataManager.getInstance().getConfiguration().getSearchHitMetadataValueLength();
int number = DataManager.getInstance().getConfiguration().getSearchHitMetadataValueNumber();
for (Metadata md : this.metadataList) {
for (MetadataParameter param : md.getParams()) {
StructElement elementToUse = structElement;
if (StringUtils.isNotEmpty(param.getSource())) {
tempElement = structElement;
while (tempElement != null) {
if (param.getSource().equals(tempElement.getDocStructType())) {
elementToUse = tempElement;
break;
}
tempElement = tempElement.getParent();
}
} else if (MetadataParameterType.TOPSTRUCTFIELD.equals(param.getType()) && topStructElement != null) {
// Use topstruct value, if the parameter has the type "topstructfield"
elementToUse = topStructElement;
} else if (MetadataParameterType.ANCHORFIELD.equals(param.getType())) {
// Use anchor value, if the parameter has the type "anchorfield"
if (anchorStructElement != null) {
elementToUse = anchorStructElement;
} else {
// Add empty parameter if there is no anchor
md.setParamValue(0, md.getParams().indexOf(param), Collections.singletonList(""), null, null, null, null, locale);
continue;
}
}
int count = 0;
List<String> metadataValues = elementToUse.getMetadataValues(param.getKey());
// If the current element does not contain metadata values, look in the topstruct
if (metadataValues.isEmpty()) {
if (topStructElement != null && !topStructElement.equals(elementToUse)
&& !MetadataParameterType.ANCHORFIELD.equals(param.getType()) && param.isTopstructValueFallback()) {
metadataValues = topStructElement.getMetadataValues(param.getKey());
// logger.debug("Checking topstruct metadata: " + topStructElement.getDocStruct());
} else {
md.setParamValue(count, md.getParams().indexOf(param), Collections.singletonList(""), null, null, null, null, locale);
count++;
}
}
// Set actual values
for (String value : metadataValues) {
if (count >= md.getNumber() && md.getNumber() != -1 || count >= number) {
break;
}
// Apply replace rules
if (!param.getReplaceRules().isEmpty()) {
value = MetadataTools.applyReplaceRules(value, param.getReplaceRules(), topStructElement.getPi());
}
// Truncate long values
if (length > 0 && value.length() > length) {
value = new StringBuilder(value.substring(0, length - 3)).append("...").toString();
}
// Add highlighting
if (searchTerms != null) {
if (searchTerms.get(md.getLabel()) != null) {
value = SearchHelper.applyHighlightingToPhrase(value, searchTerms.get(md.getLabel()));
} else if (md.getLabel().startsWith("MD_SHELFMARK") && searchTerms.get("MD_SHELFMARKSEARCH") != null) {
value = SearchHelper.applyHighlightingToPhrase(value, searchTerms.get("MD_SHELFMARKSEARCH"));
}
if (searchTerms.get(SolrConstants.DEFAULT) != null) {
value = SearchHelper.applyHighlightingToPhrase(value, searchTerms.get(SolrConstants.DEFAULT));
}
}
md.setParamValue(count, md.getParams().indexOf(param), Collections.singletonList(StringTools.intern(value)), null,
param.isAddUrl() ? elementToUse.getUrl() : null, null, null, locale);
existingMetadataFields.add(md.getLabel());
count++;
}
}
}
populateMetadataList(structElement, topStructElement, anchorStructElement, searchTerms, length, number, locale);
}

if (navigationHelper == null) {
Expand Down Expand Up @@ -438,6 +370,92 @@ public class BrowseElement implements Serializable {
Collections.reverse(structElements);
}

/**
*
* @param structElement
* @param topStructElement
* @param anchorStructElement
* @param searchTerms
* @param length
* @param number
* @param locale
* @throws IndexUnreachableException
* @throws PresentationException
*/
void populateMetadataList(StructElement structElement, StructElement topStructElement, StructElement anchorStructElement,
Map<String, Set<String>> searchTerms, int length,
int number, Locale locale) throws IndexUnreachableException, PresentationException {
for (Metadata md : this.metadataList) {
for (MetadataParameter param : md.getParams()) {
StructElement elementToUse = structElement;
if (StringUtils.isNotEmpty(param.getSource())) {
StructElement tempElement = structElement;
while (tempElement != null) {
if (param.getSource().equals(tempElement.getDocStructType())) {
elementToUse = tempElement;
break;
}
tempElement = tempElement.getParent();
}
} else if (MetadataParameterType.TOPSTRUCTFIELD.equals(param.getType()) && topStructElement != null) {
// Use topstruct value, if the parameter has the type "topstructfield"
elementToUse = topStructElement;
} else if (MetadataParameterType.ANCHORFIELD.equals(param.getType())) {
// Use anchor value, if the parameter has the type "anchorfield"
if (anchorStructElement != null) {
elementToUse = anchorStructElement;
} else {
// Add empty parameter if there is no anchor
md.setParamValue(0, md.getParams().indexOf(param), Collections.singletonList(""), null, null, null, null, locale);
continue;
}
}
int count = 0;
List<String> metadataValues = elementToUse.getMetadataValues(param.getKey());
// If the current element does not contain metadata values, look in the topstruct
if (metadataValues.isEmpty()) {
if (topStructElement != null && !topStructElement.equals(elementToUse)
&& !MetadataParameterType.ANCHORFIELD.equals(param.getType()) && param.isTopstructValueFallback()) {
metadataValues = topStructElement.getMetadataValues(param.getKey());
// logger.debug("Checking topstruct metadata: " + topStructElement.getDocStruct());
} else {
md.setParamValue(count, md.getParams().indexOf(param), Collections.singletonList(""), null, null, null, null, locale);
count++;
}
}
// Set actual values
for (String value : metadataValues) {
if (count >= md.getNumber() && md.getNumber() != -1 || count >= number) {
break;
}
// Apply replace rules
if (!param.getReplaceRules().isEmpty()) {
value = MetadataTools.applyReplaceRules(value, param.getReplaceRules(), topStructElement.getPi());
}
// Truncate long values
if (length > 0 && value.length() > length) {
value = new StringBuilder(value.substring(0, length - 3)).append("...").toString();
}
// Add highlighting
if (searchTerms != null) {
if (searchTerms.get(md.getLabel()) != null) {
value = SearchHelper.applyHighlightingToPhrase(value, searchTerms.get(md.getLabel()));
} else if (md.getLabel().startsWith("MD_SHELFMARK") && searchTerms.get("MD_SHELFMARKSEARCH") != null) {
value = SearchHelper.applyHighlightingToPhrase(value, searchTerms.get("MD_SHELFMARKSEARCH"));
}
if (searchTerms.get(SolrConstants.DEFAULT) != null) {
value = SearchHelper.applyHighlightingToPhrase(value, searchTerms.get(SolrConstants.DEFAULT));
}
}
md.setParamValue(count, md.getParams().indexOf(param), Collections.singletonList(StringTools.intern(value)), null,
param.isAddUrl() ? elementToUse.getUrl() : null, null, null, locale);
this.existingMetadataFields.add(md.getLabel());
count++;
}
}
}
}

/**
* <p>
* createMultiLanguageLabel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static boolean checkAccess(HttpServletRequest request, String action, Str
* @should work correctly with urls
*/
static String[] generateAccessCheckQuery(String identifier, String fileName) {
if (fileName == null) {
if (StringUtils.isEmpty(fileName)) {
return new String[2];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ui:repeat value="#{cmsBean.getAllowedTemplates(userBean.user)}" var="template">
<div class="admin__boxed-entry row no-gutters -std-bottom-pad -w100">
<!-- TEMPLATE -->
<div class="col-9 d-flex">
<div class="col-9 d-flex align-items-center">
<!-- ICON -->
<div class="admin__table-img">
<img title="#{msg.label__cms_template_id}: #{template.id}" alt="#{template.name}"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
margin: 0 0 21px 0;
}
}
&__theme-template-marker,
&__theme-template-marker {}
&__action {
padding: 5px 0 15px 0;
}
&__theme-template-marker {
font-size: @fontSmall;
text-align: center;
text-align: right;
color: @blue;
}
&__action {
Expand Down

0 comments on commit 622337c

Please sign in to comment.