Search in sources :

Example 1 with ApiHeaderEntity

use of io.gravitee.rest.api.model.api.header.ApiHeaderEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiServiceImpl method getPortalHeaders.

@Override
public List<ApiHeaderEntity> getPortalHeaders(String apiId) {
    List<ApiHeaderEntity> entities = apiHeaderService.findAll();
    ApiModelEntity apiEntity = this.findByIdForTemplates(apiId);
    Map<String, Object> model = new HashMap<>();
    model.put("api", apiEntity);
    entities.forEach(entity -> {
        if (entity.getValue().contains("${")) {
            String entityValue = this.notificationTemplateService.resolveInlineTemplateWithParam(entity.getId() + entity.getUpdatedAt().toString(), entity.getValue(), model);
            entity.setValue(entityValue);
        }
    });
    return entities.stream().filter(apiHeaderEntity -> apiHeaderEntity.getValue() != null && !apiHeaderEntity.getValue().isEmpty()).collect(Collectors.toList());
}
Also used : ApiHook(io.gravitee.rest.api.service.notification.ApiHook) EndpointDiscoveryService(io.gravitee.definition.model.services.discovery.EndpointDiscoveryService) Optional.of(java.util.Optional.of) Page(io.gravitee.common.data.domain.Page) Sortable(io.gravitee.rest.api.model.common.Sortable) HookScope(io.gravitee.rest.api.service.notification.HookScope) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) StringUtils(org.apache.commons.lang3.StringUtils) ApiCriteria(io.gravitee.repository.management.api.search.ApiCriteria) Matcher(java.util.regex.Matcher) AuditEvent(io.gravitee.repository.management.model.Api.AuditEvent) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntrypointReferenceType(io.gravitee.rest.api.model.EntrypointReferenceType) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) DatatypeConverter(javax.xml.bind.DatatypeConverter) java.util(java.util) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) ApiPrimaryOwnerMode(io.gravitee.rest.api.model.settings.ApiPrimaryOwnerMode) DRAFT(io.gravitee.rest.api.model.WorkflowState.DRAFT) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) DefaultMetadataUpgrader(io.gravitee.rest.api.service.impl.upgrade.DefaultMetadataUpgrader) SWAGGER(io.gravitee.rest.api.model.PageType.SWAGGER) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) MembershipMemberType(io.gravitee.rest.api.model.MembershipMemberType) PUBLIC(io.gravitee.repository.management.model.Visibility.PUBLIC) PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) Query(io.gravitee.rest.api.service.search.query.Query) UuidString(io.gravitee.rest.api.service.common.UuidString) IOException(java.io.IOException) io.gravitee.definition.model(io.gravitee.definition.model) io.gravitee.rest.api.model.api(io.gravitee.rest.api.model.api) CronTrigger(org.springframework.scheduling.support.CronTrigger) MembershipReferenceType(io.gravitee.rest.api.model.MembershipReferenceType) GenericNotificationConfigEntity(io.gravitee.rest.api.model.notification.GenericNotificationConfigEntity) io.gravitee.repository.management.model(io.gravitee.repository.management.model) StringReader(java.io.StringReader) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) SearchResult(io.gravitee.rest.api.service.impl.search.SearchResult) REVIEW(io.gravitee.rest.api.model.WorkflowType.REVIEW) Plan(io.gravitee.definition.model.Plan) API(io.gravitee.rest.api.model.WorkflowReferenceType.API) Properties(io.gravitee.definition.model.Properties) URL(java.net.URL) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ApiRepository(io.gravitee.repository.management.api.ApiRepository) Lifecycle(io.gravitee.common.component.Lifecycle) PatternSyntaxException(java.util.regex.PatternSyntaxException) ApiQualityRuleRepository(io.gravitee.repository.management.api.ApiQualityRuleRepository) Predicate(java.util.function.Predicate) ApiLifecycleState(io.gravitee.repository.management.model.ApiLifecycleState) MetadataFormat(io.gravitee.rest.api.model.MetadataFormat) Collectors(java.util.stream.Collectors) ApiFieldExclusionFilter(io.gravitee.repository.management.api.search.ApiFieldExclusionFilter) Key(io.gravitee.rest.api.model.parameters.Key) Api(io.gravitee.repository.management.model.Api) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) APIV1toAPIV2Converter(io.gravitee.rest.api.service.migration.APIV1toAPIV2Converter) SubscriptionQuery(io.gravitee.rest.api.model.subscription.SubscriptionQuery) Pattern(java.util.regex.Pattern) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) NotNull(org.jetbrains.annotations.NotNull) SystemRole(io.gravitee.rest.api.model.permissions.SystemRole) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) io.gravitee.rest.api.service(io.gravitee.rest.api.service) TagReferenceType(io.gravitee.rest.api.model.TagReferenceType) Pageable(io.gravitee.rest.api.model.common.Pageable) ImportConfiguration(io.gravitee.rest.api.service.spring.ImportConfiguration) ApiPermission(io.gravitee.rest.api.model.permissions.ApiPermission) Visibility(io.gravitee.repository.management.model.Visibility) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EventType(io.gravitee.rest.api.model.EventType) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Comparator.comparing(java.util.Comparator.comparing) PUBLISH_API(io.gravitee.rest.api.model.EventType.PUBLISH_API) ApiSynchronizationProcessor(io.gravitee.rest.api.service.processor.ApiSynchronizationProcessor) Step(io.gravitee.definition.model.flow.Step) AlertReferenceType(io.gravitee.rest.api.model.alert.AlertReferenceType) Logger(org.slf4j.Logger) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) MalformedURLException(java.net.MalformedURLException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FileInputStream(java.io.FileInputStream) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Component(org.springframework.stereotype.Component) INLINE(io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity.Type.INLINE) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) AuditEvent(io.gravitee.repository.management.model.Workflow.AuditEvent) QueryBuilder(io.gravitee.rest.api.service.search.query.QueryBuilder) Collections(java.util.Collections) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) UuidString(io.gravitee.rest.api.service.common.UuidString)

Example 2 with ApiHeaderEntity

use of io.gravitee.rest.api.model.api.header.ApiHeaderEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiHeaderServiceImpl method delete.

@Override
public void delete(String apiHeaderId) {
    try {
        Optional<ApiHeader> optionalApiHeader = apiHeaderRepository.findById(apiHeaderId);
        if (!optionalApiHeader.isPresent()) {
            throw new ApiHeaderNotFoundException(apiHeaderId);
        }
        apiHeaderRepository.delete(apiHeaderId);
        auditService.createEnvironmentAuditLog(Collections.singletonMap(API_HEADER, apiHeaderId), API_HEADER_DELETED, new Date(), optionalApiHeader.get(), null);
        // reorder headers
        int currentOrder = 1;
        for (ApiHeaderEntity apiHeaderEntity : this.findAll()) {
            if (apiHeaderEntity.getOrder() != currentOrder) {
                UpdateApiHeaderEntity updateEntity = convert(apiHeaderEntity);
                updateEntity.setOrder(currentOrder);
                this.update(updateEntity);
                break;
            }
            currentOrder++;
        }
    } catch (TechnicalException e) {
        LOGGER.error("An error occurs while trying to delete a header {}", apiHeaderId, e);
        throw new TechnicalManagementException("An error occurs while trying to delete a header " + apiHeaderId, e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UpdateApiHeaderEntity(io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity) NewApiHeaderEntity(io.gravitee.rest.api.model.api.header.NewApiHeaderEntity) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) ApiHeaderNotFoundException(io.gravitee.rest.api.service.exceptions.ApiHeaderNotFoundException) ApiHeader(io.gravitee.repository.management.model.ApiHeader) UpdateApiHeaderEntity(io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 3 with ApiHeaderEntity

use of io.gravitee.rest.api.model.api.header.ApiHeaderEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiInformationsResource method getApiInformations.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@RequirePortalAuth
public Response getApiInformations(@Context Request request, @PathParam("apiId") String apiId) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
    if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
        List<ApiHeaderEntity> all = apiService.getPortalHeaders(apiId);
        List<ApiInformation> information = all.stream().map(apiHeaderEntity -> {
            ApiInformation ai = new ApiInformation();
            ai.setName(apiHeaderEntity.getName());
            ai.setValue(apiHeaderEntity.getValue());
            return ai;
        }).collect(Collectors.toList());
        return Response.ok(information).build();
    }
    throw new ApiNotFoundException(apiId);
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) PathParam(javax.ws.rs.PathParam) Context(javax.ws.rs.core.Context) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Collection(java.util.Collection) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth) Collectors(java.util.stream.Collectors) ApiService(io.gravitee.rest.api.service.ApiService) Inject(javax.inject.Inject) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) ApiInformation(io.gravitee.rest.api.portal.rest.model.ApiInformation) Response(javax.ws.rs.core.Response) Request(javax.ws.rs.core.Request) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) Collections(java.util.Collections) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ApiInformation(io.gravitee.rest.api.portal.rest.model.ApiInformation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 4 with ApiHeaderEntity

use of io.gravitee.rest.api.model.api.header.ApiHeaderEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiHeaderServiceImpl method convert.

private ApiHeaderEntity convert(ApiHeader apiHeader) {
    ApiHeaderEntity entity = new ApiHeaderEntity();
    entity.setId(apiHeader.getId());
    entity.setName(apiHeader.getName());
    entity.setValue(apiHeader.getValue());
    entity.setOrder(apiHeader.getOrder());
    entity.setCreatedAt(apiHeader.getCreatedAt());
    entity.setUpdatedAt(apiHeader.getUpdatedAt());
    return entity;
}
Also used : UpdateApiHeaderEntity(io.gravitee.rest.api.model.api.header.UpdateApiHeaderEntity) NewApiHeaderEntity(io.gravitee.rest.api.model.api.header.NewApiHeaderEntity) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity)

Aggregations

ApiHeaderEntity (io.gravitee.rest.api.model.api.header.ApiHeaderEntity)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Strings (com.google.common.base.Strings)1 Lifecycle (io.gravitee.common.component.Lifecycle)1 Page (io.gravitee.common.data.domain.Page)1 MediaType (io.gravitee.common.http.MediaType)1 io.gravitee.definition.model (io.gravitee.definition.model)1 Plan (io.gravitee.definition.model.Plan)1 Properties (io.gravitee.definition.model.Properties)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1 Step (io.gravitee.definition.model.flow.Step)1 EndpointDiscoveryService (io.gravitee.definition.model.services.discovery.EndpointDiscoveryService)1 HealthCheckService (io.gravitee.definition.model.services.healthcheck.HealthCheckService)1 ApiQualityRuleRepository (io.gravitee.repository.management.api.ApiQualityRuleRepository)1 ApiRepository (io.gravitee.repository.management.api.ApiRepository)1