Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIR-1226 rework subject editor #885

Merged
merged 12 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

public abstract class MIREditorController extends MIRTestController {

Expand Down Expand Up @@ -44,7 +45,8 @@ protected void setHTMLAreaText(String childElementName, String text) {
protected void clickRepeater(String field) {
driver
.waitAndFindElement(
By.xpath(".//button[contains(@name, '" + field + "') and contains(@name, '_xed_submit_insert')]"))
By.xpath(".//button[contains(@name, '" + field + "') and contains(@name, '_xed_submit_insert')]"),
ExpectedConditions::elementToBeClickable)
.click();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.MCRException;
import org.mycore.common.selenium.drivers.MCRWebdriverWrapper;
import org.mycore.mir.it.model.MIRAbstract;
import org.mycore.mir.it.model.MIRAccess;
Expand Down Expand Up @@ -263,19 +262,86 @@ public void setIdentifier(List<AbstractMap.Entry<MIRIdentifier, String>> typeIde

public void setTopics(List<String> topics) {
if (topics.size() > 0) {
if (topics.size() > 1) {
IntStream.range(1, topics.size()).forEach((n) -> clickRepeaterAndWait("mods:topic",
".//input[contains(@name, 'mods:topic[" + (n + 1) + "]')]"));
}

IntStream.range(0, topics.size()).forEach(i -> {
String xp = "mods:topic[" + (i + 1) + "]";
String topic = topics.get(i);
setInputText(xp, topic);
IntStream.range(0, topics.size()).forEach((i) -> {
String appBaseXPath = ".//input[contains(@name, 'mods:subjectXML[" + (i + 1)
+ "]')]/following-sibling::div[contains(@class, 'editorToolsApp')]";
String searchInputXPath = appBaseXPath + "//input[contains(@class, 'search-topic')]";

if(i > 0) {
clickRepeaterAndWait("mods:subjectXML", searchInputXPath);
}

WebElement searchInput = driver.waitAndFindElement(By.xpath(searchInputXPath));
searchInput.click();
searchInput.sendKeys(topics.get(i));
searchInput.sendKeys(Keys.ENTER);

String searchAddCustomXPath = appBaseXPath + "//button[contains(@class, 'search-add-custom')]";
WebElement searchAddCustom = driver.waitAndFindElement(By.xpath(searchAddCustomXPath));
searchAddCustom.click();;

WebElement selectElement = driver
.waitAndFindElement(By.xpath(appBaseXPath + "//select[contains(@class, 'custom-type-select')]"));
new Select(selectElement).selectByValue("Topic");
WebElement topicInput = driver.waitAndFindElement(
By.xpath(appBaseXPath + "//input[contains(@id, 'topic') and contains(@class, 'form-control')]"));
topicInput.clear();
topicInput.sendKeys(topics.get(i));
waitForAnimationFinish();
driver.waitAndFindElement(By.xpath(appBaseXPath + "//button[contains(@class, 'custom-add')]"))
.click();
});
}
}

public void setGeoPair(String place, String coordinates) {
IntStream.range(0, 2).forEach((i) -> {
String appBaseXPath = ".//input[contains(@name, 'mods:subjectGEO[1]')]/following-sibling::div[contains(@class, 'editorToolsApp')]";

if(i==1) {
String addCoordinateButton = appBaseXPath + "//a[contains(@class, 'add-coordinate')]";
driver.waitAndFindElement(By.xpath(addCoordinateButton)).click();
} else {
String searchInputXPath = appBaseXPath + "//input[contains(@class, 'search-topic')]";
WebElement searchInput = driver.waitAndFindElement(By.xpath(searchInputXPath));
searchInput.click();
searchInput.sendKeys("Jena");
searchInput.sendKeys(Keys.ENTER);
String searchAddCustomXPath = appBaseXPath + "//button[contains(@class, 'search-add-custom')]";
WebElement searchAddCustom = driver.waitAndFindElement(By.xpath(searchAddCustomXPath));
searchAddCustom.click();;
}
if (i == 0) {
WebElement selectElement = driver
.waitAndFindElement(By.xpath(appBaseXPath + "//select[contains(@class, 'custom-type-select')]"));
new Select(selectElement).selectByValue("Geographic");
} else {
WebElement selectElement = driver
.waitAndFindElement(By.xpath(appBaseXPath + "//select[contains(@class, 'custom-type-select')]"));
new Select(selectElement).selectByValue("Cartographics");

driver.waitAndFindElement(
By.xpath(
appBaseXPath + "//div[label[contains(text(), 'Koordinaten')]]/following-sibling::div/button"))
.click();
}

WebElement topicInput = driver.waitAndFindElement(By.xpath(appBaseXPath + "//input[contains(@id, "
+ (i == 0 ? "'geographic'" : "'coordinates'") + ") and contains(@class, 'form-control')]"));
topicInput.clear();
if (i == 0) {
topicInput.sendKeys(place);
} else {
topicInput.sendKeys(coordinates);
}

waitForAnimationFinish();
driver.waitAndFindElement(By.xpath(appBaseXPath + "//button[contains(@class, 'custom-add')]"))
.click();
});
}

public void setClassifications(List<MIRDNBClassification> classifications) {
if (classifications.size() > 0) {
if (classifications.size() > 1) {
Expand All @@ -292,14 +358,6 @@ public void setClassifications(List<MIRDNBClassification> classifications) {
}
}

public void setGeograhicPlace(String place) {
setInputText("mods:geographic", place);
}

public void setCoordinates(String coordinates) {
setInputText("mods:coordinates", coordinates);
}

public void setAuthors(List<String> names) {
setAuthors(names, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ private void fillEditorForm() {
editorController.setEdition(MIRTestData.EDITION);
editorController.setExtend(MIRTestData.EXTEND_SOLO);
editorController.setTypeOfResource(MIRTypeOfResource.still_image);
editorController.setCoordinates(MIRTestData.COORDINATES);
editorController.setGeograhicPlace(MIRTestData.GEOGRAPHIC_PLACE);
editorController.setGeoPair(MIRTestData.GEOGRAPHIC_PLACE, MIRTestData.COORDINATES);
editorController.setClassifications(
Stream.of(MIRDNBClassification._004, MIRDNBClassification._010).collect(Collectors.toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.mycore.mir.it.model.MIRLanguage;
import org.mycore.mir.it.model.MIRLicense;
import org.mycore.mir.it.model.MIRTypeOfResource;
import org.openqa.selenium.By;

public class MIRAuthorEditorITCase extends MIRITBase {

Expand Down Expand Up @@ -240,8 +241,11 @@ public void testTeachingMaterial() throws InterruptedException {
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_UNI_GER));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_INFORMATIK));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_BIBLIOGRAPHIEN));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC1));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC2));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC1 + ")]"));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC2 + ")]"));

// TODO: enable validation for license
//driver.waitAndFindElement(MCRBy.partialText(MIRLicense.cc_by_40.getValue()));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_RESOURCE_TEXT));
Expand Down Expand Up @@ -326,8 +330,10 @@ private void refPublicationCommonValidation(boolean standAlone) {
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.URN));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.DOI));

driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC1));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC2));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC1 + ")]"));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC2 + ")]"));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.ABSTRACT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@
}
}

ol.topic-list{
list-style: none;
display: block;
padding: 0;
margin-bottom: 0;
}

ol.topic-list:not(:last-child){
margin-bottom: 0.5em;
}

li.topic-element {
&:not(:last-child):after {
content: "/";
margin-right: 5px;
margin-left: 5px;
}
display: inline;
}

.workflow-box {
padding: 0.75rem 1rem;;
margin-bottom: 1rem;
Expand Down
5 changes: 3 additions & 2 deletions mir-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"engineStrict": true,
"devDependencies": {
"@fortawesome/fontawesome-free": "5.11.2",
"@fortawesome/fontawesome-free": "6.4.0",
"bootstrap": "4.4.1",
"bootstrap-3-typeahead": "4.0.2",
"bootstrap-datepicker": "1.9.0",
Expand All @@ -36,6 +36,7 @@
"ckeditor-notification": "^4.11.2",
"ckeditor-wordcount-plugin": "^1.17.6",
"ckeditor4": "^4.18.0",
"vue": "2.6.14"
"vue": "3.2.13",
"vue3-openlayers": "^1.0.0"
}
}
14 changes: 14 additions & 0 deletions mir-module/src/main/java/org/mycore/mir/editor/MIREditorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import org.jsoup.safety.Safelist;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.frontend.MCRFrontendUtil;
import org.w3c.dom.Node;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -44,6 +51,13 @@ protected static Document getCleanDocument(Document document, Safelist elementWh
return new Cleaner(elementWhitelist).clean(document);
}

public static String xmlAsString(Node node) throws TransformerException {
StringWriter writer = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(node), new StreamResult(writer));
return writer.toString();
}

protected static Safelist getSafeList() {
final Safelist elementSafelist = Safelist.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static org.mycore.common.xml.MCRXMLFunctions.isHtml;

import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -16,6 +18,7 @@
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.DOMOutputter;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
Expand All @@ -33,7 +36,45 @@ public Document process(Document oldXML) throws IOException, JDOMException {
final Document newXML = oldXML.clone();

fixAbstracts(newXML);
fixTitleInfos(newXML);

fixSubject(newXML);

return super.process(newXML);
}

private static void fixSubject(Document newXML) throws JDOMException, IOException {
final XPathExpression<Element> subjectsXPath
= XPathFactory.instance().compile(".//mods:*[local-name()='subjectXML' or local-name()='subjectGEO']",
Filters.element(), null, MCRConstants.MODS_NAMESPACE,
MCRConstants.XLINK_NAMESPACE);
final List<Element> subjectElements = new ArrayList<>(subjectsXPath.evaluate(newXML));

List<Element> subjectsToRemove = new ArrayList<>();
for (Element subject : subjectElements) {
subject.setName("subject");
subject.removeAttribute("geo");
String xmlContent = subject.getText();
SAXBuilder saxBuilder = new SAXBuilder();
Document result;
try (StringReader characterStream = new StringReader(xmlContent)) {
result = saxBuilder.build(characterStream);
}
Element newSubject = result.getRootElement();
subject.removeContent();
new ArrayList<>(newSubject.getChildren()).forEach(child -> {
child.detach();
subject.addContent(child);
});
if (subject.getChildren().size() == 0) {
subjectsToRemove.add(subject);
}
}

subjectsToRemove.forEach(subjectToRemove -> subjectToRemove.getParent().removeContent(subjectToRemove));
}

private static void fixTitleInfos(Document newXML) {
final XPathExpression<Element> titleInfoXPath = XPathFactory.instance().compile(".//mods:titleInfo",
Filters.element(), null, MCRConstants.MODS_NAMESPACE,
MCRConstants.XLINK_NAMESPACE);
Expand All @@ -50,8 +91,6 @@ public Document process(Document oldXML) throws IOException, JDOMException {
throw new MCRException("Error while converting HTML title!", e);
}
});

return super.process(newXML);
}

private static void fixTitle(Element titleInfoElement)
Expand Down
Loading
Loading