use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class AddressController method viewDirection.
public void viewDirection(ActionRequest request, ActionResponse response) {
AddressRepository addressRepository = Beans.get(AddressRepository.class);
try {
MapService mapService = Beans.get(MapService.class);
String key = null;
if (Beans.get(AppBaseService.class).getAppBase().getMapApiSelect() == AppBaseRepository.MAP_API_GOOGLE) {
key = mapService.getGoogleMapsApiKey();
}
Company company = Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
if (company == null) {
response.setFlash(I18n.get(IExceptionMessage.PRODUCT_NO_ACTIVE_COMPANY));
return;
}
Address departureAddress = company.getAddress();
if (departureAddress == null) {
response.setFlash(I18n.get(IExceptionMessage.ADDRESS_7));
return;
}
departureAddress = addressRepository.find(departureAddress.getId());
Optional<Pair<BigDecimal, BigDecimal>> departureLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(departureAddress);
if (!departureLatLong.isPresent()) {
response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), departureAddress.getFullName()));
return;
}
Address arrivalAddress = request.getContext().asType(Address.class);
arrivalAddress = addressRepository.find(arrivalAddress.getId());
Optional<Pair<BigDecimal, BigDecimal>> arrivalLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(arrivalAddress);
if (!arrivalLatLong.isPresent()) {
response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), arrivalAddress.getFullName()));
return;
}
Map<String, Object> mapView = new HashMap<>();
mapView.put("title", "Map");
mapView.put("resource", mapService.getDirectionUrl(key, departureLatLong.get(), arrivalLatLong.get()));
mapView.put("viewType", "html");
response.setView(mapView);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class AddressController method updateLatLong.
public void updateLatLong(ActionRequest request, ActionResponse response) {
AddressService addressService = Beans.get(AddressService.class);
try {
Address address = request.getContext().asType(Address.class);
address = Beans.get(AddressRepository.class).find(address.getId());
addressService.resetLatLong(address);
addressService.updateLatLong(address);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class AddressController method autocompleteAddress.
public void autocompleteAddress(ActionRequest request, ActionResponse response) {
Address address = request.getContext().asType(Address.class);
Beans.get(AddressService.class).autocompleteAddress(address);
response.setValues(address);
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class SyncContactService method createAddress.
protected Address createAddress(com.google.api.services.people.v1.model.Address googleAddr) {
Address partnerAddr = new Address();
Country partnerCountry = countryRepo.findByName(googleAddr.getCountry());
if (partnerCountry == null) {
partnerCountry = createCountry(googleAddr.getCountry(), googleAddr.getCountryCode());
}
partnerAddr.setAddressL7Country(partnerCountry);
if (!Strings.isNullOrEmpty(googleAddr.getCity())) {
City partnerCity = cityRepo.findByName(googleAddr.getCity());
if (partnerCity == null) {
partnerCity = createCity(googleAddr.getCity(), partnerCountry);
}
partnerAddr.setCity(partnerCity);
}
StringBuilder addrL4 = new StringBuilder();
if (!Strings.isNullOrEmpty(googleAddr.getPoBox())) {
addrL4.append(googleAddr.getPoBox()).append(" - ");
}
partnerAddr.setZip(googleAddr.getPostalCode());
addrL4.append(googleAddr.getStreetAddress());
partnerAddr.setAddressL4(addrL4.toString());
partnerAddr.setAddressL5(googleAddr.getCity());
partnerAddr.setAddressL2(googleAddr.getExtendedAddress());
partnerAddr.setAddressL6(googleAddr.getPostalCode() + " " + googleAddr.getCity());
partnerAddr.setFullName(Beans.get(AddressService.class).computeFullName(partnerAddr));
partnerAddr.setImportOrigin(importOrigin);
return partnerAddr;
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class MapRest method getPartners.
@Path("/partner")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getPartners() {
ObjectNode mainNode = nodeFactory.objectNode();
try {
List<? extends Partner> partners = partnerRepo.all().filter("self.isCustomer = true OR self.isSupplier = true AND self.isContact=?", false).fetch();
ArrayNode arrayNode = nodeFactory.arrayNode();
for (Partner partner : partners) {
ObjectNode objectNode = nodeFactory.objectNode();
Address address = partnerService.getInvoicingAddress(partner);
if (address != null && StringUtils.notBlank(address.getFullName()) && address.getIsValidLatLong()) {
String addressString = mapRestService.makeAddressString(address, objectNode);
if (StringUtils.isBlank(addressString)) {
continue;
}
objectNode.put("address", addressString);
} else {
continue;
}
objectNode.put("fullName", partner.getFullName());
if (partner.getFixedPhone() != null) {
objectNode.put("fixedPhone", partner.getFixedPhone());
}
if (partner.getEmailAddress() != null) {
objectNode.put("emailAddress", partner.getEmailAddress().getAddress());
}
objectNode.put("pinColor", partner.getIsProspect() ? "red" : "orange");
String pinChar = partner.getIsProspect() ? "P" : "C";
if (partner.getIsSupplier()) {
pinChar = pinChar + "/S";
}
objectNode.put("pinChar", pinChar);
arrayNode.add(objectNode);
}
mapRestService.setData(mainNode, arrayNode);
} catch (Exception e) {
mapRestService.setError(mainNode, e);
}
return mainNode;
}
Aggregations