This commit is contained in:
Efstratios Giannopoulos 2024-02-21 09:55:29 +02:00
parent d6cd18729f
commit 07cdb91b9e
9 changed files with 48 additions and 22 deletions

View File

@ -9,8 +9,8 @@ public enum FieldType implements DatabaseEnum<String> {
SELECT(Names.Select), SELECT(Names.Select),
BOOLEAN_DECISION(Names.BooleanDecision), BOOLEAN_DECISION(Names.BooleanDecision),
RADIO_BOX(Names.RadioBox), RADIO_BOX(Names.RadioBox),
INTERNAL_DMP_ENTRIES_DMPS(Names.InternalDmpDmps), //TODO: rename InternalEntitiesDmps INTERNAL_ENTRIES_DMPS(Names.InternalDmpDmps),
INTERNAL_DMP_ENTRIES_DATASETS(Names.InternalDmpDescriptions),//TODO: rename InternalEntitiesDescriptions INTERNAL_ENTRIES_DESCRIPTIONS(Names.InternalDmpDescriptions),
CHECK_BOX(Names.CheckBox), CHECK_BOX(Names.CheckBox),
FREE_TEXT(Names.FreeText), FREE_TEXT(Names.FreeText),
TEXT_AREA(Names.TextArea), TEXT_AREA(Names.TextArea),
@ -69,12 +69,12 @@ public enum FieldType implements DatabaseEnum<String> {
return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.TEXT_AREA) || return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.TEXT_AREA) ||
fieldType.equals(FieldType.RICH_TEXT_AREA) || fieldType.equals(FieldType.UPLOAD) || fieldType.equals(FieldType.BOOLEAN_DECISION) || fieldType.equals(FieldType.RICH_TEXT_AREA) || fieldType.equals(FieldType.UPLOAD) || fieldType.equals(FieldType.BOOLEAN_DECISION) ||
fieldType.equals(FieldType.RADIO_BOX) || fieldType.equals(FieldType.CURRENCY) || fieldType.equals(FieldType.SELECT) || fieldType.equals(FieldType.RADIO_BOX) || fieldType.equals(FieldType.CURRENCY) || fieldType.equals(FieldType.SELECT) ||
fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); fieldType.equals(FieldType.INTERNAL_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS);
} }
public static boolean isTextListType(FieldType fieldType){ public static boolean isTextListType(FieldType fieldType){
return fieldType.equals(FieldType.SELECT) || fieldType.equals(FieldType.TAGS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || return fieldType.equals(FieldType.SELECT) || fieldType.equals(FieldType.TAGS) || fieldType.equals(FieldType.INTERNAL_ENTRIES_DMPS) ||
fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); fieldType.equals(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS);
} }
public static boolean isDateType(FieldType fieldType){ public static boolean isDateType(FieldType fieldType){

View File

@ -83,8 +83,8 @@ public class DescriptionFieldDepositBuilder extends BaseDepositBuilder<Descripti
case SELECT -> m.setFieldType(FieldType.WORD_LIST); case SELECT -> m.setFieldType(FieldType.WORD_LIST);
case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION);
case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX);
case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS); case INTERNAL_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS);
case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); case INTERNAL_ENTRIES_DESCRIPTIONS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS);
case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX);
case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT); case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT);
case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA); case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA);

View File

@ -1,7 +1,6 @@
package eu.eudat.model.mapper.publicapi; package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.descriptiontemplatedefinition.Page; import eu.eudat.model.descriptiontemplatedefinition.Page;
import eu.eudat.model.descriptiontemplatedefinition.Section;
import eu.eudat.model.publicapi.datasetwizard.DatasetProfilePage; import eu.eudat.model.publicapi.datasetwizard.DatasetProfilePage;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -126,7 +126,7 @@ public class FieldPersist {
.must(() -> this.isUUID(item.getTextValue())) .must(() -> this.isUUID(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> !this.isNull(item.getTextListValue()) && (fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS))) .iff(()-> !this.isNull(item.getTextListValue()) && (fieldType.equals(FieldType.INTERNAL_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS)))
.must(() -> item.getTextListValue().stream().allMatch(this::isUUID)) .must(() -> item.getTextListValue().stream().allMatch(this::isUUID))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.navSpec() this.navSpec()

View File

@ -66,7 +66,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.io.IOException; import java.io.IOException;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.file.Files;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
@ -412,13 +411,13 @@ public class DescriptionServiceImpl implements DescriptionService {
} }
} }
else if (FieldType.isTextListType(fieldType)) { else if (FieldType.isTextListType(fieldType)) {
if (FieldType.INTERNAL_DMP_ENTRIES_DMPS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){ if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList(); List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
Set<UUID> existingIds = this.queryFactory.query(DmpQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id)).stream().map(DmpEntity::getId).collect(Collectors.toSet()); Set<UUID> existingIds = this.queryFactory.query(DmpQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id)).stream().map(DmpEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){ for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} }
} if (FieldType.INTERNAL_DMP_ENTRIES_DATASETS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){ } if (FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList(); List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
Set<UUID> existingIds = this.queryFactory.query(DescriptionQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Description._id)).stream().map(DescriptionEntity::getId).collect(Collectors.toSet()); Set<UUID> existingIds = this.queryFactory.query(DescriptionQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Description._id)).stream().map(DescriptionEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){ for (UUID id : ids){

View File

@ -15,8 +15,8 @@ public class FieldDataHelperServiceProvider {
BaseFieldDataHelperService<?, ?, ?, ? > item = null; BaseFieldDataHelperService<?, ?, ?, ? > item = null;
switch (type) { switch (type) {
case INTERNAL_DMP_ENTRIES_DATASETS: case INTERNAL_ENTRIES_DESCRIPTIONS:
case INTERNAL_DMP_ENTRIES_DMPS: { case INTERNAL_ENTRIES_DMPS: {
item = this.applicationContext.getBean(LabelAndMultiplicityFieldDataHelperService.class); item = this.applicationContext.getBean(LabelAndMultiplicityFieldDataHelperService.class);
break; break;
} }

View File

@ -24,6 +24,8 @@ import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import org.hibernate.FlushMode;
import org.hibernate.annotations.FlushModeType;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -75,10 +77,11 @@ public class LanguageServiceImpl implements LanguageService {
LanguageEntity data; LanguageEntity data;
if (isUpdate) { if (isUpdate) {
((org.hibernate.Session) entityManager).setHibernateFlushMode(FlushMode.MANUAL);
data = this.entityManager.find(LanguageEntity.class, model.getId()); data = this.entityManager.find(LanguageEntity.class, model.getId());
if (data == null) if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Language.class.getSimpleName()}, LocaleContextHolder.getLocale())); throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Language.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
} else { } else {
data = new LanguageEntity(); data = new LanguageEntity();
@ -86,16 +89,15 @@ public class LanguageServiceImpl implements LanguageService {
data.setIsActive(IsActive.Active); data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now()); data.setCreatedAt(Instant.now());
} }
data.setCode(model.getCode()); data.setCode(model.getCode());
data.setPayload(model.getPayload() != null && model.getPayload().length() > 0 ? model.getPayload() : null); data.setPayload(model.getPayload() != null && !model.getPayload().isEmpty() ? model.getPayload() : null);
data.setOrdinal(model.getOrdinal()); data.setOrdinal(model.getOrdinal());
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());
data.setIsActive(IsActive.Inactive);
if (isUpdate) this.entityManager.merge(data); // if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data); // else this.entityManager.persist(data);
//
this.entityManager.flush(); // this.entityManager.flush();
return this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Language._id), data); return this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Language._id), data);
} }

View File

@ -0,0 +1,23 @@
//package eu.eudat.configurations;
//
//import jakarta.persistence.PersistenceException;
//import org.hibernate.FlushMode;
//import org.hibernate.Session;
//import org.springframework.context.annotation.Bean;
//import org.springframework.lang.Nullable;
//import org.springframework.orm.jpa.JpaVendorAdapter;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
//import org.springframework.stereotype.Service;
//
//import javax.sql.DataSource;
//import java.sql.SQLException;
//
//@Service
//public class MyHibernateJpaDialect extends HibernateJpaDialect {
// @Override
// protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException {
// return null;
// }
//}

View File

@ -7,6 +7,9 @@
spring: spring:
jpa: jpa:
properties: properties:
org:
hibernate:
flushMode: MANUAL
hibernate: hibernate:
globally_quoted_identifiers: true globally_quoted_identifiers: true
ddl-auto: validate ddl-auto: validate