use of eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptService method toType.
/**
* Transform dto to type.
*
* @param dto
* @return
*/
@Override
protected IdmScriptType toType(IdmScriptDto dto) {
IdmScriptType type = new IdmScriptType();
if (dto == null) {
return type;
}
// transform DTO to type
type.setCode(dto.getCode());
type.setName(dto.getName());
// parameter isn't implemented yet
// type.setParameters(dto.getParameter());
type.setBody(dto.getScript());
type.setCategory(dto.getCategory());
type.setDescription(dto.getDescription());
type.setType(SCRIPT_DEFAULT_TYPE);
//
if (dto.getId() == null) {
return type;
}
IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
filter.setScriptId(dto.getId());
List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmScriptAuthority_.type.getName(), IdmScriptAuthority_.service.getName(), IdmScriptAuthority_.className.getName()))).getContent();
if (authorities.isEmpty()) {
return type;
}
//
List<IdmScriptAllowClassType> classes = new ArrayList<>();
List<IdmScriptServiceType> services = new ArrayList<>();
for (IdmScriptAuthorityDto auth : authorities) {
if (auth.getType() == ScriptAuthorityType.CLASS_NAME) {
IdmScriptAllowClassType classType = new IdmScriptAllowClassType();
classType.setClassName(auth.getClassName());
classes.add(classType);
} else {
IdmScriptServiceType service = new IdmScriptServiceType();
service.setClassName(auth.getClassName());
service.setName(auth.getService());
services.add(service);
}
}
if (!classes.isEmpty()) {
type.setAllowClasses(new IdmScriptAllowClassesType());
type.getAllowClasses().setAllowClasses(classes);
}
if (!services.isEmpty()) {
type.setServices(new IdmScriptServicesType());
type.getServices().setServices(services);
}
//
return type;
}
use of eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptService method authorityTypeToDto.
/**
* Generate list of authorities from {@ IdmScriptType}
*
* @param type
* @return
*/
private List<IdmScriptAuthorityDto> authorityTypeToDto(IdmScriptType type, IdmScriptDto scriptDto) {
List<IdmScriptAuthorityDto> authorities = new ArrayList<>();
if (type.getAllowClasses() != null && type.getAllowClasses().getAllowClasses() != null) {
for (IdmScriptAllowClassType allowClass : type.getAllowClasses().getAllowClasses()) {
try {
Class.forName(allowClass.getClassName());
} catch (ClassNotFoundException e) {
LOG.error("Class [{}] isn't reachable, for script [{}] skip add this authority", allowClass.getClassName(), type.getCode(), e);
continue;
}
IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
authDto.setType(ScriptAuthorityType.CLASS_NAME);
authDto.setClassName(allowClass.getClassName());
authDto.setScript(scriptDto.getId());
authorities.add(authDto);
}
}
//
if (type.getServices() != null && type.getServices().getServices() != null) {
for (IdmScriptServiceType service : type.getServices().getServices()) {
if (scriptAuthorityService.isServiceReachable(service.getName(), service.getClassName())) {
IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
authDto.setType(ScriptAuthorityType.SERVICE);
authDto.setClassName(service.getClassName());
authDto.setService(service.getName());
authDto.setScript(scriptDto.getId());
authorities.add(authDto);
} else {
LOG.error("Service [{}] [{}] isn't reachable, for script [{}] skip add this authority", service.getName(), service.getClassName(), type.getCode());
continue;
}
}
}
//
return authorities;
}
use of eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptService method dtoToType.
/**
* Transform dto to type.
*
* @param dto
* @return
*/
private IdmScriptType dtoToType(IdmScriptDto dto, List<IdmScriptAuthorityDto> authorities) {
IdmScriptType type = new IdmScriptType();
if (dto == null) {
return type;
}
// transform DTO to type
type.setCode(dto.getCode());
type.setName(dto.getName());
// parameter isn't implemented yet
// type.setParameters(dto.getParameter());
type.setBody(dto.getScript());
type.setCategory(dto.getCategory());
type.setDescription(dto.getDescription());
type.setType(SCRIPT_DEFAULT_TYPE);
//
if (authorities != null && !authorities.isEmpty()) {
List<IdmScriptAllowClassType> classes = new ArrayList<>();
List<IdmScriptServiceType> services = new ArrayList<>();
for (IdmScriptAuthorityDto auth : authorities) {
if (auth.getType() == ScriptAuthorityType.CLASS_NAME) {
IdmScriptAllowClassType classType = new IdmScriptAllowClassType();
classType.setClassName(auth.getClassName());
classes.add(classType);
} else {
IdmScriptServiceType service = new IdmScriptServiceType();
service.setClassName(auth.getClassName());
service.setName(auth.getService());
services.add(service);
}
}
if (!classes.isEmpty()) {
type.setAllowClasses(new IdmScriptAllowClassesType());
type.getAllowClasses().setAllowClasses(classes);
}
if (!services.isEmpty()) {
type.setServices(new IdmScriptServicesType());
type.getServices().setServices(services);
}
}
return type;
}
Aggregations