Skip to content

Commit

Permalink
Merge pull request #839 from camille-hdl/master
Browse files Browse the repository at this point in the history
1.4.0 déplacer genreform physdesc
  • Loading branch information
camille-hdl committed May 22, 2023
2 parents 93fe90e + a108560 commit 3479ddf
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "2" # required to adjust maintainability checks
checks:
argument-count:
enabled: false
complex-logic:
config:
threshold: 9
file-lines:
config:
threshold: 1000
method-complexity:
config:
threshold: 10
method-count:
config:
threshold: 20
method-lines:
config:
threshold: 250
nested-control-flow:
config:
threshold: 4
return-statements:
enabled: false
similar-code:
config:
threshold: 75
identical-code:
config:
threshold: 55
8 changes: 8 additions & 0 deletions cypress/fixtures/example-ffas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@
<p>DEVRAIT ETRE<lb />IGNORE</p>
</controlaccess>
</c>
<c id="test-genreform-physdesc">
<did><unitid>testChild 132</unitid></did>
<controlaccess>
<persname>Top, Jean Frédéric</persname>
<genreform role="test">val1</genreform>
<genreform>val2</genreform>
</controlaccess>
</c>
</dsc>
</archdesc>
</ead>
15 changes: 15 additions & 0 deletions cypress/integration/recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,19 @@ describe("Recipe unit test", function () {
expect(matchesAfter[0].getAttribute("role")).to.be.equal("notaire");
expect(matchesAfter[1].getAttribute("role")).to.be.equal("notaire");
});
it("deplacer_genreform_physdesc", function () {
const xpathExpr = '//c[@id="test-genreform-physdesc"]/did/physdesc/genreform';
const matchesBefore = xpathFilter(doc, xpathExpr);
expect(matchesBefore.length).to.be.equal(0);
expect(xpathFilter(doc, '//c[@id="test-genreform-physdesc"]/did/physdesc').length).to.be.equal(0);
expect(xpathFilter(doc, '//c[@id="test-genreform-physdesc"]/controlaccess/*').length).to.be.equal(3);

doc = recipes.deplacer_genreform_physdesc()(doc);
expect(xpathFilter(doc, '//c[@id="test-genreform-physdesc"]/did/physdesc').length).to.be.equal(1);
const matchesAfter = xpathFilter(doc, xpathExpr);
expect(matchesAfter.length).to.be.equal(2);
expect(xpathFilter(doc, '//c[@id="test-genreform-physdesc"]/controlaccess/*').length).to.be.equal(1);
expect(xpathFilter(doc, '//c[@id="test-genreform-physdesc"]/did/physdesc/genreform[@role="test"]').length).to.be.equal(1);
expect(xpathFilter(doc, '//c[@id="test-genreform-physdesc"]/did/physdesc/genreform[@source="genreform"]').length).to.be.equal(2);
});
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cuisine-ead",
"version": "1.3.0",
"version": "1.4.0",
"description": "",
"main": "public/index.html",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/recipes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import extraireDaoFromDaodesc from "./individual-recipes/extraire-dao-daodesc.js
import remplaceDaoHref from "./individual-recipes/remplace-dao-href.js";
import separerControlaccessLb from "./individual-recipes/separer-controlaccess-lb.js";
import separerControlaccessSeparator from "./individual-recipes/separer-controlaccess-separator.js";
import deplacerGenreformPhysdesc from "./individual-recipes/deplacer-genreform-physdesc.js";
import insertIntoDocument from "./insert-into-document.js";

/**
Expand Down Expand Up @@ -121,6 +122,7 @@ export const getRecipes = () => {
{ key: "corriger_source_contexte", fn: corrigerSubjectContexteHisto },
{ key: "corriger_mat_spec_donnees", fn: corrigerMatSpecDonnees },
{ key: "corriger_deplacer_genreform", fn: corrigerGenreformPhysdesc },
{ key: "deplacer_genreform_physdesc", fn: deplacerGenreformPhysdesc },
{ key: "pack_ligeo", fn: traitementsLigeo },
{ key: "suppr_mnesys_internal", fn: supprimerMnesysInternal },
{ key: "suppr_accessrestrict_formate", fn: supprimerAccessRestrictFormate },
Expand Down
38 changes: 38 additions & 0 deletions src/lib/recipes/individual-recipes/deplacer-genreform-physdesc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@flow
import { xpathFilter } from "../../xml.js";
import { each } from "../utils.js";
import { last } from "ramda";

/**
* Ligeo
* Déplacer tous les //controlaccess/genreform dans physdesc.
* C'est une version moins spécifique de ./corriger-genreform-physdesc.js
*/
export default () => (doc: Document): Document => {
const CAs = xpathFilter(doc, "//controlaccess");
each(CAs, (elem) => {
const genreforms = xpathFilter(doc, elem, "genreform");
if (genreforms.length <= 0) return;
const existingPhysdesc = last(xpathFilter(doc, elem, "(parent::c/did/physdesc)|(parent::archdesc/did/physdesc)"));
const newPhysdesc = !existingPhysdesc;
const physdesc = existingPhysdesc ? existingPhysdesc : doc.createElement("physdesc");
each(genreforms, (el) => {
if (!el.hasAttribute("source")) {
el.setAttribute("source", "genreform");
}
if (!el.hasAttribute("type")) {
el.setAttribute("type", "genre");
}
physdesc.appendChild(el);
});
if (newPhysdesc && physdesc.hasChildNodes()) {
const did = last(xpathFilter(doc, elem, "(parent::c/did)|(parent::archdesc/did)"));
if (!did) {
console.log("Pas de did pour créer le physdesc.");
return;
}
did.appendChild(physdesc);
}
});
return doc;
};
8 changes: 8 additions & 0 deletions src/lib/recipes/recipes-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ const availables: Array<[string, RecipeInfo]> = [
"corriger_deplacer_genreform",
{
label: "Déplacer certains genreform dans physdesc",
complement: "Uniquement les valeurs : matrice cadastrale, état de sections, tableau d'assemblage, plan-minute de conservation, liste, iconographie, nomenclature des propriétaires",
category: "Spécifique",
},
],
[
"deplacer_genreform_physdesc",
{
label: "Déplacer TOUS les genreform dans physdesc",
category: "Spécifique",
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { CacheableResponsePlugin } = workbox.cacheableResponse;
const { ExpirationPlugin } = workbox.expiration;
const { skipWaiting, clientsClaim, setCacheNameDetails } = workbox.core;

var VERSION = "v1.3.0";
var VERSION = "v1.4.0";
setCacheNameDetails({
prefix: "cuisine-ead",
suffix: VERSION,
Expand Down

0 comments on commit 3479ddf

Please sign in to comment.