Skip to content

Commit

Permalink
Merge branch 'releases/release-0.13.0' into ria/master
Browse files Browse the repository at this point in the history
  • Loading branch information
valesu committed Jan 17, 2018
2 parents b74fa36 + 55f0e51 commit 431a968
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>ee.eesti.riha</groupId>
<artifactId>rest</artifactId>
<version>0.12.0</version>
<version>0.13.0</version>

<packaging>war</packaging>

Expand Down
39 changes: 38 additions & 1 deletion sql/create_views.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DROP VIEW IF EXISTS riha.main_resource_view CASCADE;

CREATE OR REPLACE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid')
main_resource.*,
Expand All @@ -7,7 +8,10 @@ CREATE OR REPLACE VIEW riha.main_resource_view AS
((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_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
FROM riha.main_resource AS main_resource
LEFT JOIN (SELECT DISTINCT ON (infosystem_uuid)
infosystem_uuid,
Expand All @@ -23,6 +27,39 @@ CREATE OR REPLACE VIEW riha.main_resource_view AS
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
ORDER BY json_content ->> 'uuid',
j_update_timestamp DESC NULLS LAST,
main_resource_id DESC;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
-- Drop main_resource_view and views that depend on it
DROP VIEW IF EXISTS riha.main_resource_view CASCADE;

-- Create main_resource_view with last positive coordination statuses data columns
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
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
ORDER BY json_content ->> 'uuid',
j_update_timestamp DESC NULLS LAST,
main_resource_id DESC;

-- Recreate views
DROP VIEW IF EXISTS riha.main_resource_relation_view;
CREATE OR REPLACE VIEW riha.main_resource_relation_view AS
SELECT
mrr.*,
infosystem.json_content ->> 'short_name' AS infosystem_short_name,
infosystem.json_content ->> 'name' AS infosystem_name,
related_infosystem.json_content ->> 'short_name' AS related_infosystem_short_name,
related_infosystem.json_content ->> 'name' AS related_infosystem_name
FROM riha.main_resource_relation mrr
LEFT JOIN riha.main_resource_view infosystem ON (infosystem.json_content ->> 'uuid') = mrr.infosystem_uuid :: TEXT
LEFT JOIN riha.main_resource_view related_infosystem
ON (related_infosystem.json_content ->> 'uuid') = mrr.related_infosystem_uuid :: TEXT;

DROP VIEW IF EXISTS riha.comment_type_issue_view;
CREATE OR REPLACE VIEW riha.comment_type_issue_view AS
SELECT
issue.*,
infosystem.json_content ->> 'short_name' AS infosystem_short_name
FROM riha.comment issue
INNER JOIN riha.main_resource_view infosystem
ON (infosystem.json_content ->> 'uuid') = issue.infosystem_uuid :: TEXT
WHERE issue.type = 'ISSUE'
ORDER BY issue.comment_id;
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,29 @@ public class Main_resource_view implements BaseModel {
@Column(name = "j_creation_timestamp")
private Date j_creation_timestamp;

@JsonIgnore
@Column(name = "j_update_timestamp")
private Date j_update_timestamp;

@Column(name = "last_positive_approval_request_type")
private String last_positive_approval_request_type;

@Column(name = "last_positive_approval_request_date")
@Temporal(TemporalType.TIMESTAMP)
private Date last_positive_approval_request_date;

@Column(name = "last_positive_establishment_request_date")
@Temporal(TemporalType.TIMESTAMP)
private Date last_positive_establishment_request_date;

@Column(name = "last_positive_take_into_use_request_date")
@Temporal(TemporalType.TIMESTAMP)
private Date last_positive_take_into_use_request_date;

@Column(name = "last_positive_finalization_request_date")
@Temporal(TemporalType.TIMESTAMP)
private Date last_positive_finalization_request_date;

public Integer getMain_resource_id() {
return main_resource_id;
}
Expand Down Expand Up @@ -166,4 +182,28 @@ public Date getLast_positive_approval_request_date() {
public void setLast_positive_approval_request_date(Date last_positive_approval_request_date) {
this.last_positive_approval_request_date = last_positive_approval_request_date;
}

public Date getLast_positive_establishment_request_date() {
return last_positive_establishment_request_date;
}

public void setLast_positive_establishment_request_date(Date last_positive_establishment_request_date) {
this.last_positive_establishment_request_date = last_positive_establishment_request_date;
}

public Date getLast_positive_take_into_use_request_date() {
return last_positive_take_into_use_request_date;
}

public void setLast_positive_take_into_use_request_date(Date last_positive_take_into_use_request_date) {
this.last_positive_take_into_use_request_date = last_positive_take_into_use_request_date;
}

public Date getLast_positive_finalization_request_date() {
return last_positive_finalization_request_date;
}

public void setLast_positive_finalization_request_date(Date last_positive_finalization_request_date) {
this.last_positive_finalization_request_date = last_positive_finalization_request_date;
}
}

0 comments on commit 431a968

Please sign in to comment.