diff --git a/src/main/java/project/dao/entity/EntityDao.java b/src/main/java/project/dao/entity/EntityDao.java index 9acba07..0ed94bd 100644 --- a/src/main/java/project/dao/entity/EntityDao.java +++ b/src/main/java/project/dao/entity/EntityDao.java @@ -22,8 +22,11 @@ @Repository public class EntityDao extends BaseVersionableModelDao implements FindAbility, EntityValidatorDao { - private RowMapper mapper = (rs, rowNum) -> new Entity(rs.getString("id"), rs.getString("name"), rs.getString("description"), rs.getInt("version"), rs.getString("commentary")); - + private RowMapper mapper = (rs, rowNum) -> { + Entity entity = new Entity(rs.getString("id"), rs.getString("name"), rs.getString("description"), rs.getInt("version"), rs.getString("commentary")); + entity.setDeactivated(rs.getBoolean("deactivated")); + return entity; + }; public EntityDao(DataSource ds) { super(ds); @@ -51,6 +54,11 @@ public void update(Entity entity) { createHistory(entity); } + public void updateDeactivated(Entity entity) { + jdbc.update(lookup("entity/UpdateDeactivatedEntity"), prepareParams(entity)); + createHistory(entity); + } + public void remove(Entity entity) { int rowsAffected = jdbc.update(lookup("entity/DeleteEntity"), prepareParams(entity)); diff --git a/src/main/java/project/dao/message/MessageDao.java b/src/main/java/project/dao/message/MessageDao.java index b49d3da..6700eb7 100644 --- a/src/main/java/project/dao/message/MessageDao.java +++ b/src/main/java/project/dao/message/MessageDao.java @@ -23,7 +23,12 @@ @Repository public class MessageDao extends BaseVersionableModelDao implements FindAbility, MessageValidatorDao, MessageExportDao { - private RowMapper mapper = (rs, rowNum) -> new Message(rs.getString("id"), rs.getString("text"), rs.getInt("version"), rs.getString("commentary")); + private RowMapper mapper = (rs, rowNum) -> { + Message message = new Message(rs.getString("id"), rs.getString("text"), rs.getInt("version"), rs.getString("commentary")); + message.setDeactivated(rs.getBoolean("deactivated")); + return message; + }; + private RowMapper exportMapper = (rs, rowNum) -> new MessageExportRow(rs.getString("code"), rs.getString("text")); public MessageDao(DataSource ds) { @@ -50,6 +55,12 @@ public void update(Message message) { createHistory(message); } + + public void updateDeactivated(Message message) { + jdbc.update(lookup("message/UpdateDeactivatedMessage"), prepareParams(message)); + createHistory(message); + } + @Override public void remove(Message message) { int affectedRows = jdbc.update(lookup("message/DeleteMessage"), prepareParams(message)); @@ -113,5 +124,4 @@ public List exportMessages() { public String getCurrentCommentary(String messageId) { return jdbc.queryForObject(lookup("message/GetCurrentCommentary"), singletonMap("messageId", messageId), String.class); } - } diff --git a/src/main/java/project/dao/operation/OperationDao.java b/src/main/java/project/dao/operation/OperationDao.java index 937f97b..f7ce744 100644 --- a/src/main/java/project/dao/operation/OperationDao.java +++ b/src/main/java/project/dao/operation/OperationDao.java @@ -22,7 +22,11 @@ @Repository public class OperationDao extends BaseVersionableModelDao implements FindAbility, OperationValidatorDao { - private RowMapper mapper = (rs, rowNum) -> new Operation(rs.getString("id"), rs.getString("name"), rs.getString("description"), rs.getInt("version"), rs.getString("commentary")); + private RowMapper mapper = (rs, rowNum) -> { + Operation operation = new Operation(rs.getString("id"), rs.getString("name"), rs.getString("description"), rs.getInt("version"), rs.getString("commentary")); + operation.setDeactivated(rs.getBoolean("deactivated")); + return operation; + }; public OperationDao(DataSource ds) { super(ds); @@ -49,6 +53,10 @@ public void update(Operation operation) { createHistory(operation); } + public void updateDeactivated(Operation operation) { + jdbc.update(lookup("operation/UpdateDeactivatedOperation"), prepareParams(operation)); + createHistory(operation); + } public void remove(Operation operation) { int rowsAffected = jdbc.update(lookup("operation/DeleteOperation"), prepareParams(operation)); diff --git a/src/main/java/project/dao/tag/TagDao.java b/src/main/java/project/dao/tag/TagDao.java index d2c1708..f3b9282 100644 --- a/src/main/java/project/dao/tag/TagDao.java +++ b/src/main/java/project/dao/tag/TagDao.java @@ -32,8 +32,12 @@ public class TagDao extends BaseVersionableModelDao implements FindAbility { public static final RowMapper TAG_MAPPER = - (rs, rowNum) -> new Tag(rs.getString("id"), rs.getString("name"), rs.getInt("version"), - rs.getString("commentary"), rs.getString("description")); + (rs, rowNum) -> { + Tag tag = new Tag(rs.getString("id"), rs.getString("name"), rs.getInt("version"), + rs.getString("commentary"), rs.getString("description")); + tag.setDeactivated(rs.getBoolean("deactivated")); + return tag; + }; private final static String TAG_ID_COLUMN = "tag_id"; @@ -80,6 +84,11 @@ public void update(Tag tag) { createHistory(tag); } + public void updateDeactivated(Tag tag) { + jdbc.update(lookup("tag/UpdateDeactivatedTag"), prepareParams(tag)); + createHistory(tag); + } + @Override public void remove(Tag tag) { int affectedRows = jdbc.update(lookup("tag/DeleteTag"), prepareParams(tag)); diff --git a/src/main/java/project/dao/validation/ValidationDao.java b/src/main/java/project/dao/validation/ValidationDao.java index c8d999a..5faeb88 100644 --- a/src/main/java/project/dao/validation/ValidationDao.java +++ b/src/main/java/project/dao/validation/ValidationDao.java @@ -1,24 +1,11 @@ package project.dao.validation; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import javax.sql.DataSource; - import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.stereotype.Repository; - import project.dao.BaseVersionableModelDao; import project.dao.ConcurrentModificationException; import project.dao.FindAbility; @@ -30,11 +17,11 @@ import project.model.operation.Operation; import project.model.query.SearchParams; import project.model.tag.Tag; -import project.model.validation.Severity; -import project.model.validation.Validation; -import project.model.validation.ValidationDto; -import project.model.validation.ValidationEntity; -import project.model.validation.ValidationExportRow; +import project.model.validation.*; + +import javax.sql.DataSource; +import java.util.*; +import java.util.stream.Collectors; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; @@ -48,7 +35,9 @@ public class ValidationDao extends BaseVersionableModelDao implement private RowMapper mapper = (rs, rowNum) -> { Message message = new Message(rs.getString("m_id"), rs.getString("m_text"), rs.getInt("m_version"), rs.getString("m_commentary")); Severity severity = Severity.resolveById(rs.getInt("severityId")); - return new Validation(rs.getString("id"), severity, message, rs.getString("description"), rs.getInt("version"), rs.getString("commentary")); + Validation validation = new Validation(rs.getString("id"), severity, message, rs.getString("description"), rs.getInt("version"), rs.getString("commentary")); + validation.setDeactivated(rs.getBoolean("deactivated")); + return validation; }; private ResultSetExtractor> validationsByIdExtractor = rs -> { @@ -93,6 +82,7 @@ public class ValidationDao extends BaseVersionableModelDao implement dto.entityNames = rs.getString("entityNames"); dto.operationNames = rs.getString("operationNames"); dto.tagNames = rs.getString("tagNames"); + dto.deactivated = rs.getBoolean("deactivated"); return dto; }; @@ -148,7 +138,7 @@ public ValidationDao(DataSource ds) { public Validation load(String validationId) { return requiredSingleResult(load(singletonList(validationId))); } - + public List load(List validationIds) { Map validations = jdbc.query(lookup("validation/LoadValidation"), singletonMap("ids", validationIds), validationsByIdExtractor); @@ -202,6 +192,15 @@ public void update(List validations) { } } + public void updateDeactivated(Validation validation) { + jdbc.update(lookup("validation/UpdateDeactivatedValidation"), prepareParams(validation)); + + createEntityOperations(singletonList(validation)); + createTags(singletonList(validation)); + + createHistory(validation); + } + private void createEntityOperations(List validations) { List params = new ArrayList<>(); @@ -290,6 +289,7 @@ protected Map prepareParams(Validation validation) { Map params = super.prepareParams(validation); params.put("severityId", validation.getSeverity().getId()); params.put("messageId", validation.getMessage().getId()); + params.put("messageText", validation.getMessage().getText()); params.put("description", validation.getDescription()); return params; } diff --git a/src/main/java/project/model/BaseVersionableModel.java b/src/main/java/project/model/BaseVersionableModel.java index 6c20b3a..6ea858c 100644 --- a/src/main/java/project/model/BaseVersionableModel.java +++ b/src/main/java/project/model/BaseVersionableModel.java @@ -13,6 +13,9 @@ public class BaseVersionableModel extends AbstractModel implements Versionable, /** Комментарий. */ protected String commentary; + /** Флаг для проверки удаленных сущностей. */ + protected Boolean deactivated; + public BaseVersionableModel() { } @@ -36,6 +39,14 @@ public void setCommentary(String commentary) { this.commentary = commentary; } + public Boolean isDeactivated() { + return deactivated; + } + + public void setDeactivated(Boolean deactivated) { + this.deactivated = deactivated; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/project/model/validation/ValidationDto.java b/src/main/java/project/model/validation/ValidationDto.java index 80bf47e..6380b62 100644 --- a/src/main/java/project/model/validation/ValidationDto.java +++ b/src/main/java/project/model/validation/ValidationDto.java @@ -13,4 +13,5 @@ public class ValidationDto { public String operationNames; public String entityNames; public String tagNames; + public Boolean deactivated; } diff --git a/src/main/java/project/service/EntityServiceImpl.java b/src/main/java/project/service/EntityServiceImpl.java index d77d4a6..eda5c65 100644 --- a/src/main/java/project/service/EntityServiceImpl.java +++ b/src/main/java/project/service/EntityServiceImpl.java @@ -33,7 +33,11 @@ public void create(Entity entity) { @Override public void update(Entity entity) { - dao.update(entity); + if(entity.isDeactivated()) { + dao.updateDeactivated(entity); + } else { + dao.update(entity); + } } @Override diff --git a/src/main/java/project/service/MessageServiceImpl.java b/src/main/java/project/service/MessageServiceImpl.java index 8937bb3..e5b8d3f 100644 --- a/src/main/java/project/service/MessageServiceImpl.java +++ b/src/main/java/project/service/MessageServiceImpl.java @@ -33,7 +33,11 @@ public void create(Message message) { @Override public void update(Message message) { - dao.update(message); + if(message.isDeactivated()) { + dao.updateDeactivated(message); + } else { + dao.update(message); + } } @Override diff --git a/src/main/java/project/service/OperationServiceImpl.java b/src/main/java/project/service/OperationServiceImpl.java index 88c7607..37317e3 100644 --- a/src/main/java/project/service/OperationServiceImpl.java +++ b/src/main/java/project/service/OperationServiceImpl.java @@ -33,7 +33,11 @@ public void create(Operation operation) { @Override public void update(Operation operation) { - dao.update(operation); + if(operation.isDeactivated()) { + dao.updateDeactivated(operation); + } else { + dao.update(operation); + } } @Override diff --git a/src/main/java/project/service/TagServiceImpl.java b/src/main/java/project/service/TagServiceImpl.java index 6bda7cd..1a5e594 100644 --- a/src/main/java/project/service/TagServiceImpl.java +++ b/src/main/java/project/service/TagServiceImpl.java @@ -49,7 +49,12 @@ public void create(Tag model) { @Override public void update(Tag model) { - tagDao.update(model); + if(model.isDeactivated()) { + tagDao.updateDeactivated(model); + model.setDeactivated(false); + } else { + tagDao.update(model); + } } @Override diff --git a/src/main/java/project/service/ValidationServiceImpl.java b/src/main/java/project/service/ValidationServiceImpl.java index b8dcb61..59e14f4 100644 --- a/src/main/java/project/service/ValidationServiceImpl.java +++ b/src/main/java/project/service/ValidationServiceImpl.java @@ -3,7 +3,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import project.dao.tag.TagDao; import project.dao.validation.ValidationDao; import project.model.Change; @@ -32,7 +31,9 @@ public ValidationServiceImpl(ValidationDao dao, TagDao tagDao) { @Override public Validation load(String validationId) { - return dao.load(validationId); + Validation load = dao.load(validationId); +// Validation loadHist = dao.load(loadVersion); + return load; } @Override @@ -42,7 +43,11 @@ public void create(Validation validation) { @Override public void update(Validation validation) { - dao.update(validation); + if(validation.isDeactivated()) { + dao.updateDeactivated(validation); + } else { + dao.update(validation); + } } @Override diff --git a/src/main/resources/messages_ru.properties b/src/main/resources/messages_ru.properties index 916bcd1..78f7ed0 100644 --- a/src/main/resources/messages_ru.properties +++ b/src/main/resources/messages_ru.properties @@ -14,7 +14,7 @@ 012=Сообщение об ошибке не задано. 013=Указан несуществующий код сообщения об ошибке. 014=Описание обязательно для заполнения. -015={0}. Комментарий должен отличаться от комментария предудыщей версии. +015={0}. Комментарий должен отличаться от комментария предыдущей версии. 016={0} - не указано. 017=Пароль не совпадает с повторно введенным паролем. diff --git a/src/main/resources/public/app/controllers/ModelGridController.js b/src/main/resources/public/app/controllers/ModelGridController.js index 3c63e89..d31e052 100644 --- a/src/main/resources/public/app/controllers/ModelGridController.js +++ b/src/main/resources/public/app/controllers/ModelGridController.js @@ -23,6 +23,9 @@ Ext.define('app.controllers.ModelGridController', { gridStore: this.getView().store }); window.show(); + if (row.get('deactivated') === true) { + window.setReadOnly(); + } window.setLoading(true); var requestConfig = { diff --git a/src/main/resources/public/app/controllers/ModelWindowController.js b/src/main/resources/public/app/controllers/ModelWindowController.js index aebde49..a795046 100644 --- a/src/main/resources/public/app/controllers/ModelWindowController.js +++ b/src/main/resources/public/app/controllers/ModelWindowController.js @@ -127,7 +127,9 @@ Ext.define('app.controllers.ModelWindowController', { setModelToForm: function (form, model) { // Версию модели обновлять не будем, чтобы была возможность сохранить старую версию в качестве актуальной. var version = form.down('numberfield[name=version]').getValue(); + var deactivated = form.down('checkbox[name=deactivated]').getValue(); model.set('version', version); + model.set('deactivated', deactivated); form.loadRecord(model); } diff --git a/src/main/resources/public/app/controllers/ValidationWindowController.js b/src/main/resources/public/app/controllers/ValidationWindowController.js index 381c20e..6810cb3 100644 --- a/src/main/resources/public/app/controllers/ValidationWindowController.js +++ b/src/main/resources/public/app/controllers/ValidationWindowController.js @@ -56,6 +56,12 @@ Ext.define('app.controllers.ValidationWindowController', { grid.getStore().remove(row); }, + /** Добавление текста сообщения по его id. */ + onCodeOfMessageChange: function(){ + var messageId = this.getView().down('custom-combo[name=messageId]').getValue(); + this.getView().down('custom-combo[name=messageText]').setValue(messageId); + }, + /** Удаление строки с сущностью и операциями по нажатию на крестик той же строки. */ onDeleteGridRow: function (view, rowIndex) { view.getStore().removeAt(rowIndex); diff --git a/src/main/resources/public/app/models/BaseVersionableModel.js b/src/main/resources/public/app/models/BaseVersionableModel.js index 3526df6..85418f3 100644 --- a/src/main/resources/public/app/models/BaseVersionableModel.js +++ b/src/main/resources/public/app/models/BaseVersionableModel.js @@ -4,7 +4,8 @@ Ext.define('app.models.BaseVersionableModel', { fields: [ {name: 'id'}, {name: 'commentary'}, - {name: 'version'} + {name: 'version'}, + {name: 'deactivated'} ] }); \ No newline at end of file diff --git a/src/main/resources/public/app/models/Validation.js b/src/main/resources/public/app/models/Validation.js index 7acba7d..1a7c228 100644 --- a/src/main/resources/public/app/models/Validation.js +++ b/src/main/resources/public/app/models/Validation.js @@ -18,6 +18,7 @@ Ext.define('app.models.Validation', { fields: [ {name: 'messageId', mapping: 'message.id'}, + {name: 'messageText', mapping: 'message.text'}, {name: 'description'}, {name: 'validationEntities'}, {name: 'tags'}, diff --git a/src/main/resources/public/app/models/ValidationDto.js b/src/main/resources/public/app/models/ValidationDto.js index 67c0911..9e2d192 100644 --- a/src/main/resources/public/app/models/ValidationDto.js +++ b/src/main/resources/public/app/models/ValidationDto.js @@ -13,7 +13,8 @@ Ext.define('app.models.ValidationDto', { {name: 'entityNames'}, {name: 'operationNames'}, {name: 'tagNames'}, - {name: 'severityId'} + {name: 'severityId'}, + {name: 'deactivated'} ] }); \ No newline at end of file diff --git a/src/main/resources/public/app/views/EntityWindow.js b/src/main/resources/public/app/views/EntityWindow.js index 52fd342..975cf13 100644 --- a/src/main/resources/public/app/views/EntityWindow.js +++ b/src/main/resources/public/app/views/EntityWindow.js @@ -36,6 +36,13 @@ Ext.define('app.views.EntityWindow', { xtype: 'numberfield', name: 'version', hidden: true + }, + { + xtype: 'checkbox', + inputValue: true, + uncheckedValue: false, + name: 'deactivated', + hidden: true } ]; } diff --git a/src/main/resources/public/app/views/MessageWindow.js b/src/main/resources/public/app/views/MessageWindow.js index 03f349f..0fbebd0 100644 --- a/src/main/resources/public/app/views/MessageWindow.js +++ b/src/main/resources/public/app/views/MessageWindow.js @@ -31,6 +31,13 @@ Ext.define('app.views.MessageWindow', { xtype: 'numberfield', name: 'version', hidden: true + }, + { + xtype: 'checkbox', + inputValue: true, + uncheckedValue: false, + name: 'deactivated', + hidden: true } ]; } diff --git a/src/main/resources/public/app/views/ModelGrid.js b/src/main/resources/public/app/views/ModelGrid.js index f4abf57..033404f 100644 --- a/src/main/resources/public/app/views/ModelGrid.js +++ b/src/main/resources/public/app/views/ModelGrid.js @@ -10,6 +10,13 @@ Ext.define('app.views.ModelGrid', { plugins: 'gridfilters', + viewConfig: { + getRowClass: function (record) { + if (record.get('deactivated') === true) + return 'red-row' + } + }, + constructor: function () { this.callParent(arguments); diff --git a/src/main/resources/public/app/views/ModelWindow.js b/src/main/resources/public/app/views/ModelWindow.js index 95a1d45..a448eba 100644 --- a/src/main/resources/public/app/views/ModelWindow.js +++ b/src/main/resources/public/app/views/ModelWindow.js @@ -138,6 +138,10 @@ Ext.define('app.views.ModelWindow', { click: 'delete' } } - ] + ], + + setReadOnly: function () { + this.down('button[name=delete]').setDisabled(true); + } }); \ No newline at end of file diff --git a/src/main/resources/public/app/views/OperationWindow.js b/src/main/resources/public/app/views/OperationWindow.js index 94e632e..392135e 100644 --- a/src/main/resources/public/app/views/OperationWindow.js +++ b/src/main/resources/public/app/views/OperationWindow.js @@ -36,6 +36,13 @@ Ext.define('app.views.OperationWindow', { xtype: 'numberfield', name: 'version', hidden: true + }, + { + xtype: 'checkbox', + inputValue: true, + uncheckedValue: false, + name: 'deactivated', + hidden: true } ]; } diff --git a/src/main/resources/public/app/views/TagWindow.js b/src/main/resources/public/app/views/TagWindow.js index 90a6efb..cdcaf3f 100644 --- a/src/main/resources/public/app/views/TagWindow.js +++ b/src/main/resources/public/app/views/TagWindow.js @@ -33,6 +33,13 @@ Ext.define('app.views.TagWindow', { xtype: 'numberfield', name: 'version', hidden: true + }, + { + xtype: 'checkbox', + inputValue: true, + uncheckedValue: false, + name: 'deactivated', + hidden: true } ]; } diff --git a/src/main/resources/public/app/views/ValidationWindow.js b/src/main/resources/public/app/views/ValidationWindow.js index aa37051..6ba3e3e 100644 --- a/src/main/resources/public/app/views/ValidationWindow.js +++ b/src/main/resources/public/app/views/ValidationWindow.js @@ -153,13 +153,28 @@ Ext.define('app.views.ValidationWindow', { xtype: 'custom-combo', store: { type: 'message-store', - autoLoad: false + autoLoad: true }, valueField: 'id', displayField: 'id', fieldLabel: 'Код сообщения об ошибке', + listeners: { + change: 'onCodeOfMessageChange' + }, name: 'messageId' }, + { + xtype: 'custom-combo', + store: { + type: 'message-store', + autoLoad: true + }, + valueField: 'id', + displayField: 'text', + editable: false, + fieldLabel: 'Текст сообщения об ошибке', + name: 'messageText' + }, { xtype: 'resizable-textarea', fieldLabel: 'Описание', @@ -176,6 +191,13 @@ Ext.define('app.views.ValidationWindow', { xtype: 'numberfield', name: 'version', hidden: true + }, + { + xtype: 'checkbox', + inputValue: true, + uncheckedValue: false, + name: 'deactivated', + hidden: true } ]; } diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index 19da867..fe5ad14 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -50,6 +50,9 @@ font-size: large; } + .red-row { + background-color: brown; + } diff --git a/src/main/resources/queries/entity/FindEntity.sql b/src/main/resources/queries/entity/FindEntity.sql index 8448882..461e02b 100644 --- a/src/main/resources/queries/entity/FindEntity.sql +++ b/src/main/resources/queries/entity/FindEntity.sql @@ -1,9 +1,16 @@ SELECT * FROM ( - SELECT - entity_id AS id, - name, - description, - version, - commentary - FROM entity ORDER BY entity_id + SELECT eh2.entity_id AS id, + eh2.name, + eh2.description, + eh2.version, + eh2.commentary, + e.entity_id is null as deactivated + FROM (SELECT eh.entity_id AS id, + MAX(eh.version) AS maxVersion + FROM entity_h eh + GROUP BY eh.entity_id + ORDER BY eh.entity_id) AS maxVersions + JOIN entity_h eh2 on eh2.entity_id = maxVersions.id AND eh2.version = maxVersions.maxVersion + LEFT JOIN entity e on e.entity_id = maxVersions.id + ORDER BY eh2.entity_id ) wrapper \ No newline at end of file diff --git a/src/main/resources/queries/entity/GetCurrentCommentary.sql b/src/main/resources/queries/entity/GetCurrentCommentary.sql index da6d618..cfb9d01 100644 --- a/src/main/resources/queries/entity/GetCurrentCommentary.sql +++ b/src/main/resources/queries/entity/GetCurrentCommentary.sql @@ -1 +1,8 @@ -SELECT commentary FROM entity WHERE entity_id = :entityId \ No newline at end of file +SELECT eh2.commentary +FROM (SELECT eh.entity_id AS id, + MAX(eh.version) AS version + FROM entity_h eh + GROUP BY eh.entity_id) AS maxVersions + JOIN entity_h eh2 on eh2.entity_id = maxVersions.id AND eh2.version = maxVersions.version + LEFT JOIN entity e on e.entity_id = maxVersions.id +WHERE eh2.entity_id = :entityId \ No newline at end of file diff --git a/src/main/resources/queries/entity/LoadEntity.sql b/src/main/resources/queries/entity/LoadEntity.sql index b104d68..5b5ca0d 100644 --- a/src/main/resources/queries/entity/LoadEntity.sql +++ b/src/main/resources/queries/entity/LoadEntity.sql @@ -1,8 +1,15 @@ -SELECT - entity_id AS id, - name, - description, - version, - commentary -FROM entity -WHERE entity_id = :id \ No newline at end of file +SELECT eh2.entity_id AS id, + eh2.name, + eh2.description, + eh2.version, + eh2.commentary, + e.entity_id is null as deactivated +FROM (SELECT eh.entity_id AS id, + MAX(eh.version) AS maxVersion + FROM entity_h eh + GROUP BY eh.entity_id + ORDER BY eh.entity_id) AS maxVersions + JOIN entity_h eh2 on eh2.entity_id = maxVersions.id AND eh2.version = maxVersions.maxVersion + LEFT JOIN entity e on e.entity_id = maxVersions.id +WHERE eh2.entity_id = :id +ORDER BY eh2.entity_id; \ No newline at end of file diff --git a/src/main/resources/queries/entity/UpdateDeactivatedEntity.sql b/src/main/resources/queries/entity/UpdateDeactivatedEntity.sql new file mode 100644 index 0000000..6b9f1d6 --- /dev/null +++ b/src/main/resources/queries/entity/UpdateDeactivatedEntity.sql @@ -0,0 +1,10 @@ +INSERT INTO entity (entity_id, + name, + version, + description, + commentary) +VALUES (:id, + :name, + :version + 1, + :description, + :commentary) \ No newline at end of file diff --git a/src/main/resources/queries/message/FindMessage.sql b/src/main/resources/queries/message/FindMessage.sql index 12b5f12..ecb3f35 100644 --- a/src/main/resources/queries/message/FindMessage.sql +++ b/src/main/resources/queries/message/FindMessage.sql @@ -1,8 +1,14 @@ SELECT * FROM ( - SELECT - message_id AS id, - text, - version, - commentary - FROM message ORDER BY message_id + SELECT mh2.message_id AS id, + mh2.text, + mh2.version, + mh2.commentary, + m.message_id is null as deactivated + FROM (SELECT mh.message_id AS id, + MAX(mh.version) AS maxVersion + FROM message_h mh + GROUP BY mh.message_id + ORDER BY mh.message_id) AS maxVersions + JOIN message_h mh2 on mh2.message_id = maxVersions.id AND mh2.version = maxVersions.maxVersion + LEFT JOIN message m on m.message_id = maxVersions.id ) wrapper \ No newline at end of file diff --git a/src/main/resources/queries/message/GetCurrentCommentary.sql b/src/main/resources/queries/message/GetCurrentCommentary.sql index 6ba381e..6d35a4f 100644 --- a/src/main/resources/queries/message/GetCurrentCommentary.sql +++ b/src/main/resources/queries/message/GetCurrentCommentary.sql @@ -1 +1,8 @@ -SELECT commentary FROM message WHERE message_id = :messageId \ No newline at end of file +SELECT mh2.commentary +FROM (SELECT mh.message_id AS id, + MAX(mh.version) AS version + FROM message_h mh + GROUP BY mh.message_id) AS maxVersions + JOIN message_h mh2 on mh2.message_id = maxVersions.id AND mh2.version = maxVersions.version + LEFT JOIN message m on m.message_id = maxVersions.id +WHERE mh2.message_id = :messageId \ No newline at end of file diff --git a/src/main/resources/queries/message/LoadMessage.sql b/src/main/resources/queries/message/LoadMessage.sql index c5b0bd7..9931e80 100644 --- a/src/main/resources/queries/message/LoadMessage.sql +++ b/src/main/resources/queries/message/LoadMessage.sql @@ -1,7 +1,13 @@ -SELECT - message_id AS id, - text, - version, - commentary -FROM message -WHERE message_id = :id \ No newline at end of file +SELECT mh2.message_id AS id, + mh2.text, + mh2.version, + mh2.commentary, + m.message_id is null as deactivated +FROM (SELECT mh.message_id AS id, + MAX(mh.version) AS maxVersion + FROM message_h mh + GROUP BY mh.message_id + ORDER BY mh.message_id) AS maxVersions + JOIN message_h mh2 on mh2.message_id = maxVersions.id AND mh2.version = maxVersions.maxVersion + LEFT JOIN message m on m.message_id = maxVersions.id +WHERE mh2.message_id = :id \ No newline at end of file diff --git a/src/main/resources/queries/message/UpdateDeactivatedMessage.sql b/src/main/resources/queries/message/UpdateDeactivatedMessage.sql new file mode 100644 index 0000000..12cf8de --- /dev/null +++ b/src/main/resources/queries/message/UpdateDeactivatedMessage.sql @@ -0,0 +1,8 @@ +INSERT INTO message (message_id, + text, + version, + commentary) +VALUES (:id, + :text, + :version + 1, + :commentary) \ No newline at end of file diff --git a/src/main/resources/queries/operation/FindOperation.sql b/src/main/resources/queries/operation/FindOperation.sql index 11e9fef..d4b1ba3 100644 --- a/src/main/resources/queries/operation/FindOperation.sql +++ b/src/main/resources/queries/operation/FindOperation.sql @@ -1,9 +1,17 @@ -SELECT * FROM ( - SELECT - operation_id AS id, - name, - description, - version, - commentary - FROM operation ORDER BY operation_id -) wrapper \ No newline at end of file +SELECT * +FROM ( + SELECT oh2.operation_id AS id, + oh2.name, + oh2.description, + oh2.version, + oh2.commentary, + o.operation_id is null as deactivated + FROM (SELECT oh.operation_id AS id, + MAX(oh.version) AS maxVersion + FROM operation_h oh + GROUP BY oh.operation_id + ORDER BY oh.operation_id) AS maxVersions + JOIN operation_h oh2 on oh2.operation_id = maxVersions.id AND oh2.version = maxVersions.maxVersion + LEFT JOIN operation o on o.operation_id = maxVersions.id + ORDER BY oh2.operation_id + ) wrapper \ No newline at end of file diff --git a/src/main/resources/queries/operation/GetCurrentCommentary.sql b/src/main/resources/queries/operation/GetCurrentCommentary.sql index c240031..10faa56 100644 --- a/src/main/resources/queries/operation/GetCurrentCommentary.sql +++ b/src/main/resources/queries/operation/GetCurrentCommentary.sql @@ -1 +1,8 @@ -SELECT commentary FROM operation WHERE operation_id = :operationId \ No newline at end of file +SELECT oh2.commentary +FROM (SELECT oh.operation_id AS id, + MAX(oh.version) AS version + FROM operation_h oh + GROUP BY oh.operation_id) AS maxVersions + JOIN operation_h oh2 on oh2.operation_id = maxVersions.id AND oh2.version = maxVersions.version + LEFT JOIN operation o on o.operation_id = maxVersions.id +WHERE oh2.operation_id = :operationId \ No newline at end of file diff --git a/src/main/resources/queries/operation/LoadOperation.sql b/src/main/resources/queries/operation/LoadOperation.sql index d3314ab..ddf4ea9 100644 --- a/src/main/resources/queries/operation/LoadOperation.sql +++ b/src/main/resources/queries/operation/LoadOperation.sql @@ -1,8 +1,15 @@ -SELECT - operation_id AS id, - name, - description, - version, - commentary -FROM operation -WHERE operation_id = :id \ No newline at end of file +SELECT oh2.operation_id AS id, + oh2.name, + oh2.description, + oh2.version, + oh2.commentary, + o.operation_id is null as deactivated +FROM (SELECT oh.operation_id AS id, + MAX(oh.version) AS maxVersion + FROM operation_h oh + GROUP BY oh.operation_id + ORDER BY oh.operation_id) AS maxVersions + JOIN operation_h oh2 on oh2.operation_id = maxVersions.id AND oh2.version = maxVersions.maxVersion + LEFT JOIN operation o on o.operation_id = maxVersions.id +WHERE oh2.operation_id = :id +ORDER BY oh2.operation_id diff --git a/src/main/resources/queries/operation/UpdateDeactivatedOperation.sql b/src/main/resources/queries/operation/UpdateDeactivatedOperation.sql new file mode 100644 index 0000000..577041f --- /dev/null +++ b/src/main/resources/queries/operation/UpdateDeactivatedOperation.sql @@ -0,0 +1,10 @@ +insert into operation(operation_id, + name, + version, + description, + commentary) +values (:id, + :name, + :version + 1, + :description, + :commentary) \ No newline at end of file diff --git a/src/main/resources/queries/tag/FindTag.sql b/src/main/resources/queries/tag/FindTag.sql index 07dd30f..a841ae7 100644 --- a/src/main/resources/queries/tag/FindTag.sql +++ b/src/main/resources/queries/tag/FindTag.sql @@ -1,9 +1,16 @@ -SELECT * FROM ( - SELECT - tag_id AS id, - name, - version, - description, - commentary - FROM tag ORDER BY name -) wrapper +SELECT * +FROM ( + SELECT th2.tag_id AS id, + th2.name, + th2.version, + th2.description, + th2.commentary, + t.tag_id is null as deactivated + FROM (SELECT th.tag_id AS id, + MAX(th.version) AS maxVersion + FROM tag_h th + GROUP BY th.tag_id + ORDER BY th.tag_id) AS maxVersions + JOIN tag_h th2 on th2.tag_id = maxVersions.id AND th2.version = maxVersions.maxVersion + LEFT JOIN tag t on t.tag_id = maxVersions.id + ) wrapper \ No newline at end of file diff --git a/src/main/resources/queries/tag/LoadTag.sql b/src/main/resources/queries/tag/LoadTag.sql index 1e4786a..f5cf3cb 100644 --- a/src/main/resources/queries/tag/LoadTag.sql +++ b/src/main/resources/queries/tag/LoadTag.sql @@ -1,8 +1,14 @@ -SELECT - tag_id AS id, - name, - version, - description, - commentary -FROM tag -WHERE tag_id IN (:ids) +SELECT th2.tag_id AS id, + th2.name, + th2.version, + th2.description, + th2.commentary, + t.tag_id is null as deactivated +FROM (SELECT th.tag_id AS id, + MAX(th.version) AS maxVersion + FROM tag_h th + GROUP BY th.tag_id + ORDER BY th.tag_id) AS maxVersions + JOIN tag_h th2 on th2.tag_id = maxVersions.id AND th2.version = maxVersions.maxVersion + LEFT JOIN tag t on t.tag_id = maxVersions.id +WHERE th2.tag_id IN (:ids) diff --git a/src/main/resources/queries/tag/UpdateDeactivatedTag.sql b/src/main/resources/queries/tag/UpdateDeactivatedTag.sql new file mode 100644 index 0000000..02c6733 --- /dev/null +++ b/src/main/resources/queries/tag/UpdateDeactivatedTag.sql @@ -0,0 +1,10 @@ +INSERT INTO tag (tag_id, + name, + version, + description, + commentary) +VALUES (:id, + :name, + :version + 1, + :description, + :commentary) diff --git a/src/main/resources/queries/validation/FindValidation.sql b/src/main/resources/queries/validation/FindValidation.sql index 84af3ca..6889c6b 100644 --- a/src/main/resources/queries/validation/FindValidation.sql +++ b/src/main/resources/queries/validation/FindValidation.sql @@ -1,24 +1,30 @@ -select * from ( -SELECT - v.validation_id AS id, - m.message_id AS messageId, - m.text AS messageText, - v.description AS description, - v.version AS version, - v.commentary AS commentary, - s.severity_id AS severityId, - s.name AS severityName, - string_agg(DISTINCT en.name, ', ') AS entityNames, - string_agg(DISTINCT op.name, ', ') AS operationNames, - string_agg(DISTINCT t.name, ', ') AS tagNames -FROM validation v - JOIN validation_entity_operation veo on v.validation_id = veo.validation_id - JOIN operation op on veo.operation_id = op.operation_id - JOIN entity en on veo.entity_id = en.entity_id - JOIN message m on v.message_id = m.message_id - JOIN severity s on v.severity_id = s.severity_id - LEFT JOIN validation_tag vt on v.validation_id = vt.validation_id - LEFT JOIN tag t on vt.tag_id = t.tag_id -GROUP BY v.validation_id, m.message_id, s.severity_id -ORDER BY v.validation_id -) wrapper \ No newline at end of file +SELECT * +FROM ( + SELECT vh2.validation_id AS id, + mh.message_id AS messageId, + mh.text AS messageText, + vh2.description AS description, + vh2.version AS version, + vh2.commentary AS commentary, + s.severity_id AS severityId, + s.name AS severityName, + string_agg(DISTINCT eh.name, ', ') AS entityNames, + string_agg(DISTINCT oh.name, ', ') AS operationNames, + string_agg(DISTINCT th.name, ', ') AS tagNames, + v.validation_id is null AS deactivated + FROM (SELECT vh.validation_id AS id, + MAX(vh.version) AS version + FROM validation_h vh + GROUP BY vh.validation_id) AS maxVersions + JOIN validation_h vh2 on vh2.validation_id = maxVersions.id AND vh2.version = maxVersions.version + LEFT JOIN validation v on vh2.validation_id = v.validation_id + JOIN message_h mh on vh2.message_version_id = mh.message_version_id + JOIN validation_entity_operation_h veoh on vh2.validation_version_id = veoh.validation_version_id + JOIN operation_h oh on veoh.operation_version_id = oh.operation_version_id + JOIN entity_h eh on veoh.entity_version_id = eh.entity_version_id + JOIN severity s on vh2.severity_id = s.severity_id + LEFT JOIN validation_tag_h vth on vh2.validation_version_id = vth.validation_version_id + LEFT JOIN tag_h th on vth.tag_version_id = th.tag_version_id + GROUP BY vh2.validation_version_id, mh.message_version_id, s.severity_id, v.validation_id, vh2.validation_id + ORDER BY vh2.validation_id + ) wrapper \ No newline at end of file diff --git a/src/main/resources/queries/validation/GetCurrentCommentary.sql b/src/main/resources/queries/validation/GetCurrentCommentary.sql index b2b4a55..fd9e7c4 100644 --- a/src/main/resources/queries/validation/GetCurrentCommentary.sql +++ b/src/main/resources/queries/validation/GetCurrentCommentary.sql @@ -1 +1,8 @@ -SELECT commentary FROM validation WHERE validation_id = :validationId \ No newline at end of file +SELECT vh2.commentary +FROM (SELECT vh.validation_id AS id, + MAX(vh.version) AS version + FROM validation_h vh + GROUP BY vh.validation_id) AS maxVersions + JOIN validation_h vh2 on vh2.validation_id = maxVersions.id AND vh2.version = maxVersions.version + LEFT JOIN validation v on v.validation_id = maxVersions.id +WHERE vh2.validation_id = :validationId \ No newline at end of file diff --git a/src/main/resources/queries/validation/LoadTags.sql b/src/main/resources/queries/validation/LoadTags.sql index 908260f..de0e5e6 100644 --- a/src/main/resources/queries/validation/LoadTags.sql +++ b/src/main/resources/queries/validation/LoadTags.sql @@ -1,10 +1,18 @@ SELECT - vt.validation_id AS v_id, - t.tag_id AS id, - t.name, - t.version, - t.description, - t.commentary -FROM validation_tag vt - JOIN tag t ON vt.tag_id = t.tag_id -WHERE vt.validation_id IN (:ids) + vh2.validation_id AS v_id, + t.tag_id AS id, + t.name, + t.version, + t.description, + t.commentary, + t.tag_id is null AS deactivated +FROM (SELECT vh.validation_id AS id, + MAX(vh.version) AS maxVersion + FROM validation_h vh + GROUP BY vh.validation_id + ORDER BY vh.validation_id) AS maxVersions + JOIN validation_h vh2 ON vh2.validation_id = maxVersions.id AND vh2.version = maxVersions.maxVersion + JOIN validation_tag_h vth ON vh2.validation_version_id = vth.validation_version_id + JOIN tag_h th2 ON vth.tag_version_id = th2.tag_version_id + JOIN tag t ON th2.tag_id = t.tag_id +WHERE vh2.validation_id IN (:ids) diff --git a/src/main/resources/queries/validation/LoadTagsVersion.sql b/src/main/resources/queries/validation/LoadTagsVersion.sql index 28d3102..7117e73 100644 --- a/src/main/resources/queries/validation/LoadTagsVersion.sql +++ b/src/main/resources/queries/validation/LoadTagsVersion.sql @@ -6,4 +6,4 @@ SELECT t.commentary FROM validation_tag_h vth JOIN tag_h t ON vth.tag_version_id = t.tag_version_id -WHERE vth.validation_version_id = :id +WHERE vth.validation_version_id IN (:id) diff --git a/src/main/resources/queries/validation/LoadValidation.sql b/src/main/resources/queries/validation/LoadValidation.sql index b60c0e1..1988d84 100644 --- a/src/main/resources/queries/validation/LoadValidation.sql +++ b/src/main/resources/queries/validation/LoadValidation.sql @@ -1,16 +1,23 @@ -SELECT - v.validation_id AS id, - v.description AS description, - v.version AS version, - v.commentary AS commentary, +SELECT vh2.validation_id AS id, + vh2.description AS description, + vh2.version AS version, + vh2.commentary AS commentary, - v.severity_id AS severityId, + vh2.severity_id AS severityId, - m.message_id AS m_id, - m.text AS m_text, - m.version AS m_version, - m.commentary AS m_commentary + mh.message_id AS m_id, + mh.text AS m_text, + mh.version AS m_version, + mh.commentary AS m_commentary, -FROM validation v - JOIN message m ON v.message_id = m.message_id -WHERE v.validation_id in (:ids) \ No newline at end of file + v.validation_id is null AS deactivated +FROM (SELECT vh.validation_id AS id, + MAX(vh.version) AS version + FROM validation_h vh + GROUP BY vh.validation_id) AS maxVersions + JOIN validation_h vh2 on vh2.validation_id = maxVersions.id AND vh2.version = maxVersions.version + LEFT JOIN validation v on vh2.validation_id = v.validation_id + JOIN message_h mh on vh2.message_version_id = mh.message_version_id +WHERE vh2.validation_id IN (:ids) +GROUP BY vh2.validation_version_id, mh.message_version_id, v.validation_id, vh2.validation_id +ORDER BY vh2.validation_id \ No newline at end of file diff --git a/src/main/resources/queries/validation/LoadValidationEntities.sql b/src/main/resources/queries/validation/LoadValidationEntities.sql index 691bb04..1a58304 100644 --- a/src/main/resources/queries/validation/LoadValidationEntities.sql +++ b/src/main/resources/queries/validation/LoadValidationEntities.sql @@ -1,18 +1,26 @@ -SELECT - veo.validation_id AS v_id, - e.entity_id AS e_id, - e.name AS e_name, - e.description AS e_description, - e.version AS e_version, - e.commentary AS e_commentary, +SELECT vh2.validation_id AS v_id, - o.operation_id AS o_id, - o.name AS o_name, - o.description AS o_description, - o.version AS o_version, - o.commentary AS o_commentary + e.entity_id AS e_id, + e.name AS e_name, + e.description AS e_description, + e.version AS e_version, + e.commentary AS e_commentary, -FROM validation_entity_operation veo - JOIN entity e ON veo.entity_id = e.entity_id - JOIN operation o ON veo.operation_id = o.operation_id -WHERE veo.validation_id IN (:ids) \ No newline at end of file + o.operation_id AS o_id, + o.name AS o_name, + o.description AS o_description, + o.version AS o_version, + o.commentary AS o_commentary +FROM (SELECT vh.validation_id AS id, + MAX(vh.version) AS maxVersion + FROM validation_h vh + GROUP BY vh.validation_id + ORDER BY vh.validation_id) AS maxVersions + JOIN validation_h vh2 ON vh2.validation_id = maxVersions.id AND vh2.version = maxVersions.maxVersion + JOIN validation_entity_operation_h veoh on vh2.validation_version_id = veoh.validation_version_id + JOIN entity_h eh2 on veoh.entity_version_id = eh2.entity_version_id + JOIN entity e on eh2.entity_id = e.entity_id + JOIN operation_h oh2 on veoh.operation_version_id = oh2.operation_version_id + JOIN operation o on oh2.operation_id = o.operation_id +WHERE vh2.validation_id IN (:ids) +ORDER BY vh2.validation_id \ No newline at end of file diff --git a/src/main/resources/queries/validation/LoadValidationEntitiesVersions.sql b/src/main/resources/queries/validation/LoadValidationEntitiesVersions.sql index 13bc28f..3c36b99 100644 --- a/src/main/resources/queries/validation/LoadValidationEntitiesVersions.sql +++ b/src/main/resources/queries/validation/LoadValidationEntitiesVersions.sql @@ -14,4 +14,4 @@ SELECT FROM validation_entity_operation_h veo JOIN entity_h e ON veo.entity_version_id = e.entity_version_id JOIN operation_h o ON veo.operation_version_id = o.operation_version_id -WHERE veo.validation_version_id = :id \ No newline at end of file +WHERE veo.validation_version_id IN (:id) \ No newline at end of file diff --git a/src/main/resources/queries/validation/LoadValidationVersionIdByValidationId.sql b/src/main/resources/queries/validation/LoadValidationVersionIdByValidationId.sql new file mode 100644 index 0000000..7532566 --- /dev/null +++ b/src/main/resources/queries/validation/LoadValidationVersionIdByValidationId.sql @@ -0,0 +1,9 @@ +SELECT vh2.validation_version_id + FROM (SELECT vh.validation_id AS id, + MAX(vh.version) AS version + FROM validation_h vh + GROUP BY vh.validation_id) AS maxVersions + JOIN validation_h vh2 on vh2.validation_id = maxVersions.id AND vh2.version = maxVersions.version + AND NOT EXISTS(SELECT * FROM validation v WHERE v.validation_id = vh2.validation_id) + WHERE vh2.validation_id in (:ids) + GROUP BY vh2.validation_version_id \ No newline at end of file diff --git a/src/main/resources/queries/validation/UpdateDeactivatedValidation.sql b/src/main/resources/queries/validation/UpdateDeactivatedValidation.sql new file mode 100644 index 0000000..d2a2fa6 --- /dev/null +++ b/src/main/resources/queries/validation/UpdateDeactivatedValidation.sql @@ -0,0 +1,12 @@ +INSERT INTO validation (validation_id, + version, + severity_id, + message_id, + description, + commentary) +VALUES (:id, + :version + 1, + :severityId, + :messageId, + :description, + :commentary) \ No newline at end of file