Skip to content

Commit

Permalink
prepare to new convert
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlissoviy committed Jan 23, 2023
1 parent b1759f2 commit de805a5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
46 changes: 28 additions & 18 deletions ldif/src/main/java/ldapCreater/LDAPCreater.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private synchronized int getId() {
}

private String[] fileData;
private String[] userNames;
private final List<String> userNames = new ArrayList<>();
private final StringBuffer userLdifData;

private synchronized int getIndex() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 21 additions & 4 deletions transliteration/src/main/java/transliteration/Transliteration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down

0 comments on commit de805a5

Please sign in to comment.