use of com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository in project cloudbreak by hortonworks.
the class RepositoryBasedDataCollector method fetchDataFromDbIfNeed.
/**
* Attaches {@code RESOURCE_ID}, {@code RESOURCE_CRN}, or {@code RESOURCE_NAME} to the provided {@code params} if they're missing.
*
* @param params should include exactly one of {@code RESOURCE_CRN} or {@code RESOURCE_NAME}
*/
public void fetchDataFromDbIfNeed(Map<String, String> params) {
String resourceCrn = params.get(RESOURCE_CRN);
String resourceName = params.get(RESOURCE_NAME);
// check each repository for a matching CRN or Name.
for (Map.Entry<String, AccountAwareResourceRepository<?, ?>> pathRepositoryEntry : pathRepositoryMap.entrySet()) {
AccountAwareResourceRepository<?, ?> resourceRepository = pathRepositoryEntry.getValue();
if (resourceCrn == null && resourceName != null) {
String accountId = ThreadBasedUserCrnProvider.getAccountId();
Optional<ResourceBasicView> entity = resourceRepository.findResourceBasicViewByNameAndAccountId(resourceName, accountId);
if (entity.isPresent()) {
ResourceBasicView resource = entity.get();
params.put(RESOURCE_ID, Long.toString(resource.getId()));
params.put(RESOURCE_CRN, resource.getResourceCrn());
break;
}
} else if (resourceName == null) {
Optional<ResourceBasicView> entity = resourceRepository.findResourceBasicViewByResourceCrn(resourceCrn);
if (entity.isPresent()) {
ResourceBasicView resource = entity.get();
params.put(RESOURCE_ID, Long.toString(resource.getId()));
params.put(RESOURCE_NAME, resource.getName());
break;
}
}
}
}
Aggregations