Skip to content

Commit

Permalink
redirect broken pages to search
Browse files Browse the repository at this point in the history
  • Loading branch information
GeReinhart committed Sep 15, 2020
2 parents 22af79f + 7e4f6aa commit b20ab15
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/services/PageService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class PageService @Inject()(config: Configuration, projectRepository: ProjectRep

private def insertOrUpdateIndex(pageJoinProject: PageJoinProject) = {

hierarchyService.getHierarchyPath(pageJoinProject).map{ hierarchy =>
hierarchyService.getHierarchyPath(pageJoinProject).map { hierarchy =>
val document = PageIndexDocument(id = hierarchy + "/" + pageJoinProject.page.path,
hierarchy = hierarchy,
path = pageJoinProject.page.path,
Expand Down
3 changes: 2 additions & 1 deletion app/services/ProjectService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.concurrent.duration._
@Singleton
class ProjectService @Inject()(projectRepository: ProjectRepository, gitService: GitService, featureService: FeatureService,
featureRepository: FeatureRepository, branchRepository: BranchRepository, directoryRepository: DirectoryRepository,
pageRepository: PageRepository, menuService: MenuService, pageService: PageService,
pageRepository: PageRepository, menuService: MenuService, pageService: PageService, indexService: IndexService,
config: Configuration, environment: Environment, actorSystem: ActorSystem)(implicit ec: ExecutionContext) extends Logging {
val projectsRootDirectory = config.get[String]("projects.root.directory")
val synchronizeInterval = config.get[Int]("projects.synchronize.interval")
Expand Down Expand Up @@ -288,6 +288,7 @@ class ProjectService @Inject()(projectRepository: ProjectRepository, gitService:
def refreshAllPagesFromAllProjects(): Unit = {
val startTime = System.currentTimeMillis()
logger.info("Start refreshing pages not in cache")
indexService.reset()
projectRepository.findAll().foreach(p => refreshAllPages(p, forceRefresh = false))
val endTime = System.currentTimeMillis()
val duration = DurationUtil.durationFromMillisToHumanReadable( endTime-startTime )
Expand Down
3 changes: 2 additions & 1 deletion app/services/SearchService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object SearchResult {
@Singleton
class IndexService {

val luceneSearchIndex = new DirectLucene(uniqueFields = List("id"), defaultFullTextSearchable = true, appendIfExists = false, autoCommit = true)
val luceneSearchIndex = new DirectLucene(uniqueFields = List("id"), defaultFullTextSearchable = true, appendIfExists = false, autoCommit = false)

private val id = luceneSearchIndex.create.field[String]("id")
private val hierarchy = luceneSearchIndex.create.field[String]("hierarchy")
Expand Down Expand Up @@ -65,6 +65,7 @@ class IndexService {
pageContent(document.pageContent)
).index()
luceneSearchIndex.commit()
()
}

private def exists(document: PageIndexDocument) = {
Expand Down
5 changes: 4 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions frontend/src/app/_components/page/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ export class HeaderComponent implements OnInit {
});
}

getCurrentRoute(): NavigationRoute{
let params : NavigationParams;
if (this.activatedRoute.firstChild && this.activatedRoute.firstChild.snapshot){
getCurrentRoute(): NavigationRoute {
let params: NavigationParams;
if (this.activatedRoute.firstChild && this.activatedRoute.firstChild.snapshot) {
params = this.activatedRoute.firstChild.snapshot.params;
if (this.activatedRoute.firstChild.snapshot.url){
this.url = this.activatedRoute.firstChild.snapshot.url.join('/');
if (this.activatedRoute.firstChild.snapshot.url) {
this.url = this.activatedRoute.firstChild.snapshot.url.join('/');
}
}
if (!params && this.activatedRoute && this.activatedRoute.snapshot){
if (!params && this.activatedRoute && this.activatedRoute.snapshot) {
params = this.activatedRoute.snapshot.params;
if (this.activatedRoute.firstChild.snapshot.url){
this.url = this.activatedRoute.firstChild.snapshot.url.join('/');
if (this.activatedRoute.snapshot.url) {
this.url = this.activatedRoute.snapshot.url.join('/');
}
}
return this.routeService.navigationParamsToNavigationRoute(params);
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/app/_services/route.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ describe('RouteService', () => {
});

it('relativeUrlToFullFrontEndUrl ', () => {

expect(service.relativeUrlToFullFrontEndUrl('Public/Features/OfferFeeds/Feature',{nodes: '_publisher_systems_services_shopping',project: 'shoppingAPI',branch: 'qa',directories: '_',page: 'Why'} ))
.toEqual("app/documentation/navigate/_publisher_systems_services_shopping/shoppingAPI/qa/_Public_Features_OfferFeeds/Feature");
expect(service.relativeUrlToFullFrontEndUrl('../../Guides/Feeds/UseCases',{nodes: '_publisher_systems_services_shopping',project: 'shoppingAPI',branch: 'qa',directories: '_Public_Features_OfferFeeds',page: 'Feature'} ))
.toEqual("app/documentation/navigate/_publisher_systems_services_shopping/shoppingAPI/qa/_Public_Guides_Feeds/UseCases");
expect(service.relativeUrlToFullFrontEndUrl('../OfferSearch/Feature',{nodes: '_platform_publisher_systems_public',project: 'shoppingAPIPublic',branch: 'feature_PUB-4629-review-doc',directories: '_Features_OfferFeeds',page: 'Feature'} ))
.toEqual("app/documentation/navigate/_platform_publisher_systems_public/shoppingAPIPublic/feature_PUB-4629-review-doc/_Features_OfferSearch/Feature");

expect(service.relativeUrlToFullFrontEndUrl('https://thegardener.kelkoogroup.com',{nodes: 'Tools',project: 'theGardener',branch: 'master',directories: '_Guide_Write',page: 'Basics'} ))
.toEqual("https://thegardener.kelkoogroup.com");
expect(service.relativeUrlToFullFrontEndUrl('OpenApi',{nodes: 'Tools',project: 'theGardener',branch: 'master',directories: '_Guide_Write',page: 'Basics'} ))
Expand Down Expand Up @@ -198,7 +200,6 @@ describe('RouteService', () => {
expect(service.directoryPathSimilar(navigationRoute, { nodes: ["publisher"], project: "ecs", branch: "master", directories: [] as Array<string>, page: "Meta" })).toBeTrue();
});


it('pagePathSimilar ', () => {
const navigationRoute = { nodes: ["publisher"], project: "ecs", branch: "_", directories: [] as Array<string>, page: "Meta" };

Expand All @@ -218,4 +219,10 @@ describe('RouteService', () => {
expect(service.urlToRelativePath('_features_foo_bar')).toEqual('/features/foo/bar');
expect(service.urlToRelativePath('_features_foo.foo_bar')).toEqual('/features/foo_foo/bar');
});

it('extractKeyword ', () => {
expect(service.extractKeyword({ nodes: ["publisher","services","shopping"], project: "shoppingAPI", branch: "_", directories: ["Public","Guides"], page: "AuthenticationWithSignedUrlGuide" }))
.toEqual('publisher services shopping shopping A P I Authentication With Signed Url Guide');
});

});
9 changes: 8 additions & 1 deletion frontend/src/app/_services/route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export class RouteService {
} else {
directoryNavigationForward = directoriesAndPageArray.join(EMPTY_CHAR);
}
targetDirectoriesPath += directoryNavigationForward;
targetDirectoriesPath += EMPTY_CHAR + directoryNavigationForward;
targetDirectoriesPath = targetDirectoriesPath.replace('__','_')
}


Expand All @@ -125,6 +126,7 @@ export class RouteService {
} else {
const subDirectories = subDirectoriesAndPage.slice(0, subDirectoriesAndPage.length - 1);
targetDirectoriesPath = navigationParams.directories + EMPTY_CHAR + subDirectories.join(EMPTY_CHAR);
targetDirectoriesPath = targetDirectoriesPath.replace('__','_')
}
return `${NAVIGATE_PATH}${navigationParams.nodes}/${navigationParams.project}/${navigationParams.branch}/${targetDirectoriesPath}/${page}`;
}
Expand Down Expand Up @@ -328,4 +330,9 @@ export class RouteService {
}
return hierarchyFrontEndPath + '/' + navigationRoute.project + '/' + navigationRoute.branch + '/' + directories + '/' + navigationRoute.page;
}

extractKeyword(targetedRoute: NavigationRoute) {
const join = targetedRoute.nodes.join(" ")+ " " + targetedRoute.project+ " " + targetedRoute.page;
return join.replace(/([a-zA-Z])(?=[A-Z])/g, '$1 ');
}
}
15 changes: 8 additions & 7 deletions frontend/src/app/output/page-content/page-content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
PagePart,
ScenarioPart
} from '../../_models/page';
import {NotificationService} from '../../_services/notification.service';
import {RouteService} from "../../_services/route.service";
import {RouteService, SEARCH_PATH} from "../../_services/route.service";
import {NavigationRoute} from "../../_models/route";


@Component({
Expand All @@ -28,11 +28,11 @@ export class PageContentComponent implements OnInit, OnDestroy, AfterViewChecked
private routerSubscription: Subscription;
private fragment: string;
private canScroll: boolean = true;
private targetedRoute: NavigationRoute;

constructor(private activatedRoute: ActivatedRoute,
private pageService: PageService,
private routeService: RouteService,
private notificationService: NotificationService,
private router: Router,
private ngZone: NgZone) {
}
Expand Down Expand Up @@ -62,16 +62,17 @@ export class PageContentComponent implements OnInit, OnDestroy, AfterViewChecked
return params;
}),
switchMap(params => {
const navigationRoute = this.routeService.navigationParamsToNavigationRoute(params);
if ( navigationRoute.page == undefined ){
this.targetedRoute = this.routeService.navigationParamsToNavigationRoute(params);
if ( this.targetedRoute.page == undefined ){
return of<Page>();
}else{
const backEndPath = this.routeService.navigationRouteToBackEndPath(navigationRoute);
const backEndPath = this.routeService.navigationRouteToBackEndPath(this.targetedRoute);
return this.pageService.getPage(backEndPath.pathFromProject);
}
}),
catchError(err => {
this.notificationService.showError(`Error while loading page`, err);
const keyword = this.routeService.extractKeyword(this.targetedRoute);
this.router.navigateByUrl(SEARCH_PATH + `?keyword=${keyword.trim()}`);
return of<Page>();
})
).subscribe(page => {
Expand Down
2 changes: 1 addition & 1 deletion local-conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ play.evolutions.autoApply = true
# db.default.jndiName=DefaultDS

projects.root.directory = "target/data/git/"
projects.synchronize.interval = 1800
projects.synchronize.interval = 600
projects.synchronize.initial.delay = 5

projects.synchronize.from.remote.enabled = true
Expand Down
3 changes: 2 additions & 1 deletion test/services/ProjectServiceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class ProjectServiceTest extends WordSpec with MustMatchers with BeforeAndAfter
val featureService = mock[FeatureService]
val menuService = mock[MenuService]
val pageService = mock[PageService]
val indexService = mock[IndexService]
val environment = mock[Environment]


val projectService = new ProjectService(projectRepository, gitService, featureService, featureRepository, branchRepository, directoryRepository, pageRepository, menuService, pageService, Configuration.load(Environment.simple()), environment, ActorSystem())
val projectService = new ProjectService(projectRepository, gitService, featureService, featureRepository, branchRepository, directoryRepository, pageRepository, menuService, pageService, indexService, Configuration.load(Environment.simple()), environment, ActorSystem())

val project = Project("suggestionsWS", "Suggestions WebServices", "git@github.com:library/suggestionsWS.git", Some("http://github.com:library/suggestionsWS/blob/${branch}/${path}"), "master", Some("^(^master$)|(^feature\\/.*$)"), Some("test/features"))
val masterDirectory = projectService.getLocalRepository(project.id, project.stableBranch)
Expand Down
2 changes: 1 addition & 1 deletion test/steps/CommonSteps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object CommonSteps extends MockitoSugar with MustMatchers {
val spyMenuService = spy(menuService)
val replicaService = new ReplicaClient(conf, wsClient)
val spyReplicaService = spy(replicaService)
val projectService = new ProjectService(projectRepository, gitService, featureService, featureRepository, branchRepository, directoryRepository, pageRepository, menuService, pageService, conf, environment, actorSystem)
val projectService = new ProjectService(projectRepository, gitService, featureService, featureRepository, branchRepository, directoryRepository, pageRepository, menuService, pageService, pageIndex, conf, environment, actorSystem)
val spyProjectService = spy(projectService)


Expand Down

0 comments on commit b20ab15

Please sign in to comment.