use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class FilteringServiceImpl method getCurrentUserSubscribedApis.
private FilteredEntities<ApiEntity> getCurrentUserSubscribedApis(Collection<ApiEntity> apis, boolean excluded) {
// get Current user applications
List<String> currentUserApplicationsId = applicationService.findByUser(getAuthenticatedUser().getUsername()).stream().map(ApplicationListItem::getId).collect(Collectors.toList());
// find all subscribed apis for these applications
SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
subscriptionQuery.setApplications(currentUserApplicationsId);
List<String> subscribedApis = subscriptionService.search(subscriptionQuery).stream().map(SubscriptionEntity::getApi).distinct().collect(Collectors.toList());
// filter apis list with subscribed apis list
return new FilteredEntities<>(apis.stream().filter(api -> (!excluded && subscribedApis.contains(api.getId())) || (excluded && !subscribedApis.contains(api.getId()))).sorted((a1, a2) -> String.CASE_INSENSITIVE_ORDER.compare(a1.getName(), a2.getName())).collect(Collectors.toList()), null);
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PromotionTasksServiceImpl method convert.
private TaskEntity convert(PromotionEntity promotionEntity, boolean isUpdate, Optional<String> foundTargetApiId) {
TaskEntity taskEntity = new TaskEntity();
taskEntity.setType(TaskType.PROMOTION_APPROVAL);
taskEntity.setCreatedAt(promotionEntity.getCreatedAt());
ApiEntity apiEntity;
try {
apiEntity = objectMapper.readValue(promotionEntity.getApiDefinition(), ApiEntity.class);
} catch (JsonProcessingException e) {
logger.warn("Problem while deserializing api definition for promotion {}", promotionEntity.getId());
throw new TechnicalManagementException();
}
Map<String, Object> data = new HashMap<>();
data.put("apiName", apiEntity.getName());
data.put("apiId", promotionEntity.getApiId());
data.put("sourceEnvironmentName", promotionEntity.getSourceEnvName());
data.put("targetEnvironmentName", promotionEntity.getTargetEnvName());
data.put("authorDisplayName", promotionEntity.getAuthor().getDisplayName());
data.put("authorEmail", promotionEntity.getAuthor().getEmail());
data.put("authorPicture", promotionEntity.getAuthor().getPicture());
data.put("promotionId", promotionEntity.getId());
data.put("isApiUpdate", isUpdate);
foundTargetApiId.ifPresent(targetApiId -> data.put("targetApiId", targetApiId));
taskEntity.setData(data);
return taskEntity;
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class QualityMetricsServiceTest method shouldScore50PercentWithManualRules.
@Test
public void shouldScore50PercentWithManualRules() {
when(parameterService.findAsBoolean(Key.API_QUALITY_METRICS_ENABLED, ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
Map<String, List<Object>> map = new HashMap<>();
map.put(Key.API_QUALITY_METRICS_LOGO_WEIGHT.key(), singletonList(1));
map.put(Key.API_QUALITY_METRICS_CATEGORIES_WEIGHT.key(), singletonList(1));
when(parameterService.findAll(anyList(), any(Function.class), any(ParameterReferenceType.class))).thenReturn(map);
ApiEntity api = mock(ApiEntity.class);
when(api.getId()).thenReturn("apiID");
when(apiQualityMetricLogo.isValid(any())).thenReturn(Boolean.TRUE);
when(apiQualityMetricCategories.isValid(any())).thenReturn(Boolean.TRUE);
final QualityRuleEntity qualityRule = mock(QualityRuleEntity.class);
when(qualityRule.getId()).thenReturn("1");
when(qualityRule.getWeight()).thenReturn(2);
when(qualityRuleService.findAll()).thenReturn(singletonList(qualityRule));
final ApiQualityRuleEntity apiQualityRule = mock(ApiQualityRuleEntity.class);
when(apiQualityRule.getApi()).thenReturn("apiID");
when(apiQualityRule.getQualityRule()).thenReturn("1");
when(apiQualityRule.isChecked()).thenReturn(false);
when(apiQualityRuleService.findByApi("apiID")).thenReturn(singletonList(apiQualityRule));
ApiQualityMetricsEntity metrics = srv.getMetrics(api);
assertEquals(0.5, metrics.getScore(), 0);
assertFalse(metrics.getMetricsPassed().isEmpty());
assertTrue(metrics.getMetricsPassed().get(Key.API_QUALITY_METRICS_LOGO_WEIGHT.key()));
assertTrue(metrics.getMetricsPassed().get(Key.API_QUALITY_METRICS_CATEGORIES_WEIGHT.key()));
assertFalse(metrics.getMetricsPassed().get("1"));
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class QualityMetricsServiceTest method shouldScore100Percent.
@Test
public void shouldScore100Percent() {
when(parameterService.findAsBoolean(Key.API_QUALITY_METRICS_ENABLED, ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
Map<String, List<Object>> map = new HashMap<>();
map.put(Key.API_QUALITY_METRICS_LOGO_WEIGHT.key(), singletonList(1));
map.put(Key.API_QUALITY_METRICS_CATEGORIES_WEIGHT.key(), singletonList(1));
when(parameterService.findAll(anyList(), any(Function.class), any(ParameterReferenceType.class))).thenReturn(map);
ApiEntity api = mock(ApiEntity.class);
when(apiQualityMetricLogo.isValid(any())).thenReturn(Boolean.TRUE);
when(apiQualityMetricCategories.isValid(any())).thenReturn(Boolean.TRUE);
ApiQualityMetricsEntity metrics = srv.getMetrics(api);
assertEquals(1, metrics.getScore(), 0);
assertFalse(metrics.getMetricsPassed().isEmpty());
assertTrue(metrics.getMetricsPassed().get(Key.API_QUALITY_METRICS_LOGO_WEIGHT.key()));
assertTrue(metrics.getMetricsPassed().get(Key.API_QUALITY_METRICS_CATEGORIES_WEIGHT.key()));
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class QualityMetricsServiceTest method shouldThrowExceptionIfDisabled.
@Test(expected = ApiQualityMetricsDisableException.class)
public void shouldThrowExceptionIfDisabled() {
when(parameterService.findAsBoolean(Key.API_QUALITY_METRICS_ENABLED, ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.FALSE);
ApiEntity api = mock(ApiEntity.class);
srv.getMetrics(api);
fail();
}
Aggregations