Search in sources :

Example 1 with AccountTag

use of com.sequenceiq.environment.tags.domain.AccountTag in project cloudbreak by hortonworks.

the class AccountTagsRequestToAccountTagConverter method convert.

public AccountTag convert(AccountTagRequest source) {
    AccountTag accountTag = new AccountTag();
    accountTag.setTagKey(source.getKey());
    accountTag.setTagValue(source.getValue());
    return accountTag;
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag)

Example 2 with AccountTag

use of com.sequenceiq.environment.tags.domain.AccountTag in project cloudbreak by hortonworks.

the class EnvironmentDtoConverter method getTags.

private Json getTags(EnvironmentCreationDto creationDto) {
    boolean internalTenant = entitlementService.internalTenant(creationDto.getAccountId());
    Map<String, String> userDefinedTags = creationDto.getTags();
    Set<AccountTag> accountTags = accountTagService.get(creationDto.getAccountId());
    List<AccountTagResponse> accountTagResponses = accountTags.stream().map(accountTagToAccountTagResponsesConverter::convert).collect(Collectors.toList());
    defaultInternalAccountTagService.merge(accountTagResponses);
    Map<String, String> accountTagsMap = accountTagResponses.stream().collect(Collectors.toMap(AccountTagResponse::getKey, AccountTagResponse::getValue));
    CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(creationDto.getCreator()).withEnvironmentCrn(creationDto.getCrn()).withAccountId(creationDto.getAccountId()).withPlatform(creationDto.getCloudPlatform()).withResourceCrn(creationDto.getCrn()).withIsInternalTenant(internalTenant).withUserName(getUserNameFromCrn(creationDto.getCreator())).withAccountTags(accountTagsMap).withUserDefinedTags(userDefinedTags).build();
    try {
        Map<String, String> defaultTags = costTagging.prepareDefaultTags(request);
        return new Json(new EnvironmentTags(Objects.requireNonNullElseGet(userDefinedTags, HashMap::new), defaultTags));
    } catch (AccountTagValidationFailed aTVF) {
        throw new BadRequestException(aTVF.getMessage());
    } catch (Exception e) {
        throw new BadRequestException("Failed to convert dynamic tags. " + e.getMessage(), e);
    }
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag) HashMap(java.util.HashMap) AccountTagResponse(com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest)

Example 3 with AccountTag

use of com.sequenceiq.environment.tags.domain.AccountTag in project cloudbreak by hortonworks.

the class DefaultInternalAccountTagServiceTest method accountTags.

// CHECKSTYLE:ON
// @formatter:on
private List<AccountTag> accountTags(String key, String value) {
    List<AccountTag> accountTagList = new ArrayList<>();
    AccountTag accountTag = new AccountTag();
    accountTag.setTagValue(key);
    accountTag.setTagKey(value);
    accountTagList.add(accountTag);
    return accountTagList;
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag) ArrayList(java.util.ArrayList)

Example 4 with AccountTag

use of com.sequenceiq.environment.tags.domain.AccountTag in project cloudbreak by hortonworks.

the class EnvironmentTagProviderTest method setUp.

@BeforeEach
void setUp() {
    when(accountTagService.get(ACCOUNT_ID)).thenReturn(Set.of(new AccountTag()));
    when(accountTagToAccountTagResponsesConverter.convert(any())).thenReturn(ACCOUNT_TAGS.get(0));
    CrnUser crnUser = new CrnUser("userId", USER_CRN, USERNAME, "email", "tenant", "role");
    when(crnUserDetailsService.loadUserByUsername(USER_CRN)).thenReturn(crnUser);
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with AccountTag

use of com.sequenceiq.environment.tags.domain.AccountTag in project cloudbreak by hortonworks.

the class AccountTagService method create.

public List<AccountTag> create(List<AccountTag> accountTags, String accountId) {
    try {
        accountTagRepository.arhiveAll(accountId);
        List<AccountTag> result = new ArrayList<>();
        for (AccountTag accountTag : accountTags) {
            accountTag.setAccountId(accountId);
            accountTag.setArchived(false);
            accountTag.setResourceCrn(createCRN(accountId));
            result.add(accountTagRepository.save(accountTag));
        }
        return result;
    } catch (DataIntegrityViolationException e) {
        throw new AccessDeniedException("Access denied", e);
    }
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag) AccessDeniedException(org.springframework.security.access.AccessDeniedException) ArrayList(java.util.ArrayList) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

AccountTag (com.sequenceiq.environment.tags.domain.AccountTag)6 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 AccountTagResponse (com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse)2 ArrayList (java.util.ArrayList)2 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)1 CloudbreakResourceReaderService (com.sequenceiq.cloudbreak.service.CloudbreakResourceReaderService)1 AccountTagValidationFailed (com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed)1 HandleBarModelKey (com.sequenceiq.cloudbreak.tag.HandleBarModelKey)1 CDPTagGenerationRequest (com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest)1 AccountTagStatus (com.sequenceiq.environment.api.v1.tags.model.AccountTagStatus)1 AccountTagResponses (com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponses)1 EnvironmentTags (com.sequenceiq.environment.environment.domain.EnvironmentTags)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1