Commit e9a75b01 authored by Valentin Suhnjov's avatar Valentin Suhnjov

Merge branch 'releases/release-0.9.0' into master

parents 4a5f4ccc 94e85fc0
......@@ -5,7 +5,7 @@
<groupId>ee.eesti.riha</groupId>
<artifactId>rest</artifactId>
<version>0.8.0</version>
<version>0.9.0</version>
<packaging>war</packaging>
......
......@@ -66,6 +66,14 @@ CREATE SEQUENCE riha.large_object_seq
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.large_object_seq TO riha;
CREATE SEQUENCE riha.main_resource_relation_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.main_resource_relation_seq TO riha;
-- Table: riha.kind
-- DROP TABLE riha.kind;
......@@ -417,3 +425,31 @@ CREATE INDEX ixfk_comment_comment
USING btree
(comment_parent_id);
-- Table: riha.main_resource_relation
-- DROP TABLE riha.main_resource_relation;
CREATE TABLE riha.main_resource_relation
(
main_resource_relation_id INTEGER NOT NULL
CONSTRAINT main_resource_relation_pkey
PRIMARY KEY,
creation_date TIMESTAMP,
infosystem_uuid UUID,
modified_date TIMESTAMP,
related_infosystem_uuid UUID,
type VARCHAR(255)
);
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.main_resource_relation TO riha;
ALTER TABLE riha.main_resource_relation
ADD CONSTRAINT main_resource_relation_unique UNIQUE (infosystem_uuid, related_infosystem_uuid, type);
-- DROP INDEX riha.idx_main_resource_relation_infosystem_uuid;
CREATE INDEX idx_main_resource_relation_infosystem_uuid
ON riha.main_resource_relation (infosystem_uuid);
-- DROP INDEX riha.idx_main_resource_relation_related_infosystem_uuid;
CREATE INDEX idx_main_resource_relation_related_infosystem_uuid
ON riha.main_resource_relation (related_infosystem_uuid);
\ No newline at end of file
-- DROP VIEW riha.main_resource_relation_view;
CREATE OR REPLACE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid') *,
((main_resource.json_content #>> '{meta,creation_timestamp}'::text[]))::timestamp AS j_creation_timestamp,
((main_resource.json_content #>> '{meta,update_timestamp}'::text[]))::timestamp AS j_update_timestamp
FROM riha.main_resource as main_resource
SELECT DISTINCT ON (json_content ->> 'uuid')
*,
((main_resource.json_content #>> '{meta,creation_timestamp}' :: TEXT [])) :: TIMESTAMP AS j_creation_timestamp,
((main_resource.json_content #>> '{meta,update_timestamp}' :: TEXT [])) :: TIMESTAMP AS j_update_timestamp
FROM riha.main_resource AS main_resource
ORDER BY json_content ->> 'uuid',
j_update_timestamp DESC NULLS LAST,
main_resource_id DESC;
\ No newline at end of file
main_resource_id DESC;
-- DROP VIEW 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;
\ No newline at end of file
......@@ -6,4 +6,4 @@ alter table riha.document drop CONSTRAINT fk_data_object;
alter TABLE riha.document DROP CONSTRAINT fk_main_resource;
alter table riha.comment drop CONSTRAINT fk_comment_comment;
alter table riha.file_resource drop CONSTRAINT fk_file_resource_large_object;
DROP TRIGGER IF EXISTS tr_infosystem_update ON main_resource;
DROP TRIGGER IF EXISTS tr_infosystem_update ON main_resource;
\ No newline at end of file
......@@ -22,6 +22,11 @@ DROP INDEX riha.ixfk_data_object_data_object;
DROP TABLE riha.data_object;
-- Table: riha.main_resource_relation
DROP INDEX riha.idx_main_resource_relation_infosystem_uuid;
DROP INDEX riha.idx_main_resource_relation_related_infosystem_uuid;
DROP TABLE riha.main_resource_relation;
-- Index: riha.ixfk_main_resource_kind_template
DROP INDEX riha.ixfk_main_resource_kind_template;
......@@ -69,3 +74,7 @@ DROP SEQUENCE riha.kind_seq;
-- Sequence: riha.main_resource_seq
DROP SEQUENCE riha.main_resource_seq;
-- Sequence: riha.main_resource_relation_seq
DROP SEQUENCE riha.main_resource_relation_seq;
\ No newline at end of file
CREATE SEQUENCE riha.main_resource_relation_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.main_resource_relation_seq TO riha;
CREATE TABLE riha.main_resource_relation
(
main_resource_relation_id INTEGER NOT NULL
CONSTRAINT main_resource_relation_pkey
PRIMARY KEY,
creation_date TIMESTAMP,
infosystem_uuid UUID,
modified_date TIMESTAMP,
related_infosystem_uuid UUID,
type VARCHAR(255)
);
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.main_resource_relation TO riha;
ALTER TABLE riha.main_resource_relation
ADD CONSTRAINT main_resource_relation_unique UNIQUE (infosystem_uuid, related_infosystem_uuid, type);
-- DROP INDEX riha.idx_main_resource_relation_infosystem_uuid;
CREATE INDEX idx_main_resource_relation_infosystem_uuid
ON riha.main_resource_relation (infosystem_uuid);
-- DROP INDEX riha.idx_main_resource_relation_related_infosystem_uuid;
CREATE INDEX idx_main_resource_relation_related_infosystem_uuid
ON riha.main_resource_relation (related_infosystem_uuid);
\ No newline at end of file
package ee.eesti.riha.rest.dao;
import java.math.BigInteger;
import javax.transaction.Transactional;
import ee.eesti.riha.rest.dao.util.DAOConstants;
import ee.eesti.riha.rest.model.*;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
......@@ -12,11 +10,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ee.eesti.riha.rest.dao.util.DAOConstants;
import ee.eesti.riha.rest.model.Comment;
import ee.eesti.riha.rest.model.Data_object;
import ee.eesti.riha.rest.model.Document;
import ee.eesti.riha.rest.model.Main_resource;
import javax.transaction.Transactional;
import java.math.BigInteger;
// TODO: Auto-generated Javadoc
/**
......@@ -47,17 +42,15 @@ public class UtilitiesDAOImpl<T> implements UtilitiesDAO<T> {
String seqName = "";
if (classRepresentingTable.equals(Main_resource.class)) {
seqName = DAOConstants.MAIN_RESOURCE_PK_SEQ_NAME;
}
if (classRepresentingTable.equals(Document.class)) {
} else if (classRepresentingTable.equals(Main_resource_relation.class)) {
seqName = DAOConstants.MAIN_RESOURCE_RELATION_PK_SEQ_NAME;
} else if (classRepresentingTable.equals(Document.class)) {
seqName = DAOConstants.DOCUMENT_PK_SEQ_NAME;
}
if (classRepresentingTable.equals(Data_object.class)) {
} else if (classRepresentingTable.equals(Data_object.class)) {
seqName = DAOConstants.DATA_OBJECT_PK_SEQ_NAME;
}
if (classRepresentingTable.equals(Comment.class)) {
} else if (classRepresentingTable.equals(Comment.class)) {
seqName = DAOConstants.COMMENT_PK_SEQ_NAME;
}
if (seqName.isEmpty()) {
} else {
throw new IllegalStateException("Wrong class provided or code needs class->seq mapping specified.");
}
Query query = session.createSQLQuery("SELECT nextval('" + seqName + "')");
......
......@@ -9,6 +9,7 @@ public final class DAOConstants {
}
public static final String MAIN_RESOURCE_PK_SEQ_NAME = "main_resource_seq";
public static final String MAIN_RESOURCE_RELATION_PK_SEQ_NAME = "main_resource_relation_seq";
public static final String DOCUMENT_PK_SEQ_NAME = "document_seq";
public static final String DATA_OBJECT_PK_SEQ_NAME = "data_object_seq";
public static final String COMMENT_PK_SEQ_NAME = "comment_seq";
......
......@@ -49,6 +49,8 @@ public class FilterComponent {
// nested json value operators
ALLOWED_OPERATORS.put("jilike", "ok");
// operator to look for text values in json arrays
ALLOWED_OPERATORS.put("jarr", "ok");
}
/**
......
......@@ -157,6 +157,21 @@ public class SqlFilter {
params.put(jsonFieldNameParameter, jsonFieldName);
params.put(opRight + i, fc.getOperandRight());
} else if (fc.getOperator().equals("jarr")) {
String updatedOperandLeft = fc.getOperandLeft().replaceAll("\\.", ",");
String jsonFieldAndArrayParametersValues = "{" + updatedOperandLeft + "}";
String jsonFieldNameParameter = "jFieldParam";
String jsonArrayTextValueParameter = "jArrayParam";
String filter = "EXISTS(SELECT FROM jsonb_array_elements_text((" + ITEM_PREFIX + Finals.JSON_CONTENT + " #> :"
+ jsonFieldNameParameter + "\\:\\:text[])) WHERE " + ITEM_PREFIX + Finals.JSON_CONTENT + " #>> :" + jsonArrayTextValueParameter
+ "\\:\\:text[] is not null AND value ilike :" + (opRight + i) + ")";
allFilters.add(filter);
params.put(jsonFieldNameParameter, jsonFieldAndArrayParametersValues);
params.put(jsonArrayTextValueParameter, jsonFieldAndArrayParametersValues);
params.put(opRight + i, fc.getOperandRight());
} else if (StringHelper.isNumber(fc.getOperandRight())) {
jsonField = Finals.JSON_CONTENT + "->>" + "'" + fc.getOperandLeft() + "'";
allFilters.add("cast(item." + jsonField + " AS int) " + fc.getOperator() + " :" + (opRight + i));
......
......@@ -113,7 +113,7 @@ public final class ErrorCodes {
public static final String CONSTRAINT_VIOLATION_MSG = "Andmeväli ei vasta nõutud tingimustele";
public static final int SQL_NO_SUCH_OPERATOR_EXISTS = 73;
public static final String SQL_NO_SUCH_OPERATOR_EXISTS_MSG = "Op peab olema "
+ "(=, >, <, >=, <=, !=, <>, like, ilike, ?&, null_or_>, isnull, isnotnull, jilike), aga on: ";
+ "(=, >, <, >=, <=, !=, <>, like, ilike, ?&, null_or_>, isnull, isnotnull, jilike, jarr), aga on: ";
public static final int CAN_UPDATE_VERSION_HERE = 74;
public static final String CAN_UPDATE_VERSION_HERE_MSG = "Versiooni ei ole võimalik selle meetodiga muuta";
......
......@@ -6,12 +6,10 @@ import java.util.List;
import java.util.Map;
import ee.eesti.riha.rest.logic.util.StringHelper;
import ee.eesti.riha.rest.model.Comment;
import ee.eesti.riha.rest.model.Data_object;
import ee.eesti.riha.rest.model.Document;
import ee.eesti.riha.rest.model.Main_resource;
import ee.eesti.riha.rest.model.*;
import ee.eesti.riha.rest.model.readonly.Asutus;
import ee.eesti.riha.rest.model.readonly.Isik;
import ee.eesti.riha.rest.model.readonly.Main_resource_relation_view;
import ee.eesti.riha.rest.model.readonly.Main_resource_view;
import ee.eesti.riha.rest.util.PropsReader;
......@@ -35,14 +33,17 @@ public final class Finals {
addClassRepresentingTable(Document.class);
addClassRepresentingTable(Data_object.class);
addClassRepresentingTable(Comment.class);
addClassRepresentingTable(Main_resource_relation.class);
// read only
addClassRepresentingTable(Isik.class);
addClassRepresentingTable(Asutus.class);
addClassRepresentingTable(Main_resource_view.class);
addClassRepresentingTable(Main_resource_relation_view.class);
TABLE_CLASS_MAP_READONLY.put(Isik.class.getSimpleName().toLowerCase(), Isik.class);
TABLE_CLASS_MAP_READONLY.put(Asutus.class.getSimpleName().toLowerCase(), Asutus.class);
TABLE_CLASS_MAP_READONLY.put(Main_resource_view.class.getSimpleName().toLowerCase(), Main_resource_view.class);
TABLE_CLASS_MAP_READONLY.put(Main_resource_relation_view.class.getSimpleName().toLowerCase(), Main_resource_relation_view.class);
}
/**
......
package ee.eesti.riha.rest.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.logic.Finals;
import ee.eesti.riha.rest.model.util.FieldIsPK;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.Date;
import java.util.UUID;
import static javax.persistence.GenerationType.AUTO;
@Entity
@Table(name = "main_resource_relation")
@DynamicUpdate
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Main_resource_relation implements BaseModel {
@Id
@GeneratedValue(strategy = AUTO, generator = "main_resource_relation_seq")
@SequenceGenerator(name = "main_resource_relation_seq", sequenceName = "main_resource_relation_seq")
@Column(name = "main_resource_relation_id", updatable = false)
@FieldIsPK
private int main_resource_relation_id;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Finals.DATE_FORMAT)
@Temporal(TemporalType.TIMESTAMP)
private Date creation_date;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Finals.DATE_FORMAT)
@Temporal(TemporalType.TIMESTAMP)
private Date modified_date;
@Column(name = "infosystem_uuid")
@Type(type = "pg-uuid")
private UUID infosystem_uuid;
@Column(name = "related_infosystem_uuid")
@Type(type = "pg-uuid")
private UUID related_infosystem_uuid;
@Column(name = "type")
private String type;
public int getMain_resource_relation_id() {
return main_resource_relation_id;
}
public void setMain_resource_relation_id(int main_resource_relation_id) {
this.main_resource_relation_id = main_resource_relation_id;
}
public UUID getInfosystem_uuid() {
return infosystem_uuid;
}
public void setInfosystem_uuid(UUID infosystem_uuid) {
this.infosystem_uuid = infosystem_uuid;
}
public UUID getRelated_infosystem_uuid() {
return related_infosystem_uuid;
}
public void setRelated_infosystem_uuid(UUID related_infosystem_uuid) {
this.related_infosystem_uuid = related_infosystem_uuid;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public int callGetId() {
return main_resource_relation_id;
}
@Override
public void callSetId(int id) {
this.main_resource_relation_id = id;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getUri() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setUri(String uri) {
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public JsonObject getJson_content() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setJson_content(JsonObject json_content) {
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getCreator() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setCreator(String creator) {
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getModifier() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setModifier(String modifier) {
}
@Override
public Date getCreation_date() {
return creation_date;
}
@Override
public void setCreation_date(Date creation_date) {
this.creation_date = creation_date;
}
@Override
public Date getModified_date() {
return modified_date;
}
@Override
public void setModified_date(Date modified_date) {
this.modified_date = modified_date;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getKind() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setKind(String kind) {
}
}
package ee.eesti.riha.rest.model.readonly;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.logic.Finals;
import ee.eesti.riha.rest.model.BaseModel;
import ee.eesti.riha.rest.model.util.FieldIsPK;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.Date;
import java.util.UUID;
@Entity
@Table(name = "main_resource_relation_view")
@DynamicUpdate
@JsonInclude(JsonInclude.Include.NON_NULL)
@Immutable
public class Main_resource_relation_view implements BaseModel {
@Id
@Column(name = "main_resource_relation_id", updatable = false)
@FieldIsPK
private int main_resource_relation_id;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Finals.DATE_FORMAT)
@Temporal(TemporalType.TIMESTAMP)
private Date creation_date;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Finals.DATE_FORMAT)
@Temporal(TemporalType.TIMESTAMP)
private Date modified_date;
@Column(name = "infosystem_uuid")
@Type(type = "pg-uuid")
private UUID infosystem_uuid;
@Column(name = "infosystem_name")
private String infosystem_name;
@Column(name = "infosystem_short_name")
private String infosystem_short_name;
@Column(name = "related_infosystem_uuid")
@Type(type = "pg-uuid")
private UUID related_infosystem_uuid;
@Column(name = "related_infosystem_name")
private String related_infosystem_name;
@Column(name = "related_infosystem_short_name")
private String related_infosystem_short_name;
@Column(name = "type")
private String type;
public int getMain_resource_relation_id() {
return main_resource_relation_id;
}
public void setMain_resource_relation_id(int main_resource_relation_id) {
throw new UnsupportedOperationException();
}
public UUID getInfosystem_uuid() {
return infosystem_uuid;
}
public void setInfosystem_uuid(UUID infosystem_uuid) {
throw new UnsupportedOperationException();
}
public String getInfosystem_name() {
return infosystem_name;
}
public void setInfosystem_name(String infosystem_name) {
throw new UnsupportedOperationException();
}
public String getInfosystem_short_name() {
return infosystem_short_name;
}
public void setInfosystem_short_name(String infosystem_short_name) {
throw new UnsupportedOperationException();
}
public UUID getRelated_infosystem_uuid() {
return related_infosystem_uuid;
}
public void setRelated_infosystem_uuid(UUID related_infosystem_uuid) {
throw new UnsupportedOperationException();
}
public String getRelated_infosystem_name() {
return related_infosystem_name;
}
public void setRelated_infosystem_name(String related_infosystem_name) {
throw new UnsupportedOperationException();
}
public String getRelated_infosystem_short_name() {
return related_infosystem_short_name;
}
public void setRelated_infosystem_short_name(String related_infosystem_short_name) {
throw new UnsupportedOperationException();
}
public String getType() {
return type;
}
public void setType(String type) {
throw new UnsupportedOperationException();
}
@Override
public int callGetId() {
return main_resource_relation_id;
}
@Override
public void callSetId(int id) {
throw new UnsupportedOperationException();
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getUri() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setUri(String uri) {
throw new UnsupportedOperationException();
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public JsonObject getJson_content() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setJson_content(JsonObject json_content) {
throw new UnsupportedOperationException();
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getCreator() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setCreator(String creator) {
throw new UnsupportedOperationException();
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public String getModifier() {
return null;
}
/**
* @deprecated not used anymore and will be removed in the future
*/
@Override
@Deprecated
@Transient
public void setModifier(String modifier) {
throw new UnsupportedOperationException();
}
@Override
public Date getCreation_date() {