This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Commit a4ca8d49 authored by Michael Breu's avatar Michael Breu 💬
Browse files

First Running Version

parent 4f2ea52b
......@@ -91,6 +91,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.antMatchers("/api/sharingPluginConfig").permitAll()
.antMatchers("/api/sharingImport/**").permitAll()
.antMatchers("/api/sharingImport/basket").permitAll()
.antMatchers("/api/sharingImport/search").permitAll()
.antMatchers("/api/**").authenticated()
.antMatchers("/management/health").permitAll()
......
......@@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
......@@ -21,6 +22,7 @@ import org.codeability.sharing.plugins.api.search.SearchResultsDTO;
import org.glassfish.jersey.client.ClientConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -33,6 +35,9 @@ import com.google.common.cache.LoadingCache;
public class SharingDemoService {
@Autowired
private SharingPluginService sharingPluginService;
public SharingDemoService() {
}
......@@ -54,7 +59,16 @@ public class SharingDemoService {
}
public SearchResultsDTO searchPageDetails(@RequestBody SearchRequestDTO searchRequest) throws IOException {
return null;
ClientConfig restClientConfig = new ClientConfig();
restClientConfig.register(SearchResultsDTO.class);
Client client = ClientBuilder.newClient(restClientConfig);
WebTarget target = client.target(sharingPluginService.getApiBaseUrl()+"/pluginIF/v0.1/page-details");
SearchResultsDTO results = target.
request().
accept(MediaType.APPLICATION_JSON).post(Entity.entity(searchRequest, MediaType.APPLICATION_JSON), SearchResultsDTO.class);
return results;
}
LoadingCache<Pair<String, Integer>, File> repositoryCache = CacheBuilder.newBuilder()
......
......@@ -62,7 +62,7 @@ public class SharingDemoResource {
@PostMapping("/sharingImport/search")
public SearchResultsDTO
searchPageDetails(@RequestBody SearchRequestDTO searchRequest) throws IOException {
return searchPageDetails(searchRequest);
return exerciseSharingService.searchPageDetails(searchRequest);
}
......
......@@ -31,9 +31,8 @@
<li><a href="https://gitter.im/jhipster/generator-jhipster" target="_blank" rel="noopener noreferrer" jhiTranslate="home.link.chat">JHipster public chat room</a></li>
<li><a href="https://twitter.com/jhipster" target="_blank" rel="noopener noreferrer" jhiTranslate="home.link.follow">follow @jhipster on Twitter</a></li>
</ul>
<jhi-sharingsearch></jhi-sharingsearch>
<p>
<span jhiTranslate="home.like">If you like JHipster, don't forget to give us a star on</span> <a href="https://github.com/jhipster/generator-jhipster" target="_blank" rel="noopener noreferrer" jhiTranslate="home.github">GitHub</a>!
</p>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { LoginService } from 'app/core/login/login.service';
import { AccountService } from 'app/core/auth/account.service';
......@@ -14,15 +13,8 @@ import { SharingSearchService } from 'app/sharing/search/sharingSearch.service'
})
export class HomeComponent implements OnInit {
account: Account | null = null;
isSaving = false;
editForm = this.fb.group({
accessToken: [null, [Validators.required]],
fulltext: [],
});
constructor(private accountService: AccountService, private loginService: LoginService, private fb: FormBuilder, private sharingSearchService: SharingSearchService) {}
constructor(private accountService: AccountService, private loginService: LoginService, private sharingSearchService: SharingSearchService) {}
ngOnInit(): void {
this.accountService.identity().subscribe(account => (this.account = account));
......@@ -35,34 +27,4 @@ export class HomeComponent implements OnInit {
login(): void {
this.loginService.login();
}
updateForm(statistics: IStatistics): void {
this.editForm.patchValue({
id: statistics.id,
views: statistics.views,
downloads: statistics.downloads,
exerciseID: statistics.exerciseID,
});
save(): void {
this.isSaving = true;
const statistics = this.createFromForm();
if (statistics.id !== undefined) {
this.subscribeToSaveResponse(this.statisticsService.update(statistics));
} else {
this.subscribeToSaveResponse(this.statisticsService.create(statistics));
}
}
private createFromForm(): IStatistics {
return {
...new Statistics(),
id: this.editForm.get(['id'])!.value,
views: this.editForm.get(['views'])!.value,
downloads: this.editForm.get(['downloads'])!.value,
exerciseID: this.editForm.get(['exerciseID'])!.value,
};
}
}
......@@ -4,9 +4,10 @@ import { RouterModule } from '@angular/router';
import { PluginDemoSharedModule } from 'app/shared/shared.module';
import { HOME_ROUTE } from './home.route';
import { HomeComponent } from './home.component';
import { SearchComponent } from './search/search.component';
@NgModule({
imports: [PluginDemoSharedModule, RouterModule.forChild([HOME_ROUTE])],
declarations: [HomeComponent],
declarations: [HomeComponent, SearchComponent],
})
export class PluginDemoHomeModule {}
<div class="row justify-content-center">
<div class="col-8">
<form name="editForm" role="form" novalidate (ngSubmit)="save()" [formGroup]="editForm">
<h2 id="jhi-statistics-heading" jhiTranslate="gitsearchApp.statistics.home.createOrEditLabel">Create or edit a Statistics</h2>
<form name="editForm" role="form" novalidate (ngSubmit)="search()" [formGroup]="editForm">
<h2 id="jhi-statistics-heading" >Search via the Sharing Platform</h2>
<table><tr><th>Search Parameters</th><th style="padding-left:20px;">Search Results</th></tr>
<tr><td style="vertical-align: top">
<div>
<jhi-alert-error></jhi-alert-error>
<div class="form-group" [hidden]="!editForm.get('id')!.value">
<label for="id" jhiTranslate="global.field.id">ID</label>
<input type="text" class="form-control" id="id" name="id" formControlName="id" readonly />
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="gitsearchApp.statistics.views" for="field_views">Views</label>
<input type="number" class="form-control" name="views" id="field_views"
formControlName="views"/>
<label for="field_accessToken" >GitLab Access Token for User</label>
<input type="password" class="form-control" id="field_accessToken" name="accessToken" formControlName="accessToken" />
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="gitsearchApp.statistics.downloads" for="field_downloads">Downloads</label>
<input type="number" class="form-control" name="downloads" id="field_downloads"
formControlName="downloads"/>
<div *ngIf="editForm.get('downloads')!.invalid && (editForm.get('downloads')!.dirty || editForm.get('downloads')!.touched)">
<small class="form-text text-danger"
*ngIf="editForm.get('downloads')?.errors?.required" jhiTranslate="entity.validation.required">
This field is required.
</small>
<small class="form-text text-danger"
[hidden]="!editForm.get('downloads')?.errors?.number" jhiTranslate="entity.validation.number">
This field should be a number.
</small>
</div>
<label class="form-control-label" for="field_fulltext">Search in Fulltext</label>
<input type="text" class="form-control" name="fulltext" id="field_fulltext"
formControlName="fulltext"/>
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="gitsearchApp.statistics.exerciseID" for="field_exerciseID">Exercise ID</label>
<input type="number" class="form-control" name="exerciseID" id="field_exerciseID"
formControlName="exerciseID"/>
<label class="form-control-label" for="field_keywords">Search with Keywords</label>
<input type="text" class="form-control" name="keywords" id="field_keywords"
formControlName="keywords"/>
</div>
</div>
<div>
<button type="button" id="cancel-save" class="btn btn-secondary" (click)="previousState()">
<fa-icon icon="ban"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
</button>
<button type="submit" id="save-entity" [disabled]="editForm.invalid || isSaving" class="btn btn-primary">
<fa-icon icon="save"></fa-icon>&nbsp;<span jhiTranslate="entity.action.save">Save</span>
<button type="submit" id="seachButton" [disabled]="editForm.invalid || isSearching" class="btn btn-primary">
<fa-icon icon="save"></fa-icon>&nbsp;<span >Search</span>
</button>
</div>
</td><td style="padding-left:20px;vertical-align: top">
<p *ngIf="!resultAvailable">No results available</p>
<p *ngIf="resultAvailable">
Found {{results.hitCount}} results.
</p>
<p *ngFor="let r of results.searchResult; let i = index" style="font-weight: bold;">
Title {{i+1}}: {{r.metadata.title}}
</p>
</td></tr></table>
</form>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SharingSearchService } from '../..//sharing/search/sharingSearch.service'
import { SearchInput } from '../../shared/model/search/search-input.model';
import { SearchRequest } from '../../shared/model/search/search-input.model';
import { SearchResultsDTO } from '../../shared/model/search/search-results-dto.model'
......@@ -15,16 +15,26 @@ import { SearchResultsDTO } from '../../shared/model/search/search-results-dto.m
templateUrl: './search.component.html',
})
export class SearchComponent implements OnInit {
isSaving = false;
isSearching = false;
resultAvailable = false;
editForm = this.fb.group({
accessToken: [null, [Validators.required]],
fulltext: [],
keywords: [],
});
results: SearchResultsDTO;
constructor(protected sharingSearchService: SharingSearchService,
protected activatedRoute: ActivatedRoute, private fb: FormBuilder) {}
protected activatedRoute: ActivatedRoute, private fb: FormBuilder) {
this.results = {...
new SearchResultsDTO(),
};
}
ngOnInit(): void {
}
......@@ -33,34 +43,35 @@ export class SearchComponent implements OnInit {
window.history.back();
}
save(): void {
this.isSaving = true;
const search = this.createFromForm();
}
private search(searchInput: SearchInput): SearchResultsDTO {
return {
...new SearchInput(),
id: this.editForm.get(['id'])!.value,
views: this.editForm.get(['views'])!.value,
downloads: this.editForm.get(['downloads'])!.value,
exerciseID: this.editForm.get(['exerciseID'])!.value,
};
public search(): void {
this.isSearching = true;
const searchInput = new SearchRequest();
searchInput.query.page=0;
searchInput.query.fulltextQuery=this.editForm.get(['fulltext'])!.value;
searchInput.query.metadata.keyword=this.editForm.get(['keywords'])!.value;
searchInput.userPrincipal.gitLabAccessToken=this.editForm.get(['accessToken'])!.value;
searchInput.userPrincipal.name='Testuser from Demo'
this.subscribeToSaveResponse(this.sharingSearchService.search(searchInput));
}
protected subscribeToSaveResponse(result: Observable<HttpResponse<IStatistics>>): void {
protected subscribeToSaveResponse(result: Observable<HttpResponse<SearchResultsDTO>>): void {
result.subscribe(
() => this.onSaveSuccess(),
(r) => this.onSaveSuccess(r.body!),
() => this.onSaveError()
);
}
protected onSaveSuccess(): void {
this.isSaving = false;
this.previousState();
protected onSaveSuccess(r: SearchResultsDTO): void {
this.results = r;
this.isSearching = false;
this.resultAvailable = true;
}
protected onSaveError(): void {
this.isSaving = false;
this.isSearching = false;
this.resultAvailable = false;
}
}
......@@ -30,3 +30,17 @@ export class SearchInput {
})
}
}
export class UserPrincipal {
public gitLabAccessToken = '';
public name = '';
}
export class SearchRequest {
public userPrincipal = new UserPrincipal();
public query = new SearchInput();
}
import { SearchResultDTO } from './search-result-dto.model';
export interface SearchResultsDTO {
hitCount: number;
pageStartIndex: number;
searchResult: Array<SearchResultDTO>;
export class SearchResultsDTO {
hitCount = 0;
pageStartIndex = 0;
searchResult: SearchResultDTO[] = [];
}
......
......@@ -3,18 +3,18 @@ import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SERVER_API_URL } from '../../app.constants';
import { SearchInput } from '../../shared/model/search/search-input.model';
import { SearchRequest } from '../../shared/model/search/search-input.model';
import { SearchResultsDTO } from '../../shared/model/search/search-results-dto.model'
type EntityResponseType = HttpResponse<SearchResultsDTO>;
@Injectable({ providedIn: 'root' })
export class SharingSearchService {
public resourceUrl = SERVER_API_URL + '/sharingImport/search';
public resourceUrl = SERVER_API_URL + '/api/sharingImport/search';
constructor(protected http: HttpClient) {}
search(search: SearchInput): Observable<EntityResponseType> {
search(search: SearchRequest): Observable<EntityResponseType> {
return this.http.post<SearchResultsDTO>(this.resourceUrl, search, { observe: 'response' });
}
......
......@@ -29,7 +29,7 @@ module.exports = (options) => webpackMerge(commonConfig({ env: ENV }), {
'/login',
'/auth'
],
target: `http${options.tls ? 's' : ''}://localhost:8080`,
target: `http${options.tls ? 's' : ''}://localhost:8082`,
secure: false,
changeOrigin: options.tls
}],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment