Commit 1f459dda authored by Enriko Käsper's avatar Enriko Käsper

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/commons!101
parents f2678ff3 19b7dbe0
Pipeline #1187 failed
......@@ -25,6 +25,7 @@ public enum RolePrivilegeCode {
EX_MANAGE_AUTHORITIES, EX_VIEW_AUTHORITIES,
EX_VIEW_DASHBOARD,
EX_MANAGE_ACTION_PLAN, EX_VIEW_ACTION_PLAN,
EX_MANAGE_LOCATIONS,
EX_MANAGE_MESSAGES, EX_VIEW_MESSAGES,
EX_VIEW_PAYMENTS,
......
package ee.sm.ti.teis.types.enums;
public enum TaskDefinitionType {
ACTION_PLAN_TASK
}
......@@ -7,7 +7,8 @@ import lombok.Getter;
@Getter
public enum TaskTagType {
VIOLATION_RETURNED("TASK_TAG__VIOLATION_RETURNED", "VIOLATION_RETURNED"),
NULL_TAG("TASK_TAG__NULL_TAG", "NULL_TAG");
NULL_TAG("TASK_TAG__NULL_TAG", "NULL_TAG"),
HIGH_PRIORITY("TASK_TAG__HIGH_PRIORITY", "HIGH_PRIORITY");
private final String id;
private final String code;
......
......@@ -5,6 +5,7 @@ import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domainrequest.DomainQueryResponseDto;
import ee.sm.ti.teis.domainrequest.DomainResponseDTO;
import ee.sm.ti.teis.domainrequest.rabbit.TeisRabbitClient;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
......@@ -12,9 +13,12 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
@Service("genericClassifierService")
@Slf4j
public class ClassifierService extends TeisRabbitClient<ClassifierItem> {
......@@ -45,7 +49,60 @@ public class ClassifierService extends TeisRabbitClient<ClassifierItem> {
return classifierItem;
}
public ClassifierItem getClassifierItemByCode(String classifierDefinitionCode, String classifierItemCode, RequestMetaDTO requestMetaDTO) {
public ClassifierItem getCurrentClassifierItem(String classifierItemId, RequestMetaDTO requestMetaDTO) {
ClassifierItem item = getClassifierItem(classifierItemId, requestMetaDTO);
if (item.getObjectStatus().equals(DELETED.name())) {
throw new TeisResourceNotFoundException("Classifier item not found", List.of(item.getId()));
}
return item;
}
public ClassifierItem getClassifierItemByLevel(String classifierItemId, Integer level,
RequestMetaDTO requestMetaDTO) {
if (cacheById.containsKey(classifierItemId)) {
return cacheById.get(classifierItemId);
}
ClassifierItem item = new ClassifierItem();
item.setId(classifierItemId);
item.setLevel(level);
Optional<ClassifierItem> entity = cacheRepository.findByIdAndLevel(classifierItemId, level);
if (entity.isEmpty()) {
log.debug("Classifier {} not found from cache, requesting item from classifiers-service", classifierItemId);
}
ClassifierItem classifierItem = entity
.orElseGet(() -> getItem(item, ClassifierItemResponseMessage.class, requestMetaDTO));
cacheById.put(classifierItemId, classifierItem);
return classifierItem;
}
public ClassifierItem getClassifierItemByCode(String classifierDefinitionCode, String classifierItemCode,
RequestMetaDTO requestMetaDTO) {
String cacheKey = classifierDefinitionCode + "__" + classifierItemCode;
if (cacheByCode.containsKey(cacheKey)) {
return cacheByCode.get(cacheKey);
}
ClassifierItem item = new ClassifierItem();
item.setCode(classifierItemCode);
item.setClassifierDefinitionId(classifierDefinitionCode);
Optional<ClassifierItem> entity = cacheRepository.findByClassifierDefinitionIdAndCode(
classifierDefinitionCode, classifierItemCode);
ClassifierItem classifierItem = entity
.orElseGet(() -> getItem(item, ClassifierItemResponseMessage.class, requestMetaDTO));
cacheByCode.put(cacheKey, classifierItem);
return classifierItem;
}
public ClassifierItem getCurrentClassifierItemByCode(String classifierDefinitionCode, String classifierItemCode,
RequestMetaDTO requestMetaDTO) {
ClassifierItem item = getClassifierItemByCode(classifierDefinitionCode, classifierItemCode, requestMetaDTO);
if (item.getObjectStatus().equals(DELETED.name())) {
throw new TeisResourceNotFoundException("Classifier item not found", List.of(item.getId()));
}
return item;
}
public ClassifierItem getClassifierItemByCodeAndLevel(String classifierDefinitionCode, String classifierItemCode,
Integer level, RequestMetaDTO requestMetaDTO) {
String cacheKey = classifierDefinitionCode + "__" + classifierItemCode;
if (cacheByCode.containsKey(cacheKey)) {
return cacheByCode.get(cacheKey);
......@@ -53,7 +110,9 @@ public class ClassifierService extends TeisRabbitClient<ClassifierItem> {
ClassifierItem item = new ClassifierItem();
item.setCode(classifierItemCode);
item.setClassifierDefinitionId(classifierDefinitionCode);
Optional<ClassifierItem> entity = cacheRepository.findByClassifierDefinitionIdAndCode(classifierDefinitionCode, classifierItemCode);
item.setLevel(level);
Optional<ClassifierItem> entity = cacheRepository.findByClassifierDefinitionIdAndCodeAndLevel(classifierDefinitionCode,
classifierItemCode, level);
ClassifierItem classifierItem = entity
.orElseGet(() -> getItem(item, ClassifierItemResponseMessage.class, requestMetaDTO));
cacheByCode.put(cacheKey, classifierItem);
......
......@@ -8,4 +8,8 @@ import java.util.Optional;
public interface GenericClassifierItemCacheRepository extends JpaRepository<ClassifierItem, String> {
Optional<ClassifierItem> findByClassifierDefinitionIdAndCode(String definition, String code);
Optional<ClassifierItem> findByClassifierDefinitionIdAndCodeAndLevel(String definition, String code, Integer level);
Optional<ClassifierItem> findByIdAndLevel(String id, Integer level);
}
......@@ -24,6 +24,7 @@ public class PatchTask extends AbstractDomain {
private String description;
private TaskStatusType status;
private ClassifierItemLight tag;
private String responsiblePerson;
public boolean isSingle() {
return this.getId() != null;
......
......@@ -31,6 +31,7 @@ public class Task extends AuditedAbstractDomain {
private String description;
private TaskStatusType status;
private ClassifierItemLight tag;
private String responsiblePerson;
@Valid
private List<DataObjectReference> dataObjectReferences;
@Valid
......
......@@ -13,6 +13,7 @@ import java.util.Optional;
@Slf4j
public class SendDomainMessageEventListener {
private static final String[] ID_FIELDS = {"id", "dataObjectId", "fileId"};
private final RabbitTemplate msRabbitTemplate;
public SendDomainMessageEventListener(RabbitTemplate msRabbitTemplate) {
......@@ -23,23 +24,22 @@ public class SendDomainMessageEventListener {
if (payload == null) {
return Optional.empty();
}
Field field = ReflectionUtils.findField(payload.getClass(), "id");
if (field != null) {
ReflectionUtils.makeAccessible(field);
try {
if (field.get(payload) != null) {
return Optional.of(field.get(payload).toString());
}
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
for (String fieldName : ID_FIELDS) {
Optional<String> idFieldValue = getPayloadIdFieldValue(payload, fieldName);
if (idFieldValue.isPresent()) {
return idFieldValue;
}
}
field = ReflectionUtils.findField(payload.getClass(), "dataObjectId");
return Optional.empty();
}
private static Optional<String> getPayloadIdFieldValue(Object payload, String fieldName) {
Field field = ReflectionUtils.findField(payload.getClass(), fieldName);
if (field != null) {
ReflectionUtils.makeAccessible(field);
try {
if (field.get(payload) != null) {
return Optional.of(field.get(payload).toString());
return Optional.of(formatIdField(fieldName, field.get(payload).toString()));
}
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
......@@ -48,14 +48,18 @@ public class SendDomainMessageEventListener {
return Optional.empty();
}
private static String formatIdField(String fieldName, String fieldValue) {
return fieldName + "=" + fieldValue;
}
@TransactionalEventListener(fallbackExecution = true)
public void convertAndSendAfterCommit(SendDomainMessageEvent event) {
String payloadId = getPayloadId(event.getRequestDto().getPayload()).orElse("");
if (log.isDebugEnabled()) {
log.debug("Send domain event with routing key '{}', object id: '{}' and payload: {}", event.getRoutingKey(),
log.debug("Send domain event with routing key [{}], object id: [{}] and payload: {}", event.getRoutingKey(),
payloadId, event.getRequestDto().getPayload());
} else {
log.info("Send domain event with routing key: '{}', object id: '{}'", event.getRoutingKey(), payloadId);
log.info("Send domain event with routing key: [{}], object id: [{}]", event.getRoutingKey(), payloadId);
}
msRabbitTemplate.convertAndSend(event.getRoutingKey(), event.getRequestDto());
}
......
......@@ -69,7 +69,7 @@ class SendDomainMessageEventListenerTest {
void getPayloadId_success() {
ViolationAct payload = ViolationAct.builder().id(UUID.randomUUID()).build();
String id = SendDomainMessageEventListener.getPayloadId(payload).orElse(null);
assertThat(id).isEqualTo(payload.getId().toString());
assertThat(id).isEqualTo("id=" + payload.getId().toString());
}
@Test
......@@ -83,7 +83,7 @@ class SendDomainMessageEventListenerTest {
void getPayloadId_private_id_field_success() {
TestObjectWithPrivateId payload = new TestObjectWithPrivateId();
String id = SendDomainMessageEventListener.getPayloadId(payload).orElse(null);
assertThat(id).isEqualTo("123");
assertThat(id).isEqualTo("id=123");
}
@Test
......@@ -97,7 +97,14 @@ class SendDomainMessageEventListenerTest {
void getPayloadId_with_dataObjectId_field_success() {
TestObjectWithDataObjectId payload = new TestObjectWithDataObjectId();
String id = SendDomainMessageEventListener.getPayloadId(payload).orElse(null);
assertThat(id).isEqualTo("567");
assertThat(id).isEqualTo("dataObjectId=567");
}
@Test
void getPayloadId_with_filetId_field_success() {
TestObjectWithFileId payload = new TestObjectWithFileId();
String id = SendDomainMessageEventListener.getPayloadId(payload).orElse(null);
assertThat(id).isEqualTo("fileId=283");
}
@Test
......@@ -128,6 +135,11 @@ class SendDomainMessageEventListenerTest {
private final String dataObjectId = null;
}
class TestObjectWithFileId {
private final String id = null;
private final String fileId = "283";
}
class TestRequest extends AbstractDTO<TestObjectWithPrivateId, ErrorDTO> {
@Override
public String routingKey() {
......
# suppress inspection "UnusedProperty"
theGroup=ee.sm.ti.teis
//commonsVersion=forSearch ^commonsVersion=.*?-SNAPSHOT
version=1.16.0
version=1.17.0
publicVersion=1.11.0
pluginVersion=1.2.0
......@@ -14,15 +14,16 @@
</changeSet>
<!-- NB! only SELECT, INSERT, UPDATE privileges are assigned by default, DELETE privilege has to be assigned explicitly on tables to app_user in application changesets -->
<changeSet author="enriko" id="2000-01-01.002.grant-public-schema-privileges" runOnChange="true">
<changeSet author="enriko" id="2000-01-01.002.grant-public-schema-privileges-v2" runOnChange="true">
<preConditions onFail="CONTINUE">
<changeLogPropertyDefined property="db_app_username"/>
</preConditions>
<sql>
GRANT USAGE ON SCHEMA public TO ${db_app_username};
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO ${db_app_username};
GRANT USAGE, SELECT, UPDATE ON ALL SEQUENCES IN SCHEMA public TO ${db_app_username};
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE ON TABLES TO ${db_app_username};
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO ${db_app_username};
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT, UPDATE ON SEQUENCES TO ${db_app_username};
</sql>
</changeSet>
......
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