Search in sources :

Example 6 with AuditJobStatusModel

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

the class DefaultRestApiAuditAccessor method convertToAuditEntryModelFromNotification.

@Override
@Transactional
public AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry) {
    List<AuditNotificationRelation> relations = auditNotificationRepository.findByNotificationId(notificationContentEntry.getId());
    List<Long> auditEntryIds = relations.stream().map(AuditNotificationRelation::getAuditEntryId).collect(Collectors.toList());
    List<AuditEntryEntity> auditEntryEntities = auditEntryRepository.findAllById(auditEntryIds);
    AuditEntryStatus overallStatus = null;
    String timeLastSent = null;
    OffsetDateTime timeLastSentOffsetDateTime = null;
    List<JobAuditModel> jobAuditModels = new ArrayList<>();
    for (AuditEntryEntity auditEntryEntity : auditEntryEntities) {
        UUID jobId = auditEntryEntity.getCommonConfigId();
        if (null != auditEntryEntity.getTimeLastSent() && (null == timeLastSentOffsetDateTime || timeLastSentOffsetDateTime.isBefore(auditEntryEntity.getTimeLastSent()))) {
            timeLastSentOffsetDateTime = auditEntryEntity.getTimeLastSent();
            timeLastSent = formatAuditDate(timeLastSentOffsetDateTime);
        }
        String id = contentConverter.getStringValue(auditEntryEntity.getId());
        String configId = contentConverter.getStringValue(jobId);
        String timeCreated = formatAuditDate(auditEntryEntity.getTimeCreated());
        AuditEntryStatus status = null;
        if (auditEntryEntity.getStatus() != null) {
            status = AuditEntryStatus.valueOf(auditEntryEntity.getStatus());
            overallStatus = getWorstStatus(overallStatus, status);
        }
        String errorMessage = auditEntryEntity.getErrorMessage();
        String errorStackTrace = auditEntryEntity.getErrorStackTrace();
        Optional<DistributionJobModel> distributionJobModel = jobAccessor.getJobById(jobId);
        String distributionConfigName = distributionJobModel.map(DistributionJobModelData::getName).orElse(null);
        String eventType = distributionJobModel.map(DistributionJobModelData::getChannelDescriptorName).orElse(null);
        String statusDisplayName = null;
        if (null != status) {
            statusDisplayName = status.getDisplayName();
        }
        AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(jobId, timeCreated, timeLastSent, statusDisplayName);
        jobAuditModels.add(new JobAuditModel(id, configId, distributionConfigName, eventType, auditJobStatusModel, errorMessage, errorStackTrace));
    }
    String id = contentConverter.getStringValue(notificationContentEntry.getId());
    NotificationConfig notificationConfig = populateConfigFromEntity(notificationContentEntry);
    String overallStatusDisplayName = null;
    if (null != overallStatus) {
        overallStatusDisplayName = overallStatus.getDisplayName();
    }
    return new AuditEntryModel(id, notificationConfig, jobAuditModels, overallStatusDisplayName, timeLastSent);
}
Also used : ArrayList(java.util.ArrayList) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) OffsetDateTime(java.time.OffsetDateTime) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with AuditJobStatusModel

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

the class AuditEntryActions method queryForAuditInfoInJobs.

public ActionResponse<AuditJobStatusesModel> queryForAuditInfoInJobs(JobIdsRequestModel queryRequestModel) {
    if (!authorizationManager.hasReadPermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    List<UUID> jobIds = queryRequestModel.getJobIds();
    for (UUID jobId : jobIds) {
        if (null == jobId) {
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, "The field 'jobIds' cannot contain null values");
        }
    }
    List<AuditJobStatusModel> auditJobStatusModels = auditAccessor.findByJobIds(jobIds);
    return new ActionResponse<>(HttpStatus.OK, new AuditJobStatusesModel(auditJobStatusModels));
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AuditJobStatusesModel(com.synopsys.integration.alert.common.rest.model.AuditJobStatusesModel)

Aggregations

AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)7 Test (org.junit.jupiter.api.Test)5 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)4 UUID (java.util.UUID)4 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)3 AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 JobAuditModel (com.synopsys.integration.alert.common.rest.model.JobAuditModel)2 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)2 OffsetDateTime (java.time.OffsetDateTime)2 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)1 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)1 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)1 AuditJobStatusesModel (com.synopsys.integration.alert.common.rest.model.AuditJobStatusesModel)1 NotificationConfig (com.synopsys.integration.alert.common.rest.model.NotificationConfig)1 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)1 DefaultRestApiAuditAccessor (com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor)1 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)1