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();
}
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;
}
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;
}
Aggregations