@@ -44,18 +44,18 @@ private AzureLinkService() {
4444 }
4545
4646 public void link (Project project , LinkConfig <MySQLResourceConfig , ModuleResourceConfig > linkComposite , boolean storageResource ) {
47- ModulePO modulePO = createModulePO (linkComposite .getModule ());
47+ final ModulePO modulePO = createModulePO (linkComposite .getModule ());
4848 // create resource
49- MySQLResourcePO resource = createResourcePO (linkComposite .getResource ());
49+ final MySQLResourcePO resource = createResourcePO (linkComposite .getResource ());
5050 // create link
51- LinkPO linkPO = new LinkPO (resource .getId (), modulePO .getResourceId (), LinkType .SERVICE_WITH_MODULE , linkComposite .getEnvPrefix ());
51+ final LinkPO linkPO = new LinkPO (resource .getId (), modulePO .getResourceId (), LinkType .SERVICE_WITH_MODULE , linkComposite .getEnvPrefix ());
5252 // storage mysql
5353 if (storageResource ) {
5454 AzureMySQLStorage .getStorage ().addResource (resource );
5555 }
5656 // storage password
5757 if (ArrayUtils .isNotEmpty (linkComposite .getResource ().getPasswordConfig ().getPassword ())) {
58- String inputPassword = String .valueOf (linkComposite .getResource ().getPasswordConfig ().getPassword ());
58+ final String inputPassword = String .valueOf (linkComposite .getResource ().getPasswordConfig ().getPassword ());
5959 AzureMySQLStorage .getStorage ().savePassword (resource , resource .getPasswordSave (), resource .getUsername (), inputPassword );
6060 }
6161 // storage link
@@ -67,40 +67,39 @@ private ModulePO createModulePO(ModuleResourceConfig config) {
6767 }
6868
6969 private MySQLResourcePO createResourcePO (MySQLResourceConfig config ) {
70- JdbcUrl jdbcUrl = JdbcUrl .from (config .getUrl ());
71- String businessUniqueKey = MySQLResourcePO .getBusinessUniqueKey (config .getServer ().id (), jdbcUrl .getDatabase ());
72- MySQLResourcePO existedResourcePO = AzureMySQLStorage .getStorage ().getResourceByBusinessUniqueKey (businessUniqueKey );
73- String id = Objects .nonNull (existedResourcePO ) ? existedResourcePO .getId () : DigestUtils .md5Hex (businessUniqueKey );
74- MySQLResourcePO resourcePO = MySQLResourcePO .builder ()
70+ final JdbcUrl jdbcUrl = JdbcUrl .from (config .getUrl ());
71+ final String businessUniqueKey = MySQLResourcePO .getBusinessUniqueKey (config .getServer ().id (), jdbcUrl .getDatabase ());
72+ final MySQLResourcePO existedResourcePO = AzureMySQLStorage .getStorage ().getResourceByBusinessUniqueKey (businessUniqueKey );
73+ final String id = Objects .nonNull (existedResourcePO ) ? existedResourcePO .getId () : DigestUtils .md5Hex (businessUniqueKey );
74+ return MySQLResourcePO .builder ()
7575 .id (id )
7676 .resourceId (config .getServer ().id ())
7777 .url (config .getUrl ())
7878 .username (config .getUsername ())
7979 .passwordSave (config .getPasswordConfig ().getPasswordSaveType ())
8080 .build ();
81- return resourcePO ;
8281 }
8382
8483 public Map <String , String > retrieveLinkEnvsByModuleName (Project project , String moduleName ) {
85- Map <String , String > linkedEnvMap = new LinkedHashMap <>();
86- List <LinkPO > moduleRelatedLinkList = AzureLinkStorage .getProjectStorage (project ).getLinkByModuleId (moduleName )
84+ final Map <String , String > linkedEnvMap = new LinkedHashMap <>();
85+ final List <LinkPO > moduleRelatedLinkList = AzureLinkStorage .getProjectStorage (project ).getLinkByModuleId (moduleName )
8786 .stream ()
8887 .filter (e -> LinkType .SERVICE_WITH_MODULE .equals (e .getType ()))
8988 .collect (Collectors .toList ());
9089 if (CollectionUtils .isEmpty (moduleRelatedLinkList )) {
9190 return linkedEnvMap ;
9291 }
9392 // services in application level
94- Set <? extends BaseResourcePO > serviceSet = AzureMySQLStorage .getStorage ().getResources ();
95- for (BaseResourcePO service : serviceSet ) {
96- for (LinkPO link : moduleRelatedLinkList ) {
93+ final Set <? extends BaseResourcePO > serviceSet = AzureMySQLStorage .getStorage ().getResources ();
94+ for (final BaseResourcePO service : serviceSet ) {
95+ for (final LinkPO link : moduleRelatedLinkList ) {
9796 if (!StringUtils .equals (link .getResourceId (), service .getId ())) {
9897 continue ;
9998 }
100- String envPrefix = link .getEnvPrefix ();
99+ final String envPrefix = link .getEnvPrefix ();
101100 if (ResourceType .AZURE_DATABASE_FOR_MYSQL .equals (service .getType ())) {
102- MySQLResourcePO mysql = (MySQLResourcePO ) service ;
103- String password = readPasswordCredentials (project , mysql );
101+ final MySQLResourcePO mysql = (MySQLResourcePO ) service ;
102+ final String password = readPasswordCredentials (project , mysql );
104103 linkedEnvMap .put (envPrefix + "URL" , mysql .getUrl ());
105104 linkedEnvMap .put (envPrefix + "USERNAME" , mysql .getUsername ());
106105 linkedEnvMap .put (envPrefix + "PASSWORD" , password );
@@ -123,12 +122,12 @@ private String readPasswordCredentials(Project project, MySQLResourcePO service)
123122 }
124123 }
125124 // re-input password
126- AtomicReference <PasswordConfig > passwordConfigReference = new AtomicReference <>();
125+ final AtomicReference <PasswordConfig > passwordConfigReference = new AtomicReference <>();
127126 ApplicationManager .getApplication ().invokeAndWait (() -> {
128- PasswordDialog dialog = new PasswordDialog (project , service .getUsername (), service .getUrl ());
127+ final PasswordDialog dialog = new PasswordDialog (project , service .getUsername (), service .getUrl ());
129128 dialog .setOkActionListener (data -> {
130129 dialog .close ();
131- String inputPassword = String .valueOf (data .getPassword ());
130+ final String inputPassword = String .valueOf (data .getPassword ());
132131 if (MySQLConnectionUtils .connect (service .getUrl (), service .getUsername (), inputPassword )) {
133132 AzureMySQLStorage .getStorage ().savePassword (service , data .getPasswordSaveType (), service .getUsername (), inputPassword );
134133 if (!Objects .equals (service .getPasswordSave (), data .getPasswordSaveType ())) {
@@ -141,7 +140,7 @@ private String readPasswordCredentials(Project project, MySQLResourcePO service)
141140 EventUtil .logEvent (EventType .info , ActionConstants .parse (ActionConstants .MySQL .UPDATE_PASSWORD ).getServiceName (),
142141 ActionConstants .parse (ActionConstants .MySQL .UPDATE_PASSWORD ).getOperationName (), null );
143142 });
144- PasswordConfig passwordConfig = passwordConfigReference .get ();
143+ final PasswordConfig passwordConfig = passwordConfigReference .get ();
145144 if (Objects .nonNull (passwordConfig )) {
146145 return String .valueOf (passwordConfig .getPassword ());
147146 } else {
0 commit comments