Search in sources :

Example 1 with GeographicalCoordinates

use of de.metas.location.geocoding.GeographicalCoordinates in project metasfresh-webui-api by metasfresh.

the class GeoLocationFilterConverter method getSql.

@Override
public String getSql(@NonNull final SqlParamsCollector sqlParamsOut, @NonNull final DocumentFilter filter, @NonNull final SqlOptions sqlOpts, final SqlDocumentFilterConverterContext context_NOTUSED) {
    final GeoLocationDocumentDescriptor descriptor = filter.getParameterValueAs(PARAM_LocationAreaSearchDescriptor);
    if (descriptor == null) {
        // shall not happen
        logger.warn("Cannot convert filter to SQL because parameter {} is not set: {}", PARAM_LocationAreaSearchDescriptor, filter);
        return null;
    }
    final GeographicalCoordinates addressCoordinates = getAddressCoordinates(filter).orElse(null);
    if (addressCoordinates == null) {
        logger.warn("Cannot convert filter to SQL because geo coordinates not found for {}", filter);
        throw new AdempiereException(MSG_NoCoordinatesFoundForTheGivenLocation).markAsUserValidationError();
    }
    final String visitorAddressQuery = constructVisitorAddressQuery(filter);
    final int distanceInKm = extractDistanceInKm(filter);
    if (LocationColumnNameType.LocationId.equals(descriptor.getType())) {
        return "EXISTS (" + " SELECT 1" + " FROM " + I_C_Location.Table_Name + " l" + " WHERE " + " l." + I_C_Location.COLUMNNAME_C_Location_ID + "=" + sqlOpts.getTableNameOrAlias() + "." + descriptor.getLocationColumnName() + // no visitorAddressQuery here
        " AND " + sqlGeographicalDistance(sqlParamsOut, "l", addressCoordinates, distanceInKm) + ")";
    } else if (LocationColumnNameType.BPartnerLocationId.equals(descriptor.getType())) {
        return "EXISTS (" + " SELECT 1" + " FROM " + I_C_BPartner_Location.Table_Name + " bpl" + " INNER JOIN " + I_C_Location.Table_Name + " l ON l." + I_C_Location.COLUMNNAME_C_Location_ID + "=bpl." + I_C_BPartner_Location.COLUMNNAME_C_Location_ID + " WHERE " + " bpl." + I_C_BPartner_Location.COLUMNNAME_C_BPartner_Location_ID + "=" + sqlOpts.getTableNameOrAlias() + "." + descriptor.getLocationColumnName() + visitorAddressQuery + " AND " + sqlGeographicalDistance(sqlParamsOut, "l", addressCoordinates, distanceInKm) + ")";
    } else if (LocationColumnNameType.BPartnerId.equals(descriptor.getType())) {
        return "EXISTS (" + " SELECT 1" + " FROM " + I_C_BPartner.Table_Name + " bp" + " INNER JOIN " + I_C_BPartner_Location.Table_Name + " bpl ON bpl." + I_C_BPartner_Location.COLUMNNAME_C_BPartner_ID + "=bp." + I_C_BPartner.COLUMNNAME_C_BPartner_ID + " INNER JOIN " + I_C_Location.Table_Name + " l ON l." + I_C_Location.COLUMNNAME_C_Location_ID + "=bpl." + I_C_BPartner_Location.COLUMNNAME_C_Location_ID + " WHERE " + " bp." + I_C_BPartner.COLUMNNAME_C_BPartner_ID + "=" + sqlOpts.getTableNameOrAlias() + "." + descriptor.getLocationColumnName() + " AND bpl." + I_C_BPartner_Location.COLUMNNAME_IsActive + "='Y'" + visitorAddressQuery + " AND " + sqlGeographicalDistance(sqlParamsOut, "l", addressCoordinates, distanceInKm) + ")";
    } else {
        throw new AdempiereException("Unknown " + descriptor.getType());
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) GeographicalCoordinates(de.metas.location.geocoding.GeographicalCoordinates)

Example 2 with GeographicalCoordinates

use of de.metas.location.geocoding.GeographicalCoordinates in project metasfresh-webui-api by metasfresh.

the class ViewGeoLocationsRestController method retrieveGeoLocationsForBPartnerLocationId.

private List<JsonViewRowGeoLocation> retrieveGeoLocationsForBPartnerLocationId(final ImmutableSetMultimap<Integer, DocumentId> rowIdsByBPartnerLocationRepoId) {
    if (rowIdsByBPartnerLocationRepoId.isEmpty()) {
        return ImmutableList.of();
    }
    final List<JsonViewRowGeoLocation> result = new ArrayList<>();
    final ImmutableSet<Integer> bpartnerLocationRepoIds = rowIdsByBPartnerLocationRepoId.keySet();
    for (final GeographicalCoordinatesWithBPartnerLocationId bplCoordinates : bpartnersRepo.getGeoCoordinatesByBPartnerLocationIds(bpartnerLocationRepoIds)) {
        final int bpartnerLocationRepoId = bplCoordinates.getBpartnerLocationId().getRepoId();
        final ImmutableSet<DocumentId> rowIds = rowIdsByBPartnerLocationRepoId.get(bpartnerLocationRepoId);
        if (rowIds.isEmpty()) {
            // shall not happen
            logger.warn("Ignored unexpected bpartnerLocationId={}. We have no rows for it.", bpartnerLocationRepoId);
            continue;
        }
        final GeographicalCoordinates coordinate = bplCoordinates.getCoordinate();
        for (final DocumentId rowId : rowIds) {
            result.add(JsonViewRowGeoLocation.builder().rowId(rowId).latitude(coordinate.getLatitude()).longitude(coordinate.getLongitude()).build());
        }
    }
    return result;
}
Also used : GeographicalCoordinatesWithBPartnerLocationId(de.metas.bpartner.GeographicalCoordinatesWithBPartnerLocationId) ArrayList(java.util.ArrayList) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) JsonViewRowGeoLocation(de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation) GeographicalCoordinates(de.metas.location.geocoding.GeographicalCoordinates)

Example 3 with GeographicalCoordinates

use of de.metas.location.geocoding.GeographicalCoordinates in project metasfresh-webui-api by metasfresh.

the class ViewGeoLocationsRestController method retrieveGeoLocationsForBPartnerId.

private List<JsonViewRowGeoLocation> retrieveGeoLocationsForBPartnerId(final ImmutableSetMultimap<BPartnerId, DocumentId> rowIdsByBPartnerId) {
    if (rowIdsByBPartnerId.isEmpty()) {
        return ImmutableList.of();
    }
    final List<JsonViewRowGeoLocation> result = new ArrayList<>();
    final ImmutableSet<BPartnerId> bpartnerIds = rowIdsByBPartnerId.keySet();
    for (final GeographicalCoordinatesWithBPartnerLocationId bplCoordinates : bpartnersRepo.getGeoCoordinatesByBPartnerIds(bpartnerIds)) {
        final BPartnerId bpartnerId = bplCoordinates.getBPartnerId();
        final ImmutableSet<DocumentId> rowIds = rowIdsByBPartnerId.get(bpartnerId);
        if (rowIds.isEmpty()) {
            // shall not happen
            logger.warn("Ignored unexpected bpartnerId={}. We have no rows for it.", bpartnerId);
            continue;
        }
        final GeographicalCoordinates coordinate = bplCoordinates.getCoordinate();
        for (final DocumentId rowId : rowIds) {
            result.add(JsonViewRowGeoLocation.builder().rowId(rowId).latitude(coordinate.getLatitude()).longitude(coordinate.getLongitude()).build());
        }
    }
    return result;
}
Also used : GeographicalCoordinatesWithBPartnerLocationId(de.metas.bpartner.GeographicalCoordinatesWithBPartnerLocationId) ArrayList(java.util.ArrayList) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) BPartnerId(de.metas.bpartner.BPartnerId) JsonViewRowGeoLocation(de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation) GeographicalCoordinates(de.metas.location.geocoding.GeographicalCoordinates)

Aggregations

GeographicalCoordinates (de.metas.location.geocoding.GeographicalCoordinates)3 GeographicalCoordinatesWithBPartnerLocationId (de.metas.bpartner.GeographicalCoordinatesWithBPartnerLocationId)2 JsonViewRowGeoLocation (de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 ArrayList (java.util.ArrayList)2 BPartnerId (de.metas.bpartner.BPartnerId)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1