Commit 521870ff authored by Valentin Suhnjov's avatar Valentin Suhnjov

RIHAKB-238. Add unique main_resources view

View provides unique main_resource entities with the latest
creation_date. In case of tie situation, entity with highest id wins.
parent ca1fbbb6
......@@ -150,6 +150,9 @@ COMMENT ON COLUMN riha.main_resource.kind_id IS 'Ressursi liik (infosystem, clas
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.main_resource TO riha;
CREATE INDEX main_resource_uuid
ON riha.main_resource (((json_content ->> 'uuid')));
-- Index: riha.ixfk_main_resource_main_resource
-- DROP INDEX riha.ixfk_main_resource_main_resource;
......
CREATE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid') *
FROM riha.main_resource
ORDER BY json_content ->> 'uuid',
creation_date DESC,
main_resource_id DESC;
\ No newline at end of file
-- v_main_resource provides a view on latest info system versions from main_resource
-- provided rows are with unique uuid, latest creation_date and, in case of ties, greatest entity id.
CREATE INDEX main_resource_uuid
ON riha.main_resource (((json_content ->> 'uuid')));
CREATE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid') *
FROM riha.main_resource
ORDER BY json_content ->> 'uuid',
creation_date DESC,
main_resource_id DESC;
\ No newline at end of file
......@@ -12,6 +12,7 @@ import ee.eesti.riha.rest.model.Document;
import ee.eesti.riha.rest.model.Main_resource;
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_view;
import ee.eesti.riha.rest.util.PropsReader;
// TODO: Auto-generated Javadoc
......@@ -38,8 +39,10 @@ public final class Finals {
// read only
addClassRepresentingTable(Isik.class);
addClassRepresentingTable(Asutus.class);
addClassRepresentingTable(Main_resource_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);
}
/**
......
......@@ -7,6 +7,7 @@ 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.readonly.Main_resource_view;
/**
* Json_content based table is table that contains field json_content. All the other fields that exist in table must
......@@ -26,7 +27,7 @@ public final class JsonContentBasedTable {
jsonContentBasedTables.add(Main_resource.class);
jsonContentBasedTables.add(Document.class);
jsonContentBasedTables.add(Data_object.class);
// jsonContentBasedTables.add(Comment.class);
jsonContentBasedTables.add(Main_resource_view.class);
}
/**
......
package ee.eesti.riha.rest.model.readonly;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonRawValue;
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.hibernate.JsonObjectUserType;
import ee.eesti.riha.rest.model.util.FieldIsPK;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.*;
import java.util.Date;
@TypeDefs({@TypeDef(name = "JsonObject", typeClass = JsonObjectUserType.class)})
@Transactional
@Entity
@Table(name = "main_resource_view")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Immutable
public class Main_resource_view implements BaseModel {
@FieldIsPK
@Id
@Column(updatable = false)
private Integer main_resource_id;
private String uri;
@JsonRawValue
@Type(type = "JsonObject")
private JsonObject json_content;
private String creator;
private String modifier;
@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;
private String kind;
public Integer getMain_resource_id() {
return main_resource_id;
}
@Override
public int callGetId() {
return getMain_resource_id();
}
@Override
public void callSetId(int id) {
throw new UnsupportedOperationException();
}
@Override
public String getUri() {
return uri;
}
@Override
public void setUri(String uri) {
throw new UnsupportedOperationException();
}
@Override
public JsonObject getJson_content() {
return json_content;
}
@Override
public void setJson_content(JsonObject json_content) {
throw new UnsupportedOperationException();
}
@Override
public String getCreator() {
return creator;
}
@Override
public void setCreator(String creator) {
throw new UnsupportedOperationException();
}
@Override
public String getModifier() {
return modifier;
}
@Override
public void setModifier(String modifier) {
throw new UnsupportedOperationException();
}
@Override
public Date getCreation_date() {
return creation_date;
}
@Override
public void setCreation_date(Date creation_date) {
throw new UnsupportedOperationException();
}
@Override
public Date getModified_date() {
return modified_date;
}
@Override
public void setModified_date(Date modified_date) {
throw new UnsupportedOperationException();
}
@Override
public String getKind() {
return kind;
}
@Override
public void setKind(String kind) {
throw new UnsupportedOperationException();
}
}
......@@ -36,6 +36,7 @@
<value>ee.eesti.riha.rest.model.readonly.Kind</value>
<value>ee.eesti.riha.rest.model.readonly.Isik</value>
<value>ee.eesti.riha.rest.model.readonly.Asutus</value>
<value>ee.eesti.riha.rest.model.readonly.Main_resource_view</value>
</list>
</property>
<property name="hibernateProperties">
......
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