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));
}
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");
}
}
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);
}
}
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);
}
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;
}
Aggregations