use of io.gravitee.common.data.domain.Page in project gravitee-management-rest-api by gravitee-io.
the class AuditServiceImpl method getMetadata.
private Map<String, String> getMetadata(List<AuditEntity> content) {
Map<String, String> metadata = new HashMap<>();
for (AuditEntity auditEntity : content) {
if (auditEntity.getProperties() != null) {
for (Map.Entry<String, String> property : auditEntity.getProperties().entrySet()) {
String metadataKey = new StringJoiner(":").add(property.getKey()).add(property.getValue()).add("name").toString();
if (!metadata.containsKey(metadataKey)) {
String name = property.getValue();
try {
switch(Audit.AuditProperties.valueOf(property.getKey())) {
case PAGE:
Optional<io.gravitee.repository.management.model.Page> optPage = pageRepository.findById(property.getValue());
if (optPage.isPresent()) {
name = optPage.get().getName();
}
break;
case PLAN:
Optional<Plan> optPlan = planRepository.findById(property.getValue());
if (optPlan.isPresent()) {
name = optPlan.get().getName();
}
break;
case METADATA:
MetadataReferenceType refType = (Audit.AuditReferenceType.API.name().equals(auditEntity.getReferenceType())) ? MetadataReferenceType.API : (Audit.AuditReferenceType.APPLICATION.name().equals(auditEntity.getReferenceType())) ? MetadataReferenceType.APPLICATION : MetadataReferenceType.DEFAULT;
String refId = refType.equals(MetadataReferenceType.DEFAULT) ? getDefautReferenceId() : auditEntity.getReferenceId();
Optional<Metadata> optMetadata = metadataRepository.findById(property.getValue(), refId, refType);
if (optMetadata.isPresent()) {
name = optMetadata.get().getName();
}
break;
case GROUP:
Optional<Group> optGroup = groupRepository.findById(property.getValue());
if (optGroup.isPresent()) {
name = optGroup.get().getName();
}
break;
case USER:
Optional<User> optUser = userRepository.findById(property.getValue());
if (optUser.isPresent()) {
if (optUser.get().getFirstname() != null && optUser.get().getLastname() != null) {
name = optUser.get().getFirstname() + " " + optUser.get().getLastname();
} else {
name = optUser.get().getUsername();
}
}
default:
break;
}
} catch (TechnicalException e) {
LOGGER.error("Error finding metadata {}", metadataKey);
name = property.getValue();
}
metadata.put(metadataKey, name);
}
}
}
}
return metadata;
}
use of io.gravitee.common.data.domain.Page in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method findByApi.
@Override
public Page<RatingEntity> findByApi(final String api, final Pageable pageable) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Page<Rating> pageRating = ratingRepository.findByApiPageable(api, new PageableBuilder().pageNumber(pageable.pageNumber() - 1).pageSize(pageable.pageSize()).build());
final List<RatingEntity> ratingEntities = pageRating.getContent().stream().map(this::convert).collect(toList());
return new Page<>(ratingEntities, pageRating.getPageNumber(), (int) pageRating.getPageElements(), pageRating.getTotalElements());
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find ratings for api {}", api, ex);
throw new TechnicalManagementException("An error occurred while trying to find ratings for api " + api, ex);
}
}
use of io.gravitee.common.data.domain.Page in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method shouldNotDeployBecauseWrongConfiguration.
@Test(expected = IllegalArgumentException.class)
public void shouldNotDeployBecauseWrongConfiguration() throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
final Api mockApi = mockApi(api);
when(gatewayConfiguration.shardingTags()).thenReturn(Optional.of(Arrays.asList("test", "!test")));
when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
when(apiManager.apis()).thenReturn(Collections.singleton(mockApi));
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(eq(new EventCriteria.Builder().types(EventType.PUBLISH_API, EventType.UNPUBLISH_API, EventType.START_API, EventType.STOP_API).property(Event.EventProperties.API_ID.getValue(), api.getId()).build()), any())).thenReturn((new Page(Collections.singletonList(mockEvent), 0, 0, 0)));
syncManager.refresh();
}
Aggregations