Search in sources :

Example 1 with IdmScriptAllowClassType

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;
}
Also used : IdmScriptType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType) IdmScriptServicesType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServicesType) IdmScriptAllowClassType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptServiceType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType) ArrayList(java.util.ArrayList) IdmScriptAllowClassesType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassesType) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)

Example 2 with IdmScriptAllowClassType

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;
}
Also used : IdmScriptAllowClassType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptServiceType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType) ArrayList(java.util.ArrayList)

Example 3 with IdmScriptAllowClassType

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;
}
Also used : IdmScriptType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType) IdmScriptServicesType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServicesType) IdmScriptAllowClassType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType) IdmScriptServiceType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) ArrayList(java.util.ArrayList) IdmScriptAllowClassesType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassesType)

Aggregations

IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)3 IdmScriptAllowClassType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType)3 IdmScriptServiceType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType)3 ArrayList (java.util.ArrayList)3 IdmScriptAllowClassesType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassesType)2 IdmScriptServicesType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServicesType)2 IdmScriptType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType)2 IdmScriptAuthorityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)1