Skip to content

Commit

Permalink
fixup after API changes in #876
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed Aug 6, 2024
1 parent efdd055 commit 53fae2e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import nl.b3p.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper;
import nl.b3p.tailormap.api.geotools.featuresources.JDBCFeatureSourceHelper;
import nl.b3p.tailormap.api.geotools.featuresources.WFSFeatureSourceHelper;
Expand Down Expand Up @@ -65,11 +64,10 @@
import nl.b3p.tailormap.api.repository.UserRepository;
import nl.b3p.tailormap.api.security.InternalAdminAuthentication;
import nl.b3p.tailormap.api.solr.SolrHelper;
import nl.b3p.tailormap.api.solr.SolrService;
import nl.b3p.tailormap.api.viewer.model.AppStyling;
import nl.b3p.tailormap.api.viewer.model.Component;
import nl.b3p.tailormap.api.viewer.model.ComponentConfig;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateHttp2SolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -116,7 +114,7 @@ public class PopulateTestData {
private final CatalogRepository catalogRepository;
private final GeoServiceRepository geoServiceRepository;
private final GeoServiceHelper geoServiceHelper;

private final SolrService solrService;
private final FeatureSourceRepository featureSourceRepository;
private final ApplicationRepository applicationRepository;
private final ConfigurationRepository configurationRepository;
Expand All @@ -136,6 +134,7 @@ public PopulateTestData(
ConfigurationRepository configurationRepository,
FeatureSourceFactoryHelper featureSourceFactoryHelper,
SearchIndexRepository searchIndexRepository,
SolrService solrService,
UploadRepository uploadRepository) {
this.appContext = appContext;
this.userRepository = userRepository;
Expand All @@ -148,6 +147,7 @@ public PopulateTestData(
this.configurationRepository = configurationRepository;
this.featureSourceFactoryHelper = featureSourceFactoryHelper;
this.searchIndexRepository = searchIndexRepository;
this.solrService = solrService;
this.uploadRepository = uploadRepository;
}

Expand Down Expand Up @@ -1348,19 +1348,7 @@ public void createSolrIndex() throws Exception {
+ (connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "solr")
+ ":8983/solr/"
+ solrCoreName;
SolrHelper solrHelper =
new SolrHelper(
new ConcurrentUpdateHttp2SolrClient.Builder(
solrUrl,
new Http2SolrClient.Builder()
.useHttp1_1(true)
.withFollowRedirects(true)
.withConnectionTimeout(10000, TimeUnit.MILLISECONDS)
.withRequestTimeout(60000, TimeUnit.MILLISECONDS)
.build())
.withQueueSize(SolrHelper.SOLR_BATCH_SIZE * 2)
.withThreadCount(10)
.build());
SolrHelper solrHelper = new SolrHelper(this.solrService.getSolrClientForIndexing());

GeoService geoService = geoServiceRepository.findById("snapshot-geoserver").orElseThrow();
Application defaultApp = applicationRepository.findByName("default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
*/
package nl.b3p.tailormap.api.repository;

import java.util.List;
import java.util.Optional;
import nl.b3p.tailormap.api.persistence.Application;
import nl.b3p.tailormap.api.security.annotation.PreAuthorizeAdmin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.lang.NonNull;
import org.springframework.security.access.prepost.PreAuthorize;

Expand All @@ -21,4 +24,18 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
@Override
@NonNull
Optional<Application> findById(@NonNull Long aLong);

/**
* Find all applications that have a layer that is linked to a specific (Solr) index.
*
* @param indexId The index id to search for //TODO: This query is not working as expected. It
* should return all applications that have a layer that is linked to a specific (Solr) index.
*/
@NonNull
@PreAuthorize("permitAll()")
@Query(
value =
"select * from application app, lateral jsonb_path_query(gs.settings, ('$.layerSettings.**{1}.searchIndex.searchIndexId ? (@ == '||:indexId||')')::jsonpath)",
nativeQuery = true)
List<Application> findByIndexId(@Param("indexId") @NonNull Long indexId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,4 @@ public interface GeoServiceRepository extends JpaRepository<GeoService, String>
@PreAuthorize("permitAll()")
@Query("from GeoService s where id not in :ids")
List<GeoService> getAllExcludingIds(@Param("ids") List<String> ids);

/**
* Find all geo-services that have a layer that is linked to a specific (Solr) index.
*
* @param indexId The index id to search for
*/
@NonNull
@PreAuthorize("permitAll()")
@Query(
value =
"select * from geo_service gs, lateral jsonb_path_query(gs.settings, ('$.layerSettings.**{1}.searchIndex.searchIndexId ? (@ == '||:indexId||')')::jsonpath)",
nativeQuery = true)
List<GeoService> findByIndexId(@Param("indexId") @NonNull Long indexId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import nl.b3p.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper;
import nl.b3p.tailormap.api.persistence.SearchIndex;
import nl.b3p.tailormap.api.persistence.TMFeatureType;
import nl.b3p.tailormap.api.repository.GeoServiceRepository;
import nl.b3p.tailormap.api.persistence.json.AppLayerSettings;
import nl.b3p.tailormap.api.repository.ApplicationRepository;
import nl.b3p.tailormap.api.repository.SearchIndexRepository;
import nl.b3p.tailormap.api.solr.SolrHelper;
import nl.b3p.tailormap.api.solr.SolrService;
Expand All @@ -32,17 +33,17 @@ public class SolrTMFeatureTypeEventHandler {
private final SearchIndexRepository searchIndexRepository;
private final SolrService solrService;
private final FeatureSourceFactoryHelper featureSourceFactoryHelper;
private final GeoServiceRepository geoServiceRepository;
private final ApplicationRepository applicationRepository;

public SolrTMFeatureTypeEventHandler(
SearchIndexRepository searchIndexRepository,
SolrService solrService,
FeatureSourceFactoryHelper featureSourceFactoryHelper,
GeoServiceRepository geoServiceRepository) {
ApplicationRepository applicationRepository) {
this.searchIndexRepository = searchIndexRepository;
this.solrService = solrService;
this.featureSourceFactoryHelper = featureSourceFactoryHelper;
this.geoServiceRepository = geoServiceRepository;
this.applicationRepository = applicationRepository;
}

/**
Expand Down Expand Up @@ -104,36 +105,26 @@ public void handleTMFeatureTypeDeleteForSolr(TMFeatureType tmFeatureType) {
try (SolrHelper solrHelper = new SolrHelper(solrService.getSolrClientForIndexing())) {
solrHelper.clearIndexForLayer(searchIndex.getId());
searchIndexRepository.delete(searchIndex);
// find layers that use this index in the layer settings and clear them
geoServiceRepository
// find any application layers that use this index clear the index from them
applicationRepository
.findByIndexId(searchIndex.getId())
.forEach(
geoService ->
geoService
.getLayers()
.forEach(
layer -> {
logger.debug(
"Checking layer {} for search index {}",
layer.getName(),
searchIndex.getName());
geoService
.findSearchIndexForLayer(layer, searchIndexRepository)
.ifPresent(
searchIndex1 -> {
if (searchIndex1
.getId()
.equals(searchIndex.getId())) {
logger.debug(
"Clearing search index for layer {}",
layer.getName());
geoService
.getLayerSettings(layer.getName())
.setSearchIndex(null);
geoServiceRepository.save(geoService);
}
});
}));
application -> {
application
.getAllAppTreeLayerNode()
.forEach(
appTreeLayerNode -> {
AppLayerSettings appLayerSettings =
application.getAppLayerSettings(appTreeLayerNode);
if (null != appLayerSettings.getSearchIndexId()
&& appLayerSettings
.getSearchIndexId()
.equals(searchIndex.getId())) {
appLayerSettings.setSearchIndexId(null);
}
});
applicationRepository.save(application);
});
} catch (UnsupportedOperationException
| IOException
| SolrServerException
Expand Down

0 comments on commit 53fae2e

Please sign in to comment.