Search in sources :

Example 1 with JiraJobCustomFieldModel

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

the class StaticJobAccessor method convertToDistributionJobModel.

@Deprecated
private DistributionJobModel convertToDistributionJobModel(DistributionJobEntity jobEntity) {
    UUID jobId = jobEntity.getJobId();
    DistributionJobDetailsModel distributionJobDetailsModel = null;
    ChannelKey channelKey = ChannelKeys.getChannelKey(jobEntity.getChannelDescriptorName());
    if (ChannelKeys.AZURE_BOARDS.equals(channelKey)) {
        AzureBoardsJobDetailsEntity jobDetails = jobEntity.getAzureBoardsJobDetails();
        distributionJobDetailsModel = new AzureBoardsJobDetailsModel(jobId, jobDetails.getAddComments(), jobDetails.getProjectNameOrId(), jobDetails.getWorkItemType(), jobDetails.getWorkItemCompletedState(), jobDetails.getWorkItemReopenState());
    } else if (ChannelKeys.JIRA_CLOUD.equals(channelKey)) {
        JiraCloudJobDetailsEntity jobDetails = jobEntity.getJiraCloudJobDetails();
        List<JiraJobCustomFieldModel> customFields = jobDetails.getJobCustomFields().stream().map(entity -> new JiraJobCustomFieldModel(entity.getFieldName(), entity.getFieldValue())).collect(Collectors.toList());
        distributionJobDetailsModel = new JiraCloudJobDetailsModel(jobId, jobDetails.getAddComments(), jobDetails.getIssueCreatorEmail(), jobDetails.getProjectNameOrKey(), jobDetails.getIssueType(), jobDetails.getResolveTransition(), jobDetails.getReopenTransition(), customFields, jobDetails.getIssueSummary());
    } else if (ChannelKeys.MS_TEAMS.equals(channelKey)) {
        MSTeamsJobDetailsEntity jobDetails = jobEntity.getMsTeamsJobDetails();
        distributionJobDetailsModel = new MSTeamsJobDetailsModel(jobId, jobDetails.getWebhook());
    } else if (ChannelKeys.SLACK.equals(channelKey)) {
        SlackJobDetailsEntity slackJobDetails = jobEntity.getSlackJobDetails();
        distributionJobDetailsModel = new SlackJobDetailsModel(jobId, slackJobDetails.getWebhook(), slackJobDetails.getChannelName(), slackJobDetails.getChannelUsername());
    }
    return convertToDistributionJobModel(jobEntity, distributionJobDetailsModel);
}
Also used : MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) AzureBoardsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.AzureBoardsJobDetailsModel) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraCloudJobDetailsEntity(com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity) AzureBoardsJobDetailsEntity(com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) List(java.util.List) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) UUID(java.util.UUID) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)

Example 2 with JiraJobCustomFieldModel

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

the class JiraServerExternalConnectionTest method createDistributionDetails.

private JiraServerJobDetailsModel createDistributionDetails() {
    UUID uuid = UUID.randomUUID();
    List<JiraJobCustomFieldModel> customFields = new ArrayList<>();
    // This test requires that the JIRA server has 2 components associated with the project: "component1" and "component2"
    customFields.add(new JiraJobCustomFieldModel("Component/s", "component1 component2"));
    return new JiraServerJobDetailsModel(uuid, Boolean.parseBoolean(testProperties.getProperty(TestPropertyKey.TEST_JIRA_SERVER_ADD_COMMENTS)), testProperties.getOptionalProperty(TestPropertyKey.TEST_JIRA_SERVER_ISSUE_CREATOR).orElse(null), testProperties.getProperty(TestPropertyKey.TEST_JIRA_SERVER_PROJECT_NAME), testProperties.getProperty(TestPropertyKey.TEST_JIRA_SERVER_ISSUE_TYPE), testProperties.getProperty(TestPropertyKey.TEST_JIRA_SERVER_RESOLVE_TRANSITION), testProperties.getProperty(TestPropertyKey.TEST_JIRA_SERVER_REOPEN_TRANSITION), customFields, "");
}
Also used : JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) ArrayList(java.util.ArrayList) UUID(java.util.UUID) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel)

Example 3 with JiraJobCustomFieldModel

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

the class JiraFieldMappingValidator method validateFieldMappings.

public Optional<AlertFieldStatus> validateFieldMappings(String fieldMappingFieldKey, FieldValueModel fieldMappingField) {
    List<JiraJobCustomFieldModel> customFields = fieldMappingField.getValues().stream().map(fieldMappingString -> gson.fromJson(fieldMappingString, JiraJobCustomFieldModel.class)).collect(Collectors.toList());
    Set<String> fieldNames = new HashSet<>();
    List<String> duplicateNameList = new ArrayList<>();
    for (JiraJobCustomFieldModel jiraJobCustomFieldModel : customFields) {
        String currentFieldName = jiraJobCustomFieldModel.getFieldName();
        if (fieldNames.contains(currentFieldName)) {
            duplicateNameList.add(currentFieldName);
        }
        fieldNames.add(currentFieldName);
    }
    if (!duplicateNameList.isEmpty()) {
        String duplicateNames = StringUtils.join(duplicateNameList, ", ");
        String errorMessage = String.format("Duplicate field name(s): %s", duplicateNames);
        AlertFieldStatus fieldMappingError = AlertFieldStatus.error(fieldMappingFieldKey, errorMessage);
        return Optional.of(fieldMappingError);
    }
    return Optional.empty();
}
Also used : AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Component(org.springframework.stereotype.Component) Gson(com.google.gson.Gson) Optional(java.util.Optional) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Example 4 with JiraJobCustomFieldModel

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

the class JiraJobDetailsExtractorTest method extractFieldMappingsTest.

@Test
public void extractFieldMappingsTest() {
    String testFieldName = "field.name";
    String testFieldValue = "some random value";
    JiraJobCustomFieldModel testCustomField = new JiraJobCustomFieldModel(testFieldName, testFieldValue);
    ConfigurationFieldModel testFieldModel = ConfigurationFieldModel.create(testFieldName);
    String testCustomFieldJson = GSON.toJson(testCustomField);
    testFieldModel.setFieldValue(testCustomFieldJson);
    JiraJobDetailsExtractor jobDetailsExtractor = createJobDetailsExtractor();
    List<JiraJobCustomFieldModel> fieldMappings = jobDetailsExtractor.extractJiraFieldMappings(testFieldName, Map.of(testFieldName, testFieldModel));
    assertEquals(1, fieldMappings.size());
    JiraJobCustomFieldModel extractedFieldMapping = fieldMappings.get(0);
    assertEquals(testCustomField, extractedFieldMapping);
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) Test(org.junit.jupiter.api.Test)

Aggregations

JiraJobCustomFieldModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UUID (java.util.UUID)2 Gson (com.google.gson.Gson)1 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1 AzureBoardsJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.AzureBoardsJobDetailsModel)1 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)1 JiraCloudJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel)1 JiraServerJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel)1 MSTeamsJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel)1 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)1 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)1 AzureBoardsJobDetailsEntity (com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity)1 JiraCloudJobDetailsEntity (com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity)1 MSTeamsJobDetailsEntity (com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity)1 SlackJobDetailsEntity (com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)1 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)1 HashSet (java.util.HashSet)1