use of io.gravitee.rest.api.model.EventType.PUBLISH_API in project gravitee-management-rest-api by gravitee-io.
the class ApiServiceImpl method isSynchronized.
@Override
public boolean isSynchronized(String apiId) {
try {
// 1_ First, check the API state
ApiEntity api = findById(apiId);
Map<String, Object> properties = new HashMap<>();
properties.put(Event.EventProperties.API_ID.getValue(), apiId);
io.gravitee.common.data.domain.Page<EventEntity> events = eventService.search(Arrays.asList(PUBLISH_API, EventType.UNPUBLISH_API), properties, 0, 0, 0, 1);
if (!events.getContent().isEmpty()) {
// According to page size, we know that we have only one element in the list
EventEntity lastEvent = events.getContent().get(0);
// TODO: Done only for backward compatibility with 0.x. Must be removed later (1.1.x ?)
boolean enabled = objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Api payloadEntity = objectMapper.readValue(lastEvent.getPayload(), Api.class);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, enabled);
final ApiEntity deployedApi = convert(payloadEntity);
// Remove policy description from sync check
removeDescriptionFromPolicies(api);
removeDescriptionFromPolicies(deployedApi);
boolean sync = apiSynchronizationProcessor.processCheckSynchronization(deployedApi, api);
// but only for published or closed plan
if (sync) {
Set<PlanEntity> plans = planService.findByApi(api.getId());
sync = plans.stream().filter(plan -> (plan.getStatus() != PlanStatus.STAGING)).filter(plan -> plan.getNeedRedeployAt().after(api.getDeployedAt())).count() == 0;
}
return sync;
}
} catch (Exception e) {
LOGGER.error("An error occurs while trying to check API synchronization state {}", apiId, e);
}
return false;
}
Aggregations