Skip to content

Commit

Permalink
Merge branch 'release/v1.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
shiido committed Apr 20, 2021
2 parents e8dddb2 + bf5fe24 commit ff04d28
Show file tree
Hide file tree
Showing 23 changed files with 1,948 additions and 756 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ENV CLOUD_CONFIG=$CLOUD_CONFIG

VOLUME /tmp

ADD ./target/st-microservice-administration-1.1.2.jar st-microservice-administration.jar
ADD ./target/st-microservice-administration-1.3.5.jar st-microservice-administration.jar

EXPOSE 8080

Expand Down
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.ai.st.microservice.administration</groupId>
<artifactId>st-microservice-administration</artifactId>
<version>1.1.2</version>
<version>1.3.5</version>
<name>st-microservice-administration2</name>
<description>Microservice Administration Users and Roles</description>

Expand Down Expand Up @@ -74,6 +74,11 @@
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -92,6 +97,12 @@
<artifactId>commons-codec</artifactId>
</dependency>

<dependency>
<groupId>com.ai.st.microservice.common</groupId>
<artifactId>st-common</artifactId>
<version>1.0.0</version>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}

}
}
}
}

}
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;
}

}
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());
}

}

}
Loading

0 comments on commit ff04d28

Please sign in to comment.