Search in sources :

Example 1 with GeneratedAccountTagResponse

use of com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponse in project cloudbreak by hortonworks.

the class AccountTagController method generate.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public GeneratedAccountTagResponses generate(@ResourceName String environmentName, @ResourceCrn @TenantAwareParam String environmentCrn) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    EnvironmentDto environmentDto = null;
    if (!Strings.isNullOrEmpty(environmentCrn)) {
        environmentDto = environmentService.getByCrnAndAccountId(environmentCrn, accountId);
    } else if (!Strings.isNullOrEmpty(environmentName)) {
        environmentDto = environmentService.getByNameAndAccountId(environmentName, accountId);
    }
    Map<String, String> accountTagsMap = new HashMap<>();
    if (environmentDto != null) {
        accountTagsMap = accountTagService.generate(accountId, environmentDto);
    }
    Set<GeneratedAccountTagResponse> accountTags = new HashSet<>();
    for (Map.Entry<String, String> entry : accountTagsMap.entrySet()) {
        GeneratedAccountTagResponse accountTag = new GeneratedAccountTagResponse();
        accountTag.setKey(entry.getKey());
        accountTag.setValue(entry.getValue());
        accountTags.add(accountTag);
    }
    return new GeneratedAccountTagResponses(accountTags);
}
Also used : GeneratedAccountTagResponses(com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponses) GeneratedAccountTagResponse(com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponse) HashMap(java.util.HashMap) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Aggregations

CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)1 GeneratedAccountTagResponse (com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponse)1 GeneratedAccountTagResponses (com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponses)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1