Merge remote-tracking branch 'origin/dmp-refactoring' into dmp-refactoring

This commit is contained in:
Alexandros Mandilaras 2024-05-16 09:59:48 +03:00
commit c7661e8a2c
13 changed files with 36 additions and 43 deletions

View File

@ -87,7 +87,7 @@ public class DmpAssociatedUserBuilder extends BaseBuilder<DmpAssociatedUser, Use
itemMap = this.builderFactory.builder(UserContactInfoBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserContactInfo._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).forEach(x -> {
x.getUser().setId(null);
});
}

View File

@ -113,7 +113,7 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
}
if (!fields.hasField(Dmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;
@ -130,7 +130,7 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asMasterKey(query, clone, DescriptionTemplate::getGroupId);
if (!fields.hasField(DescriptionTemplate._groupId)) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getGroupId() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getGroupId() != null).forEach(x -> {
x.setGroupId(null);
});
}
@ -159,7 +159,7 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getGroupId);
}
if (!fields.hasField(DescriptionTemplate._groupId)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setGroupId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setGroupId(null));
}
return itemMap;

View File

@ -136,7 +136,7 @@ public class DmpUserBuilder extends BaseBuilder<DmpUser, DmpUserEntity>{
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
}
if (!fields.hasField(Dmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;

View File

@ -107,7 +107,7 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
itemMap = this.builderFactory.builder(PublicDmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(PublicDmpReference._dmp, PublicDmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -125,7 +125,7 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
itemMap = this.builderFactory.builder(PublicDmpUserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(PublicDmpUser._dmp, PublicDmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -143,7 +143,7 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
itemMap = this.builderFactory.builder(PublicDescriptionBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(PublicDescription._dmp, PublicDescription._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -161,7 +161,7 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
itemMap = this.builderFactory.builder(PublicEntityDoiBuilder.class).authorize(this.authorize).asMasterKey(query, clone, PublicEntityDoi::getEntityId);
if (!fields.hasField(this.asIndexer(PublicEntityDoi._entityId))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getEntityId() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getEntityId() != null).forEach(x -> {
x.setEntityId(null);
});
}
@ -176,10 +176,10 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
Map<UUID, List<PublicDmp>> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDmp._id);
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(this.authorize).groupIds(data.stream().map(DmpEntity::getGroupId).distinct().collect(Collectors.toList())).isActive(IsActive.Active);
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getGroupId());
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asMasterKey(query, clone, PublicDmp::getGroupId);
if (!fields.hasField(this.asIndexer(PublicDmp._otherDmpVersions, PublicDmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(Objects::nonNull).forEach(x -> {
x.setId(null);
});
}

View File

@ -89,7 +89,7 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder<PublicDmpDe
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDmp::getId);
}
if (!fields.hasField(PublicDmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;

View File

@ -96,7 +96,7 @@ public class PublicDmpReferenceBuilder extends BaseBuilder<PublicDmpReference, D
itemMap = this.builderFactory.builder(PublicReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicReference::getId);
}
if (!fields.hasField(PublicReference._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;
@ -123,7 +123,7 @@ public class PublicDmpReferenceBuilder extends BaseBuilder<PublicDmpReference, D
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDmp::getId);
}
if (!fields.hasField(PublicDmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;

View File

@ -126,7 +126,7 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDmp::getId);
}
if (!fields.hasField(PublicDmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;

View File

@ -92,7 +92,7 @@ public class PublicReferenceBuilder extends BaseBuilder<PublicReference, Referen
itemMap = this.builderFactory.builder(PublicReferenceTypeBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicReferenceType::getId);
}
if (!fields.hasField(PublicReferenceType._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;

View File

@ -98,7 +98,7 @@ public class RecentActivityItemBuilder extends BaseBuilder<RecentActivityItem, R
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
}
if (!fields.hasField(Dmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;
@ -125,7 +125,7 @@ public class RecentActivityItemBuilder extends BaseBuilder<RecentActivityItem, R
itemMap = this.builderFactory.builder(DescriptionBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Description::getId);
}
if (!fields.hasField(Description._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;

View File

@ -14,7 +14,6 @@ import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.types.user.AdditionalInfoEntity;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.data.UserEntity;
import org.opencdmp.model.TenantUser;
import org.opencdmp.model.UserContactInfo;
@ -29,7 +28,6 @@ import org.opencdmp.query.UserRoleQuery;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@ -46,25 +44,21 @@ public class UserBuilder extends BaseBuilder<User, UserEntity> {
private final BuilderFactory builderFactory;
private final JsonHandlingService jsonHandlingService;
private final AuthorizationProperties authorizationProperties;
private final TenantEntityManager tenantEntityManager;
private final TenantScope tenantScope;
private final MessageSource messageSource;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserBuilder(ConventionService conventionService,
QueryFactory queryFactory,
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, AuthorizationProperties authorizationProperties, TenantEntityManager tenantEntityManager, TenantScope tenantScope, MessageSource messageSource) {
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, AuthorizationProperties authorizationProperties, TenantScope tenantScope) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
this.jsonHandlingService = jsonHandlingService;
this.authorizationProperties = authorizationProperties;
this.tenantEntityManager = tenantEntityManager;
this.tenantScope = tenantScope;
this.messageSource = messageSource;
}
public UserBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -131,7 +125,7 @@ public class UserBuilder extends BaseBuilder<User, UserEntity> {
itemMap = this.builderFactory.builder(UserContactInfoBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserContactInfo._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).forEach(x -> {
x.getUser().setId(null);
});
}
@ -149,7 +143,7 @@ public class UserBuilder extends BaseBuilder<User, UserEntity> {
itemMap = this.builderFactory.builder(UserRoleBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserRole._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).forEach(x -> {
x.getUser().setId(null);
});
}
@ -178,7 +172,7 @@ public class UserBuilder extends BaseBuilder<User, UserEntity> {
itemMap = this.builderFactory.builder(UserRoleBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserRole._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).forEach(x -> {
x.getUser().setId(null);
});
}
@ -196,7 +190,7 @@ public class UserBuilder extends BaseBuilder<User, UserEntity> {
itemMap = this.builderFactory.builder(UserCredentialBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserCredential._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).forEach(x -> {
x.getUser().setId(null);
});
}
@ -214,10 +208,9 @@ public class UserBuilder extends BaseBuilder<User, UserEntity> {
itemMap = this.builderFactory.builder(TenantUserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(TenantUser._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).map(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).forEach(x -> {
x.getUser().setId(null);
return x;
}).collect(Collectors.toList());
});
}
return itemMap;
}

View File

@ -288,7 +288,7 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
itemMap = this.builderFactory.builder(DescriptionReferenceBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDescription().getId());
if (!fields.hasField(this.asIndexer(DescriptionReference._description, Description._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).forEach(x -> {
x.getDescription().setId(null);
});
}
@ -306,7 +306,7 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
itemMap = this.builderFactory.builder(DescriptionTagBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDescription().getId());
if (!fields.hasField(this.asIndexer(DescriptionTag._description, Description._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).forEach(x -> {
x.getDescription().setId(null);
});
}

View File

@ -160,7 +160,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -178,7 +178,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
itemMap = this.builderFactory.builder(EntityDoiBuilder.class).authorize(this.authorize).asMasterKey(query, clone, EntityDoi::getEntityId);
if (!fields.hasField(this.asIndexer(EntityDoi._entityId))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getEntityId() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getEntityId() != null).forEach(x -> {
x.setEntityId(null);
});
}
@ -257,7 +257,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
itemMap = this.builderFactory.builder(DmpUserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(DmpUser._dmp, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -275,7 +275,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
itemMap = this.builderFactory.builder(DescriptionBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(Description._dmp, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -293,7 +293,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
itemMap = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(DmpDescriptionTemplate._dmp, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).forEach(x -> {
x.getDmp().setId(null);
});
}
@ -308,10 +308,10 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
Map<UUID, List<Dmp>> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(this.authorize).groupIds(data.stream().map(DmpEntity::getGroupId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getGroupId());
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asMasterKey(query, clone, Dmp::getGroupId);
if (!fields.hasField(this.asIndexer(Dmp._otherDmpVersions, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null).peek(x -> {
itemMap.values().stream().flatMap(List::stream).filter(Objects::nonNull).forEach(x -> {
x.setId(null);
});
}

View File

@ -114,7 +114,7 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
}
if (!fields.hasField(Reference._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;
@ -141,7 +141,7 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
}
if (!fields.hasField(Dmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
itemMap.values().stream().filter(Objects::nonNull).forEach(x -> x.setId(null));
}
return itemMap;