Commit 4f118179 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch 'issue/164' into 'develop'

Issue SCRUM#164: Upgrade database to accept digital cities 2

See merge request !851
parents b34fb64d c2958b6c
Pipeline #19008 passed with stage
in 6 minutes and 44 seconds
variables:
SIMMC_URL: 'marula.c3sl.ufpr.br:5000/c3sl/simmc'
SIMMC_URL: 'dockerregistry.c3sl.ufpr.br:5000/c3sl/simmc'
stages:
- build
- deploy
......
......@@ -110,6 +110,11 @@ BEGIN
, p.id_city
, n.ip
, en.id as id_ent_net
, CASE
WHEN e2.id_point IS NULL
THEN '0'::boolean
ELSE '1'::boolean
END AS is_dc2
, n.macaddr
, n.city_code
, n.collect_date
......@@ -126,6 +131,7 @@ n.collect_date::text || n.collect_time::text) AS md5
LEFT JOIN point p ON n.id_point = p.id
LEFT JOIN entity_net en ON n.ip <<= en.net
AND n.id_point = en.id_point
LEFT JOIN entity2 e2 ON n.id_point = e2.id_point
) AS a;
-- how many rows were inserted?
......@@ -605,10 +611,18 @@ BEGIN
valid = '0'
, reason = concat_ws(', ', reason, 'null data on download or upload')
WHERE
down_bytes IS NULL
OR down_packages IS NULL
OR up_bytes IS NULL
OR up_packages IS NULL;
(is_dc2 AND ( -- if the point is dc2,
down_bytes IS NULL -- up and down packages are NOT required
OR up_bytes IS NULL
))
OR
( is_dc2 = false AND ( -- if the point is NOT dc2
down_bytes IS NULL -- up and down packages are required
OR down_packages IS NULL
OR up_bytes IS NULL
OR up_packages IS NULL
))
;
-- check if id point is null
UPDATE
......@@ -683,6 +697,7 @@ BEGIN
WHERE
ip IS NOT NULL
AND id_ent_net IS NULL
AND is_dc2 = false
AND id_point IN (SELECT id_point FROM active_dc);
-- check macaddress and ip. One of them must be null.
......
......@@ -988,6 +988,211 @@ BEGIN
END;
$$ language plpgsql;
SELECT remove_function_by_name('insert_update_entity2');
CREATE OR REPLACE FUNCTION insert_update_entity2(
id_point_in INTEGER
, establishment_in TEXT
, reference_in TEXT
, address_in TEXT
, neighborhood_in TEXT
, email_in TEXT
, complement_in TEXT
, zipcode_in TEXT
, phone_in TEXT
, id_city_in INTEGER
, id_pp_in INTEGER
, id_pcg_in INTEGER
, ip_addr_in INET
, oid_download_in TEXT
, oid_upload_in TEXT
, port_in INTEGER
, latitude_in TEXT DEFAULT NULL
, longitude_in TEXT DEFAULT NULL
) RETURNS INTEGER AS $$
DECLARE
id_point_row RECORD;
id_point_return INTEGER;
latitude_double DOUBLE PRECISION;
longitude_double DOUBLE PRECISION;
BEGIN
--INSERT PART
IF (id_point_in IS NULL) THEN
WITH id_point_row AS (
INSERT INTO point (
id_city
, is_gesac
, is_telecenter
, is_digital_city
, id_pp
) VALUES (
id_city_in
, '0'
, '0'
, '1'
, id_pp_in
) RETURNING id
)
INSERT INTO entity2 (
id_point
, id_pcg
, ip_addr
, oid_download
, oid_upload
, port
) (
SELECT
r.id
, id_pcg_in
, ip_addr_in
, oid_download_in
, oid_upload_in
, port_in
FROM
id_point_row r
);
-- Get id_point inserted
SELECT
max(id)
INTO
id_point_return
FROM
point;
-- Insert geolocation data
latitude_double := degrees_to_decimal_degrees(latitude_in);
longitude_double := degrees_to_decimal_degrees(longitude_in);
IF (latitude_double IS NOT NULL AND longitude_double IS NOT NULL) THEN
INSERT INTO
point_geolocation (
id_point
, latitude
, longitude
, geometry
) VALUES (
id_point_return
, latitude_double
, longitude_double
, st_makepoint(longitude_double, latitude_double)
);
END IF;
-- Insert address and contact information
INSERT INTO address (
id_point
, establishment
, phone
, email
, street
, neighborhood
, complement
, reference
, zipcode
, has_alt_address
) VALUES (
id_point_return
, establishment_in
, phone_in
, email_in
, address_in
, neighborhood_in
, complement_in
, reference_in
, zipcode_in
, false
);
--UPDATE PART
ELSE
PERFORM remove_point(id_point_in);
INSERT INTO point(
id
, id_city
, is_gesac
, is_telecenter
, is_digital_city
, id_pp
) VALUES (
id_point_in
, id_city_in
, '0'
, '0'
, '1'
, id_pp_in
);
INSERT INTO entity2 (
id_point
, id_pcg
, ip_addr
, oid_download
, oid_upload
, port
) VALUES (
id_point_in
, id_pcg_in
, ip_addr_in
, oid_download_in
, oid_upload_in
, port_in
);
-- Insert geolocation data
latitude_double := degrees_to_decimal_degrees(latitude_in);
longitude_double := degrees_to_decimal_degrees(longitude_in);
IF (latitude_double IS NOT NULL AND longitude_double IS NOT NULL) THEN
INSERT INTO
point_geolocation (
id_point
, latitude
, longitude
, geometry
) VALUES (
id_point_in
, latitude_double
, longitude_double
, st_makepoint(longitude_double, latitude_double)
);
END IF;
INSERT INTO address (
id_point
, establishment
, phone
, email
, street
, neighborhood
, complement
, reference
, zipcode
, has_alt_address
) VALUES (
id_point_in
, establishment_in
, phone_in
, email_in
, address_in
, neighborhood_in
, complement_in
, reference_in
, zipcode_in
, '0'
);
id_point_return := id_point_in;
END IF;
RETURN id_point_return;
END;
$$ language plpgsql;
-- REMOVE FUNCTIONS
SELECT remove_function_by_name('remove_contact');
CREATE OR REPLACE FUNCTION remove_contact(id_point_in INTEGER) RETURNS void AS $$
......
CREATE TABLE entity2 (
id SERIAL PRIMARY KEY,
id_point INTEGER NOT NULL references point,
id_pcg INTEGER,
ip_addr INET,
oid_download TEXT,
oid_upload TEXT,
port INTEGER
);
ALTER TABLE fact_net_usage ALTER COLUMN up_packages DROP NOT NULL;
ALTER TABLE fact_net_usage ALTER COLUMN down_packages DROP NOT NULL;
......@@ -166,7 +166,7 @@ CREATE MATERIALIZED VIEW availability_report_dc (
, green
, yellow
, red) AS
(SELECT
((SELECT
pt.id_point
, to_char(current_date, 'DD/MM/YYYY') AS load_date
, INITCAP(REGEXP_REPLACE(a.establishment, '\n', '')) AS entity_name
......@@ -199,6 +199,42 @@ CREATE MATERIALIZED VIEW availability_report_dc (
FROM
availability_last_contact
) alc ON alc.id_point = pt.id_point
)
UNION
(SELECT
pt.id_point
, to_char(current_date, 'DD/MM/YYYY') AS load_date
, INITCAP(REGEXP_REPLACE(a.establishment, '\n', '')) AS entity_name
, NULL -- Could be e.id_pcg, but there is no garaty that this is unique
, 'PCG'
, cy.id AS id_city
, cy.region
, cy.state
, cy.name AS city
, alc.last_contact
, alc.days_last_contact
, con.n AS month_contacts
, alc.days_last_contact <= 4 AS g
-- as digital city doesn't have a 'yellow' state we are using it as
-- true when the point has never contacted us. In the future we will
-- need a specific attribute for this matter
, CASE WHEN alc.id_point IS NULL THEN true ELSE false END AS y
, days_last_contact > 4 AS r
FROM
active_dc pt
INNER JOIN city cy ON pt.id_city = cy.id
INNER JOIN address a ON a.id_point = pt.id_point
INNER JOIN entity2 e ON e.id_point = pt.id_point
LEFT JOIN contacts_this_month con ON con.id_point = pt.id_point
LEFT JOIN (
SELECT
id_point
, collect_date AS last_contact
, current_date - collect_date AS days_last_contact
FROM
availability_last_contact
) alc ON alc.id_point = pt.id_point
)
);
-- unique index is needed for 'refresh concorrently'
ALTER MATERIALIZED VIEW availability_report_dc OWNER TO :DBUSER;
......
......@@ -29,7 +29,7 @@ RUN \
chmod +x /tini &&\
chown -R node:node $WORKSPACE &&\
apt-get update && \
apt-get install default-jdk libcairo-dev libjpeg-dev libgif-dev libpango1.0-dev ant -y
apt-get install default-jdk libcairo-dev libjpeg-dev libgif-dev libpango1.0-dev ant git apt-transport-https ca-certificates -y
USER node
WORKDIR $WORKSPACE
......
......@@ -2,7 +2,7 @@
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="cidadesAvail" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8aebead2-33a3-49b2-80db-ae7b6301ad20">
<property name="ireport.zoom" value="4.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="205"/>
<property name="ireport.y" value="49"/>
<parameter name="imagesPath" class="java.lang.String"/>
<parameter name="ID_CITY" class="java.lang.Integer"/>
<parameter name="STATE" class="java.lang.String"/>
......@@ -240,7 +240,7 @@ ORDER BY
<textElement textAlignment="Right">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA['(' + $F{access_point_type} + ($F{access_point_type} == "PEAS"? ')' : ' ' + $F{access_point_id} + ')')]]></textFieldExpression>
<textFieldExpression><![CDATA['(' + $F{access_point_type} + ($F{access_point_type} == "PEAS" || $F{access_point_type} == "PCG"? ')' : ' ' + $F{access_point_id} + ')')]]></textFieldExpression>
</textField>
</band>
</detail>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment