Skip to content
Snippets Groups Projects
Commit c001a312 authored by latlon team's avatar latlon team
Browse files

Code drop


- XPLANBOX-3701 - disable chunk encoding, ensure startup if bucket policy cannot be set (eed3d7ce1)
- XPLANBOX-3696 - Update tests with internalId and enhance assertions for planStatus (7337c0999)
- XPLANBOX-3696 - Enhance assertion to check if not requested status is not returned (252ac98fd)
- XPLANBOX-3562 - renamed Query param planStatus and splitted values in v2 (not comma separated) in SoapUI-Tests (f6618f75f)
- XPLANBOX-3562 - implemented support of multiple planStatus query params, renamed planStatus param (6139a7a07)
- XPLANBOX-3696 - Enhance v1 SoapUI tests to test internalId and planstatus parameters in /plans TestCase (c1192f0ae)
- XPLANBOX-3696 - Disable test GET BP 6.0.2 pI getByPlanIdNoResult (c0f90aea9)
- XPLANBOX-3696 - Enhance v2 /plans tests by two new parameter tests and four tests checking empty results (negative verification) (344d1fddb)
- XPLANBOX-3696 - Implement assertions for new parameters of /plans path in OpenAPI document in v1 and v2 test suites (b75116f9a)
- XPLANBOX-3562 - implemented filter parameter internalId and planstatus (db92d4dc0)

Co-authored-by: default avatarDirk Stenger <stenger@lat-lon.de>
Co-authored-by: default avatarLyn Elisa Goltz <goltz@lat-lon.de>

Dropped from commit: 677f1992e8dfeb962d1d625d2903616ed640e4f0
parent 75fe22b4
No related branches found
No related tags found
No related merge requests found
Showing
with 1287 additions and 207 deletions
......@@ -72,18 +72,26 @@ public class S3Storage {
public void setBucketExpirationDate(String id, int expirationInDays) throws StorageException {
createBucketIfNotExists();
LifecycleRule rule = LifecycleRule.builder()
.id(id)
.expiration(LifecycleExpiration.builder().days(expirationInDays).build())
.status(ExpirationStatus.ENABLED)
.filter(LifecycleRuleFilter.builder().build())
.build();
BucketLifecycleConfiguration bucketLifecycleConfig = BucketLifecycleConfiguration.builder().rules(rule).build();
PutBucketLifecycleConfigurationRequest lifecycleRequest = PutBucketLifecycleConfigurationRequest.builder()
.bucket(bucketName)
.lifecycleConfiguration(bucketLifecycleConfig)
.build();
client.putBucketLifecycleConfiguration(lifecycleRequest);
try {
LifecycleRule rule = LifecycleRule.builder()
.id(id)
.expiration(LifecycleExpiration.builder().days(expirationInDays).build())
.status(ExpirationStatus.ENABLED)
.filter(LifecycleRuleFilter.builder().build())
.build();
BucketLifecycleConfiguration bucketLifecycleConfig = BucketLifecycleConfiguration.builder()
.rules(rule)
.build();
PutBucketLifecycleConfigurationRequest lifecycleRequest = PutBucketLifecycleConfigurationRequest.builder()
.bucket(bucketName)
.lifecycleConfiguration(bucketLifecycleConfig)
.build();
client.putBucketLifecycleConfiguration(lifecycleRequest);
}
catch (Exception e) {
LOG.warn("Could not set expiration date for bucket {} to {} days: {}", bucketName, expirationInDays,
e.getMessage());
}
}
/**
......
......@@ -35,6 +35,7 @@ import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Configuration;
/**
* Spring configuration for using AWS S3 as a storage.
......@@ -53,15 +54,21 @@ public class AmazonS3ReadOnlyContext {
@Bean(destroyMethod = "close")
public S3Client s3Client(AwsCredentialsProvider credentialsProvider,
@Value("${xplanbox.s3.region:#{environment.XPLAN_S3_REGION}}") String region,
@Value("${xplanbox.s3.endpoint.url:#{environment.XPLAN_S3_ENDPOINT}}") String endpointUrl)
@Value("${xplanbox.s3.endpoint.url:#{environment.XPLAN_S3_ENDPOINT}}") String endpointUrl,
@Value("${xplanbox.s3.chunkedEncodingEnabled:true}") boolean chunkedEncodingEnabled)
throws URISyntaxException {
if (endpointUrl == null || endpointUrl.isEmpty()) {
LOG.info("Using S3 region {}", region);
return S3Client.builder().credentialsProvider(credentialsProvider).region(Region.of(region)).build();
return S3Client.builder()
.serviceConfiguration(S3Configuration.builder().chunkedEncodingEnabled(chunkedEncodingEnabled).build())
.credentialsProvider(credentialsProvider)
.region(Region.of(region))
.build();
}
LOG.info("Using S3 url {} (region {})", endpointUrl);
LOG.info("Using S3 url {} (region {}) chunk encoding is {}", endpointUrl, region,
chunkedEncodingEnabled ? "enabled" : "disabled");
return S3Client.builder()
.serviceConfiguration(S3Configuration.builder().chunkedEncodingEnabled(chunkedEncodingEnabled).build())
.credentialsProvider(credentialsProvider)
.region(Region.of(region))
.endpointOverride(new URI(endpointUrl))
......
......@@ -20,31 +20,34 @@
*/
package de.latlon.xplan.core.manager.db.repository;
import java.util.List;
import de.latlon.xplan.core.manager.db.model.Plan;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
* @since 7.0
*/
@Repository
@Transactional
public interface PlanRepository extends CrudRepository<Plan, Integer> {
public interface PlanRepository extends CrudRepository<Plan, Integer>, JpaSpecificationExecutor<Plan> {
List<Plan> findByName(String name);
@Query(value = "from Plan as p where lower(p.name) like lower(concat('%', :name, '%'))")
List<Plan> findByNameLike(@Param("name") String name);
@Query(value = "from Plan as p where (lower(p.name) like lower(concat('%', :name, '%')) or :name is null) "
+ "and (p.internalid = :internalid or :internalid is null) " + "and p.planstatus in :planStatuses")
List<Plan> findBySearchParams(@Param("name") String name, @Param("internalid") String internalid,
@Param("planStatuses") List<String> planStatuses);
@Query(value = "from Plan as p where p.hasRaster = true AND wmssortdate=(SELECT min(wmssortdate) FROM Plan as p1 WHERE p1.wmssortdate IS NOT NULL AND p1.wmssortdate > :sortDate)")
List<Plan> findByPlanWithMoreRecentRasterPlan(@Param("sortDate") Date sortDate);
@Query(value = "from Plan as p where (lower(p.name) like lower(concat('%', :name, '%')) or :name is null) "
+ "and (p.internalid = :internalid or :internalid is null)")
List<Plan> findBySearchParams(@Param("name") String name, @Param("internalid") String internalid);
boolean existsPlanById(Integer id);
......
......@@ -22,6 +22,8 @@ package de.latlon.xplan.core.manager.db.repository;
import static de.latlon.xplan.commons.XPlanType.BP_Plan;
import static de.latlon.xplan.commons.XPlanVersion.XPLAN_51;
import static de.latlon.xplan.manager.web.shared.PlanStatus.ARCHIVIERT;
import static de.latlon.xplan.manager.web.shared.PlanStatus.FESTGESTELLT;
import static de.latlon.xplan.manager.web.shared.PlanStatus.IN_AUFSTELLUNG;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
......@@ -147,50 +149,43 @@ class PlanRepositoryTest {
@Test
@Commit
void verify_findByNameLike() {
void verify_findBySearchParams() {
assertFalse(TestTransaction.isFlaggedForRollback());
String name = "saveAndFindByLikeName";
Bereich bereich = new Bereich().nummer("0").name("test");
Feature feature = new Feature().num(1).fid("123");
Plan plan = new Plan().name(name)
.importDate(new Date())
.version(XPLAN_51)
.type(BP_Plan)
.hasRaster(false)
.bereiche(Collections.singleton(bereich))
.features(Collections.singleton(feature));
planRepository.save(plan);
List<Plan> existingPlan = planRepository.findByNameLike("iKEnAme");
assertFalse(existingPlan.isEmpty());
createAndSavePlan("saveAndFindByLikeName1", null, null);
createAndSavePlan("saveAndFindByLikeName2", "internalId1", null);
createAndSavePlan("saveAndFindByLikeName3", "internalId2", FESTGESTELLT);
createAndSavePlan("saveAndFindByLikeName4", null, IN_AUFSTELLUNG);
createAndSavePlan(null, null, ARCHIVIERT);
createAndSavePlan(null, "internalId3", null);
createAndSavePlan(null, "internalId4", FESTGESTELLT);
List<Plan> existingPlanByName = planRepository.findBySearchParams("iKEnAme", null);
assertFalse(existingPlanByName.isEmpty());
List<Plan> nonExistingPlan = planRepository.findByNameLike("unknown");
assertTrue(nonExistingPlan.isEmpty());
}
List<Plan> existingPlanByInternalId = planRepository.findBySearchParams(null, "internalId2");
assertFalse(existingPlanByInternalId.isEmpty());
@Test
@Commit
void verify_findByPlanWithMoreRecentRasterPlan() {
assertFalse(TestTransaction.isFlaggedForRollback());
Bereich bereich = new Bereich().nummer("0").name("test");
Feature feature = new Feature().num(1).fid("123");
Date wmsSortDate = new Date();
Plan plan = new Plan().name("saveAndFindPlanWithMoreRecentRasterPlan")
.importDate(new Date())
.version(XPLAN_51)
.type(BP_Plan)
.hasRaster(true)
.wmssortdate(wmsSortDate)
.bereiche(Collections.singleton(bereich))
.features(Collections.singleton(feature));
planRepository.save(plan);
List<Plan> existingPlanByPlanstatus = planRepository.findBySearchParams(null, null,
Collections.singletonList(FESTGESTELLT.getMessage()));
assertFalse(existingPlanByPlanstatus.isEmpty());
Date tomorrow = new Date(wmsSortDate.getTime() - (1000 * 60 * 60 * 24));
List<Plan> existingPlan = planRepository.findByPlanWithMoreRecentRasterPlan(tomorrow);
assertFalse(existingPlan.isEmpty());
List<Plan> existingPlanByNameAndPlanstatus = planRepository.findBySearchParams("veand", null,
Collections.singletonList(FESTGESTELLT.getMessage()));
assertFalse(existingPlanByNameAndPlanstatus.isEmpty());
Date yesterday = new Date(wmsSortDate.getTime() + (1000 * 60 * 60 * 24));
List<Plan> nonExistingPlan = planRepository.findByPlanWithMoreRecentRasterPlan(yesterday);
assertTrue(nonExistingPlan.isEmpty());
List<Plan> existingPlanByNameAndInternalId = planRepository.findBySearchParams("veand", "internalId1");
assertFalse(existingPlanByNameAndInternalId.isEmpty());
List<Plan> existingPlanByNameAndInternalIdAndPlanStatus = planRepository.findBySearchParams("veand",
"internalId2", Collections.singletonList(FESTGESTELLT.getMessage()));
assertFalse(existingPlanByNameAndInternalIdAndPlanStatus.isEmpty());
List<Plan> nonExistingPlanByNameAndInternalId = planRepository.findBySearchParams("unknown", "unknown");
assertTrue(nonExistingPlanByNameAndInternalId.isEmpty());
List<Plan> nonExistingPlanByNameAndInternalIdAndPlanstatus = planRepository.findBySearchParams(
"saveAndFindByLikeName2", "internalId1",
List.of(FESTGESTELLT.getMessage(), IN_AUFSTELLUNG.getMessage()));
assertTrue(nonExistingPlanByNameAndInternalIdAndPlanstatus.isEmpty());
}
@Test
......@@ -246,4 +241,19 @@ class PlanRepositoryTest {
assertFalse(notPlanExists);
}
private void createAndSavePlan(String name, String internalId, PlanStatus planStatus) {
Bereich bereich = new Bereich().nummer("0").name("test");
Feature feature = new Feature().num(1).fid("123");
Plan plan = new Plan().name(name)
.internalid(internalId)
.planstatus(planStatus != null ? planStatus.getMessage() : null)
.importDate(new Date())
.version(XPLAN_51)
.type(BP_Plan)
.hasRaster(false)
.bereiche(Collections.singleton(bereich))
.features(Collections.singleton(feature));
planRepository.save(plan);
}
}
......@@ -22,7 +22,6 @@ package de.latlon.xplan.manager.database;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -160,18 +159,8 @@ public class XPlanDao {
return xPlanDbAdapter.getXPlanByName(planName);
}
public List<XPlan> getXPlansLikeName(String planName) {
return xPlanDbAdapter.getXPlansLikeName(planName);
}
/**
* retrieves the id of the plan closest in future to the date passed
* @param releaseDate minimal release date
* @return id of plan with minimal release date
* @throws SQLException
*/
public int getPlanIdOfMoreRecentRasterPlan(Date releaseDate) {
return xPlanDbAdapter.selectXPlanIdOfMoreRecentRasterPlan(releaseDate);
public List<XPlan> getXPlansBySearchParams(String planName, String internalId, List<PlanStatus> planStatuses) {
return xPlanDbAdapter.getXPlansBySearchParams(planName, internalId, planStatuses);
}
/**
......
......@@ -38,7 +38,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -279,27 +278,14 @@ public class XPlanDbAdapter {
}
@Transactional(readOnly = true)
public List<XPlan> getXPlansLikeName(String planName) {
List<Plan> plans = planRepository.findByNameLike(planName);
public List<XPlan> getXPlansBySearchParams(String planName, String internalId, List<PlanStatus> planStatuses) {
List<Plan> plans = planStatuses != null && !planStatuses.isEmpty()
? planRepository.findBySearchParams(planName, internalId,
planStatuses.stream().map(PlanStatus::getMessage).toList())
: planRepository.findBySearchParams(planName, internalId);
return plans.stream().map(plan -> convertToXPlan(plan)).collect(Collectors.toList());
}
/**
* retrieves the id of the plan closest in future to the date passed
* @param releaseDate minimal release date
* @return id of plan with minimal release date, -1 if no such plan exists
* @throws SQLException
*/
@Transactional(readOnly = true)
public int selectXPlanIdOfMoreRecentRasterPlan(Date releaseDate) {
if (releaseDate == null)
return -1;
List<Plan> plan = planRepository.findByPlanWithMoreRecentRasterPlan(releaseDate);
if (plan.isEmpty())
return -1;
return plan.get(0).getId();
}
/**
* exports a plan
* @param planId of plan to export
......
......@@ -49,6 +49,7 @@ import de.latlon.xplanbox.api.commons.exception.InvalidPlanIdSyntax;
import de.latlon.xplanbox.api.commons.exception.UnsupportedParameterValue;
import de.latlon.xplanbox.api.manager.v1.model.Bereich;
import de.latlon.xplanbox.api.manager.v1.model.Gemeinde;
import de.latlon.xplanbox.api.manager.v1.model.PlanStatusEnum;
import de.latlon.xplanbox.api.manager.v1.model.StatusMessage;
import de.latlon.xplanbox.security.authorization.AgsAccessor;
import jakarta.inject.Singleton;
......@@ -127,11 +128,11 @@ public class PlanHandler implements AgsAccessor {
return xPlanDao.getXPlanByName(planName);
}
public List<XPlan> findPlans(String planName) throws Exception {
LOG.info("Searching plan by name '{}'", StringUtils.normalizeSpace(planName));
if (planName != null)
return xPlanDao.getXPlansLikeName(planName);
return xPlanDao.getXPlanList();
public List<XPlan> findPlans(String planName, String internalId, List<PlanStatusEnum> planStatuses) {
LOG.info("Searching plan by name '{}', internalId '{}' and planstatus '{}'",
StringUtils.normalizeSpace(planName), StringUtils.normalizeSpace(internalId), planStatuses);
return xPlanDao.getXPlansBySearchParams(planName, internalId,
planStatuses != null ? planStatuses.stream().map(PlanStatusEnum::toPlanStatus).toList() : null);
}
public List<XPlan> findPlansById(List<Integer> planIds) throws Exception {
......
......@@ -102,7 +102,7 @@ public class ApiV1Config extends AbstractApiConfig {
protected void addInfo(OpenAPI openApi, ManagerApiConfiguration managerApiConfiguration) {
openApi.setInfo(new Info().title("XPlanManagerAPI")
.version("1.5.0")
.version("1.6.0")
.description("XPlanManager REST API")
.termsOfService(getTermsOfService(managerApiConfiguration))
.license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")));
......
......@@ -103,7 +103,7 @@ public class ApiV2Config extends AbstractApiConfig {
protected void addInfo(OpenAPI openApi, ManagerApiConfiguration managerApiConfiguration) {
openApi.setInfo(new Info().title("XPlanManagerAPI")
.version("2.0.0")
.version("2.1.0")
.description("XPlanManager REST API v2")
.termsOfService(getTermsOfService(managerApiConfiguration))
.license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")));
......
......@@ -34,6 +34,7 @@ import de.latlon.xplanbox.api.manager.handler.PlanHandler;
import de.latlon.xplanbox.api.manager.v1.model.Bereich;
import de.latlon.xplanbox.api.manager.v1.model.Gemeinde;
import de.latlon.xplanbox.api.manager.v1.model.PlanInfo;
import de.latlon.xplanbox.api.manager.v1.model.PlanStatusEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
......@@ -72,24 +73,30 @@ public class PlansApi {
@GET
@Produces({ "application/json" })
@Operation(summary = "Search for plan by name",
description = "Returns a list of plans where the plan name contains the query string case insensitve",
description = "Returns a list of plans where the plan matches the passed query parameter",
tags = { "search" },
responses = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(
array = @ArraySchema(schema = @Schema(implementation = PlanInfo.class)))),
@ApiResponse(responseCode = "406", description = "Requested format is not available") })
public Response findByNameOrId(
public Response searchPlans(
@QueryParam("planName") @Parameter(description = "The name of the plan to search for",
example = "bplan_123, fplan-123, rplan20200803") String planName,
@QueryParam("internalId") @Parameter(description = "The internalId of the plan to search for",
example = "ID_8ee57554-5f58-42ea-86a4-e9f4acd9d3c1") String internalId,
@QueryParam("planStatus") @Parameter(description = "The planStatus of the plan to search for",
example = "FESTGESTELLT") List<PlanStatusEnum> planStatuses,
@QueryParam("planId") @Parameter(description = "The ID of the plan to search for",
example = "1, 2, 42") List<Integer> planIds,
@QueryParam("includeGeltungsbereich") @DefaultValue("false") @Parameter(
description = "true if the geltungsbereichWGS84 should be included in the response, false otherwise (default: false).") boolean includeGeltungsbereich)
throws Exception {
if (planName != null && !planIds.isEmpty())
throw new InvalidSearch("Searching by name and id within the same request is not supported!");
List<XPlan> plans = searchByNameOrId(planName, planIds);
if ((planName != null || internalId != null || (planStatuses != null && !planStatuses.isEmpty()))
&& !planIds.isEmpty())
throw new InvalidSearch(
"Searching by planName, internalId or planstatus and id within the same request is not supported!");
List<XPlan> plans = searchPlans(planName, internalId, planStatuses, planIds);
List<PlanInfo> planInfos = plans.stream().map(xPlan -> {
List<Bereich> bereiche = planHandler.findBereiche(xPlan.getId());
List<Gemeinde> gemeinden = planHandler.findGemeinden(xPlan.getId());
......@@ -103,11 +110,12 @@ public class PlansApi {
return Response.ok().entity(planInfos).build();
}
private List<XPlan> searchByNameOrId(String planName, List<Integer> planIds) throws Exception {
private List<XPlan> searchPlans(String planName, String internalId, List<PlanStatusEnum> planStatuses,
List<Integer> planIds) throws Exception {
if (!planIds.isEmpty()) {
return planHandler.findPlansById(planIds);
}
return planHandler.findPlans(planName);
return planHandler.findPlans(planName, internalId, planStatuses);
}
}
......@@ -22,6 +22,7 @@ package de.latlon.xplanbox.api.manager.v1.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import de.latlon.xplan.manager.web.shared.PlanStatus;
/**
* Enumeration for plan status.
......@@ -59,4 +60,8 @@ public enum PlanStatusEnum {
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
public PlanStatus toPlanStatus() {
return PlanStatus.valueOf(value);
}
}
......@@ -33,6 +33,7 @@ import de.latlon.xplanbox.api.manager.exception.InvalidSearch;
import de.latlon.xplanbox.api.manager.handler.PlanHandler;
import de.latlon.xplanbox.api.manager.v1.model.Bereich;
import de.latlon.xplanbox.api.manager.v1.model.Gemeinde;
import de.latlon.xplanbox.api.manager.v1.model.PlanStatusEnum;
import de.latlon.xplanbox.api.manager.v2.model.PlanInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
......@@ -68,24 +69,30 @@ public class PlansApi2 {
@GET
@Produces({ "application/json" })
@Operation(summary = "Search for plan by name",
description = "Returns a list of plans where the plan name contains the query string case insensitve",
description = "Returns a list of plans where the plan matches the passed query parameter",
tags = { "search" },
responses = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(
array = @ArraySchema(schema = @Schema(implementation = PlanInfo.class)))),
@ApiResponse(responseCode = "406", description = "Requested format is not available") })
public Response findByNameOrId(
public Response searchPlans(
@QueryParam("planName") @Parameter(description = "The name of the plan to search for",
example = "bplan_123, fplan-123, rplan20200803") String planName,
example = "bplan_123") String planName,
@QueryParam("internalId") @Parameter(description = "The internalId of the plan to search for",
example = "ID_8ee57554-5f58-42ea-86a4-e9f4acd9d3c1") String internalId,
@QueryParam("planStatus") @Parameter(description = "The planStatuses of the plan to search for",
example = "FESTGESTELLT") List<PlanStatusEnum> planStatuses,
@QueryParam("planId") @Parameter(description = "The ID of the plan to search for",
example = "1, 2, 42") List<Integer> planIds,
@QueryParam("includeGeltungsbereich") @DefaultValue("false") @Parameter(
description = "true if the geltungsbereichWGS84 should be included in the response, false otherwise (default: false).") boolean includeGeltungsbereich)
throws Exception {
if (planName != null && !planIds.isEmpty())
throw new InvalidSearch("Searching by name and id within the same request is not supported!");
List<XPlan> plans = searchByNameOrId(planName, planIds);
if ((planName != null || internalId != null || (planStatuses != null && !planStatuses.isEmpty()))
&& !planIds.isEmpty())
throw new InvalidSearch(
"Searching by planName, internalId or planstatus and id within the same request is not supported!");
List<XPlan> plans = searchPlans(planName, internalId, planStatuses, planIds);
List<PlanInfo> planInfos = plans.stream().map(xPlan -> {
List<Bereich> bereiche = planHandler.findBereiche(xPlan.getId());
List<Gemeinde> gemeinden = planHandler.findGemeinden(xPlan.getId());
......@@ -98,11 +105,12 @@ public class PlansApi2 {
return Response.ok().entity(planInfos).build();
}
private List<XPlan> searchByNameOrId(String planName, List<Integer> planIds) throws Exception {
private List<XPlan> searchPlans(String planName, String internalId, List<PlanStatusEnum> planStatuses,
List<Integer> planIds) throws Exception {
if (!planIds.isEmpty()) {
return planHandler.findPlansById(planIds);
}
return planHandler.findPlans(planName);
return planHandler.findPlans(planName, internalId, planStatuses);
}
}
......@@ -46,6 +46,7 @@ xplanbox.s3.accessKeyId=${XPLAN_S3_ACCESS_KEY}
xplanbox.s3.endpoint.url=${XPLAN_S3_ENDPOINT}
xplanbox.s3.region=${XPLAN_S3_REGION}
xplanbox.s3.secretKey=${XPLAN_S3_SECRET_ACCESS_KEY}
xplanbox.s3.chunkedEncodingEnabled=${XPLAN_S3_CHUNKENCODING_ENABLED:true}
xplanbox.validation.profiles=${XPLAN_VALIDATION_PROFILES:}
xplanbox.s3.bucket.validation=${XPLAN_S3_BUCKET_VALIDATION:validation}
......
......@@ -39,7 +39,6 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -234,6 +233,7 @@ public class TestContext {
XPlan mockPlan_5 = new XPlan("lplan_51", "5", "LP_Plan", "XPLAN_51");
XPlan mockPlan_6 = new XPlan("soplan_40", "6", "SO_Plan", "XPLAN_40");
XPlan mockPlan_7 = new XPlan("bplan_51", "7", "BP_Plan", "XPLAN_51");
mockPlan_2.setInternalId("ID_2_II");
mockPlan_123.setPlanStatus(FESTGESTELLT);
mockPlan_2.setPlanStatus(FESTGESTELLT);
mockPlan_3.setPlanStatus(FESTGESTELLT);
......@@ -256,11 +256,17 @@ public class TestContext {
when(xplanDao.retrieveXPlanArtefact(7)).thenReturn(getClass().getResourceAsStream("/xplan51_ohneBereich.gml"))
.thenReturn(getClass().getResourceAsStream("/xplan51_ohneBereich.gml"));
when(xplanDao.existsPlan(123)).thenReturn(true);
List<XPlan> mockList = new ArrayList<>();
mockList.add(mockPlan_123);
List<XPlan> mockList = Collections.singletonList(mockPlan_123);
List<XPlan> allPlans = List.of(mockPlan_1, mockPlan_123, mockPlan_2, mockPlan_3, mockPlan_4, mockPlan_5,
mockPlan_6, mockPlan_7);
when(xplanDao.getXPlanByName("bplan_41")).thenReturn(mockList);
when(xplanDao.getXPlansLikeName("bplan_41")).thenReturn(mockList);
when(xplanDao.getXPlanList()).thenReturn(mockList);
when(xplanDao.getXPlansBySearchParams("bplan_41", null, Collections.emptyList())).thenReturn(mockList);
when(xplanDao.getXPlansBySearchParams(null, "ID_2_II", Collections.emptyList()))
.thenReturn(Collections.singletonList(mockPlan_2));
when(xplanDao.getXPlansBySearchParams(null, null, Collections.singletonList(FESTGESTELLT)))
.thenReturn(Collections.singletonList(mockPlan_3));
when(xplanDao.getXPlansBySearchParams(null, null, Collections.emptyList())).thenReturn(allPlans);
when(xplanDao.getXPlanList()).thenReturn(allPlans);
when(xplanDao.retrieveAllXPlanArtefacts(anyString())).thenReturn(mock(List.class));
when(xplanDao.retrieveAllXPlanArtefacts("42")).thenThrow(new PlanNotFoundException(42));
when(xplanDao.retrieveGeltungsbereichOfPlanWithId("123")).thenReturn(geltungsbereichWGS84());
......
......@@ -23,6 +23,7 @@ package de.latlon.xplanbox.api.manager.handler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Collections;
import java.util.List;
import de.latlon.xplan.commons.archive.XPlanArchiveCreator;
......@@ -32,6 +33,7 @@ import de.latlon.xplanbox.api.commons.exception.InvalidPlanIdSyntax;
import de.latlon.xplanbox.api.manager.config.ApplicationContext;
import de.latlon.xplanbox.api.manager.config.HsqlJpaContext;
import de.latlon.xplanbox.api.manager.config.TestContext;
import de.latlon.xplanbox.api.manager.v1.model.PlanStatusEnum;
import de.latlon.xplanbox.api.manager.v1.model.StatusMessage;
import jakarta.ws.rs.core.StreamingOutput;
import org.junit.jupiter.api.Test;
......@@ -70,7 +72,7 @@ class PlanHandlerTest {
}
@Test
void verifyThat_exportPlan_WithWrongIdThrowsException() throws Exception {
void verifyThat_exportPlan_WithWrongIdThrowsException() {
assertThrows(InvalidPlanId.class, () -> {
StreamingOutput planAsStream = planHandler.exportPlan("42");
assertThat(planAsStream).isNotNull();
......@@ -84,39 +86,52 @@ class PlanHandlerTest {
}
@Test
void verifyThat_findPlanById_WithWrongIdFails() throws Exception {
void verifyThat_findPlanById_WithWrongIdFails() {
assertThrows(InvalidPlanId.class, () -> {
planHandler.findPlanById("42");
});
}
@Test
void verifyThat_findPlanByName() throws Exception {
void verifyThat_findPlanByName() {
List<XPlan> plans = planHandler.findPlansByName("bplan_41");
assertThat(plans).hasSize(1);
assertThat(plans.get(0).getId()).isEqualTo("123");
}
@Test
void verifyThat_findPlans() throws Exception {
List<XPlan> planList = planHandler.findPlans("bplan_41");
void verifyThat_findPlansByName() {
List<XPlan> planList = planHandler.findPlans("bplan_41", null, Collections.emptyList());
assertThat(planList).contains(new XPlan("bplan_41", "123", "BP_Plan", "XPLAN_41"));
}
@Test
void verifyThat_findPlans_ReturnsEmptyList() throws Exception {
List<XPlan> planList = planHandler.findPlans("xplan");
void verifyThat_findPlansByInternalId() {
List<XPlan> planList = planHandler.findPlans(null, "ID_2_II", Collections.emptyList());
assertThat(planList).contains(new XPlan("bplan_51", "2", "BP_Plan", "XPLAN_51"));
}
@Test
void verifyThat_findPlansByPlanstatus() {
List<XPlan> planList = planHandler.findPlans(null, null,
Collections.singletonList(PlanStatusEnum.FESTGESTELLT));
assertThat(planList).contains(new XPlan("bplan_53", "3", "BP_Plan", "XPLAN_53"));
}
@Test
void verifyThat_findPlans_ReturnsEmptyList() {
List<XPlan> planList = planHandler.findPlans("xplan", null, Collections.emptyList());
assertThat(planList).hasSize(0);
}
@Test
void verifyThat_findPlansWithNullName() throws Exception {
List<XPlan> planList = planHandler.findPlans(null);
void verifyThat_findPlansWithNullName() {
List<XPlan> planList = planHandler.findPlans(null, null, Collections.emptyList());
assertThat(planList).isNotEmpty();
}
@Test
void verifyThat_deleteWithNonIntegerFailes() {
void verifyThat_deleteWithNonIntegerFails() {
assertThrows(InvalidPlanIdSyntax.class, () -> planHandler.deletePlan("999999999999999999999"));
}
......
......@@ -74,4 +74,14 @@ class PlansApiTest extends ManagerApiJerseyTest<PlansApi> {
"{\"id\":123,\"type\":\"BP_Plan\",\"version\":\"XPLAN_41\",\"planStatus\":\"FESTGESTELLT\",\"raster\":false,\"importDate\":null,\"inspirePublished\":false,\"bbox\":null,\"geltungsbereichWGS84\":{\"type\":\"Polygon\",\"bbox\":null,\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]},");
}
@Test
void verifyThat_GetPlansByPlanStatus_ReturnCorrectStatus() {
Response response = target("/plans").queryParam("planStatus", "FESTGESTELLT")
.queryParam("planStatus", "ARCHIVIERT")
.request()
.accept(APPLICATION_JSON)
.get();
assertThat(response.getStatus()).isEqualTo(200);
}
}
......@@ -74,4 +74,14 @@ class PlansApi2Test extends ManagerApiJerseyTest<PlansApi2> {
"{\"id\":123,\"type\":\"BP_Plan\",\"version\":\"XPLAN_41\",\"planStatus\":\"FESTGESTELLT\",\"raster\":false,\"importDate\":null,\"inspirePublished\":false,\"bbox\":null,\"geltungsbereichWGS84\":{\"type\":\"Polygon\",\"bbox\":null,\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]},");
}
@Test
void verifyThat_GetPlansByPlanStatus_ReturnCorrectStatus() {
Response response = target("/plans").queryParam("planStatus", "FESTGESTELLT")
.queryParam("planStatus", "ARCHIVIERT")
.request()
.accept(APPLICATION_JSON)
.get();
assertThat(response.getStatus()).isEqualTo(200);
}
}
......@@ -47,6 +47,7 @@ xplanbox.s3.accessKeyId=${XPLAN_S3_ACCESS_KEY}
xplanbox.s3.endpoint.url=${XPLAN_S3_ENDPOINT}
xplanbox.s3.region=${XPLAN_S3_REGION}
xplanbox.s3.secretKey=${XPLAN_S3_SECRET_ACCESS_KEY}
xplanbox.s3.chunkedEncodingEnabled=${XPLAN_S3_CHUNKENCODING_ENABLED:true}
xplanbox.validation.profiles=${XPLAN_VALIDATION_PROFILES:}
xplanbox.s3.bucket.validation=${XPLAN_S3_BUCKET_VALIDATION:validation}
......
......@@ -46,6 +46,7 @@ xplanbox.s3.accessKeyId=${XPLAN_S3_ACCESS_KEY}
xplanbox.s3.endpoint.url=${XPLAN_S3_ENDPOINT}
xplanbox.s3.region=${XPLAN_S3_REGION}
xplanbox.s3.secretKey=${XPLAN_S3_SECRET_ACCESS_KEY}
xplanbox.s3.chunkedEncodingEnabled=${XPLAN_S3_CHUNKENCODING_ENABLED:true}
xplanbox.validation.profiles=${XPLAN_VALIDATION_PROFILES:}
xplanbox.s3.bucket.validation=${XPLAN_S3_BUCKET_VALIDATION:validation}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.