Search in sources :

Example 1 with ReportPortalException

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

the class ReportPortalRepositoryImpl method getPageNumber.

@Override
public long getPageNumber(String entityId, Queryable filterable, Pageable pageable) {
    ImmutableList.Builder<AggregationOperation> pipelineBuilder = ImmutableList.<AggregationOperation>builder().add(matchOperationFromFilter(filterable, mongoOperations, this.getEntityInformation().getJavaType()));
    if (null != pageable.getSort()) {
        pipelineBuilder.add(/* sort results as requested */
        sort(pageable.getSort()));
    }
    pipelineBuilder.add(/* group items into one field pushing all results into one array */
    group("result").push("$_id").as("array"), /* unwind array adding index to each result */
    unwind("array", "ind", false), /* find needed item. How we know its index in query result */
    match(where("array").is(ObjectId.isValid(entityId) ? new ObjectId(entityId) : entityId)), /* grab index only */
    project("ind"));
    /* find items matching an provided filter */
    Aggregation a = Aggregation.newAggregation(toArray(pipelineBuilder.build(), AggregationOperation.class));
    final AggregationResults<Map> aggregate = mongoOperations.aggregate(a, getEntityInformation().getCollectionName(), Map.class);
    if (!aggregate.getUniqueMappedResult().containsKey("ind")) {
        throw new ReportPortalException(ErrorType.INCORRECT_FILTER_PARAMETERS, "Unable to calculate page number. Check your input parameters");
    }
    /* result returned as long. Calculate page number */
    return (long) Math.ceil((((Long) aggregate.getUniqueMappedResult().get("ind")).doubleValue() + 1d) / (double) pageable.getPageSize());
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) ObjectId(org.bson.types.ObjectId) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ImmutableList(com.google.common.collect.ImmutableList) CriteriaMap(com.epam.ta.reportportal.database.search.CriteriaMap) AggregationOperation(org.springframework.data.mongodb.core.aggregation.AggregationOperation)

Example 2 with ReportPortalException

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

the class CriteriaHolder method castValue.

/**
 * Casting provided criteriaHolder by specified {@link Class} for specified value.
 * <p>
 * NOTE:<br>
 * errorType - error which should be thrown when unable cast value
 *
 * @param oneValue  Value to cast
 * @param errorType ErrorType in case of error
 * @return Casted value
 */
public Object castValue(String oneValue, ErrorType errorType) {
    Object castedValue;
    if (Number.class.isAssignableFrom(getDataType())) {
        /* Verify correct number */
        Long parsedLong = NumberUtils.toLong(oneValue, -1);
        BusinessRule.expect(parsedLong, FilterRules.numberIsPositive()).verify(errorType, Suppliers.formattedSupplier("Cannot convert '{}' to valid positive number", oneValue));
        castedValue = parsedLong;
    } else if (Date.class.isAssignableFrom(getDataType())) {
        /* Verify correct date */
        BusinessRule.expect(oneValue, FilterRules.dateInMillis()).verify(errorType, Suppliers.formattedSupplier("Cannot convert '{}' to valid date", oneValue));
        castedValue = new Date(Long.parseLong(oneValue));
    } else if (boolean.class.equals(getDataType()) || Boolean.class.isAssignableFrom(getDataType())) {
        castedValue = BooleanUtils.toBoolean(oneValue);
    } else if (LogLevel.class.isAssignableFrom(getDataType())) {
        castedValue = LogLevel.toLevel(oneValue);
        BusinessRule.expect(castedValue, Predicates.notNull()).verify(errorType, Suppliers.formattedSupplier("Cannot convert '{}' to valid 'LogLevel'", oneValue));
    } else if (Status.class.isAssignableFrom(getDataType())) {
        castedValue = Status.fromValue(oneValue).orElseThrow(() -> new ReportPortalException(errorType, Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Status'", oneValue)));
    } else if (TestItemIssueType.class.isAssignableFrom(getDataType())) {
        castedValue = TestItemIssueType.validate(oneValue);
        BusinessRule.expect(castedValue, Predicates.notNull()).verify(errorType, Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Issue Type'", oneValue));
    } else if (Collection.class.isAssignableFrom(getDataType())) {
        /* Collection doesn't stores objects as ObjectId */
        castedValue = oneValue;
    } else if (String.class.isAssignableFrom(getDataType())) {
        castedValue = oneValue != null ? oneValue.trim() : null;
    } else {
        castedValue = ObjectId.isValid(oneValue) ? new ObjectId(oneValue) : oneValue;
    }
    return castedValue;
}
Also used : TestItemIssueType(com.epam.ta.reportportal.database.entity.item.issue.TestItemIssueType) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ObjectId(org.bson.types.ObjectId) Date(java.util.Date) LogLevel(com.epam.ta.reportportal.database.entity.LogLevel)

Example 3 with ReportPortalException

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

the class OAuthConfigurationEndpoint method getOAuthSettings.

/**
 * Returns oauth integration settings
 *
 * @param profileId         settings ProfileID
 * @param oauthProviderName ID of third-party OAuth provider
 * @return All defined OAuth integration settings
 */
@RequestMapping(value = "/{authId}", method = { GET })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Returns OAuth Server Settings", notes = "'default' profile is using till additional UI implementations")
public OAuthDetailsResource getOAuthSettings(@PathVariable String profileId, @PathVariable("authId") String oauthProviderName) {
    ServerSettings settings = repository.findOne(profileId);
    BusinessRule.expect(settings, Predicates.notNull()).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND, profileId);
    return Optional.ofNullable(settings.getoAuth2LoginDetails()).flatMap(details -> Optional.ofNullable(details.get(oauthProviderName))).map(OAuthDetailsConverters.TO_RESOURCE).orElseThrow(() -> new ReportPortalException(ErrorType.OAUTH_INTEGRATION_NOT_FOUND, oauthProviderName));
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ServerSettings(com.epam.ta.reportportal.database.entity.settings.ServerSettings) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with ReportPortalException

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

the class OAuthConfigurationEndpoint method deleteOAuthSetting.

/**
 * Deletes oauth integration settings
 *
 * @param profileId         settings ProfileID
 * @param oauthProviderName ID of third-party OAuth provider
 * @return All defined OAuth integration settings
 */
@RequestMapping(value = "/{authId}", method = { DELETE })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Deletes OAuth Integration Settings", notes = "'default' profile is using till additional UI implementations")
public OperationCompletionRS deleteOAuthSetting(@PathVariable String profileId, @PathVariable("authId") String oauthProviderName) {
    ServerSettings settings = repository.findOne(profileId);
    BusinessRule.expect(settings, Predicates.notNull()).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND, profileId);
    Map<String, OAuth2LoginDetails> serverOAuthDetails = Optional.of(settings.getoAuth2LoginDetails()).orElse(new HashMap<>());
    if (null != serverOAuthDetails.remove(oauthProviderName)) {
        settings.setoAuth2LoginDetails(serverOAuthDetails);
        repository.save(settings);
    } else {
        throw new ReportPortalException(ErrorType.OAUTH_INTEGRATION_NOT_FOUND);
    }
    return new OperationCompletionRS("Auth settings '" + oauthProviderName + "' were successfully removed");
}
Also used : OAuth2LoginDetails(com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ServerSettings(com.epam.ta.reportportal.database.entity.settings.ServerSettings) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with ReportPortalException

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

the class UserDataStoreServiceTest method saveLoadAndDeleteThumbnailTest.

@Test
void saveLoadAndDeleteThumbnailTest() throws IOException {
    InputStream inputStream = new ClassPathResource("meh.jpg").getInputStream();
    String thumbnailId = userDataStoreService.saveThumbnail(random.nextLong() + "thmbnail.jpg", inputStream);
    Optional<InputStream> loadedData = userDataStoreService.load(thumbnailId);
    assertTrue(loadedData.isPresent());
    assertTrue(Files.exists(Paths.get(storageRootPath, userDataStoreService.dataEncoder.decode(thumbnailId))));
    userDataStoreService.delete(thumbnailId);
    ReportPortalException exception = assertThrows(ReportPortalException.class, () -> userDataStoreService.load(thumbnailId));
    assertEquals("Unable to load binary data by id 'Unable to find file'", exception.getMessage());
    assertFalse(Files.exists(Paths.get(storageRootPath, userDataStoreService.dataEncoder.decode(thumbnailId))));
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

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