From d85c52fdd49d0b3fab2cc51f841b5612a2da730d Mon Sep 17 00:00:00 2001 From: Thomas Francart Date: Thu, 9 Jul 2020 16:31:34 +0200 Subject: [PATCH] Algorithm generation doc + version 1.1 --- issnbot-app/pom.xml | 4 +- issnbot-lib/pom.xml | 2 +- .../java/org/issn/issnbot/WikidataSerial.java | 2 +- .../doc/AlgorithmDocumentationGenerator.java | 46 +++++++++++++++++++ .../org/issn/issnbot/doc/Description.java | 6 ++- issnbot-release/pom.xml | 14 +++++- 6 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 issnbot-lib/src/main/java/org/issn/issnbot/doc/AlgorithmDocumentationGenerator.java diff --git a/issnbot-app/pom.xml b/issnbot-app/pom.xml index 38d9255..38d3302 100644 --- a/issnbot-app/pom.xml +++ b/issnbot-app/pom.xml @@ -9,7 +9,7 @@ org.issn issnbot-root-pom - 1.0 + 1.1 ../pom.xml @@ -133,7 +133,7 @@ org.issn issnbot-lib - 1.0 + 1.1 diff --git a/issnbot-lib/pom.xml b/issnbot-lib/pom.xml index 2a1ff5b..8cbb3bb 100644 --- a/issnbot-lib/pom.xml +++ b/issnbot-lib/pom.xml @@ -9,7 +9,7 @@ org.issn issnbot-root-pom - 1.0 + 1.1 ../pom.xml diff --git a/issnbot-lib/src/main/java/org/issn/issnbot/WikidataSerial.java b/issnbot-lib/src/main/java/org/issn/issnbot/WikidataSerial.java index c127979..ef4121e 100644 --- a/issnbot-lib/src/main/java/org/issn/issnbot/WikidataSerial.java +++ b/issnbot-lib/src/main/java/org/issn/issnbot/WikidataSerial.java @@ -377,7 +377,7 @@ public List updateOfficialWebsiteStatements(SerialEntry serial) @Description( title = "ISSN-L (P7363)", definition= - "The ISSN-L processing is relatively straightforward because it does not hold the ISSN reference (being an identifier):\n" + "The ISSN-L processing is relatively straightforward because it does not hold the ISSN reference (being an identifier), like title, language etc.:\n" + "- If multiple ISSN-L are found on the same item, this is not a situation we can deal with, so this is considered an error.\n" + "- If an ISSN-L statement with the same value does not exist, then:\n" + " - Create a new ISSN-L statement on the item, without any reference.\n", diff --git a/issnbot-lib/src/main/java/org/issn/issnbot/doc/AlgorithmDocumentationGenerator.java b/issnbot-lib/src/main/java/org/issn/issnbot/doc/AlgorithmDocumentationGenerator.java new file mode 100644 index 0000000..cf37db3 --- /dev/null +++ b/issnbot-lib/src/main/java/org/issn/issnbot/doc/AlgorithmDocumentationGenerator.java @@ -0,0 +1,46 @@ +package org.issn.issnbot.doc; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.issn.issnbot.WikidataSerial; + +public class AlgorithmDocumentationGenerator { + + public static void main(String[] args) throws IOException { + File outputFile = new File(args[0]); + StringBuffer sb = new StringBuffer(); + sb.append("# ISSNBot update algorithm"+"\n"); + sb.append("_note : this file is automatically generated from the documentation in `WikidataSerial.java`._"+"\n"); + sb.append("\n"); + sb.append("This is the algorithms ISSNBot uses to update Wikidata. They are applied in the order listed here."+"\n"); + sb.append("\n"); + + Method[] methods = WikidataSerial.class.getMethods(); + List descriptions = new ArrayList<>(); + for (Method m : methods) { + Description d = m.getAnnotation(Description.class); + if(d != null) { + descriptions.add(d); + } + } + + // sort based on order + Collections.sort(descriptions, (d1, d2) -> d1.order() - d2.order()); + + for (Description description : descriptions) { + sb.append("## "+description.title()+"\n"); + sb.append("\n"); + sb.append(description.definition()+"\n"); + sb.append("\n"); + } + + FileUtils.write(outputFile, sb.toString(), "UTF-8"); + } + +} diff --git a/issnbot-lib/src/main/java/org/issn/issnbot/doc/Description.java b/issnbot-lib/src/main/java/org/issn/issnbot/doc/Description.java index 402b2a5..2788b68 100644 --- a/issnbot-lib/src/main/java/org/issn/issnbot/doc/Description.java +++ b/issnbot-lib/src/main/java/org/issn/issnbot/doc/Description.java @@ -1,13 +1,17 @@ package org.issn.issnbot.doc; import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) -@Target(FIELD) +@Target({ FIELD, METHOD }) public @interface Description { public String definition(); + public String title() default ""; + public int order() default 0; } \ No newline at end of file diff --git a/issnbot-release/pom.xml b/issnbot-release/pom.xml index 5fdcc19..edaaa48 100644 --- a/issnbot-release/pom.xml +++ b/issnbot-release/pom.xml @@ -10,7 +10,7 @@ org.issn issnbot-root-pom - 1.0 + 1.1 ../pom.xml @@ -57,8 +57,20 @@ ${project.basedir}/src/main/resources/UpdateStatuses.md + + generate-algorithms-documentation + generate-resources + + java + + + org.issn.issnbot.doc.AlgorithmDocumentationGenerator + ${project.basedir}/src/main/resources/UpdateAlgorithms.md + + +