diff --git a/sql/update/20190124_add_used_type_relations_info_to_main_resource_view.sql b/sql/update/20190124_add_used_type_relations_info_to_main_resource_view.sql new file mode 100644 index 0000000..5c3d59d --- /dev/null +++ b/sql/update/20190124_add_used_type_relations_info_to_main_resource_view.sql @@ -0,0 +1,74 @@ +-- drop view riha.main_resource_view cascade + +CREATE OR REPLACE VIEW riha.main_resource_view AS + + SELECT DISTINCT ON (json_content ->> 'uuid') + main_resource.*, + ((main_resource.json_content #>> + '{meta,creation_timestamp}' :: TEXT [])) :: TIMESTAMP WITH TIME ZONE AS j_creation_timestamp, + ((main_resource.json_content #>> + '{meta,update_timestamp}' :: TEXT [])) :: TIMESTAMP WITH TIME ZONE AS j_update_timestamp, + last_positive_approval_request.sub_type AS last_positive_approval_request_type, + last_positive_approval_request.modified_date AS last_positive_approval_request_date, + last_positive_establishment_request.modified_date AS last_positive_establishment_request_date, + last_positive_take_into_use_request.modified_date AS last_positive_take_into_use_request_date, + last_positive_finalization_request.modified_date AS last_positive_finalization_request_date + ,COALESCE (has_used_system_types_relations.has_used_system_type_relations, false) AS has_used_system_type_relations + FROM riha.main_resource AS main_resource + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + sub_type, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type IN ('ESTABLISHMENT_REQUEST', + 'TAKE_INTO_USE_REQUEST', + 'FINALIZATION_REQUEST') + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_approval_request + ON (json_content ->> 'uuid') :: UUID = last_positive_approval_request.infosystem_uuid + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type = 'ESTABLISHMENT_REQUEST' + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_establishment_request + ON (json_content ->> 'uuid') :: UUID = last_positive_establishment_request.infosystem_uuid + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type = 'TAKE_INTO_USE_REQUEST' + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_take_into_use_request + ON (json_content ->> 'uuid') :: UUID = last_positive_take_into_use_request.infosystem_uuid + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type = 'FINALIZATION_REQUEST' + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_finalization_request + ON (json_content ->> 'uuid') :: UUID = last_positive_finalization_request.infosystem_uuid + + LEFT JOIN + (select count(*) > 0 as has_used_system_type_relations, infosystem_uuid from riha.main_resource_relation mrr where mrr.type ='USED_SYSTEM' group by infosystem_uuid) + as has_used_system_types_relations + ON (json_content ->> 'uuid') :: UUID = has_used_system_types_relations.infosystem_uuid + + ORDER BY json_content ->> 'uuid', + j_update_timestamp DESC NULLS LAST, + main_resource_id DESC + diff --git a/src/main/java/ee/eesti/riha/rest/model/readonly/Main_resource_view.java b/src/main/java/ee/eesti/riha/rest/model/readonly/Main_resource_view.java index c0b6bb6..9d5cd0b 100644 --- a/src/main/java/ee/eesti/riha/rest/model/readonly/Main_resource_view.java +++ b/src/main/java/ee/eesti/riha/rest/model/readonly/Main_resource_view.java @@ -83,6 +83,9 @@ public class Main_resource_view implements BaseModel { @Temporal(TemporalType.TIMESTAMP) private Date last_positive_finalization_request_date; + @Column(name = "has_used_system_type_relations") + private boolean hasUsedSystemTypeRelations; + public Integer getMain_resource_id() { return main_resource_id; } @@ -167,6 +170,14 @@ public void setKind(String kind) { throw new UnsupportedOperationException(); } + public boolean isHasUsedSystemTypeRelations() { + return hasUsedSystemTypeRelations; + } + + public void setHasUsedSystemTypeRelations(boolean hasUsedSystemTypeRelations) { + this.hasUsedSystemTypeRelations = hasUsedSystemTypeRelations; + } + public String getLast_positive_approval_request_type() { return last_positive_approval_request_type; } diff --git a/src/main/resources/liquibase/db.changelog.xml b/src/main/resources/liquibase/db.changelog.xml index 866001d..2f56c0f 100644 --- a/src/main/resources/liquibase/db.changelog.xml +++ b/src/main/resources/liquibase/db.changelog.xml @@ -50,4 +50,13 @@ /> + + + + \ No newline at end of file diff --git a/src/main/resources/liquibase/update/20190124_add_used_type_relations_info_to_main_resource_view.sql b/src/main/resources/liquibase/update/20190124_add_used_type_relations_info_to_main_resource_view.sql new file mode 100644 index 0000000..5c3d59d --- /dev/null +++ b/src/main/resources/liquibase/update/20190124_add_used_type_relations_info_to_main_resource_view.sql @@ -0,0 +1,74 @@ +-- drop view riha.main_resource_view cascade + +CREATE OR REPLACE VIEW riha.main_resource_view AS + + SELECT DISTINCT ON (json_content ->> 'uuid') + main_resource.*, + ((main_resource.json_content #>> + '{meta,creation_timestamp}' :: TEXT [])) :: TIMESTAMP WITH TIME ZONE AS j_creation_timestamp, + ((main_resource.json_content #>> + '{meta,update_timestamp}' :: TEXT [])) :: TIMESTAMP WITH TIME ZONE AS j_update_timestamp, + last_positive_approval_request.sub_type AS last_positive_approval_request_type, + last_positive_approval_request.modified_date AS last_positive_approval_request_date, + last_positive_establishment_request.modified_date AS last_positive_establishment_request_date, + last_positive_take_into_use_request.modified_date AS last_positive_take_into_use_request_date, + last_positive_finalization_request.modified_date AS last_positive_finalization_request_date + ,COALESCE (has_used_system_types_relations.has_used_system_type_relations, false) AS has_used_system_type_relations + FROM riha.main_resource AS main_resource + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + sub_type, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type IN ('ESTABLISHMENT_REQUEST', + 'TAKE_INTO_USE_REQUEST', + 'FINALIZATION_REQUEST') + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_approval_request + ON (json_content ->> 'uuid') :: UUID = last_positive_approval_request.infosystem_uuid + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type = 'ESTABLISHMENT_REQUEST' + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_establishment_request + ON (json_content ->> 'uuid') :: UUID = last_positive_establishment_request.infosystem_uuid + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type = 'TAKE_INTO_USE_REQUEST' + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_take_into_use_request + ON (json_content ->> 'uuid') :: UUID = last_positive_take_into_use_request.infosystem_uuid + LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid) + infosystem_uuid, + modified_date + FROM riha.comment + WHERE + type = 'ISSUE' + AND sub_type = 'FINALIZATION_REQUEST' + AND status = 'CLOSED' + AND resolution_type = 'POSITIVE' + ORDER BY infosystem_uuid, modified_date DESC) AS last_positive_finalization_request + ON (json_content ->> 'uuid') :: UUID = last_positive_finalization_request.infosystem_uuid + + LEFT JOIN + (select count(*) > 0 as has_used_system_type_relations, infosystem_uuid from riha.main_resource_relation mrr where mrr.type ='USED_SYSTEM' group by infosystem_uuid) + as has_used_system_types_relations + ON (json_content ->> 'uuid') :: UUID = has_used_system_types_relations.infosystem_uuid + + ORDER BY json_content ->> 'uuid', + j_update_timestamp DESC NULLS LAST, + main_resource_id DESC + diff --git a/src/test/resources/liquibase/db.changelog.xml b/src/test/resources/liquibase/db.changelog.xml index 3177bce..1789819 100644 --- a/src/test/resources/liquibase/db.changelog.xml +++ b/src/test/resources/liquibase/db.changelog.xml @@ -30,4 +30,13 @@ relativeToChangelogFile="true"/> + + + + \ No newline at end of file diff --git a/src/test/resources/riharest.project.properties b/src/test/resources/riharest.project.properties index 9ddecdd..402df2d 100644 --- a/src/test/resources/riharest.project.properties +++ b/src/test/resources/riharest.project.properties @@ -1,4 +1,4 @@ -riharest.jdbc.url=jdbc:postgresql://localhost:5438/riha?currentSchema=riha +riharest.jdbc.url=jdbc:postgresql://127.0.0.1:5438/riha?currentSchema=riha riharest.jdbc.user=riha riharest.jdbc.password=riha