-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,948 additions
and
756 deletions.
There are no files selected for viewing
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
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
20 changes: 13 additions & 7 deletions
20
...n/java/com/ai/st/microservice/administration/StMicroserviceAdministrationApplication.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
package com.ai.st.microservice.administration; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
||
@SpringBootApplication | ||
@EnableAutoConfiguration | ||
@EnableFeignClients(basePackages = {"com.ai.st.microservice.common.clients"}) | ||
@EnableEurekaClient | ||
@ComponentScan(basePackages = {"com.ai.st.microservice.common.business", "com.ai.st.microservice.administration"}) | ||
public class StMicroserviceAdministrationApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(StMicroserviceAdministrationApplication.class, args); | ||
} | ||
public static void main(String[] args) { | ||
SpringApplication.run(StMicroserviceAdministrationApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public BCryptPasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
@Bean | ||
public BCryptPasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import java.util.Date; | ||
import java.util.List; | ||
|
||
import com.ai.st.microservice.common.business.RoleBusiness; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
@@ -13,7 +14,6 @@ | |
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.ai.st.microservice.administration.business.RoleBusiness; | ||
import com.ai.st.microservice.administration.entities.RoleEntity; | ||
import com.ai.st.microservice.administration.entities.UserEntity; | ||
import com.ai.st.microservice.administration.models.services.IRoleService; | ||
|
@@ -22,102 +22,102 @@ | |
@Component | ||
public class StMicroserviceAdministrationApplicationStartup implements ApplicationListener<ContextRefreshedEvent> { | ||
|
||
@Value("${spring.profiles.active}") | ||
private String activeProfile; | ||
@Value("${spring.profiles.active}") | ||
private String activeProfile; | ||
|
||
@Value("${st.root.username}") | ||
private String rootUsername; | ||
@Value("${st.root.username}") | ||
private String rootUsername; | ||
|
||
@Value("${st.root.password}") | ||
private String rootPassword; | ||
@Value("${st.root.password}") | ||
private String rootPassword; | ||
|
||
private static final Logger log = LoggerFactory.getLogger(StMicroserviceAdministrationApplicationStartup.class); | ||
private static final Logger log = LoggerFactory.getLogger(StMicroserviceAdministrationApplicationStartup.class); | ||
|
||
@Autowired | ||
private IRoleService roleService; | ||
@Autowired | ||
private IRoleService roleService; | ||
|
||
@Autowired | ||
private IUserService userService; | ||
@Autowired | ||
private IUserService userService; | ||
|
||
@Autowired | ||
private BCryptPasswordEncoder passwordEncode; | ||
@Autowired | ||
private BCryptPasswordEncoder passwordEncode; | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
log.info("ST - Loading Domains ... "); | ||
this.initRoles(); | ||
this.initUsers(); | ||
} | ||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
log.info("ST - Loading Domains ... "); | ||
this.initRoles(); | ||
this.initUsers(); | ||
} | ||
|
||
public void initRoles() { | ||
Long countRoles = roleService.getAllCount(); | ||
if (countRoles == 0) { | ||
public void initRoles() { | ||
Long countRoles = roleService.getAllCount(); | ||
if (countRoles == 0) { | ||
|
||
try { | ||
RoleEntity roleAdministrator = new RoleEntity(); | ||
roleAdministrator.setId(RoleBusiness.ROLE_ADMINISTRATOR); | ||
roleAdministrator.setName("ADMINISTRADOR"); | ||
roleService.createRole(roleAdministrator); | ||
try { | ||
RoleEntity roleAdministrator = new RoleEntity(); | ||
roleAdministrator.setId(RoleBusiness.ROLE_ADMINISTRATOR); | ||
roleAdministrator.setName("ADMINISTRADOR"); | ||
roleService.createRole(roleAdministrator); | ||
|
||
RoleEntity roleManager = new RoleEntity(); | ||
roleManager.setId(RoleBusiness.ROLE_MANAGER); | ||
roleManager.setName("GESTOR"); | ||
roleService.createRole(roleManager); | ||
RoleEntity roleManager = new RoleEntity(); | ||
roleManager.setId(RoleBusiness.ROLE_MANAGER); | ||
roleManager.setName("GESTOR"); | ||
roleService.createRole(roleManager); | ||
|
||
RoleEntity roleOperator = new RoleEntity(); | ||
roleOperator.setId(RoleBusiness.ROLE_OPERATOR); | ||
roleOperator.setName("OPERADOR"); | ||
roleService.createRole(roleOperator); | ||
RoleEntity roleOperator = new RoleEntity(); | ||
roleOperator.setId(RoleBusiness.ROLE_OPERATOR); | ||
roleOperator.setName("OPERADOR"); | ||
roleService.createRole(roleOperator); | ||
|
||
RoleEntity roleProvider = new RoleEntity(); | ||
roleProvider.setId(RoleBusiness.ROLE_SUPPLY_SUPPLIER); | ||
roleProvider.setName("PROVEEDOR INSUMO"); | ||
roleService.createRole(roleProvider); | ||
RoleEntity roleProvider = new RoleEntity(); | ||
roleProvider.setId(RoleBusiness.ROLE_SUPPLY_SUPPLIER); | ||
roleProvider.setName("PROVEEDOR INSUMO"); | ||
roleService.createRole(roleProvider); | ||
|
||
RoleEntity roleSuper = new RoleEntity(); | ||
roleSuper.setId(RoleBusiness.ROLE_SUPER_ADMINISTRATOR); | ||
roleSuper.setName("SUPER ADMINISTRADOR"); | ||
roleService.createRole(roleSuper); | ||
RoleEntity roleSuper = new RoleEntity(); | ||
roleSuper.setId(RoleBusiness.ROLE_SUPER_ADMINISTRATOR); | ||
roleSuper.setName("SUPER ADMINISTRADOR"); | ||
roleService.createRole(roleSuper); | ||
|
||
log.info("The domains 'roles' have been loaded!"); | ||
} catch (Exception e) { | ||
log.error("Failed to load 'roles' domains"); | ||
} | ||
log.info("The domains 'roles' have been loaded!"); | ||
} catch (Exception e) { | ||
log.error("Failed to load 'roles' domains"); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
public void initUsers() { | ||
Long countUsers = userService.getAllCount(); | ||
if (countUsers == 0) { | ||
public void initUsers() { | ||
Long countUsers = userService.getAllCount(); | ||
if (countUsers == 0) { | ||
|
||
try { | ||
try { | ||
|
||
RoleEntity roleSuper = roleService.getRoleById(RoleBusiness.ROLE_SUPER_ADMINISTRATOR); | ||
RoleEntity roleSuper = roleService.getRoleById(RoleBusiness.ROLE_SUPER_ADMINISTRATOR); | ||
|
||
// User 1 | ||
// User 1 | ||
|
||
UserEntity userToTest1 = new UserEntity(); | ||
userToTest1.setFirstName("Super"); | ||
userToTest1.setLastName("Administración"); | ||
userToTest1.setCreatedAt(new Date()); | ||
userToTest1.setEmail("[email protected]"); | ||
userToTest1.setEnabled(true); | ||
userToTest1.setUsername(rootUsername); | ||
userToTest1.setPassword(passwordEncode.encode(rootPassword)); | ||
UserEntity userToTest1 = new UserEntity(); | ||
userToTest1.setFirstName("Super"); | ||
userToTest1.setLastName("Administración"); | ||
userToTest1.setCreatedAt(new Date()); | ||
userToTest1.setEmail("[email protected]"); | ||
userToTest1.setEnabled(true); | ||
userToTest1.setUsername(rootUsername); | ||
userToTest1.setPassword(passwordEncode.encode(rootPassword)); | ||
|
||
List<RoleEntity> listRoles1 = new ArrayList<RoleEntity>(); | ||
listRoles1.add(roleSuper); | ||
userToTest1.setRoles(listRoles1); | ||
List<RoleEntity> listRoles1 = new ArrayList<RoleEntity>(); | ||
listRoles1.add(roleSuper); | ||
userToTest1.setRoles(listRoles1); | ||
|
||
userService.createUser(userToTest1); | ||
userService.createUser(userToTest1); | ||
|
||
log.info("The domains 'users' have been loaded!"); | ||
} catch (Exception e) { | ||
log.error("Failed to load 'users' domains: " + e.getMessage()); | ||
} | ||
log.info("The domains 'users' have been loaded!"); | ||
} catch (Exception e) { | ||
log.error("Failed to load 'users' domains: " + e.getMessage()); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/ai/st/microservice/administration/business/CodeBusiness.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.ai.st.microservice.administration.business; | ||
|
||
import java.util.Date; | ||
|
||
import org.apache.commons.lang.RandomStringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.ai.st.microservice.administration.entities.CodeEntity; | ||
import com.ai.st.microservice.administration.entities.UserEntity; | ||
import com.ai.st.microservice.administration.models.services.ICodeService; | ||
|
||
@Component | ||
public class CodeBusiness { | ||
|
||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Autowired | ||
private ICodeService codeService; | ||
|
||
public boolean unavailableCodesByUser(Long userId) { | ||
|
||
Boolean result = false; | ||
|
||
try { | ||
codeService.unavailableCodesByUser(userId); | ||
result = true; | ||
} catch (Exception e) { | ||
log.error("Error deshabilitando los códigos por usuario: " + e.getMessage()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public CodeEntity createCode(UserEntity user, Date expirationDate) { | ||
|
||
CodeEntity codeEntity = null; | ||
|
||
try { | ||
|
||
String code = RandomStringUtils.random(6, false, true); | ||
|
||
codeEntity = new CodeEntity(); | ||
codeEntity.setAvailable(true); | ||
codeEntity.setCode(code); | ||
codeEntity.setCreatedAt(new Date()); | ||
codeEntity.setExpiredAt(expirationDate); | ||
codeEntity.setUser(user); | ||
|
||
codeEntity = codeService.createCode(codeEntity); | ||
|
||
} catch (Exception e) { | ||
codeEntity = null; | ||
log.error("Error creando código OTP: " + e.getMessage()); | ||
} | ||
|
||
return codeEntity; | ||
} | ||
|
||
public CodeEntity getOTPByCodeAndUser(String code, UserEntity user) { | ||
|
||
CodeEntity codeEntity = null; | ||
|
||
try { | ||
|
||
codeEntity = codeService.getOPTbyCodeAndUser(code, user); | ||
|
||
} catch (Exception e) { | ||
log.error("No se ha podido buscar el código OPT: " + e.getMessage()); | ||
} | ||
|
||
return codeEntity; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/ai/st/microservice/administration/business/NotificationBusiness.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.ai.st.microservice.administration.business; | ||
|
||
import com.ai.st.microservice.common.clients.NotifierFeignClient; | ||
import com.ai.st.microservice.common.dto.notifier.MicroserviceNotificationRecoverAccountDto; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NotificationBusiness { | ||
|
||
private final Logger log = LoggerFactory.getLogger(NotificationBusiness.class); | ||
|
||
@Autowired | ||
private NotifierFeignClient notifierClient; | ||
|
||
public void sendNotificationRecoverAccount(String email, String code, String username, String expirationDate, Long userCode) { | ||
|
||
try { | ||
|
||
MicroserviceNotificationRecoverAccountDto notification = new MicroserviceNotificationRecoverAccountDto(); | ||
notification.setEmail(email); | ||
notification.setCode(code); | ||
notification.setUsername(username); | ||
notification.setExpirationDate(expirationDate); | ||
notification.setStatus(0); | ||
notification.setType("success"); | ||
notification.setUserCode(userCode); | ||
|
||
notifierClient.recoverAccount(notification); | ||
|
||
} catch (Exception e) { | ||
log.error("Error enviando la notificación #1: " + e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.