Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
feat(tree): fetch pages recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud committed Feb 10, 2019
1 parent 727e5e8 commit 59f4a72
Show file tree
Hide file tree
Showing 24 changed files with 1,389 additions and 132 deletions.
Expand Up @@ -16,12 +16,13 @@
package io.gravitee.management.fetcher;

import io.gravitee.fetcher.api.FetcherConfiguration;
import io.gravitee.fetcher.api.FilepathAwareFetcherConfiguration;

/**
* @author Nicolas GERAUD (nicolas.geraud [at] graviteesource [dot] com)
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class DummyFetcherConfiguration implements FetcherConfiguration {
public class DummyFetcherConfiguration implements FetcherConfiguration, FilepathAwareFetcherConfiguration {

private int value;

Expand All @@ -32,4 +33,12 @@ public int getValue() {
public void setValue(int value) {
this.value = value;
}

public String getFilepath() {
return null;
}

public void setFilepath(String filepath) {

}
}
Expand Up @@ -15,16 +15,32 @@
*/
package io.gravitee.management.model;

import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;

/**
* @author Ludovic Dussart (ludovic.dussart at gmail.com)
* @author Guillaume GILLON
* @author Guillaume GILLON
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* Managed types for page documentation
*
*/
public enum PageType {

MARKDOWN,
RAML,
SWAGGER,
FOLDER
MARKDOWN(unmodifiableList(asList("md", "markdown"))),
SWAGGER(unmodifiableList(asList("json", "yaml", "yml"))),
FOLDER(emptyList()),
ROOT(emptyList());

List<String> extensions;
PageType(List<String> extensions) {
this.extensions = extensions;
}

public List<String> extensions() {
return extensions;
}
}
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.descriptor;

import java.util.List;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class GraviteeDescriptorDocumentationEntity {
private List<GraviteeDescriptorPageEntity> pages;

public List<GraviteeDescriptorPageEntity> getPages() {
return pages;
}

public void setPages(List<GraviteeDescriptorPageEntity> pages) {
this.pages = pages;
}
}
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.descriptor;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class GraviteeDescriptorEntity {
private int version;
private GraviteeDescriptorDocumentationEntity documentation;

public int getVersion() {
return version;
}

public void setVersion(int version) {
this.version = version;
}

public GraviteeDescriptorDocumentationEntity getDocumentation() {
return documentation;
}

public void setDocumentation(GraviteeDescriptorDocumentationEntity documentation) {
this.documentation = documentation;
}
}
@@ -0,0 +1,59 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.descriptor;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class GraviteeDescriptorPageEntity {
private String src;
private String dest;
private String name;
private boolean homepage;

public String getSrc() {
return src;
}

public void setSrc(String src) {
this.src = src;
}

public String getDest() {
return dest;
}

public void setDest(String dest) {
this.dest = dest;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isHomepage() {
return homepage;
}

public void setHomepage(boolean homepage) {
this.homepage = homepage;
}
}
Expand Up @@ -16,10 +16,7 @@
package io.gravitee.management.rest.resource;

import io.gravitee.common.http.MediaType;
import io.gravitee.management.model.NewPageEntity;
import io.gravitee.management.model.PageEntity;
import io.gravitee.management.model.PageType;
import io.gravitee.management.model.Visibility;
import io.gravitee.management.model.*;
import io.gravitee.management.model.api.ApiEntity;
import io.gravitee.management.model.documentation.PageQuery;
import io.gravitee.management.model.permissions.RolePermission;
Expand Down Expand Up @@ -115,7 +112,7 @@ public Response createPage(
int order = pageService.findMaxApiPageOrderByApi(api) + 1;
newPageEntity.setOrder(order);
newPageEntity.setLastContributor(getAuthenticatedUser());
PageEntity newPage = pageService.createApiPage(api, newPageEntity);
PageEntity newPage = pageService.createPage(api, newPageEntity);
if (newPage != null) {
return Response
.created(URI.create("/apis/" + api + "/pages/" + newPage.getId()))
Expand Down Expand Up @@ -155,6 +152,51 @@ public ApiPageResource getApiPageResource() {
return resourceContext.getResource(ApiPageResource.class);
}

@POST
@Path("/_import")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Import pages",
notes = "User must be ADMIN to use this service")
@ApiResponses({
@ApiResponse(code = 201, message = "Page successfully created", response = PageEntity.class),
@ApiResponse(code = 500, message = "Internal server error")})
@Permissions({
@Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.CREATE)
})
public List<PageEntity> importFiles(
@PathParam("api") String api,
@ApiParam(name = "page", required = true) @Valid @NotNull NewPageEntity newPageEntity) {
newPageEntity.setLastContributor(getAuthenticatedUser());
return pageService.importFiles(api, newPageEntity);
}

@PUT
@Path("/_import")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Import pages",
notes = "User must be ADMIN to use this service")
@ApiResponses({
@ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class),
@ApiResponse(code = 500, message = "Internal server error")})
@Permissions({
@Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.CREATE)
})
public List<PageEntity> updateImportFiles(
@PathParam("api") String api,
@ApiParam(name = "page", required = true) @Valid @NotNull ApiPageEntity updatePageEntity) {
NewPageEntity newPageEntity = new NewPageEntity();
newPageEntity.setName(updatePageEntity.getName());
newPageEntity.setParentId(updatePageEntity.getParentId());
newPageEntity.setConfiguration(updatePageEntity.getConfiguration());
newPageEntity.setSource(updatePageEntity.getSource());
newPageEntity.setPublished(updatePageEntity.isPublished());

updatePageEntity.setLastContributor(getAuthenticatedUser());
return this.importFiles(api, newPageEntity);
}

private boolean isDisplayable(ApiEntity api, boolean isPagePublished, List<String> excludedGroups) {
return (isAuthenticated() && isAdmin())
||
Expand Down
Expand Up @@ -30,6 +30,7 @@
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -70,7 +71,7 @@ public Collection<FetcherListItem> list(@QueryParam("expand") List<String> expan
}

return stream
.sorted((o1, o2) -> o1.getName().compareTo(o2.getName()))
.sorted(Comparator.comparing(FetcherListItem::getName))
.collect(Collectors.toList());
}

Expand Down
Expand Up @@ -134,7 +134,7 @@ public Response createPage(
int order = pageService.findMaxPortalPageOrder() + 1;
newPageEntity.setOrder(order);
newPageEntity.setLastContributor(getAuthenticatedUser());
PageEntity newPage = pageService.createPortalPage(newPageEntity);
PageEntity newPage = pageService.createPage(newPageEntity);
if (newPage != null) {
return Response
.created(URI.create("/portal/pages/" + newPage.getId()))
Expand Down Expand Up @@ -246,6 +246,49 @@ public void deletePage(
pageService.delete(page);
}

@POST
@Path("/_import")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Import pages",
notes = "User must be ADMIN to use this service")
@ApiResponses({
@ApiResponse(code = 201, message = "Page successfully created", response = PageEntity.class),
@ApiResponse(code = 500, message = "Internal server error")})
@Permissions({
@Permission(value = RolePermission.PORTAL_DOCUMENTATION, acls = RolePermissionAction.CREATE)
})
public List<PageEntity> importFiles(
@ApiParam(name = "page", required = true) @Valid @NotNull NewPageEntity newPageEntity) {
newPageEntity.setLastContributor(getAuthenticatedUser());
return pageService.importFiles(newPageEntity);
}

@PUT
@Path("/_import")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Import pages",
notes = "User must be ADMIN to use this service")
@ApiResponses({
@ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class),
@ApiResponse(code = 500, message = "Internal server error")})
@Permissions({
@Permission(value = RolePermission.PORTAL_DOCUMENTATION, acls = RolePermissionAction.CREATE)
})
public List<PageEntity> updateImportFiles(
@ApiParam(name = "page", required = true) @Valid @NotNull PageEntity updatePageEntity) {
NewPageEntity newPageEntity = new NewPageEntity();
newPageEntity.setName(updatePageEntity.getName());
newPageEntity.setParentId(updatePageEntity.getParentId());
newPageEntity.setConfiguration(updatePageEntity.getConfiguration());
newPageEntity.setSource(updatePageEntity.getSource());
newPageEntity.setPublished(updatePageEntity.isPublished());

updatePageEntity.setLastContributor(getAuthenticatedUser());
return this.importFiles(newPageEntity);
}

private boolean isDisplayable(boolean isPagePublished, List<String> excludedGroups) {
return (isAuthenticated() && isAdmin()) ||
(isPagePublished && groupService.isUserAuthorizedToAccessPortalData(excludedGroups, getAuthenticatedUserOrNull()));
Expand Down
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.service;

import io.gravitee.management.model.descriptor.GraviteeDescriptorEntity;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public interface GraviteeDescriptorService {
String descriptorName();
GraviteeDescriptorEntity read(String s);
}

0 comments on commit 59f4a72

Please sign in to comment.