package fr.insee.rmes.queries.concepts;

import org.apache.commons.lang3.StringUtils;

public class ConceptsQueries {

    public static String getConceptsByLabel(String label) {
        if (StringUtils.isEmpty(label)) {
            label = "";
        }

        return "SELECT ?id ?uri ?intitule ?remplace ?estRemplacePar WHERE { \n"
            + "?uri skos:inScheme ?conceptScheme . \n"
            + "FILTER(REGEX(STR(?conceptScheme),'/concepts/definitions/scheme')) \n"
            + "?uri skos:notation ?id . \n"
            + "?uri skos:prefLabel ?intitule . \n"
            + "FILTER(lang(?intitule) = 'fr') \n"
            + "FILTER(CONTAINS(LCASE(STR(?intitule)),\""
            + label.toLowerCase()
            + "\"))"
            + "OPTIONAL{ ?uri dcterms:replaces ?remplace } \n"
            + "OPTIONAL{ ?estRemplacePar dcterms:replaces ?uri } \n"
            + "}"
            + "ORDER BY ?intitule";
    }

    public static String getConceptById(String id) {
        return "SELECT ?uri ?intitule ?remplace ?estRemplacePar WHERE { \n"
            + "?uri skos:inScheme ?conceptScheme . \n"
            + "FILTER(REGEX(STR(?conceptScheme),'/concepts/definitions/scheme')) \n"
            + "?uri skos:notation '"
            + id
            + "' . \n"
            + "?uri skos:prefLabel ?intitule . \n"
            + "FILTER(lang(?intitule) = 'fr') \n"
            + "OPTIONAL{ ?uri dcterms:replaces ?remplace } \n"
            + "OPTIONAL{ ?estRemplacePar dcterms:replaces ?uri } \n"
            + "}"
            + "ORDER BY ?intitule";
    }

}

@@ -175,84 +175,8 @@
 l) %7B
-%0A        if (StringUtils.isEmpty(label)) %7B%0A            label = %22%22;%0A        %7D
 %0A%0A  
@@ -608,16 +608,51 @@
        +
+ (StringUtils.isEmpty(label) ? %22%22 :
  label.t
@@ -663,16 +663,17 @@
 erCase()
+)
 %0A       

refactor ConceptQueries