Skip to content

Commit

Permalink
Merge pull request #596 from entur/denormalize-entity-data
Browse files Browse the repository at this point in the history
Normalize entity data
  • Loading branch information
testower authored Jan 9, 2025
2 parents ff04e2f + 2352d60 commit 53a658f
Show file tree
Hide file tree
Showing 62 changed files with 1,455 additions and 641 deletions.
23 changes: 23 additions & 0 deletions src/main/java/org/entur/lamassu/cache/PricingPlanCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache;

import org.entur.lamassu.model.entities.PricingPlan;

public interface PricingPlanCache extends EntityCache<PricingPlan> {}
23 changes: 23 additions & 0 deletions src/main/java/org/entur/lamassu/cache/RegionCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache;

import org.entur.lamassu.model.entities.Region;

public interface RegionCache extends EntityCache<Region> {}
23 changes: 23 additions & 0 deletions src/main/java/org/entur/lamassu/cache/SystemCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache;

import org.entur.lamassu.model.entities.System;

public interface SystemCache extends EntityCache<System> {}
23 changes: 23 additions & 0 deletions src/main/java/org/entur/lamassu/cache/VehicleTypeCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache;

import org.entur.lamassu.model.entities.VehicleType;

public interface VehicleTypeCache extends EntityCache<VehicleType> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache.impl;

import org.entur.lamassu.cache.PricingPlanCache;
import org.entur.lamassu.model.entities.PricingPlan;
import org.redisson.api.RMapCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PricingPlanCacheImpl
extends EntityCacheImpl<PricingPlan>
implements PricingPlanCache {

public PricingPlanCacheImpl(@Autowired RMapCache<String, PricingPlan> cache) {
super(cache);
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/entur/lamassu/cache/impl/RegionCacheImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache.impl;

import org.entur.lamassu.cache.RegionCache;
import org.entur.lamassu.model.entities.Region;
import org.redisson.api.RMapCache;
import org.springframework.stereotype.Component;

@Component
public class RegionCacheImpl extends EntityCacheImpl<Region> implements RegionCache {

public RegionCacheImpl(RMapCache<String, Region> cache) {
super(cache);
}
}
33 changes: 33 additions & 0 deletions src/main/java/org/entur/lamassu/cache/impl/SystemCacheImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache.impl;

import org.entur.lamassu.cache.SystemCache;
import org.entur.lamassu.model.entities.System;
import org.redisson.api.RMapCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SystemCacheImpl extends EntityCacheImpl<System> implements SystemCache {

public SystemCacheImpl(@Autowired RMapCache<String, System> cache) {
super(cache);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.cache.impl;

import org.entur.lamassu.cache.VehicleTypeCache;
import org.entur.lamassu.model.entities.VehicleType;
import org.redisson.api.RMapCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class VehicleTypeCacheImpl
extends EntityCacheImpl<VehicleType>
implements VehicleTypeCache {

protected VehicleTypeCacheImpl(@Autowired RMapCache<String, VehicleType> cache) {
super(cache);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import org.entur.lamassu.cache.VehicleSpatialIndexId;
import org.entur.lamassu.config.project.LamassuProjectInfoConfiguration;
import org.entur.lamassu.model.entities.GeofencingZones;
import org.entur.lamassu.model.entities.PricingPlan;
import org.entur.lamassu.model.entities.Region;
import org.entur.lamassu.model.entities.Station;
import org.entur.lamassu.model.entities.System;
import org.entur.lamassu.model.entities.Vehicle;
import org.entur.lamassu.model.entities.VehicleType;
import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RGeo;
Expand All @@ -30,8 +34,12 @@ public class RedissonCacheConfig {

public static final String GBFS_FEED_CACHE_KEY = "gbfsFeedCache";
public static final String GBFS_V3_FEED_CACHE_KEY = "gbfsV3FeedCache";
public static final String SYSTEM_CACHE_KEY = "systemCache";
public static final String VEHICLE_TYPE_CACHE_KEY = "vehicleTypeCache";
public static final String PRICING_PLAN_CACHE_KEY = "pricingPlanCache";
public static final String VEHICLE_CACHE_KEY = "vehicleCache";
public static final String STATION_CACHE_KEY = "stationCache";
public static final String REGION_CACHE_KEY = "regionCache";
public static final String GEOFENCING_ZONES_CACHE_KEY = "geofencingZonesCache";
public static final String VEHICLE_SPATIAL_INDEX_KEY = "vehicleSpatialIndex";
public static final String STATION_SPATIAL_INDEX_KEY = "stationSpatialIndex";
Expand Down Expand Up @@ -114,6 +122,25 @@ RMapCache<String, Object> v3FeedCache(RedissonClient redissonClient) {
);
}

@Bean
public RMapCache<String, System> systemCache(RedissonClient redissonClient) {
return redissonClient.getMapCache(SYSTEM_CACHE_KEY + "_" + serializationVersion);
}

@Bean
public RMapCache<String, VehicleType> vehicleTypeCache(RedissonClient redissonClient) {
return redissonClient.getMapCache(
VEHICLE_TYPE_CACHE_KEY + "_" + serializationVersion
);
}

@Bean
public RMapCache<String, PricingPlan> pricingPlanCache(RedissonClient redissonClient) {
return redissonClient.getMapCache(
PRICING_PLAN_CACHE_KEY + "_" + serializationVersion
);
}

@Bean
public RMapCache<String, Vehicle> vehicleCache(RedissonClient redissonClient) {
return redissonClient.getMapCache(VEHICLE_CACHE_KEY + "_" + serializationVersion);
Expand All @@ -124,6 +151,11 @@ public RMapCache<String, Station> stationCache(RedissonClient redissonClient) {
return redissonClient.getMapCache(STATION_CACHE_KEY + "_" + serializationVersion);
}

@Bean
public RMapCache<String, Region> regionCache(RedissonClient redissonClient) {
return redissonClient.getMapCache(REGION_CACHE_KEY + "_" + serializationVersion);
}

@Bean
public RMapCache<String, GeofencingZones> geofencingZonesCache(
RedissonClient redissonClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.entur.lamassu.controller;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.entur.lamassu.graphql.controller;
package org.entur.lamassu.graphql.query;

import java.util.Collection;
import org.entur.lamassu.model.entities.Operator;
Expand All @@ -7,18 +7,17 @@
import org.springframework.stereotype.Controller;

@Controller
public class FeedProviderGraphQLController extends BaseGraphQLController {
public class FeedProviderQueryController {

private final FeedProviderService feedProviderService;

public FeedProviderGraphQLController(FeedProviderService feedProviderService) {
super(feedProviderService);
public FeedProviderQueryController(FeedProviderService feedProviderService) {
this.feedProviderService = feedProviderService;
}

@QueryMapping
public Collection<String> codespaces() {
return getCodespaces();
return feedProviderService.getCodespaces();
}

@QueryMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package org.entur.lamassu.graphql.controller;
package org.entur.lamassu.graphql.query;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.entur.lamassu.cache.GeofencingZonesCache;
import org.entur.lamassu.graphql.validation.QueryParameterValidator;
import org.entur.lamassu.model.entities.GeofencingZones;
import org.entur.lamassu.service.FeedProviderService;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;

@Controller
public class GeofencingZonesGraphQLController extends BaseGraphQLController {
public class GeofencingZonesQueryController {

private final GeofencingZonesCache geofencingZonesCache;
private final QueryParameterValidator validationService;

public GeofencingZonesGraphQLController(
FeedProviderService feedProviderService,
GeofencingZonesCache geofencingZonesCache
public GeofencingZonesQueryController(
GeofencingZonesCache geofencingZonesCache,
QueryParameterValidator validationService
) {
super(feedProviderService);
this.geofencingZonesCache = geofencingZonesCache;
this.validationService = validationService;
}

@QueryMapping
public Collection<GeofencingZones> geofencingZones(@Argument List<String> systemIds) {
validateSystems(systemIds);
public List<GeofencingZones> geofencingZones(@Argument List<String> systemIds) {
validationService.validateSystems(systemIds);
if (systemIds != null && !systemIds.isEmpty()) {
return geofencingZonesCache.getAll(Set.copyOf(systemIds));
}
Expand Down
Loading

0 comments on commit 53a658f

Please sign in to comment.