Search in sources :

Example 11 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.

the class LogRepositoryCustomImpl method getPageNumber.

@Override
public Integer getPageNumber(Long id, Filter filter, Pageable pageable) {
    Sort.Order order = ofNullable(pageable.getSort().getOrderFor(CRITERIA_LOG_TIME)).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_SORTING_PARAMETERS));
    OrderField<?> sortField = order.getDirection().isAscending() ? LOG.LOG_TIME.asc() : LOG.LOG_TIME.desc();
    return ofNullable(dsl.select(fieldName(ROW_NUMBER)).from(dsl.select(LOG.ID, DSL.rowNumber().over(DSL.orderBy(sortField)).as(ROW_NUMBER)).from(LOG).join(QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter, pageable.getSort())).with(pageable.getSort()).build().asTable(DISTINCT_LOGS_TABLE)).on(LOG.ID.eq(fieldName(DISTINCT_LOGS_TABLE, ID).cast(Long.class)))).where(fieldName(ID).cast(Long.class).eq(id)).fetchAny()).map(r -> {
        Long rowNumber = r.into(Long.class);
        return BigDecimal.valueOf(rowNumber).divide(BigDecimal.valueOf(pageable.getPageSize()), RoundingMode.CEILING).intValue();
    }).orElseThrow(() -> new ReportPortalException(ErrorType.LOG_NOT_FOUND, id));
}
Also used : TimestampUtils(com.epam.ta.reportportal.dao.util.TimestampUtils) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) CRITERIA_STATUS(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_STATUS) java.util(java.util) DSL(org.jooq.impl.DSL) RecordMappers(com.epam.ta.reportportal.dao.util.RecordMappers) QueryBuilder(com.epam.ta.reportportal.commons.querygen.QueryBuilder) LOG(com.epam.ta.reportportal.jooq.Tables.LOG) DSL.field(org.jooq.impl.DSL.field) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem) NESTED_ITEM_FETCHER(com.epam.ta.reportportal.dao.util.ResultFetchers.NESTED_ITEM_FETCHER) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) LAUNCH(com.epam.ta.reportportal.jooq.Tables.LAUNCH) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) Log(com.epam.ta.reportportal.entity.log.Log) org.jooq(org.jooq) Duration(java.time.Duration) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Repository(org.springframework.stereotype.Repository) RoundingMode(java.math.RoundingMode) ATTACHMENT(com.epam.ta.reportportal.jooq.tables.JAttachment.ATTACHMENT) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) NestedItem(com.epam.ta.reportportal.entity.item.NestedItem) CLUSTERS(com.epam.ta.reportportal.jooq.Tables.CLUSTERS) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Timestamp(java.sql.Timestamp) LogRepositoryConstants(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) Page(org.springframework.data.domain.Page) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) NESTED(com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants.NESTED) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) CRITERIA_LOG_TIME(com.epam.ta.reportportal.commons.querygen.constant.LogCriteriaConstant.CRITERIA_LOG_TIME) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) LOG_FETCHER(com.epam.ta.reportportal.dao.util.ResultFetchers.LOG_FETCHER) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Sort(org.springframework.data.domain.Sort)

Example 12 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.

the class UserBinaryDataServiceImpl method loadUserPhoto.

@Override
public BinaryData loadUserPhoto(User user, boolean loadThumbnail) {
    Optional<String> fileId = ofNullable(loadThumbnail ? user.getAttachmentThumbnail() : user.getAttachment());
    InputStream data;
    String contentType;
    try {
        if (fileId.isPresent()) {
            contentType = (String) user.getMetadata().getMetadata().get(ATTACHMENT_CONTENT_TYPE);
            data = dataStoreService.load(fileId.get()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, fileId.get()));
        } else {
            data = new ClassPathResource(DEFAULT_USER_PHOTO).getInputStream();
            contentType = MimeTypeUtils.IMAGE_JPEG_VALUE;
        }
        return new BinaryData(contentType, (long) data.available(), data);
    } catch (IOException e) {
        LOGGER.error("Unable to load user photo", e);
        throw new ReportPortalException(ErrorType.UNCLASSIFIED_REPORT_PORTAL_ERROR, "Unable to load user photo");
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BinaryData(com.epam.ta.reportportal.entity.attachment.BinaryData) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 13 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.

the class JsonbUserType method nullSafeSet.

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
    if (value == null) {
        st.setNull(index, Types.OTHER);
        return;
    }
    try {
        PGobject pGobject = new PGobject();
        pGobject.setType("jsonb");
        pGobject.setValue(mapper.writeValueAsString(value));
        st.setObject(index, pGobject);
    } catch (final Exception ex) {
        throw new ReportPortalException("Failed to convert Invoice to String: " + ex.getMessage(), ex);
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) SerializationException(org.hibernate.type.SerializationException) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) SQLException(java.sql.SQLException) HibernateException(org.hibernate.HibernateException) PGobject(org.postgresql.util.PGobject)

Example 14 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.

the class CreateLogAttachmentService method create.

public void create(Attachment attachment, Long logId) {
    Log log = logRepository.findById(logId).orElseThrow(() -> new ReportPortalException(ErrorType.LOG_NOT_FOUND, logId));
    log.setAttachment(attachment);
    logRepository.save(log);
}
Also used : Log(com.epam.ta.reportportal.entity.log.Log) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Example 15 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.

the class GetActiveDirectoryStrategy method getIntegration.

@Override
public ActiveDirectoryResource getIntegration() {
    IntegrationType adIntegrationType = integrationTypeRepository.findByName(AuthIntegrationType.ACTIVE_DIRECTORY.getName()).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, AuthIntegrationType.ACTIVE_DIRECTORY.getName()));
    // or else empty integration with default 'enabled = false' flag
    ActiveDirectoryResource adResource = ActiveDirectoryConverter.TO_RESOURCE.apply(integrationRepository.findByNameAndTypeIdAndProjectIdIsNull(AuthIntegrationType.ACTIVE_DIRECTORY.getName(), adIntegrationType.getId()).orElseGet(Integration::new));
    adResource.setType(adIntegrationType.getName());
    return adResource;
}
Also used : ActiveDirectoryResource(com.epam.ta.reportportal.ws.model.integration.auth.ActiveDirectoryResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) AuthIntegrationType(com.epam.reportportal.auth.integration.AuthIntegrationType) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType)

Aggregations

ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)33 Test (org.junit.jupiter.api.Test)7 InputStream (java.io.InputStream)6 AuthIntegrationType (com.epam.reportportal.auth.integration.AuthIntegrationType)5 BaseTest (com.epam.ta.reportportal.BaseTest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 Integration (com.epam.ta.reportportal.entity.integration.Integration)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 QueryBuilder (com.epam.ta.reportportal.commons.querygen.QueryBuilder)2 ID (com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID)2 JooqFieldNameTransformer.fieldName (com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName)2 QueryUtils (com.epam.ta.reportportal.dao.util.QueryUtils)2 ServerSettings (com.epam.ta.reportportal.database.entity.settings.ServerSettings)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 Log (com.epam.ta.reportportal.entity.log.Log)2 JStatusEnum (com.epam.ta.reportportal.jooq.enums.JStatusEnum)2