ref #10260 add getter for url created by urlPattern
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 24 Mar 2023 07:55:55 +0000 (08:55 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 24 Mar 2023 07:55:55 +0000 (08:55 +0100)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Identifier.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/IdentifierType.java

index 969b7fab89e4a01887a38fa15211d79cdb6bb2bf..e09d0b13519afdb9a599f3d0949087918ea6e9fd 100644 (file)
@@ -79,7 +79,7 @@ public class Identifier
 // ************************* CONSTRUCTOR ************************************
 
     @Deprecated  //for hibernate use only
-    protected Identifier(){};
+    protected Identifier(){}
 
     public Identifier (String identifier, IdentifierType type){
        this.identifier = identifier;
@@ -108,6 +108,18 @@ public class Identifier
                this.type = identifierType;
        }
 
+       public String getUrl() {
+           try {
+            if (type == null || isBlank(type.getUrlPattern()) || isBlank(this.identifier) ) {
+                return null;
+            }else {
+                return type.getUrlPattern().replace("{@ID}", this.identifier);
+            }
+        } catch (Exception e) {
+            return "error creating url pattern";
+        }
+       }
+
        //****************** CLONE ************************************************/
 
        @Override
index de2afabb44a506a85b232dd1e3b72bd848ca21cf..25d036f5953012ddf9915d57695b28a04ef6e104 100644 (file)
@@ -83,6 +83,9 @@ public class IdentifierType
                return new IdentifierType(description, label, labelAbbrev, null);
        }
 
+       //#10260
+       //a pattern representing an URL and which includes the placeholde "{@ID}"
+       //which will be replaced by the actual identifier
        private String urlPattern;
 
 //******************* CONSTRUCTOR ***********************************/
@@ -116,10 +119,20 @@ public class IdentifierType
 
 // ******************** GETTER /SETTER *********
 
+
+    /**
+     * A pattern which represents an URL and which includes the placeholde "{@ID}"
+     * which will be replaced by the actual identifier
+     * @see https://dev.e-taxonomy.eu/redmine/issues/10260
+     */
     public String getUrlPattern() {
         return urlPattern;
     }
 
+    /**
+     * @param urlPattern the url pattern
+     * @see #getUrlPattern()
+     */
     public void setUrlPattern(String urlPattern) {
         this.urlPattern = urlPattern;
     }