All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.foodtechlab.lib.auth.service.domain.credential.usecases.CheckAvailableInitCredentialsUseCase Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package ru.foodtechlab.lib.auth.service.domain.credential.usecases;

import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.FiltersInputValues;
import com.rcore.domain.commons.usecase.model.SearchResultEntityOutputValues;
import com.rcore.domain.commons.usecase.model.SingleOutput;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import ru.foodtechlab.lib.auth.service.domain.credential.entity.CredentialEntity;
import ru.foodtechlab.lib.auth.service.domain.credential.filters.SearchByRoleFilters;
import ru.foodtechlab.lib.auth.service.domain.role.entity.RoleEntity;
import ru.foodtechlab.lib.auth.service.domain.role.usecases.CreateRoleUseCase;
import ru.foodtechlab.lib.auth.service.domain.role.usecases.FindRoleByCodeUseCase;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
public class CheckAvailableInitCredentialsUseCase extends UseCase> {

    private final FindCredentialsByRoleUseCase findCredentialsByRole;
    private final FindRoleByCodeUseCase findRoleByCode;
    private final CreateRoleUseCase createRole;

    @Override
    public SingleOutput execute(CheckAvailableInitCredentialsUseCase.InputValues inputValues) {
        List roles = new ArrayList<>();

        //Проверка ролей
        findRoleByCode.execute(FindRoleByCodeUseCase.InputValues.of("SUPER_USER")).getEntity()
                .ifPresentOrElse(roles::add,
                        () -> roles.add(createRole.execute(CreateRoleUseCase.InputValues.builder()
                                .code("SUPER_USER")
                                .build()).getEntity()));

        SearchResultEntityOutputValues creds = findCredentialsByRole.execute(FiltersInputValues.of(SearchByRoleFilters.builder().roles(roles).build()));
        if( creds.getResult() == null || creds.getResult().getItems() == null || creds.getResult().getItems().size() == 0){
            return SingleOutput.of(true);
        }
        return SingleOutput.of(false);
    }

    @NoArgsConstructor
    @Builder
    public static class InputValues implements UseCase.InputValues {
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy