Skip to content

Commit 5e05ef6

Browse files
committed
fix iplan url query
1 parent 6daec0a commit 5e05ef6

5 files changed

Lines changed: 121 additions & 120 deletions

File tree

server/api/controller/cron.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ const PlanAreaChangesController = require('../controller/plan_area_changes');
2020
const getPlanTagger = require('../lib/tags');
2121
const PlanStatusChange = require('../model/plan_status_change');
2222
const { meirimStatuses } = require('../constants');
23-
const { report } = require('../../metrics')
23+
const { report } = require('../../metrics');
2424

2525
const iplan = (limit = -1) =>
2626
iplanApi
2727
.getBlueLines()
2828
.then(iPlans => {
29-
report({metricName: "iplane.bluelines.count", value: iPlans.length})
29+
report({ metricName: 'iplane.bluelines.count', value: iPlans.length });
3030

3131
// limit blue lines found so we output only *limit* plans
3232
if (limit > -1) {
@@ -35,7 +35,7 @@ const iplan = (limit = -1) =>
3535

3636
return Bluebird.mapSeries(iPlans, iPlan => fetchIplan(iPlan));
3737
}).catch(e => {
38-
Log.error(`Error fetching new plans`, e);
38+
Log.error('Error fetching new plans', e);
3939
});
4040

4141
const fix_geodata = () => {
@@ -69,27 +69,27 @@ const complete_mavat_data = () =>
6969
})
7070
.fetchAll()
7171
.then(planCollection => {
72-
Log.info({ message: "found incomplete mavat data", length: planCollection.length })
72+
Log.info({ message: 'found incomplete mavat data', length: planCollection.length });
7373
return planCollection;
7474
})
7575
.then(planCollection =>
7676

77-
Bluebird.mapSeries(planCollection.models, plan => {
78-
Log.info({ message: "about to work on plan", id: plan.get("id"), url: plan.get('plan_url') })
77+
Bluebird.mapSeries(planCollection.models, plan => {
78+
Log.info({ message: 'about to work on plan', id: plan.get('id'), url: plan.get('plan_url') });
7979

8080
return MavatAPI.getByPlan(plan)
8181
.then(mavatData => {
82-
Log.info({message: 'Saving with mavat',data: JSON.stringify(mavatData)});
82+
Log.info({ message: 'Saving with mavat',data: JSON.stringify(mavatData) });
8383
return Plan.setMavatData(plan, mavatData).then(Promise.all([plan.save(),
8484
PlanAreaChangesController.refreshPlanAreaChanges(plan.id, plan.attributes.areaChanges)
85-
]))
85+
]));
8686
})
8787
.catch((e) => {
88-
Log.error({message: "failure in complete_mavat_data", e, id: plan.get("id")})
88+
Log.error({ message: 'failure in complete_mavat_data', e, id: plan.get('id') });
8989
// do nothing on error
9090
}).finally(() => {
91-
Log.info({ message: "finish working on plan", id: plan.get("id") })
92-
})
91+
Log.info({ message: 'finish working on plan', id: plan.get('id') });
92+
});
9393
})
9494
);
9595

@@ -121,7 +121,7 @@ const sendPlanningAlerts = () => {
121121
limit: 1
122122
})
123123
.then(unsentPlans => {
124-
report({ metricName: "planning_alerts.unsent", value: unsentPlans.models.length })
124+
report({ metricName: 'planning_alerts.unsent', value: unsentPlans.models.length });
125125
Log.debug('Got', unsentPlans.models.length, 'Plans');
126126
return unsentPlans.models;
127127
})
@@ -418,17 +418,17 @@ const fetchPlanStatus = () => {
418418
const dateString = moment(date).format('YYYY-MM-DD h:mm');
419419
return Plan.query(qb => {
420420
qb.leftJoin('status_mapping', 'plan.status', '=' ,'status_mapping.mavat_status')
421-
.whereRaw(`(status_mapping.meirim_status is null or status_mapping.meirim_status != '${meirimStatuses.APPROVED}') and plan.MP_ID NOT LIKE \'NOT_FOUND\' and (plan.last_visited_status < '${dateString}' OR plan.last_visited_status IS NULL)`)
422-
.orderBy('plan.last_visited_status','asc');
421+
.whereRaw(`(status_mapping.meirim_status is null or status_mapping.meirim_status != '${meirimStatuses.APPROVED}') and plan.MP_ID NOT LIKE \'NOT_FOUND\' and (plan.last_visited_status < '${dateString}' OR plan.last_visited_status IS NULL)`)
422+
.orderBy('plan.last_visited_status','asc');
423423
qb.limit(planStatusLimit);
424424
})
425425
.fetchAll()
426426
.then(planCollection =>
427427
Bluebird.mapSeries(planCollection.models, plan => {
428428

429429
Log.info({
430-
planId: plan.get("id") ,
431-
message: "working on plan",
430+
planId: plan.get('id') ,
431+
message: 'working on plan',
432432
last_visited_status: plan.get('last_visited_status'),
433433
status:plan.get('status'),
434434
});
@@ -461,7 +461,7 @@ const fetchPlanStatus = () => {
461461
return;
462462
}
463463
const mostRecentStatus = mostRecent[0].attributes.status;
464-
Log.info({message: 'updating plan status', status: mostRecentStatus, planId: plan.get('id'), oldStatus: plan.get('status')});
464+
Log.info({ message: 'updating plan status', status: mostRecentStatus, planId: plan.get('id'), oldStatus: plan.get('status') });
465465
await plan.save({ 'last_visited_status': now , 'status': mostRecentStatus });
466466

467467
// save all plan statuses into plan_status_change table
@@ -475,13 +475,13 @@ const fetchPlanStatus = () => {
475475
await sendEmailIfNeeded(plan, planStatuses, mavatStatus);
476476
}
477477
catch (err) {
478-
Log.error({err});
478+
Log.error({ err });
479479
const now = moment().format('YYYY-MM-DD HH:mm:ss');
480480
await plan.save({ 'last_visited_status': now });
481481
}
482482
})
483483
.catch(async (err)=> {
484-
Log.error({err});
484+
Log.error({ err });
485485
const now = moment().format('YYYY-MM-DD HH:mm:ss');
486486
await plan.save({ 'last_visited_status': now });
487487
});

server/api/lib/iplanApi.js

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const axios = require('axios');
22
const GeoJSON = require('esri-to-geojson');
33
const Bluebird = require('bluebird');
44
const _ = require('lodash');
5-
const { map, chunk, reduce, extend, get } = require('lodash');
65
// const proj4 = require('proj4');
76
const reproject = require('reproject');
87
const Config = require('../lib/config');
@@ -13,7 +12,7 @@ const BASE_AGS_URL =
1312
// "https://ags.iplan.gov.il/arcgis/rest/services/" +
1413
// "PlanningPublic/Xplan_2039/MapServer";
1514

16-
const MAVAT_SERVICE_ID = 1;
15+
//const MAVAT_SERVICE_ID = 1;
1716

1817
const options = {
1918
rejectUnauthorized: false,
@@ -23,39 +22,39 @@ const options = {
2322
json: true
2423
};
2524

26-
const fields = [
27-
'objectid',
28-
'shape',
29-
// 'plan_area_code',
30-
// 'jurstiction_code',
31-
'plan_county_name',
32-
// 'plan_county_code',
33-
'entity_subtype_desc',
34-
'pl_number',
35-
'pl_name',
36-
'pl_area_dunam',
37-
'depositing_date',
38-
'mp_id',
39-
// 'DATE_SAF',
40-
// 'PL_LAST_DEPOSIT_DATE',
41-
// 'PL_REJECTION_DATE',
42-
// 'PLAN_CHARACTOR_NAME',
43-
// 'מטרות',
44-
// 'PQ_AUTHORISED_QUANTITY_110',
45-
// 'PQ_AUTHORISED_QUANTITY_120',
46-
'pl_date_8',
47-
'pl_landuse_string',
48-
// 'station',
49-
'station_desc',
50-
'pl_by_auth_of',
51-
'pl_url',
52-
'shape_area',
53-
'quantity_delta_120',
54-
'quantity_delta_125',
55-
'last_update',
56-
'pl_order_print_version',
57-
'pl_tasrit_prn_version'
58-
];
25+
// const fields = [
26+
// 'objectid',
27+
// 'shape',
28+
// // 'plan_area_code',
29+
// // 'jurstiction_code',
30+
// 'plan_county_name',
31+
// // 'plan_county_code',
32+
// 'entity_subtype_desc',
33+
// 'pl_number',
34+
// 'pl_name',
35+
// 'pl_area_dunam',
36+
// 'depositing_date',
37+
// 'mp_id',
38+
// // 'DATE_SAF',
39+
// // 'PL_LAST_DEPOSIT_DATE',
40+
// // 'PL_REJECTION_DATE',
41+
// // 'PLAN_CHARACTOR_NAME',
42+
// // 'מטרות',
43+
// // 'PQ_AUTHORISED_QUANTITY_110',
44+
// // 'PQ_AUTHORISED_QUANTITY_120',
45+
// 'pl_date_8',
46+
// 'pl_landuse_string',
47+
// // 'station',
48+
// 'station_desc',
49+
// 'pl_by_auth_of',
50+
// 'pl_url',
51+
// 'shape_area',
52+
// 'quantity_delta_120',
53+
// 'quantity_delta_125',
54+
// 'last_update',
55+
// 'pl_order_print_version',
56+
// 'pl_tasrit_prn_version'
57+
// ];
5958

6059
// const EPSG2039 = proj4.Proj(
6160
// '+proj=tmerc +lat_0=31.73439361111111 +lon_0=35.20451694444445 +k=1.0000067 +x_0=219529.584 +y_0=626907.39 +ellps=GRS80 +towgs84=-48,55,52,0,0,0,0 +units=m +no_defs'
@@ -65,10 +64,13 @@ const EPSG3857 =
6564
'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs';
6665

6766
// TODO: save the links of the new website and the old website
68-
const buildMavatURL = (serviceId, fieldsToFill, whereClause, return_geom) => {
69-
return `${BASE_AGS_URL}/${serviceId}/query?f=json&outFields=${fieldsToFill.join(
70-
','
71-
)}&returnGeometry=${return_geom}&where=${whereClause}&orderByFields=last_update DESC&outSR=3857`;
67+
//const buildMavatURL = (serviceId, fieldsToFill, whereClause, return_geom)
68+
const buildMavatURL = () => {
69+
// return `${BASE_AGS_URL}/${serviceId}/query?f=json&outFields=${fieldsToFill.join(
70+
// ','
71+
// )}&returnGeometry=${return_geom}&where=${whereClause}&outSR=3857`;
72+
73+
return 'https://ags.iplan.gov.il/arcgisiplan/rest/services/PlanningPublic/Xplan/MapServer/1/query?f=json&outFields=objectid,shape,plan_county_name,entity_subtype_desc,pl_number&returnGeometry=true&where=objectid%3E0&outSR=3857';
7274
};
7375

7476

@@ -82,12 +84,12 @@ const getBlueLines = async () => {
8284
// we need MP_ID field to know the id in the new mavat website.
8385
// xplan doesn't have MP_ID in the polygons API (service id of 0)
8486
// so we query the centroid API (service id of 1) as well in order to get MP_ID.
85-
const urlWithPolygons = buildMavatURL(MAVAT_SERVICE_ID, fields, 'objectid > 0', 'true');
86-
87+
const urlWithPolygons = buildMavatURL();
88+
Log.info(`urlWithPolygons: ${urlWithPolygons}`);
8789
try {
8890
const responseWithPolygons = await axios.get(urlWithPolygons, options);
8991
const geojson = GeoJSON.fromEsri(responseWithPolygons.data, {});
90-
Log.info('mavat plans', {plans: geojson.features.length});
92+
Log.info('mavat plans', { plans: geojson.features.length });
9193

9294
// Need to populate all plans with their MP_ID
9395
// TODO- export to a mapping function

server/api/model/plan.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class Plan extends Model {
367367
PLAN_COUNTY_NAME: iPlan.properties.PLAN_COUNTY_NAME || '',
368368
PL_NUMBER: iPlan.properties.PL_NUMBER || '',
369369
PL_NAME: iPlan.properties.PL_NAME || '',
370-
plan_display_name: Plan.cleanPlanName(iPlan.properties.PL_NAME),
370+
plan_display_name: iPlan.properties.PL_NAME? Plan.cleanPlanName(iPlan.properties.PL_NAME): '',
371371
// 'PLAN_CHARACTOR_NAME': iPlan.properties.PLAN_CHARACTOR_NAME || '',
372372
data: iPlan.properties,
373373
geom: iPlan.geometry,

server/bin/iplan

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
const controller = require('../api/controller/cron');
44
const Log = require('../api/lib/log');
5-
const axios = require('axios');
6-
const Config = require('../api/lib/config');
7-
const { runAndReport } = require('../metrics')
5+
const { runAndReport } = require('../metrics');
86

97

10-
runAndReport({ func: () => {
11-
return controller
12-
.iplan()
13-
.then(async () => {
14-
Log.info('iplan completed');
15-
})
16-
.finally(() => process.exit());
17-
}, name: "iplan"})
8+
runAndReport({
9+
func: () => {
10+
return controller.iplan().then(async () => {
11+
Log.info('iplan completed');
12+
})
13+
.finally(() => process.exit());
14+
}, name: 'iplan'
15+
});
1816

0 commit comments

Comments
 (0)