mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-10-28 17:16:16 +01:00
Add queryable store with SQLite implementation
This adds the new "queryable store" API, that allows complex queries and is backed by SQLite. This new API can be used for entities annotated with the new QueryableType annotation.
This commit is contained in:
@@ -24,14 +24,24 @@ import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import sonia.scm.api.v2.resources.LinkBuilder;
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import store.RepositoryTestData;
|
||||
import store.RepositoryTestDataStoreFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static de.otto.edison.hal.Embedded.embeddedBuilder;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
/**
|
||||
* Web Service Resource to support integration tests.
|
||||
@@ -43,11 +53,15 @@ public class IntegrationTestResource {
|
||||
|
||||
private final ScmPathInfoStore scmPathInfoStore;
|
||||
private final MergeDetectionHelper mergeDetectionHelper;
|
||||
private final RepositoryManager repositoryManager;
|
||||
private final RepositoryTestDataStoreFactory testDataStoreFactory;
|
||||
|
||||
@Inject
|
||||
public IntegrationTestResource(ScmPathInfoStore scmPathInfoStore, MergeDetectionHelper mergeDetectionHelper) {
|
||||
public IntegrationTestResource(ScmPathInfoStore scmPathInfoStore, MergeDetectionHelper mergeDetectionHelper, RepositoryManager repositoryManager, RepositoryTestDataStoreFactory testDataStoreFactory) {
|
||||
this.scmPathInfoStore = scmPathInfoStore;
|
||||
this.mergeDetectionHelper = mergeDetectionHelper;
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.testDataStoreFactory = testDataStoreFactory;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -71,6 +85,26 @@ public class IntegrationTestResource {
|
||||
mergeDetectionHelper.initialize(mergeDetectionConfiguration.getTarget(), mergeDetectionConfiguration.getBranch());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{namespace}/{name}/test-data")
|
||||
@Produces("application/json")
|
||||
public Collection<RepositoryTestData> getData(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||
Repository repository = repositoryManager.get(new NamespaceAndName(namespace, name));
|
||||
return testDataStoreFactory.get(repository).query().findAll();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{namespace}/{name}/test-data")
|
||||
@Consumes("application/json")
|
||||
public void storeData(@PathParam("namespace") String namespace, @PathParam("name") String name, RepositoryTestData testData) {
|
||||
NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
|
||||
Repository repository = repositoryManager.get(namespaceAndName);
|
||||
if (repository == null) {
|
||||
throw notFound(entity(namespaceAndName));
|
||||
}
|
||||
testDataStoreFactory.getMutable(repository).put(testData);
|
||||
}
|
||||
|
||||
private String self() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), IntegrationTestResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - present Cloudogu GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
package sonia.scm.it.resource;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Provider;
|
||||
import sonia.scm.api.v2.resources.Enrich;
|
||||
import sonia.scm.api.v2.resources.HalAppender;
|
||||
import sonia.scm.api.v2.resources.HalEnricher;
|
||||
import sonia.scm.api.v2.resources.HalEnricherContext;
|
||||
import sonia.scm.api.v2.resources.LinkBuilder;
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
@Extension
|
||||
@Enrich(Repository.class)
|
||||
public class RepositoryIntegrationTestLinkEnricher implements HalEnricher {
|
||||
|
||||
private final Provider<ScmPathInfoStore> pathInfoStore;
|
||||
|
||||
@Inject
|
||||
public RepositoryIntegrationTestLinkEnricher(Provider<ScmPathInfoStore> pathInfoStore) {
|
||||
this.pathInfoStore = pathInfoStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enrich(HalEnricherContext context, HalAppender appender) {
|
||||
Repository repository = context.oneRequireByType(Repository.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(pathInfoStore.get().get(), IntegrationTestResource.class);
|
||||
String dataUrl = linkBuilder.method("getData").parameters(repository.getNamespace(), repository.getName()).href();
|
||||
appender.appendLink("test-data", dataUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - present Cloudogu GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
package store;
|
||||
|
||||
import lombok.Data;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.QueryableType;
|
||||
|
||||
@Data
|
||||
@QueryableType(Repository.class)
|
||||
public class RepositoryTestData {
|
||||
private String value;
|
||||
}
|
||||
Reference in New Issue
Block a user