From de805a558690e529f1ce379d1ea0b70beae73da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D1=96=D1=81=D0=BE=D0=B2=D0=B8=D0=B9=20=D0=92=D1=96?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80?= Date: Mon, 23 Jan 2023 05:42:25 +0200 Subject: [PATCH] prepare to new convert --- .../main/java/ldapCreater/LDAPCreater.java | 46 +++++++++++-------- .../java/transliteration/Transliteration.java | 25 ++++++++-- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ldif/src/main/java/ldapCreater/LDAPCreater.java b/ldif/src/main/java/ldapCreater/LDAPCreater.java index a522c7a..957e2b1 100644 --- a/ldif/src/main/java/ldapCreater/LDAPCreater.java +++ b/ldif/src/main/java/ldapCreater/LDAPCreater.java @@ -29,7 +29,7 @@ private synchronized int getId() { } private String[] fileData; - private String[] userNames; + private final List userNames = new ArrayList<>(); private final StringBuffer userLdifData; private synchronized int getIndex() { @@ -117,9 +117,13 @@ public void createLDAPInfo() { private synchronized boolean checkAndAddData(String LDAPData) { -// boolean check + boolean notExist = !userNames.contains(LDAPData); - return false; + if (notExist) { + userNames.add(LDAPData); + } + + return notExist; } private void work(int currentThreadIndex) { @@ -151,23 +155,29 @@ public String getOneLDAP(String line, int i) { String[] lines = line.split(" "); String transLit = trs[i].convert(lines[1], lines[0]); + boolean added = checkAndAddData(transLit); + + if (!added) { + transLit = trs[i].convert(lines[1], lines[0]); + } + return String.format( "dn: cn=%1$s,ou=%2$s,dc=kubd,dc=kub\n" + - "objectClass: top\n" + - "objectClass: account\n" + - "objectClass: posixAccount\n" + - "objectClass: shadowAccount\n" + - "cn: %3$s\n" + - "uid: %1$s\n" + - "uidNumber: %4$d\n" + - "gidNumber: %4$d\n" + - "homeDirectory: /home/%1$s\n" + - "userPassword:\n" + - "loginShell: /bin/bash\n" + - "gecos: %1$s\n" + - "shadowLastChange: -1\n" + - "shadowMax: -1\n" + - "shadowWarning: 0\n", + "objectClass: top\n" + + "objectClass: account\n" + + "objectClass: posixAccount\n" + + "objectClass: shadowAccount\n" + + "cn: %3$s\n" + + "uid: %1$s\n" + + "uidNumber: %4$d\n" + + "gidNumber: %4$d\n" + + "homeDirectory: /home/%1$s\n" + + "userPassword:\n" + + "loginShell: /bin/bash\n" + + "gecos: %1$s\n" + + "shadowLastChange: -1\n" + + "shadowMax: -1\n" + + "shadowWarning: 0\n", transLit, ou, line, diff --git a/transliteration/src/main/java/transliteration/Transliteration.java b/transliteration/src/main/java/transliteration/Transliteration.java index 8dd4bba..f8fa9d9 100644 --- a/transliteration/src/main/java/transliteration/Transliteration.java +++ b/transliteration/src/main/java/transliteration/Transliteration.java @@ -70,21 +70,38 @@ private String convertSymbol(final Character symbol) { * @return custom format string */ public String convert(final String name, final String lastname) { - readFile(); + return convert(name, lastname, 0); + } - String lowerLastName = lastname.toLowerCase(); - String prepareLastName = lowerLastName.replace(masLinks[0][0], masLinks[0][1]); + public String convert(String name, String lastname, int count) { + readFile(); StringBuilder resultLine = new StringBuilder(); + String loverName = name.toLowerCase(); + String prepareName = loverName.replace(masLinks[0][0], masLinks[0][1]); + firstSymbol = true; resultLine.append(convertSymbol(name.charAt(0)).charAt(0)); + + firstSymbol = false; + + int n = name.length(); + for (int i = 1; i < n; i++) { + resultLine.append(convertSymbol(name.charAt(i))); + } + + String lowerLastName = lastname.toLowerCase(); + String prepareLastName = lowerLastName.replace(masLinks[0][0], masLinks[0][1]); + + firstSymbol = true; + resultLine.append(convertSymbol(prepareLastName.charAt(0))); firstSymbol = false; - int n = prepareLastName.length(); + n = prepareLastName.length(); for (int i = 1; i < n; i++) { resultLine.append(convertSymbol(prepareLastName.charAt(i))); }