Search in sources :

Example 1 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class WidgetBuilder method addWidgetPreviewRq.

public WidgetBuilder addWidgetPreviewRq(WidgetPreviewRQ previewRQ) {
    WidgetOptions widgetOptions = ofNullable(widget.getWidgetOptions()).orElseGet(WidgetOptions::new);
    Map<String, Object> options = ofNullable(widgetOptions.getOptions()).orElseGet(LinkedHashMap::new);
    options.putAll(previewRQ.getContentParameters().getWidgetOptions());
    widgetOptions.setOptions(options);
    widget.setWidgetOptions(widgetOptions);
    widget.setWidgetType(previewRQ.getWidgetType());
    widget.setItemsCount(previewRQ.getContentParameters().getItemsCount());
    widget.getContentFields().clear();
    widget.getContentFields().addAll(ofNullable(previewRQ.getContentParameters().getContentFields()).orElse(Collections.emptyList()));
    return this;
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class MaterializedWidgetProviderHandlerImpl method validateState.

private void validateState(WidgetOptions widgetOptions) {
    WidgetState widgetState = ofNullable(WidgetOptionUtil.getValueByKey(STATE, widgetOptions)).flatMap(WidgetState::findByName).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_UPDATE_WIDGET_REQUEST, "Widget state not provided"));
    BusinessRule.expect(widgetState, it -> !WidgetState.RENDERING.equals(it)).verify(ErrorType.BAD_UPDATE_WIDGET_REQUEST, "Unable to remove widget in 'rendering' state");
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) WidgetState(com.epam.ta.reportportal.entity.widget.WidgetState) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) GetShareableEntityHandler(com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler) Statistics(com.epam.ta.reportportal.entity.statistics.Statistics) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Map(java.util.Map) Pageable(org.springframework.data.domain.Pageable) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) VIEW_NAME(com.epam.ta.reportportal.core.widget.content.loader.materialized.handler.MaterializedWidgetStateHandler.VIEW_NAME) Optional.ofNullable(java.util.Optional.ofNullable) WidgetOptionUtil(com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Set(java.util.Set) Page(org.springframework.data.domain.Page) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) Component(org.springframework.stereotype.Component) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) Optional(java.util.Optional) Widget(com.epam.ta.reportportal.entity.widget.Widget) DataProviderHandler(com.epam.ta.reportportal.core.item.impl.provider.DataProviderHandler) ControllerUtils(com.epam.ta.reportportal.util.ControllerUtils) STATE(com.epam.ta.reportportal.core.widget.content.updater.MaterializedWidgetStateUpdater.STATE) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) WidgetState(com.epam.ta.reportportal.entity.widget.WidgetState)

Example 3 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class WidgetOptionUtilTest method getMapValueWhenCorrectTypeTest.

@Test
void getMapValueWhenCorrectTypeTest() {
    // given
    WidgetOptions widgetOptions = new WidgetOptions(getMapWithNonStringValues());
    // when
    Map<String, String> mapByKey = WidgetOptionUtil.getMapByKey(FIRST_KEY, widgetOptions);
    // then
    assertNotNull(mapByKey);
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Test(org.junit.jupiter.api.Test)

Example 4 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class WidgetOptionUtilTest method throwExceptionWhenGetStringValueWithInCorrectTypeTest.

@Test
void throwExceptionWhenGetStringValueWithInCorrectTypeTest() {
    // given
    WidgetOptions widgetOptions = new WidgetOptions(getMapWithNonStringValues());
    // when //then throw exception
    assertThrows(ReportPortalException.class, () -> WidgetOptionUtil.getValueByKey(FIRST_KEY, widgetOptions));
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) Test(org.junit.jupiter.api.Test)

Example 5 with WidgetOptions

use of com.epam.ta.reportportal.entity.widget.WidgetOptions in project service-api by reportportal.

the class NotPassedTestsContentValidatorTest method testValidateWithException.

@Test
public void testValidateWithException() {
    Exception exception = assertThrows(ReportPortalException.class, () -> {
        notPassedTestsContentValidator.validate(Collections.singletonList("test"), new HashMap<>(), new WidgetOptions(), 5);
    });
    String expectedMessage = "Filter-Sort mapping should not be empty";
    String actualMessage = exception.getMessage();
    assertTrue(actualMessage.contains(expectedMessage));
}
Also used : WidgetOptions(com.epam.ta.reportportal.entity.widget.WidgetOptions) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Test(org.junit.jupiter.api.Test)

Aggregations

WidgetOptions (com.epam.ta.reportportal.entity.widget.WidgetOptions)34 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)20 Test (org.junit.jupiter.api.Test)20 Sort (org.springframework.data.domain.Sort)15 Filter (com.epam.ta.reportportal.commons.querygen.Filter)13 WidgetOptionUtil (com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil)10 Launch (com.epam.ta.reportportal.entity.launch.Launch)10 HashMap (java.util.HashMap)10 Optional.ofNullable (java.util.Optional.ofNullable)10 WidgetContentRepository (com.epam.ta.reportportal.dao.WidgetContentRepository)8 Map (java.util.Map)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Service (org.springframework.stereotype.Service)7 ContentLoaderConstants (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants)6 GROUP_FILTERS (com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS)6 List (java.util.List)6 CollectionUtils (org.apache.commons.collections.CollectionUtils)6 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)5 LoadContentStrategy (com.epam.ta.reportportal.core.widget.content.LoadContentStrategy)5 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)5