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;
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations