use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class StopPlaceRegisterGraphQLSchema method init.
@PostConstruct
public void init() {
/**
* Common field list for quays, stop places and addressable place.
*/
List<GraphQLFieldDefinition> commonFieldsList = new ArrayList<>();
commonFieldsList.add(newFieldDefinition().name(PLACE_EQUIPMENTS).type(equipmentType).dataFetcher(env -> {
if (env.getSource() instanceof StopPlace) {
return ((StopPlace) env.getSource()).getPlaceEquipments();
} else if (env.getSource() instanceof Quay) {
return ((Quay) env.getSource()).getPlaceEquipments();
}
return null;
}).build());
commonFieldsList.add(newFieldDefinition().name(ACCESSIBILITY_ASSESSMENT).description("This field is set either on StopPlace (i.e. all Quays are equal), or on every Quay.").type(accessibilityAssessmentObjectType).build());
commonFieldsList.add(newFieldDefinition().name(PUBLIC_CODE).type(GraphQLString).build());
commonFieldsList.add(privateCodeFieldDefinition);
commonFieldsList.add(newFieldDefinition().name(MODIFICATION_ENUMERATION).type(modificationEnumerationType).build());
GraphQLObjectType validBetweenObjectType = createValidBetweenObjectType();
List<GraphQLFieldDefinition> zoneCommandFieldList = zoneCommonFieldListCreator.create(validBetweenObjectType);
commonFieldsList.addAll(zoneCommandFieldList);
GraphQLObjectType quayObjectType = createQuayObjectType(commonFieldsList);
GraphQLObjectType topographicPlaceObjectType = topographicPlaceObjectTypeCreator.create();
GraphQLObjectType tariffZoneObjectType = tariffZoneObjectTypeCreator.create(zoneCommandFieldList);
GraphQLObjectType fareZoneObjectType = fareZoneObjectTypeCreator.create(zoneCommandFieldList);
MutableTypeResolver stopPlaceTypeResolver = new MutableTypeResolver();
List<GraphQLFieldDefinition> stopPlaceInterfaceFields = stopPlaceInterfaceCreator.createCommonInterfaceFields(tariffZoneObjectType, fareZoneObjectType, topographicPlaceObjectType, validBetweenObjectType);
GraphQLInterfaceType stopPlaceInterface = stopPlaceInterfaceCreator.createInterface(stopPlaceInterfaceFields, commonFieldsList, stopPlaceTypeResolver);
GraphQLObjectType stopPlaceObjectType = stopPlaceObjectTypeCreator.create(stopPlaceInterface, stopPlaceInterfaceFields, commonFieldsList, quayObjectType);
GraphQLObjectType parentStopPlaceObjectType = parentStopPlaceObjectTypeCreator.create(stopPlaceInterface, stopPlaceInterfaceFields, commonFieldsList, stopPlaceObjectType);
stopPlaceTypeResolver.setResolveFunction(object -> {
if (object instanceof StopPlace) {
StopPlace stopPlace = (StopPlace) object;
if (stopPlace.isParentStopPlace()) {
return parentStopPlaceObjectType;
} else {
return stopPlaceObjectType;
}
}
throw new IllegalArgumentException("StopPlaceTypeResolver cannot resolve type of Object " + object + ". Was expecting StopPlace");
});
GraphQLObjectType groupOfStopPlacesObjectType = groupOfStopPlaceObjectTypeCreator.create(stopPlaceInterface);
GraphQLObjectType groupOfTariffZonesObjectType = groupOfTariffZonesObjectTypeCreator.create();
GraphQLObjectType addressablePlaceObjectType = createAddressablePlaceObjectType(commonFieldsList);
GraphQLObjectType entityRefObjectType = entityRefObjectTypeCreator.create(addressablePlaceObjectType);
GraphQLObjectType pathLinkEndObjectType = pathLinkEndObjectTypeCreator.create(entityRefObjectType, netexIdFieldDefinition);
GraphQLObjectType pathLinkObjectType = pathLinkObjectTypeCreator.create(pathLinkEndObjectType, netexIdFieldDefinition, geometryFieldDefinition);
GraphQLObjectType parkingObjectType = createParkingObjectType(validBetweenObjectType);
GraphQLArgument allVersionsArgument = GraphQLArgument.newArgument().name(ALL_VERSIONS).type(GraphQLBoolean).description(ALL_VERSIONS_ARG_DESCRIPTION).build();
GraphQLObjectType stopPlaceRegisterQuery = newObject().name("StopPlaceRegister").description("Query and search for data").field(newFieldDefinition().type(new GraphQLList(stopPlaceInterface)).name(FIND_STOPPLACE).description("Search for StopPlaces").argument(createFindStopPlaceArguments(allVersionsArgument)).dataFetcher(stopPlaceFetcher)).field(newFieldDefinition().type(new GraphQLList(stopPlaceInterface)).name(FIND_STOPPLACE_BY_BBOX).description("Find StopPlaces within given BoundingBox.").argument(createBboxArguments()).dataFetcher(stopPlaceFetcher)).field(newFieldDefinition().name(FIND_TOPOGRAPHIC_PLACE).type(new GraphQLList(topographicPlaceObjectType)).description("Find topographic places").argument(createFindTopographicPlaceArguments(allVersionsArgument)).dataFetcher(topographicPlaceFetcher)).field(newFieldDefinition().name(FIND_PATH_LINK).type(new GraphQLList(pathLinkObjectType)).description("Find path links").argument(createFindPathLinkArguments(allVersionsArgument)).dataFetcher(pathLinkFetcher)).field(newFieldDefinition().name(FIND_PARKING).type(new GraphQLList(parkingObjectType)).description("Find parking").argument(createFindParkingArguments(allVersionsArgument)).dataFetcher(parkingFetcher)).field(newFieldDefinition().name(VALID_TRANSPORT_MODES).type(new GraphQLList(transportModeSubmodeObjectType)).description("List all valid Transportmode/Submode-combinations.").staticValue(transportModeScalar.getConfiguredTransportModes().keySet())).field(newFieldDefinition().name(CHECK_AUTHORIZED).type(createAuthorizationCheckOutputType()).description(AUTHORIZATION_CHECK_DESCRIPTION).argument(createAuthorizationCheckArguments()).dataFetcher(authorizationCheckDataFetcher)).field(newFieldDefinition().name(TAGS).type(new GraphQLList(tagObjectTypeCreator.create())).description(TAGS_DESCRIPTION).argument(GraphQLArgument.newArgument().name(TAG_NAME).description(TAG_NAME_DESCRIPTION).type(new GraphQLNonNull(GraphQLString))).dataFetcher(tagFetcher).build()).field(newFieldDefinition().name(GROUP_OF_STOP_PLACES).type(new GraphQLList(groupOfStopPlacesObjectType)).description("Group of stop places").argument(createFindGroupOfStopPlacesArguments()).dataFetcher(groupOfStopPlacesFetcher).build()).field(newFieldDefinition().name(GROUP_OF_TARIFF_ZONES).type(new GraphQLList(groupOfTariffZonesObjectType)).description("Group of tariff zones").argument(createFindGroupOfTariffZonesArguments()).dataFetcher(groupOfTariffZonesFetcher).build()).field(newFieldDefinition().name(TARIFF_ZONES).type(new GraphQLList(tariffZoneObjectType)).description("Tariff zones").argument(createFindTariffZonesArguments()).dataFetcher(tariffZonesFetcher).build()).field(newFieldDefinition().name(FARE_ZONES).type(new GraphQLList(fareZoneObjectType)).description("Fare zones").argument(createFindFareZonesArguments()).dataFetcher(fareZonesFetcher).build()).build();
List<GraphQLInputObjectField> commonInputFieldList = createCommonInputFieldList(embeddableMultiLingualStringInputObjectType);
GraphQLInputObjectType quayInputObjectType = createQuayInputObjectType(commonInputFieldList);
GraphQLInputObjectType validBetweenInputObjectType = createValidBetweenInputObjectType();
GraphQLInputObjectType stopPlaceInputObjectType = createStopPlaceInputObjectType(commonInputFieldList, topographicPlaceInputObjectType, quayInputObjectType, validBetweenInputObjectType);
GraphQLInputObjectType parentStopPlaceInputObjectType = parentStopPlaceInputObjectTypeCreator.create(commonInputFieldList, validBetweenInputObjectType, stopPlaceInputObjectType);
GraphQLInputObjectType parkingInputObjectType = createParkingInputObjectType(validBetweenInputObjectType);
GraphQLInputObjectType groupOfStopPlacesInputObjectType = createGroupOfStopPlacesInputObjectType();
GraphQLObjectType stopPlaceRegisterMutation = newObject().name("StopPlaceMutation").description("Create and edit stopplaces").field(newFieldDefinition().type(new GraphQLList(stopPlaceObjectType)).name(MUTATE_STOPPLACE).description("Create new or update existing StopPlace").argument(GraphQLArgument.newArgument().name(OUTPUT_TYPE_STOPPLACE).type(stopPlaceInputObjectType)).dataFetcher(stopPlaceUpdater)).field(newFieldDefinition().type(new GraphQLList(parentStopPlaceObjectType)).name(MUTATE_PARENT_STOPPLACE).description("Update existing Parent StopPlace").argument(GraphQLArgument.newArgument().name(OUTPUT_TYPE_PARENT_STOPPLACE).type(parentStopPlaceInputObjectType)).dataFetcher(stopPlaceUpdater)).field(newFieldDefinition().name(MUTATE_GROUP_OF_STOP_PLACES).type(groupOfStopPlacesObjectType).description("Mutate group of stop places").argument(GraphQLArgument.newArgument().name(OUTPUT_TYPE_GROUP_OF_STOPPLACES).type(groupOfStopPlacesInputObjectType)).dataFetcher(groupOfStopPlacesUpdater)).field(newFieldDefinition().type(new GraphQLList(pathLinkObjectType)).name(MUTATE_PATH_LINK).description("Create new or update existing PathLink").argument(GraphQLArgument.newArgument().name(OUTPUT_TYPE_PATH_LINK).type(new GraphQLList(pathLinkObjectInputType))).description("Create new or update existing " + OUTPUT_TYPE_PATH_LINK).dataFetcher(pathLinkUpdater)).field(newFieldDefinition().type(new GraphQLList(parkingObjectType)).name(MUTATE_PARKING).argument(GraphQLArgument.newArgument().name(OUTPUT_TYPE_PARKING).type(new GraphQLList(parkingInputObjectType))).description("Create new or update existing " + OUTPUT_TYPE_PARKING).dataFetcher(parkingUpdater)).field(newFieldDefinition().type(tariffZoneObjectType).name(TERMINATE_TARIFF_ZONE).description("TariffZone will be terminated and no longer be active after the given date.").argument(newArgument().name(TARIFF_ZONE_ID).type(new GraphQLNonNull(GraphQLString))).argument(newArgument().name(VALID_BETWEEN_TO_DATE).type(new GraphQLNonNull(dateScalar.getGraphQLDateScalar()))).argument(newArgument().name(VERSION_COMMENT).type(GraphQLString)).dataFetcher(environment -> tariffZoneTerminator.terminateTariffZone(environment.getArgument(TARIFF_ZONE_ID), environment.getArgument(VALID_BETWEEN_TO_DATE), environment.getArgument(VERSION_COMMENT)))).fields(tagOperationsBuilder.getTagOperations()).fields(stopPlaceOperationsBuilder.getStopPlaceOperations(stopPlaceInterface)).fields(parkingOperationsBuilder.getParkingOperations()).fields(multiModalityOperationsBuilder.getMultiModalityOperations(parentStopPlaceObjectType, validBetweenInputObjectType)).field(newFieldDefinition().type(GraphQLBoolean).name("deleteGroupOfStopPlaces").argument(GraphQLArgument.newArgument().name(ID).type(new GraphQLNonNull(GraphQLString))).description("Hard delete group of stop places by ID").dataFetcher(groupOfStopPlacesDeleterFetcher)).build();
stopPlaceRegisterSchema = GraphQLSchema.newSchema().query(stopPlaceRegisterQuery).mutation(stopPlaceRegisterMutation).build();
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneRepositoryImpl method getTariffZonesFromStopPlaceIds.
@Override
public List<TariffZone> getTariffZonesFromStopPlaceIds(Set<Long> stopPlaceIds) {
if (stopPlaceIds == null || stopPlaceIds.isEmpty()) {
return new ArrayList<>();
}
Query query = entityManager.createNativeQuery(generateTariffZoneQueryFromStopPlaceIds(stopPlaceIds), TariffZone.class);
@SuppressWarnings("unchecked") List<TariffZone> tariffZones = query.getResultList();
return tariffZones;
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneRepositoryImpl method findTariffZones.
@Override
public List<TariffZone> findTariffZones(TariffZoneSearch search) {
Pair<String, Map<String, Object>> pair = tariffZoneQueryFromSearchBuilder.buildQueryFromSearch(search);
Session session = entityManager.unwrap(SessionImpl.class);
NativeQuery nativeQuery = session.createNativeQuery(pair.getFirst());
nativeQuery.addEntity(TariffZone.class);
searchHelper.addParams(nativeQuery, pair.getSecond());
@SuppressWarnings("unchecked") List<TariffZone> tariffZones = nativeQuery.list();
return tariffZones;
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneSaverServiceTest method updateTariffZoneShouldHaveValidFromDate.
@Test(expected = IllegalArgumentException.class)
public void updateTariffZoneShouldHaveValidFromDate() {
TariffZone existingTariffZone = new TariffZone();
existingTariffZone.setNetexId(randomizedTestNetexIdGenerator.generateRandomizedNetexId(existingTariffZone));
Geometry geometry = geometryFactory.createPoint(new Coordinate(9.84, 59.26)).buffer(20);
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
existingTariffZone.setPolygon(geometryFactory.createPolygon(linearRing, null));
existingTariffZone.setVersion(2L);
var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
Instant existingTariffZoneFromDate = zonedDateTime.toInstant();
existingTariffZone.setValidBetween(new ValidBetween(existingTariffZoneFromDate, null));
tariffZoneRepository.save(existingTariffZone);
TariffZone newTariffZone = new TariffZone();
newTariffZone.setNetexId(existingTariffZone.getNetexId());
newTariffZone.setName(new EmbeddableMultilingualString("name"));
newTariffZone.setPolygon(null);
Instant newTariffZoneFromDate = zonedDateTime.minusDays(1L).toInstant();
newTariffZone.setValidBetween(new ValidBetween(newTariffZoneFromDate, null));
tariffZoneSaverService.saveNewVersion(newTariffZone);
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneSaverServiceTest method saveExistingTariffZone.
@Test
public void saveExistingTariffZone() {
TariffZone existingTariffZone = new TariffZone();
existingTariffZone.setNetexId(randomizedTestNetexIdGenerator.generateRandomizedNetexId(existingTariffZone));
Geometry geometry = geometryFactory.createPoint(new Coordinate(9.84, 59.26)).buffer(20);
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
existingTariffZone.setPolygon(geometryFactory.createPolygon(linearRing, null));
existingTariffZone.setVersion(2L);
var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
Instant fromDate = zonedDateTime.toInstant();
existingTariffZone.setValidBetween(new ValidBetween(fromDate, null));
tariffZoneRepository.save(existingTariffZone);
TariffZone newTariffZone = new TariffZone();
newTariffZone.setNetexId(existingTariffZone.getNetexId());
newTariffZone.setName(new EmbeddableMultilingualString("name"));
newTariffZone.setPolygon(null);
TariffZone actual = tariffZoneSaverService.saveNewVersion(newTariffZone);
assertThat(actual.getPolygon()).isNull();
assertThat(actual.getVersion()).isEqualTo(3L);
assertThat(actual.getName().getValue()).isEqualTo(newTariffZone.getName().getValue());
}
Aggregations