Skip to content

Commit

Permalink
Merge branch 'release/v1.3.2'
Browse files Browse the repository at this point in the history
Release v1.3.2
  • Loading branch information
shiido committed Nov 3, 2020
2 parents 2ad37ed + ad038ee commit c6b5aca
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public void initManagers() {
.getManagerStateById(ManagerStateBusiness.MANAGER_STATE_ACTIVE);

ManagerEntity managerIGAC = new ManagerEntity();
managerIGAC.setName("IGAC");
managerIGAC.setTaxIdentificationNumber("000-1");
managerIGAC.setName("INSTITUTO GEOGRÁFICO AGUSTÍN CODAZZI");
managerIGAC.setAlias("IGAC");
managerIGAC.setTaxIdentificationNumber("8999990049");
managerIGAC.setCreatedAt(new Date());
managerIGAC.setManagerState(stateActive);
managerIGAC = managerService.createManager(managerIGAC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,8 @@ public List<ManagerDto> getManagers(Long managerStateId) throws BusinessExceptio
}

for (ManagerEntity managerEntity : listManagersEntity) {

ManagerDto managerDto = new ManagerDto();
managerDto.setId(managerEntity.getId());
managerDto.setName(managerEntity.getName());
managerDto.setTaxIdentificationNumber(managerEntity.getTaxIdentificationNumber());
managerDto.setCreatedAt(managerEntity.getCreatedAt());
managerDto.setManagerState(new ManagerStateDto(managerEntity.getManagerState().getId(),
managerEntity.getManagerState().getName()));

ManagerDto managerDto = transformEntityToDto(managerEntity);
listManagersDto.add(managerDto);

}

return listManagersDto;
Expand All @@ -71,13 +62,7 @@ public ManagerDto getManagerById(Long id) throws BusinessException {

ManagerEntity managerEntity = managerService.getManagerById(id);
if (managerEntity instanceof ManagerEntity) {
managerDto = new ManagerDto();
managerDto.setId(managerEntity.getId());
managerDto.setName(managerEntity.getName());
managerDto.setTaxIdentificationNumber(managerEntity.getTaxIdentificationNumber());
managerDto.setCreatedAt(managerEntity.getCreatedAt());
managerDto.setManagerState(new ManagerStateDto(managerEntity.getManagerState().getId(),
managerEntity.getManagerState().getName()));
managerDto = transformEntityToDto(managerEntity);
}

return managerDto;
Expand Down Expand Up @@ -195,7 +180,7 @@ public List<ManagerUserDto> getUsersByManager(Long managerId, List<Long> profile
return listUsersDto;
}

public ManagerDto addManager(String name, String taxIdentification) throws BusinessException {
public ManagerDto addManager(String name, String taxIdentification, String alias) throws BusinessException {

if (name.isEmpty()) {
throw new BusinessException("El gestor debe contener un nombre.");
Expand All @@ -210,11 +195,15 @@ public ManagerDto addManager(String name, String taxIdentification) throws Busin

ManagerEntity managerEntity = new ManagerEntity();

managerEntity.setName(name);
managerEntity.setName(name.toUpperCase());
managerEntity.setCreatedAt(new Date());
managerEntity.setTaxIdentificationNumber(taxIdentification);
managerEntity.setManagerState(managerState);

if (alias != null) {
managerEntity.setAlias(alias);
}

managerEntity = managerService.createManager(managerEntity);

ManagerDto managerDto = this.transformEntityToDto(managerEntity);
Expand All @@ -226,6 +215,7 @@ protected ManagerDto transformEntityToDto(ManagerEntity managerEntity) {

ManagerDto managerDto = new ManagerDto();
managerDto.setId(managerEntity.getId());
managerDto.setAlias(managerEntity.getAlias());
managerDto.setCreatedAt(managerEntity.getCreatedAt());
managerDto.setName(managerEntity.getName());
managerDto.setTaxIdentificationNumber(managerEntity.getTaxIdentificationNumber());
Expand All @@ -246,14 +236,14 @@ public ManagerDto activateManager(Long managerId) throws BusinessException {
// verify manager exists
ManagerEntity managerEntity = managerService.getManagerById(managerId);
if (!(managerEntity instanceof ManagerEntity)) {
throw new BusinessException("Manager not found.");
throw new BusinessException("El gestor no existe.");
}

// set manager state
ManagerStateEntity managerStateEntity = managerStateService
.getManagerStateById(ManagerStateBusiness.MANAGER_STATE_ACTIVE);
if (managerStateEntity == null) {
throw new BusinessException("Manager state not found.");
throw new BusinessException("El estado no existe.");
}

managerEntity.setManagerState(managerStateEntity);
Expand All @@ -262,7 +252,7 @@ public ManagerDto activateManager(Long managerId) throws BusinessException {
ManagerEntity managerUpdatedEntity = managerService.updateManager(managerEntity);
managerDto = this.transformEntityToDto(managerUpdatedEntity);
} catch (Exception e) {
throw new BusinessException("The task could not be updated.");
throw new BusinessException("No se ha podido activar el gestor.");
}

return managerDto;
Expand All @@ -275,14 +265,14 @@ public ManagerDto deactivateManager(Long managerId) throws BusinessException {
// verify manager exists
ManagerEntity managerEntity = managerService.getManagerById(managerId);
if (!(managerEntity instanceof ManagerEntity)) {
throw new BusinessException("Manager not found.");
throw new BusinessException("El gestor no existe.");
}

// set manager state
ManagerStateEntity managerStateEntity = managerStateService
.getManagerStateById(ManagerStateBusiness.MANAGER_STATE_INACTIVE);
if (managerStateEntity == null) {
throw new BusinessException("Manager state not found.");
throw new BusinessException("El estado no existe.");
}

managerEntity.setManagerState(managerStateEntity);
Expand All @@ -291,13 +281,14 @@ public ManagerDto deactivateManager(Long managerId) throws BusinessException {
ManagerEntity managerUpdatedEntity = managerService.updateManager(managerEntity);
managerDto = this.transformEntityToDto(managerUpdatedEntity);
} catch (Exception e) {
throw new BusinessException("The task could not be updated.");
throw new BusinessException("No se ha podido desactivar el gestor.");
}

return managerDto;
}

public ManagerDto updateManager(Long managerId, String name, String taxIdentification) throws BusinessException {
public ManagerDto updateManager(Long managerId, String name, String taxIdentification, String alias)
throws BusinessException {

if (managerId <= 0) {
throw new BusinessException("El gestor debe contener un id.");
Expand All @@ -314,13 +305,19 @@ public ManagerDto updateManager(Long managerId, String name, String taxIdentific
// verify manager exists
ManagerEntity managerEntity = managerService.getManagerById(managerId);
if (!(managerEntity instanceof ManagerEntity)) {
throw new BusinessException("Manager not found.");
throw new BusinessException("El gestor no existe.");
}

managerEntity.setName(name);
managerEntity.setName(name.toUpperCase());
managerEntity.setCreatedAt(new Date());
managerEntity.setTaxIdentificationNumber(taxIdentification);

if (alias != null) {
managerEntity.setAlias(alias);
} else {
managerEntity.setAlias(null);
}

managerEntity = managerService.updateManager(managerEntity);

ManagerDto managerDto = this.transformEntityToDto(managerEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public ManagerDto getManagerByUserCode(Long userCode) throws BusinessException {

managerDto = new ManagerDto();
managerDto.setId(managerEntity.getId());
managerDto.setAlias(managerEntity.getAlias());
managerDto.setName(managerEntity.getName());
managerDto.setTaxIdentificationNumber(managerEntity.getTaxIdentificationNumber());
managerDto.setCreatedAt(managerEntity.getCreatedAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public ResponseEntity<Object> createManager(@RequestBody CreateManagerDto reques
throw new InputValidationException("El identificador de impuesto es requerido.");
}

responseDto = managerBusiness.addManager(managerName, taxIdentification);
responseDto = managerBusiness.addManager(managerName, taxIdentification, requestCreateManager.getAlias());
httpStatus = HttpStatus.CREATED;

} catch (InputValidationException e) {
Expand Down Expand Up @@ -255,19 +255,20 @@ public ResponseEntity<Object> updateManager(@RequestBody UpdateManagerDto reques
throw new InputValidationException("El identificador de impuesto es requerido.");
}

responseDto = managerBusiness.updateManager(managerId, managerName, taxIdentification);
httpStatus = HttpStatus.CREATED;
responseDto = managerBusiness.updateManager(managerId, managerName, taxIdentification,
requestUpdateManager.getAlias());
httpStatus = HttpStatus.OK;

} catch (InputValidationException e) {
log.error("Error ManagerV1Controller@createManager#Validation ---> " + e.getMessage());
log.error("Error ManagerV1Controller@updateManager#Validation ---> " + e.getMessage());
httpStatus = HttpStatus.BAD_REQUEST;
responseDto = new ErrorDto(e.getMessage(), 1);
} catch (BusinessException e) {
log.error("Error ManagerV1Controller@createManager#Business ---> " + e.getMessage());
log.error("Error ManagerV1Controller@updateManager#Business ---> " + e.getMessage());
httpStatus = HttpStatus.UNPROCESSABLE_ENTITY;
responseDto = new ErrorDto(e.getMessage(), 2);
} catch (Exception e) {
log.error("Error ManagerV1Controller@createManager#General ---> " + e.getMessage());
log.error("Error ManagerV1Controller@updateManager#General ---> " + e.getMessage());
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
responseDto = new ErrorDto(e.getMessage(), 3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class CreateManagerDto implements Serializable {
@ApiModelProperty(required = true, notes = "Manager tax identification number")
private String taxIdentificationNumber;

@ApiModelProperty(required = false, notes = "Manager Alias")
private String alias;

public CreateManagerDto() {

}
Expand All @@ -36,4 +39,12 @@ public void setTaxIdentificationNumber(String taxIdentificationNumber) {
this.taxIdentificationNumber = taxIdentificationNumber;
}

public String getAlias() {
return alias;
}

public void setAlias(String alias) {
this.alias = alias;
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/ai/st/microservice/managers/dto/ManagerDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class ManagerDto implements Serializable {

@ApiModelProperty(required = true, notes = "Manager name")
private String name;

@ApiModelProperty(required = false, notes = "Manager Alias")
private String alias;

@ApiModelProperty(required = true, notes = "Manager tax identification number")
private String taxIdentificationNumber;
Expand Down Expand Up @@ -70,4 +73,12 @@ public void setManagerState(ManagerStateDto managerState) {
this.managerState = managerState;
}

public String getAlias() {
return alias;
}

public void setAlias(String alias) {
this.alias = alias;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class UpdateManagerDto implements Serializable {

private static final long serialVersionUID = 8630363838327832666L;

@ApiModelProperty(required = true, notes = "Manager ID")
private Long id;

Expand All @@ -19,6 +19,9 @@ public class UpdateManagerDto implements Serializable {
@ApiModelProperty(required = true, notes = "Manager tax identification number")
private String taxIdentificationNumber;

@ApiModelProperty(required = false, notes = "Manager Alias")
private String alias;

public UpdateManagerDto() {

}
Expand Down Expand Up @@ -47,4 +50,12 @@ public void setId(Long id) {
this.id = id;
}

public String getAlias() {
return alias;
}

public void setAlias(String alias) {
this.alias = alias;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ManagerEntity {

@Column(name = "name", nullable = false, length = 255)
private String name;

@Column(name = "alias", nullable = true, length = 20)
private String alias;

@Column(name = "tax_identification_number", nullable = false, length = 255)
private String taxIdentificationNumber;
Expand Down Expand Up @@ -81,4 +84,12 @@ public void setManagerState(ManagerStateEntity managerState) {
this.managerState = managerState;
}

public String getAlias() {
return alias;
}

public void setAlias(String alias) {
this.alias = alias;
}

}

0 comments on commit c6b5aca

Please sign in to comment.