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());
}
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);
}
}
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);
}
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;
}
Aggregations