persist external reference to type tenant
This commit is contained in:
parent
74526f7927
commit
125b0aa408
|
@ -189,6 +189,7 @@ public class ReferenceTypeQuery extends QueryBase<ReferenceTypeEntity> {
|
||||||
else if (item.match(ReferenceType._isActive)) return ReferenceTypeEntity._isActive;
|
else if (item.match(ReferenceType._isActive)) return ReferenceTypeEntity._isActive;
|
||||||
else if (item.match(ReferenceType._definition)) return ReferenceTypeEntity._definition;
|
else if (item.match(ReferenceType._definition)) return ReferenceTypeEntity._definition;
|
||||||
else if (item.prefix(ReferenceType._definition)) return ReferenceTypeEntity._definition;
|
else if (item.prefix(ReferenceType._definition)) return ReferenceTypeEntity._definition;
|
||||||
|
else if (item.match(ReferenceTypeEntity._tenantId)) return ReferenceTypeEntity._tenantId;
|
||||||
else if (item.match(ReferenceType._belongsToCurrentTenant)) return ReferenceTypeEntity._tenantId;
|
else if (item.match(ReferenceType._belongsToCurrentTenant)) return ReferenceTypeEntity._tenantId;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import eu.eudat.commons.JsonHandlingService;
|
||||||
import eu.eudat.commons.XmlHandlingService;
|
import eu.eudat.commons.XmlHandlingService;
|
||||||
import eu.eudat.commons.enums.*;
|
import eu.eudat.commons.enums.*;
|
||||||
import eu.eudat.commons.enums.notification.NotificationContactType;
|
import eu.eudat.commons.enums.notification.NotificationContactType;
|
||||||
|
import eu.eudat.commons.scope.tenant.TenantScope;
|
||||||
import eu.eudat.commons.scope.user.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.commons.types.description.*;
|
import eu.eudat.commons.types.description.*;
|
||||||
import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity;
|
import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity;
|
||||||
|
@ -101,10 +102,11 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
private final AuthorizationContentResolver authorizationContentResolver;
|
private final AuthorizationContentResolver authorizationContentResolver;
|
||||||
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
|
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
|
||||||
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
|
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
|
||||||
|
private final TenantScope tenantScope;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DescriptionServiceImpl(
|
public DescriptionServiceImpl(
|
||||||
TenantEntityManager entityManager,
|
TenantEntityManager entityManager,
|
||||||
AuthorizationService authorizationService,
|
AuthorizationService authorizationService,
|
||||||
DeleterFactory deleterFactory,
|
DeleterFactory deleterFactory,
|
||||||
BuilderFactory builderFactory,
|
BuilderFactory builderFactory,
|
||||||
|
@ -115,7 +117,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
JsonHandlingService jsonHandlingService,
|
JsonHandlingService jsonHandlingService,
|
||||||
UserScope userScope,
|
UserScope userScope,
|
||||||
XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService, ValidatorFactory validatorFactory, StorageFileProperties storageFileConfig, StorageFileService storageFileService, AuthorizationContentResolver authorizationContentResolver, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler) {
|
XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService, ValidatorFactory validatorFactory, StorageFileProperties storageFileConfig, StorageFileService storageFileService, AuthorizationContentResolver authorizationContentResolver, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, TenantScope tenantScope) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -138,6 +140,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
this.authorizationContentResolver = authorizationContentResolver;
|
this.authorizationContentResolver = authorizationContentResolver;
|
||||||
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
|
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
|
||||||
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
|
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
|
||||||
|
this.tenantScope = tenantScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -617,7 +620,17 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
referenceEntity.setAbbreviation(referencePersist.getAbbreviation());
|
referenceEntity.setAbbreviation(referencePersist.getAbbreviation());
|
||||||
referenceEntity.setSource(referencePersist.getSource());
|
referenceEntity.setSource(referencePersist.getSource());
|
||||||
referenceEntity.setSourceType(referencePersist.getSourceType());
|
referenceEntity.setSourceType(referencePersist.getSourceType());
|
||||||
this.entityManager.persist(referenceEntity);
|
try {
|
||||||
|
ReferenceTypeEntity referenceType = this.queryFactory.query(ReferenceTypeQuery.class).ids(fieldEntity.getReferenceTypeId()).firstAs(new BaseFieldSet().ensure(ReferenceType._id).ensure(ReferenceTypeEntity._tenantId));
|
||||||
|
if (referenceType == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{fieldEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
|
if (referenceEntity.getSourceType().equals(ReferenceSourceType.External) && !this.tenantScope.isDefaultTenant() && referenceType.getTenantId() == null){
|
||||||
|
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
|
||||||
|
}
|
||||||
|
this.entityManager.persist(referenceEntity);
|
||||||
|
} finally {
|
||||||
|
tenantScope.removeTempTenant(this.entityManager.getEntityManager());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -463,7 +463,18 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
||||||
data.setAbbreviation(model.getAbbreviation());
|
data.setAbbreviation(model.getAbbreviation());
|
||||||
data.setSource(model.getSource());
|
data.setSource(model.getSource());
|
||||||
data.setSourceType(model.getSourceType());
|
data.setSourceType(model.getSourceType());
|
||||||
this.entityManager.persist(data);
|
|
||||||
|
try {
|
||||||
|
ReferenceTypeEntity referenceType = this.queryFactory.query(ReferenceTypeQuery.class).ids(referenceTypeDataEntity.getReferenceTypeId()).firstAs(new BaseFieldSet().ensure(ReferenceType._id).ensure(ReferenceTypeEntity._tenantId));
|
||||||
|
if (referenceType == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referenceTypeDataEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
|
if (data.getSourceType().equals(ReferenceSourceType.External) && !this.tenantScope.isDefaultTenant() && referenceType.getTenantId() == null){
|
||||||
|
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
|
||||||
|
}
|
||||||
|
this.entityManager.persist(data);
|
||||||
|
} finally {
|
||||||
|
tenantScope.removeTempTenant(this.entityManager.getEntityManager());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
referenceIds.add(data.getId());
|
referenceIds.add(data.getId());
|
||||||
|
|
|
@ -8,6 +8,7 @@ import eu.eudat.commons.JsonHandlingService;
|
||||||
import eu.eudat.commons.XmlHandlingService;
|
import eu.eudat.commons.XmlHandlingService;
|
||||||
import eu.eudat.commons.enums.*;
|
import eu.eudat.commons.enums.*;
|
||||||
import eu.eudat.commons.enums.notification.NotificationContactType;
|
import eu.eudat.commons.enums.notification.NotificationContactType;
|
||||||
|
import eu.eudat.commons.scope.tenant.TenantScope;
|
||||||
import eu.eudat.commons.scope.user.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity;
|
import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity;
|
||||||
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
|
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
|
||||||
|
@ -61,6 +62,7 @@ import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
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 gr.cite.tools.validation.ValidationFailure;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -126,10 +128,10 @@ public class DmpServiceImpl implements DmpService {
|
||||||
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
|
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
|
||||||
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
|
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
|
||||||
private final AuthorizationContentResolver authorizationContentResolver;
|
private final AuthorizationContentResolver authorizationContentResolver;
|
||||||
|
private final TenantScope tenantScope;
|
||||||
@Autowired
|
@Autowired
|
||||||
public DmpServiceImpl(
|
public DmpServiceImpl(
|
||||||
TenantEntityManager entityManager,
|
TenantEntityManager entityManager,
|
||||||
AuthorizationService authorizationService,
|
AuthorizationService authorizationService,
|
||||||
DeleterFactory deleterFactory,
|
DeleterFactory deleterFactory,
|
||||||
BuilderFactory builderFactory,
|
BuilderFactory builderFactory,
|
||||||
|
@ -148,7 +150,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
FileTransformerService fileTransformerService,
|
FileTransformerService fileTransformerService,
|
||||||
ValidatorFactory validatorFactory,
|
ValidatorFactory validatorFactory,
|
||||||
ElasticService elasticService,
|
ElasticService elasticService,
|
||||||
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver) {
|
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -171,6 +173,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
|
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
|
||||||
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
|
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
|
||||||
this.authorizationContentResolver = authorizationContentResolver;
|
this.authorizationContentResolver = authorizationContentResolver;
|
||||||
|
this.tenantScope = tenantScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
|
public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
|
||||||
|
@ -808,7 +811,17 @@ public class DmpServiceImpl implements DmpService {
|
||||||
referenceEntity.setAbbreviation(referencePersist.getAbbreviation());
|
referenceEntity.setAbbreviation(referencePersist.getAbbreviation());
|
||||||
referenceEntity.setSource(referencePersist.getSource());
|
referenceEntity.setSource(referencePersist.getSource());
|
||||||
referenceEntity.setSourceType(referencePersist.getSourceType());
|
referenceEntity.setSourceType(referencePersist.getSourceType());
|
||||||
this.entityManager.persist(referenceEntity);
|
try {
|
||||||
|
ReferenceTypeEntity referenceType = this.queryFactory.query(ReferenceTypeQuery.class).ids(fieldEntity.getReferenceTypeId()).firstAs(new BaseFieldSet().ensure(ReferenceType._id).ensure(ReferenceTypeEntity._tenantId));
|
||||||
|
if (referenceType == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{fieldEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
|
if (referenceEntity.getSourceType().equals(ReferenceSourceType.External) && !this.tenantScope.isDefaultTenant() && referenceType.getTenantId() == null){
|
||||||
|
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
|
||||||
|
}
|
||||||
|
this.entityManager.persist(referenceEntity);
|
||||||
|
} finally {
|
||||||
|
tenantScope.removeTempTenant(this.entityManager.getEntityManager());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +924,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
throw new MyApplicationException("DMP is already finalized");
|
throw new MyApplicationException("DMP is already finalized");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.validate(id).getResult().equals(DescriptionValidationOutput.Invalid)){
|
if (this.validate(id).getResult().equals(DmpValidationOutput.Invalid)){
|
||||||
throw new MyApplicationException("Dmp is invalid");
|
throw new MyApplicationException("Dmp is invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,7 +1003,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
DmpPersist.DmpPersistValidator validator = this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class);
|
DmpPersist.DmpPersistValidator validator = this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class);
|
||||||
validator.validate(this.buildDmpPersist(dmp));
|
validator.validate(this.buildDmpPersist(dmp));
|
||||||
if (validator.result().isValid()) dmpValidationResult.setResult(DmpValidationOutput.Valid);
|
if (validator.result().isValid()) dmpValidationResult.setResult(DmpValidationOutput.Valid);
|
||||||
else dmpValidationResult.setErrors(validator.result().getErrors().stream().map(x -> x.getErrorMessage()).collect(Collectors.toList()));
|
else dmpValidationResult.setErrors(validator.result().getErrors().stream().map(ValidationFailure::getErrorMessage).collect(Collectors.toList()));
|
||||||
|
|
||||||
return dmpValidationResult;
|
return dmpValidationResult;
|
||||||
}
|
}
|
||||||
|
@ -1050,7 +1063,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
|
|
||||||
List<ReferenceEntity> referencesFromAllFields = new ArrayList<>();
|
List<ReferenceEntity> referencesFromAllFields = new ArrayList<>();
|
||||||
if (!this.conventionService.isListNullOrEmpty(dmpReferenceEntities)) {
|
if (!this.conventionService.isListNullOrEmpty(dmpReferenceEntities)) {
|
||||||
referencesFromAllFields = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(dmpReferenceEntities.stream().map(x-> x.getReferenceId()).collect(Collectors.toList())).isActive(IsActive.Active).collect();
|
referencesFromAllFields = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(dmpReferenceEntities.stream().map(DmpReferenceEntity::getReferenceId).collect(Collectors.toList())).isActive(IsActive.Active).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
|
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class ReferenceServiceImpl implements ReferenceService {
|
||||||
public Reference persist(ReferencePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, TransformerException, ParserConfigurationException {
|
public Reference persist(ReferencePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, TransformerException, ParserConfigurationException {
|
||||||
logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields));
|
logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields));
|
||||||
|
|
||||||
this.authorizationService.authorizeForce(Permission.EditDmpBlueprint);
|
this.authorizationService.authorizeForce(Permission.EditReference);
|
||||||
|
|
||||||
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue