Search in sources :

Example 1 with JsonViewRowGeoLocation

use of de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation in project metasfresh-webui-api by metasfresh.

the class ViewGeoLocationsRestController method getAll.

@GetMapping
public JsonViewGeoLocationsResult getAll(@PathVariable(PARAM_WindowId) final String windowIdStr, @PathVariable(PARAM_ViewId) final String viewIdStr, @RequestParam(value = "limit", required = false, defaultValue = "0") final int limit) {
    userSession.assertLoggedIn();
    final ViewId viewId = ViewId.of(windowIdStr, viewIdStr);
    final int limitEffective = limit > 0 ? limit : DEFAULT_LIMIT;
    final IView view = viewsRepo.getView(viewId);
    final ImmutableSet<String> viewFieldNames = getViewFieldNames(view);
    final GeoLocationDocumentDescriptor geoLocationDescriptor = geoLocationDocumentService.getGeoLocationDocumentDescriptor(viewFieldNames);
    final ViewRowsOrderBy orderBy = ViewRowsOrderBy.of(view.getDefaultOrderBys(), newJsonOpts());
    final ViewResult rows = view.getPage(0, limitEffective, orderBy);
    final List<JsonViewRowGeoLocation> geoLocations = retrieveGeoLocations(rows, geoLocationDescriptor);
    return JsonViewGeoLocationsResult.builder().viewId(viewId.toJson()).locations(geoLocations).build();
}
Also used : IView(de.metas.ui.web.view.IView) ViewId(de.metas.ui.web.view.ViewId) JsonViewRowGeoLocation(de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation) ViewResult(de.metas.ui.web.view.ViewResult) ViewRowsOrderBy(de.metas.ui.web.view.ViewRowsOrderBy) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with JsonViewRowGeoLocation

use of de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation 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 JsonViewRowGeoLocation

use of de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation 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

JsonViewRowGeoLocation (de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation)3 GeographicalCoordinatesWithBPartnerLocationId (de.metas.bpartner.GeographicalCoordinatesWithBPartnerLocationId)2 GeographicalCoordinates (de.metas.location.geocoding.GeographicalCoordinates)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 ArrayList (java.util.ArrayList)2 BPartnerId (de.metas.bpartner.BPartnerId)1 IView (de.metas.ui.web.view.IView)1 ViewId (de.metas.ui.web.view.ViewId)1 ViewResult (de.metas.ui.web.view.ViewResult)1 ViewRowsOrderBy (de.metas.ui.web.view.ViewRowsOrderBy)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1