Search in sources :

Example 1 with BlackDuckServerData

use of com.synopsys.integration.blackduck.service.model.BlackDuckServerData in project hub-alert by blackducksoftware.

the class BlackDuckPhoneHomeHandler method populatePhoneHomeData.

@Override
public PhoneHomeRequestBodyBuilder populatePhoneHomeData(ConfigurationModel configurationModel, NameVersion alertArtifactInfo) {
    String registrationId = null;
    String blackDuckUrl = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    String blackDuckVersion = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    try {
        descriptorAccessor.getRegisteredDescriptorById(configurationModel.getDescriptorId());
        StatefulProvider statefulProvider = provider.createStatefulProvider(configurationModel);
        BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
        BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
        BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
        BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
        BlackDuckServerData blackDuckServerData = blackDuckRegistrationService.getBlackDuckServerData();
        blackDuckVersion = blackDuckServerData.getVersion();
        registrationId = blackDuckServerData.getRegistrationKey().orElse(null);
        blackDuckUrl = blackDuckProperties.getBlackDuckUrl().orElse(PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE);
    } catch (IntegrationException ignored) {
    // ignoring this exception
    }
    // We must check if the reg id is blank because of an edge case in which Black Duck can authenticate (while the webserver is coming up) without registration
    if (StringUtils.isBlank(registrationId)) {
        registrationId = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    }
    PhoneHomeRequestBodyBuilder phoneHomeBuilder = new PhoneHomeRequestBodyBuilder(registrationId, blackDuckUrl, alertArtifactInfo, UniquePhoneHomeProduct.BLACK_DUCK, blackDuckVersion);
    return phoneHomeBuilder;
}
Also used : PhoneHomeRequestBodyBuilder(com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BlackDuckServerData(com.synopsys.integration.blackduck.service.model.BlackDuckServerData) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService)

Aggregations

StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 BlackDuckRegistrationService (com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService)1 BlackDuckServerData (com.synopsys.integration.blackduck.service.model.BlackDuckServerData)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)1 PhoneHomeRequestBodyBuilder (com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder)1