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

Recipe deplacer dans did #860

Merged
merged 2 commits into from
Aug 6, 2024
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
21 changes: 21 additions & 0 deletions cypress/fixtures/example-ffas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
</scopecontent>
</did>

<physdesc data-cy="should-move-to-did-archdesc">
<extent>TEST</extent>
</physdesc>

<acqinfo>
<p>Versement.</p>
</acqinfo>
Expand Down Expand Up @@ -452,6 +456,23 @@
</did>
</c>
</c>
<c id="test-deplacer-dans-did-1">
<did>
<unittitle>test-deplacer-dans-did-1</unittitle>
<physloc>devrait rester</physloc>
</did>
<physdesc data-cy="should-move-to-did-c">
<extent>TEST</extent>
</physdesc>
</c>
<c id="test-deplacer-dans-did-2">
<physdesc data-cy="should-move-to-new-did-c">
TEST
</physdesc>
<physloc data-cy="should-move-to-new-did-c-2">
TEST2
</physloc>
</c>
</dsc>
</archdesc>
</ead>
33 changes: 33 additions & 0 deletions cypress/integration/recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,37 @@ describe("Recipe unit test", function () {
expect(xpathFilter(doc, ficheC3, 'did/unitdate')[0].textContent).to.be.equal("Année 3000");
expect(xpathFilter(doc, ficheC3, 'did/unittitle')[0].textContent).to.be.equal("test-unitdate-3 Année 3000");
});
it("deplacer_dans_did", function () {
const archdesc = xpathFilter(doc, '//archdesc')[0];
expect(xpathFilter(doc, archdesc, 'did/physdesc').length).to.be.equal(0);
expect(xpathFilter(doc, archdesc, 'did/physdesc/extent').length).to.be.equal(0);
expect(xpathFilter(doc, archdesc, 'physdesc').length).to.be.equal(1);

const ficheC1 = xpathFilter(doc, '//c[@id="test-deplacer-dans-did-1"]')[0];
expect(xpathFilter(doc, ficheC1, 'did/physdesc').length).to.be.equal(0);
expect(xpathFilter(doc, ficheC1, 'did/physloc').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC1, 'physdesc').length).to.be.equal(1);

const ficheC2 = xpathFilter(doc, '//c[@id="test-deplacer-dans-did-2"]')[0];
expect(xpathFilter(doc, ficheC2, 'did').length).to.be.equal(0);
expect(xpathFilter(doc, ficheC2, 'physloc').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC2, 'physdesc').length).to.be.equal(1);

doc = recipes.deplacer_dans_did(IMap({balises: "physdesc|physloc"}))(doc);

expect(xpathFilter(doc, archdesc, 'did/physdesc').length).to.be.equal(1);
expect(xpathFilter(doc, archdesc, 'did/physdesc/extent').length).to.be.equal(1);
expect(xpathFilter(doc, archdesc, 'did/physdesc/extent')[0].textContent).to.be.equal("TEST");
expect(xpathFilter(doc, archdesc, 'physdesc').length).to.be.equal(0);

expect(xpathFilter(doc, ficheC1, 'did/physdesc').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC1, 'did/physloc').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC1, 'physdesc').length).to.be.equal(0);

expect(xpathFilter(doc, ficheC2, 'did').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC2, 'did/physdesc').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC2, 'did/physloc').length).to.be.equal(1);
expect(xpathFilter(doc, ficheC2, 'physloc').length).to.be.equal(0);
expect(xpathFilter(doc, ficheC2, 'physdesc').length).to.be.equal(0);
});
});
6 changes: 1 addition & 5 deletions src/components/changelog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
<ExpansionPanelDetails>
<Typography className={classes.changelog}>
<ul>
<li>{"Nouveau traitement : diviser les controlaccess à partir d'un texte séparateur (ex: ' / ')"}</li>
<li>{"Nouveau traitement : rechercher/remplacer dans les dao* href"}</li>
<li>{"Nouveau traitement : diviser les controlaccess entre chaque <lb />"}</li>
<li>{"Nouveau traitement : sortir scopecontent du did et le placer juste après"}</li>
<li>{"Sur la page des résultats : fusionner les fichiers en un seul, à partir des archref"}</li>
<li>{"Nouveau traitement : déplacer des balises dans did"}</li>
</ul>
</Typography>
</ExpansionPanelDetails>
Expand Down
10 changes: 10 additions & 0 deletions src/components/recipes-args/recipe-args.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ArgumentList(props: Props) {
if (props.recipe === "index_from_unittitle_multi") return <IndexFromUnittitleMultiArgs {...props} />;
if (props.recipe === "remplace_dao_href") return <RechRemplacerDaoHrefArgs {...props} />;
if (props.recipe === "separer_controlaccess_separator") return <SeparerControlaccessSeparatorArgs {...props} />;
if (props.recipe === "deplacer_dans_did") return <DeplacerDansDidArgs {...props} />;
return null;
}

Expand Down Expand Up @@ -115,3 +116,12 @@ function IndexFromUnittitleMultiArgs(props: Props) {
function SeparerControlaccessSeparatorArgs(props: Props) {
return <TextArg {...props} argName="separator" label="Texte à utiliser comme séparateur" />;
}


function DeplacerDansDidArgs(props: Props) {
return (
<>
<TextArg {...props} argName="balises" label="Balises à déplacer." />
</>
);
}
2 changes: 2 additions & 0 deletions src/lib/recipes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import separerControlaccessSeparator from "./individual-recipes/separer-controla
import deplacerGenreformPhysdesc from "./individual-recipes/deplacer-genreform-physdesc.js";
import insertIntoDocument from "./insert-into-document.js";
import deplacerUnitdateUnittitle from "./individual-recipes/deplacer-unitdate-unittitle.js";
import deplacerDansDid from "./individual-recipes/deplacer-dans-did.js";

/**
* Returns an array of 'simple' recipes creators : functions that create functions that take a single DOM `Document` as argument and returns
Expand Down Expand Up @@ -158,6 +159,7 @@ export const getRecipes = () => {
{ key: "separer_controlaccess_lb", fn: separerControlaccessLb },
{ key: "separer_controlaccess_separator", fn: separerControlaccessSeparator },
{ key: "deplacer_unitdate_unittitle", fn: deplacerUnitdateUnittitle },
{ key: "deplacer_dans_did", fn: deplacerDansDid },
];
};

Expand Down
32 changes: 32 additions & 0 deletions src/lib/recipes/individual-recipes/deplacer-dans-did.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@flow
import { xpathFilter } from "../../xml.js";
import { each } from "../utils.js";
import { last } from "ramda";

const SEPARATOR = "|";
/**
* Move some tags to <did> within <c>, <archdesc>, <archdescgrp>.
* <did> is created if it doesn't exist.
*/
export default (args: Map<string, any>) => (doc: Document): Document => {
const tags = args.get("balises") ?? "";
const tagNames = ("" + tags).split(SEPARATOR).map((s) => s.trim());
if (tagNames.length <= 0) return doc;

const balises = xpathFilter(doc, "//archdesc|//archdescgrp|//c");
each(balises, (elem: Element) => {
const hasDid = xpathFilter(doc, elem, "did").length > 0;
let shouldHaveDid = false;
const did = last(xpathFilter(doc, elem, "did")) ?? doc.createElement("did");
each(tagNames, (tagName) => {
each(xpathFilter(doc, elem, `${tagName}`), (tag) => {
did.appendChild(tag);
shouldHaveDid = true;
});
});
if (!hasDid && shouldHaveDid) {
elem.appendChild(did);
}
});
return doc;
};
9 changes: 9 additions & 0 deletions src/lib/recipes/recipes-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,15 @@ const availables: Array<[string, RecipeInfo]> = [
defaultArgs: { separator: "/" },
},
],
[
"deplacer_dans_did",
{
label: "Déplacer des balises de <c>, <archdesc>, <archdescgrp> dans leur <did>",
category: "Corrections",
complement: "Séparateur pour indiquer plusieurs balises: |",
defaultArgs: { balises: "physdesc|physloc" },
},
],
];

/**
Expand Down
Loading