Created
September 30, 2023 21:03
-
-
Save SinTeZWh1te/442ed8593d962361eaed319ba441eb50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.test.bgbilling.modules.inet; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import ru.bitel.bgbilling.common.BGException; | |
import ru.bitel.bgbilling.kernel.container.managed.ServerContext; | |
import ru.bitel.bgbilling.kernel.contract.api.common.bean.Contract; | |
import ru.bitel.bgbilling.kernel.contract.api.common.service.ContractService; | |
import ru.bitel.bgbilling.modules.inet.common.bean.InetServ; | |
import ru.bitel.bgbilling.modules.inet.common.bean.InetServType; | |
import ru.bitel.bgbilling.modules.inet.common.service.InetServService; | |
import ru.bitel.bgbilling.modules.inet.server.bean.InetAccountGenerate; | |
import ru.bitel.common.ParameterMap; | |
import java.util.List; | |
/** | |
* @author sintezwh1te@gmail.com | |
*/ | |
public class InetGenerateAccountAndPswd implements InetAccountGenerate { | |
private ContractService contractService; | |
private InetServService inetServService; | |
private ServerContext serverContext; | |
private final Logger logger = LogManager.getLogger(); | |
public InetGenerateAccountAndPswd() throws BGException { | |
init(); | |
} | |
private void init() throws BGException { | |
serverContext = ServerContext.get(); | |
contractService = serverContext.getService(ContractService.class, 0); | |
inetServService = serverContext.getService(InetServService.class, serverContext.getModuleId()); | |
} | |
@Override | |
public String generateLogin(InetServ inetServ, InetServType servType, ParameterMap moduleSetup) { | |
logger.info("generateLogin"); | |
try { | |
Contract contract = contractService.contractGet(inetServ.getContractId()); | |
int count = 1; | |
String login = contract.getTitle(); | |
while (true) { | |
List<InetServ> inetServList = inetServService.searchInetServ(login, null, 0, 0, "", "", "", true); | |
if (inetServList.isEmpty()) { | |
break; | |
} | |
login = contract.getTitle() + "_" + count++; | |
} | |
return login; | |
} catch (BGException e) { | |
logger.error(e); | |
} | |
return null; | |
} | |
@Override | |
public String generatePassword(InetServ inetServ, InetServType servType, ParameterMap moduleSetup) { | |
try { | |
return contractService.contractGet(inetServ.getContractId()).getPassword(); | |
} catch (BGException e) { | |
logger.error(e); | |
} | |
return null; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment