Search in sources :

Example 6 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class EmailTestActionHelper method createUpdatedEmailAddresses.

public Set<String> createUpdatedEmailAddresses(DistributionJobModel distributionJobModel) throws AlertException {
    Set<String> emailAddresses = new HashSet<>();
    DistributionJobDetailsModel distributionJobDetails = distributionJobModel.getDistributionJobDetails();
    EmailJobDetailsModel emailJobDetails = distributionJobDetails.getAs(DistributionJobDetailsModel.EMAIL);
    Long providerConfigId = distributionJobModel.getBlackDuckGlobalConfigId();
    boolean onlyAdditionalEmails = emailJobDetails.isAdditionalEmailAddressesOnly();
    if (null != providerConfigId && !onlyAdditionalEmails) {
        Set<ProviderProject> providerProjects = retrieveProviderProjects(distributionJobModel, providerConfigId);
        if (CollectionUtils.isNotEmpty(providerProjects)) {
            Set<String> providerEmailAddresses = addEmailAddresses(providerConfigId, providerProjects, distributionJobModel, emailJobDetails);
            emailAddresses.addAll(providerEmailAddresses);
        }
    }
    return emailAddresses;
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) HashSet(java.util.HashSet)

Example 7 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method retrieveProjectsForProvider.

private AlertPagedModel<ProviderProject> retrieveProjectsForProvider(ConfigurationModel blackDuckConfigurationModel, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
    BlackDuckQuery nameQuery = new BlackDuckQuery("name", searchTerm);
    BlackDuckPageDefinition blackDuckPageDefinition = new BlackDuckPageDefinition(pageSize, pageNumber * pageSize);
    BlackDuckMultipleRequest<ProjectView> projectSpec = new BlackDuckRequestBuilder().commonGet().addBlackDuckQuery(nameQuery).setBlackDuckPageDefinition(blackDuckPageDefinition).buildBlackDuckRequest(apiDiscovery.metaProjectsLink());
    BlackDuckPageResponse<ProjectView> pageOfProjects = blackDuckApiClient.getPageResponse(projectSpec);
    List<ProviderProject> foundProjects = convertBlackDuckProjects(pageOfProjects.getItems(), blackDuckApiClient);
    int totalPageCount = computeTotalCount(pageOfProjects, pageSize);
    return new AlertPagedModel<>(totalPageCount, pageNumber, pageSize, foundProjects);
}
Also used : BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject)

Example 8 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method convertBlackDuckProjects.

private List<ProviderProject> convertBlackDuckProjects(List<ProjectView> projectViews, BlackDuckApiClient blackDuckService) {
    List<ProviderProject> providerProjects = new ArrayList<>();
    for (ProjectView projectView : projectViews) {
        ProviderProject providerProject = createProviderProject(projectView, blackDuckService);
        providerProjects.add(providerProject);
    }
    return providerProjects;
}
Also used : ArrayList(java.util.ArrayList) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Example 9 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class BlackDuckGlobalApiAction method afterDeleteAction.

@Override
public void afterDeleteAction(FieldModel fieldModel) {
    Map<String, FieldValueModel> keyToValues = fieldModel.getKeyToValues();
    FieldValueModel fieldValueModel = keyToValues.get(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    String blackDuckGlobalConfigName = fieldValueModel.getValue().orElse("");
    Long configId = Long.parseLong(fieldModel.getId());
    providerLifecycleManager.unscheduleTasksForProviderConfig(configId);
    List<ProviderProject> blackDuckProjects = providerDataAccessor.getProjectsByProviderConfigName(blackDuckGlobalConfigName);
    providerDataAccessor.deleteProjects(blackDuckProjects);
}
Also used : ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 10 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class BlackDuckDataSyncTask method mapBlackDuckProjectsToAlertProjects.

private Map<ProjectView, ProviderProject> mapBlackDuckProjectsToAlertProjects(List<ProjectView> projectViews, BlackDuckApiClient blackDuckApiClient) {
    Map<ProjectView, ProviderProject> projectMap = new ConcurrentHashMap<>();
    projectViews.parallelStream().forEach(projectView -> {
        String projectOwnerEmail = null;
        if (StringUtils.isNotBlank(projectView.getProjectOwner())) {
            try {
                HttpUrl projectOwnerHttpUrl = new HttpUrl(projectView.getProjectOwner());
                UserView projectOwner = blackDuckApiClient.getResponse(projectOwnerHttpUrl, UserView.class);
                projectOwnerEmail = projectOwner.getEmail();
            } catch (IntegrationException e) {
                logger.error(String.format("Could not get the project owner for Project: %s. Error: %s", projectView.getName(), e.getMessage()), e);
            }
        }
        projectMap.put(projectView, new ProviderProject(projectView.getName(), StringUtils.trimToEmpty(projectView.getDescription()), projectView.getMeta().getHref().toString(), projectOwnerEmail));
    });
    return projectMap;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)13 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)3 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)3 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Test (org.junit.jupiter.api.Test)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)2 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ProviderDescriptor (com.synopsys.integration.alert.api.provider.ProviderDescriptor)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 PagedCustomFunctionAction (com.synopsys.integration.alert.common.action.PagedCustomFunctionAction)1