]> WPIA git - gigi.git/blobdiff - src/club/wpia/gigi/dbObjects/Name.java
add: handling of who issued a certificate
[gigi.git] / src / club / wpia / gigi / dbObjects / Name.java
index d5bff5cbd8b52e9d5620dc065468afe574ed8ab0..fbcf10eed4c94fc76c8c975102e339e31c83f7a8 100644 (file)
@@ -45,6 +45,11 @@ public class Name implements Outputable, IdCachable {
          */
         public abstract void output(PrintWriter out);
 
          */
         public abstract void output(PrintWriter out);
 
+        /**
+         * @see Name#toInitialsString()
+         */
+        public abstract String toInitialsString();
+
     }
 
     private static class SingleName extends SchemedName {
     }
 
     private static class SingleName extends SchemedName {
@@ -70,6 +75,11 @@ public class Name implements Outputable, IdCachable {
             return singlePart.getValue();
         }
 
             return singlePart.getValue();
         }
 
+        @Override
+        public String toInitialsString() {
+            return singlePart.getValue().substring(0, 1);
+        }
+
         @Override
         public NameSchemaType getSchemeName() {
             return NameSchemaType.SINGLE;
         @Override
         public NameSchemaType getSchemeName() {
             return NameSchemaType.SINGLE;
@@ -223,6 +233,14 @@ public class Name implements Outputable, IdCachable {
         public String toAbbreviatedString() {
             return firstNames[0].getValue() + " " + lastNames[0].getValue().charAt(0) + ".";
         }
         public String toAbbreviatedString() {
             return firstNames[0].getValue() + " " + lastNames[0].getValue().charAt(0) + ".";
         }
+
+        @Override
+        public String toInitialsString() {
+
+            String initals = getInitialByNamePart(firstNames, lastNames, suffixes);
+
+            return initals;
+        }
     }
 
     private int id;
     }
 
     private int id;
@@ -378,8 +396,8 @@ public class Name implements Outputable, IdCachable {
 
     /**
      * Transforms this String into a short form. This short form should not be
 
     /**
      * Transforms this String into a short form. This short form should not be
-     * unique. (For "western" names this would be
-     * "firstName firstCharOfLastName.".)
+     * unique. (For "western" names this would be "firstName
+     * firstCharOfLastName.".)
      * 
      * @return the short form of the name
      */
      * 
      * @return the short form of the name
      */
@@ -387,6 +405,17 @@ public class Name implements Outputable, IdCachable {
         return scheme.toAbbreviatedString();
     }
 
         return scheme.toAbbreviatedString();
     }
 
+    /**
+     * Transforms this Name object into a short form. This short form might not
+     * be unique. (For "western" names this would be all first letters of each
+     * name part)
+     * 
+     * @return the short form of the name
+     */
+    public String toInitialsString() {
+        return scheme.toInitialsString();
+    }
+
     public int getVerificationPoints() {
         try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(`points`) FROM (SELECT DISTINCT ON (`from`, `method`) `points` FROM `notary` WHERE `to`=? AND `deleted` IS NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) ORDER BY `from`, `method`, `when` DESC) AS p")) {
             query.setInt(1, getId());
     public int getVerificationPoints() {
         try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(`points`) FROM (SELECT DISTINCT ON (`from`, `method`) `points` FROM `notary` WHERE `to`=? AND `deleted` IS NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) ORDER BY `from`, `method`, `when` DESC) AS p")) {
             query.setInt(1, getId());
@@ -460,4 +489,27 @@ public class Name implements Outputable, IdCachable {
         }
         return owner;
     }
         }
         return owner;
     }
+
+    private static String getInitialByNamePart(NamePart[]... npa) {
+        StringBuilder initals = new StringBuilder();
+        for (NamePart[] np : npa) {
+            initals.append(getInitialByNamePart(np));
+        }
+        return initals.toString();
+    }
+
+    private static String getInitialByNamePart(NamePart[] np) {
+        StringBuilder initals = new StringBuilder();
+        for (NamePart p : np) {
+            switch (p.getValue()) {
+            case "-":
+            case "/":
+                break;
+            default:
+                initals.append(p.getValue().substring(0, 1).toUpperCase());
+                break;
+            }
+        }
+        return initals.toString();
+    }
 }
 }