Search in sources :

Example 11 with TariffZone

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();
}
Also used : GraphQLList(graphql.schema.GraphQLList) CustomGraphQLTypes.alternativeNameObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.alternativeNameObjectType) MultiModalityOperationsBuilder(org.rutebanken.tiamat.rest.graphql.operations.MultiModalityOperationsBuilder) CustomGraphQLTypes.embeddableMultiLingualStringInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.embeddableMultiLingualStringInputObjectType) GroupOfTariffZones(org.rutebanken.tiamat.model.GroupOfTariffZones) Quay(org.rutebanken.tiamat.model.Quay) GraphQLString(graphql.Scalars.GraphQLString) StopPlaceInterfaceCreator(org.rutebanken.tiamat.rest.graphql.types.StopPlaceInterfaceCreator) CustomGraphQLTypes.geoJsonInputType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.geoJsonInputType) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GroupOfTariffZonesObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.GroupOfTariffZonesObjectTypeCreator) CustomGraphQLTypes.alternativeNameInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.alternativeNameInputObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GroupOfStopPlacesObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.GroupOfStopPlacesObjectTypeCreator) AuthorizationCheckCreator.createAuthorizationCheckOutputType(org.rutebanken.tiamat.rest.graphql.types.AuthorizationCheckCreator.createAuthorizationCheckOutputType) StopPlace(org.rutebanken.tiamat.model.StopPlace) StopPlaceOperationsBuilder(org.rutebanken.tiamat.rest.graphql.operations.StopPlaceOperationsBuilder) GraphQLInputObjectField.newInputObjectField(graphql.schema.GraphQLInputObjectField.newInputObjectField) CustomGraphQLTypes.modificationEnumerationType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.modificationEnumerationType) PathLinkObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.PathLinkObjectTypeCreator) CustomGraphQLTypes.equipmentType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.equipmentType) GraphQLObjectType(graphql.schema.GraphQLObjectType) TariffZoneObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.TariffZoneObjectTypeCreator) GraphQLNonNull(graphql.schema.GraphQLNonNull) ZoneCommonFieldListCreator(org.rutebanken.tiamat.rest.graphql.types.ZoneCommonFieldListCreator) CustomGraphQLTypes.accessibilityAssessmentInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.accessibilityAssessmentInputObjectType) TopographicPlaceObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.TopographicPlaceObjectTypeCreator) AuthorizationCheckDataFetcher(org.rutebanken.tiamat.rest.graphql.fetchers.AuthorizationCheckDataFetcher) Page(org.springframework.data.domain.Page) GraphQLArgument(graphql.schema.GraphQLArgument) MutableTypeResolver(org.rutebanken.tiamat.rest.graphql.resolvers.MutableTypeResolver) GraphQLFieldDefinition.newFieldDefinition(graphql.schema.GraphQLFieldDefinition.newFieldDefinition) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) CustomGraphQLTypes.keyValuesObjectInputType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.keyValuesObjectInputType) List(java.util.List) CustomGraphQLTypes.privateCodeInputType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.privateCodeInputType) GraphQLBoolean(graphql.Scalars.GraphQLBoolean) CustomGraphQLTypes.interchangeWeightingEnum(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.interchangeWeightingEnum) TariffZoneTerminator(org.rutebanken.tiamat.service.TariffZoneTerminator) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) TagFetcher(org.rutebanken.tiamat.rest.graphql.fetchers.TagFetcher) ParentStopPlaceObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.ParentStopPlaceObjectTypeCreator) PostConstruct(javax.annotation.PostConstruct) CustomGraphQLTypes.scopingMethodEnumType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.scopingMethodEnumType) GraphQLNames(org.rutebanken.tiamat.rest.graphql.GraphQLNames) ParkingOperationsBuilder(org.rutebanken.tiamat.rest.graphql.operations.ParkingOperationsBuilder) CustomGraphQLTypes.pathLinkObjectInputType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.pathLinkObjectInputType) GraphQLInputObjectType.newInputObject(graphql.schema.GraphQLInputObjectType.newInputObject) TagObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.TagObjectTypeCreator) CustomGraphQLTypes.createParkingInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.createParkingInputObjectType) CustomGraphQLTypes.zoneTopologyEnumType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.zoneTopologyEnumType) CustomGraphQLTypes.topographicPlaceInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.topographicPlaceInputObjectType) TariffZone(org.rutebanken.tiamat.model.TariffZone) CustomGraphQLTypes.geometryFieldDefinition(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.geometryFieldDefinition) ArrayList(java.util.ArrayList) CustomGraphQLTypes.boardingPositionsInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.boardingPositionsInputObjectType) CustomGraphQLTypes.stopPlaceTypeEnum(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.stopPlaceTypeEnum) CustomGraphQLTypes.equipmentInputType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.equipmentInputType) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) FareZone(org.rutebanken.tiamat.model.FareZone) GraphQLBigDecimal(graphql.Scalars.GraphQLBigDecimal) ParentStopPlaceInputObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.ParentStopPlaceInputObjectTypeCreator) EntityRefObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.EntityRefObjectTypeCreator) DateScalar(org.rutebanken.tiamat.rest.graphql.scalars.DateScalar) CustomGraphQLTypes.accessibilityAssessmentObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.accessibilityAssessmentObjectType) CustomGraphQLTypes.privateCodeFieldDefinition(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.privateCodeFieldDefinition) CustomGraphQLTypes.transportModeSubmodeObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.transportModeSubmodeObjectType) CustomGraphQLTypes.versionValidityEnumType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.versionValidityEnumType) TransportModeScalar(org.rutebanken.tiamat.rest.graphql.scalars.TransportModeScalar) GraphQLArgument.newArgument(graphql.schema.GraphQLArgument.newArgument) CustomGraphQLTypes.boardingPositionsObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.boardingPositionsObjectType) CustomGraphQLTypes.createParkingObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.createParkingObjectType) TagOperationsBuilder(org.rutebanken.tiamat.rest.graphql.operations.TagOperationsBuilder) Component(org.springframework.stereotype.Component) GraphQLList(graphql.schema.GraphQLList) CustomGraphQLTypes.versionLessRefInputObjectType(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.versionLessRefInputObjectType) PathLinkEndObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.PathLinkEndObjectTypeCreator) FareZoneObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.FareZoneObjectTypeCreator) StopPlaceObjectTypeCreator(org.rutebanken.tiamat.rest.graphql.types.StopPlaceObjectTypeCreator) GraphQLInt(graphql.Scalars.GraphQLInt) AuthorizationCheckCreator.createAuthorizationCheckArguments(org.rutebanken.tiamat.rest.graphql.types.AuthorizationCheckCreator.createAuthorizationCheckArguments) CustomGraphQLTypes.topographicPlaceTypeEnum(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.topographicPlaceTypeEnum) CustomGraphQLTypes.netexIdFieldDefinition(org.rutebanken.tiamat.rest.graphql.types.CustomGraphQLTypes.netexIdFieldDefinition) StopPlace(org.rutebanken.tiamat.model.StopPlace) ArrayList(java.util.ArrayList) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) MutableTypeResolver(org.rutebanken.tiamat.rest.graphql.resolvers.MutableTypeResolver) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLNonNull(graphql.schema.GraphQLNonNull) Quay(org.rutebanken.tiamat.model.Quay) PostConstruct(javax.annotation.PostConstruct)

Example 12 with TariffZone

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;
}
Also used : TariffZone(org.rutebanken.tiamat.model.TariffZone) NativeQuery(org.hibernate.query.NativeQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList)

Example 13 with TariffZone

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;
}
Also used : TariffZone(org.rutebanken.tiamat.model.TariffZone) NativeQuery(org.hibernate.query.NativeQuery) HashMap(java.util.HashMap) Map(java.util.Map) Session(org.hibernate.Session)

Example 14 with TariffZone

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);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TariffZone(org.rutebanken.tiamat.model.TariffZone) Coordinate(org.locationtech.jts.geom.Coordinate) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) LinearRing(org.locationtech.jts.geom.LinearRing) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 15 with TariffZone

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());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TariffZone(org.rutebanken.tiamat.model.TariffZone) Coordinate(org.locationtech.jts.geom.Coordinate) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) LinearRing(org.locationtech.jts.geom.LinearRing) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

TariffZone (org.rutebanken.tiamat.model.TariffZone)25 Test (org.junit.Test)18 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)16 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)14 StopPlace (org.rutebanken.tiamat.model.StopPlace)8 Instant (java.time.Instant)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 Geometry (org.locationtech.jts.geom.Geometry)5 LinearRing (org.locationtech.jts.geom.LinearRing)5 CoordinateArraySequence (org.locationtech.jts.geom.impl.CoordinateArraySequence)5 TariffZoneSearch (org.rutebanken.tiamat.exporter.params.TariffZoneSearch)5 TariffZoneRef (org.rutebanken.tiamat.model.TariffZoneRef)5 ValidBetween (org.rutebanken.tiamat.model.ValidBetween)4 SiteFrame (org.rutebanken.netex.model.SiteFrame)3 StopPlace (org.rutebanken.netex.model.StopPlace)3 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)3 TariffZoneRefs_RelStructure (org.rutebanken.netex.model.TariffZoneRefs_RelStructure)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2