<link field="name" reltype="has_a" key="name" map="" class="coust"/>
</links>
</class>
- <class id="aoushd" controller="open-ils.cstore" oils_obj:fieldmapper="actor::org_unit_shipping_hub_distance" oils_persist:tablename="actor.org_unit_shipping_hub_distance" reporter:label="Organizational Unit Shipping Hub Distance">
+ <class id="aoushd" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::org_unit_shipping_hub_distance" oils_persist:tablename="actor.org_unit_shipping_hub_distance" reporter:label="Organizational Unit Shipping Hub Distance">
<fields oils_persist:primary="id" oils_persist:sequence="actor.org_unit_shipping_hub_distance_id_seq">
<field name="id" />
<field name="orig_hub" reporter:datatype="org_unit"/>
<field name="distance" reporter:datatype="int"/>
</fields>
<links>
- <link field="org_unit" reltype="has_a" key="id" map="" class="aou"/>
- <link field="hub" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="orig_hub" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="dest_hub" reltype="has_a" key="id" map="" class="aou"/>
</links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <create permission="UPDATE_ORG_UNIT" context_field="orig_hub"/>
+ <retrieve/>
+ <update permission="UPDATE_ORG_UNIT" context_field="orig_hub"/>
+ <delete permission="UPDATE_ORG_UNIT" context_field="orig_hub"/>
+ </actions>
+ </permacrud>
</class>
<class id="acpn" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="asset::copy_note" oils_persist:tablename="asset.copy_note" reporter:label="Copy Note">
<fields oils_persist:primary="id" oils_persist:sequence="asset.copy_note_id_seq">
<eg-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
</eg-staff-banner>
<div class="alert alert-info" i18n>
- Entries in this table contain the distance in miles between shipping locations. Shipping hubs are configured from the Orginizational Units page. These numbers are used for sorting hold targets during inter-library lending. Entries can be created manually or calculated using the free Bing Maps API if a key has been set up in the opensrf core config file. <b>Running the API will remove any existing data from this table</b>.
+ Entries in this table contain the distance in kilometers between shipping hub locations. If configured for your service, driving distance will be used instead of as-the-crow-flies. Shipping hubs are configured from the Orginizational Units page. These numbers are used for sorting hold targets during inter-library lending. Entries can be created manually or calculated using your geolocation service. <b>Recalculating the distances will clear out any existing data.</b>.
</div>
- <button [disabled]="calculating" class="btn btn-outline-dark" (click)="calculateDistances()">Calculate with API</button>
+ <button [disabled]="calculating" class="btn btn-outline-dark" (click)="calculateDistances()">Calculate with Geolocation Service</button>
<eg-progress-inline *ngIf="calculating" ></eg-progress-inline>
<br>
<br>
constructor(
private route: ActivatedRoute,
private idl: IdlService,
- private net: NetService
+ private net: NetService,
private auth: AuthService
) {
}
this.canCreate = false;
const pc = this.idlClassDef.permacrud || {};
const perms = pc.create ? pc.create.perms : [];
- if (perms.length === 0) { return; }
-
+ console.log(perms);
+ if (perms.length === 0) { return; }
this.perm.hasWorkPermAt(perms, true).then(permMap => {
+ console.log(permMap);
Object.keys(permMap).forEach(key => {
if (permMap[key].length > 0) {
this.canCreate = true;
my ($bing, $uri, $form, $json_coder) = @_;
my $json = $json_coder->encode($form);
return unless $uri;
- $logger->info($uri);
- $logger->info($form);
+ #$logger->info($uri);
+ #$logger->info($form);
my $res = $bing->{response} = $bing->ua->post($uri,'Content-Length' => 3500,'Content-Type' => 'application/json',Content => $json);
unless($res->is_success){
$logger->error("API ERROR\n");
+ my @error = split /\n/, $res->decoded_content;
+ foreach(@error){
+ $logger->error($_);
+ }
return;
- }
-
- my @error = split /\n/, $res->decoded_content;
- foreach(@error){
- $logger->error($_);
- }
-
+ }
# Change the content type of the response from 'application/json' so
# HTTP::Message will decode the character encoding.
$res->content_type('text/plain');
$dcoord{'longitude'} = $_->[1];
push(@destinations, \%dcoord);
}
- $logger->info(Dumper(\@destinations));
+ #$logger->info(Dumper(\@destinations));
# find out how many coords we can process per request.
my $budget = int(2500 / scalar(@origins));
return \@results;
}
- return [];
+ return \@results;
}
__PACKAGE__->register_method(
my $geo = OpenSRF::AppSession->create('open-ils.geo');
my $geo_request = $geo->request('open-ils.geo.calculate_bulk_driving_distance',
$self->{auth}, \@origins, \@destinations);
- my @distance_matrix = @{$geo_request};
+ my $result = $geo_request->recv();
+ my $content = $result->content();
+ $logger->info("content from API: ".Dumper($content));
+ my @distance_matrix = @{$content};
if(@distance_matrix){
$self->{editor}->xact_begin;
# clear out existing matrix
+ $logger->info("Old distance matrix is being cleared out.");
$self->clear_hub_distances();
- for my $ref (@distance_matrix) {
- for (@$ref){
+ foreach(@distance_matrix) {
+ print(Dumper $_);
# create our AOUSHD objects for the data returned
my $dist = Fieldmapper::actor::org_unit_shipping_hub_distance->new;
- $dist->orig_hub($hub_ids[$_->{originIndex}]);
- $dist->dest_hub($hub_ids[$_->{destinationIndex}]);
- $dist->distance($_->{travelDistance});
+ $dist->orig_hub($hub_ids[$_->{origin}]);
+ $dist->dest_hub($hub_ids[$_->{destination}]);
+ $dist->distance($_->{distance});
# place AOUSHD into the DB
$self->{editor}->runmethod('create', 'actor.org_unit_shipping_hub_distance', 'aoushd', $dist);
- }
+
}
# commit to DB
$self->{editor}->xact_commit;
}
}
+sub get_coord_from_ou {
+my($self,@org_ids) = @_;
+ my @ma = $self->{editor}->json_query({
+ select => {
+ aoa => [
+ {
+ column => 'org_unit',
+ },
+ {
+ column => 'latitude',
+ },{
+ column => 'longitude',
+ },{
+ column => 'address_type',
+ }
+ ]
+ },
+ from => 'aoa',
+ where => {org_unit=>[@org_ids], address_type=>['MAILING']}
+ });
+ my %coords;
+
+ for my $ref (@ma) {
+ for (@$ref){
+ $coords{$_->{org_unit}} = [$_->{latitude}, $_->{longitude}];
+ }
+ }
+ return %coords;
+}
+
# remove all existing distance calculations.
# TODO make this all happen in one query
# what could the analog to DELETE FROM TABLE be?