fix new version flow, sort other dmp versions
This commit is contained in:
parent
0945b8300e
commit
066d8c8d24
|
@ -13,6 +13,7 @@ import org.opencdmp.commons.enums.IsActive;
|
||||||
import org.opencdmp.convention.ConventionService;
|
import org.opencdmp.convention.ConventionService;
|
||||||
import org.opencdmp.data.DmpEntity;
|
import org.opencdmp.data.DmpEntity;
|
||||||
import org.opencdmp.model.*;
|
import org.opencdmp.model.*;
|
||||||
|
import org.opencdmp.model.dmp.Dmp;
|
||||||
import org.opencdmp.query.*;
|
import org.opencdmp.query.*;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -88,7 +89,10 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
|
||||||
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId()));
|
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId()));
|
||||||
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
|
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
|
||||||
if (entityDoisMap != null && !entityDoisMap.isEmpty() && entityDoisMap.containsKey(d.getId())) m.setEntityDois(entityDoisMap.get(d.getId()));
|
if (entityDoisMap != null && !entityDoisMap.isEmpty() && entityDoisMap.containsKey(d.getId())) m.setEntityDois(entityDoisMap.get(d.getId()));
|
||||||
if (otherDmpVersionsMap != null && !otherDmpVersionsMap.isEmpty() && otherDmpVersionsMap.containsKey(d.getGroupId())) m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId()));
|
if (otherDmpVersionsMap != null && !otherDmpVersionsMap.isEmpty() && otherDmpVersionsMap.containsKey(d.getGroupId())){
|
||||||
|
m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId()));
|
||||||
|
m.getOtherDmpVersions().sort(Comparator.comparing(PublicDmp::getVersion));
|
||||||
|
}
|
||||||
|
|
||||||
models.add(m);
|
models.add(m);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +182,7 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
|
||||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(this.authorize).groupIds(data.stream().map(DmpEntity::getGroupId).distinct().collect(Collectors.toList())).isActive(IsActive.Active);
|
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, PublicDmp::getGroupId);
|
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asMasterKey(query, clone, PublicDmp::getGroupId);
|
||||||
|
|
||||||
if (!fields.hasField(this.asIndexer(PublicDmp._otherDmpVersions, PublicDmp._id))) {
|
if (!fields.hasField(PublicDmp._id)) {
|
||||||
itemMap.values().stream().flatMap(List::stream).filter(Objects::nonNull).forEach(x -> {
|
itemMap.values().stream().flatMap(List::stream).filter(Objects::nonNull).forEach(x -> {
|
||||||
x.setId(null);
|
x.setId(null);
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.opencdmp.model.dmpblueprint.DmpBlueprint;
|
||||||
import org.opencdmp.model.dmpreference.DmpReference;
|
import org.opencdmp.model.dmpreference.DmpReference;
|
||||||
import org.opencdmp.model.user.User;
|
import org.opencdmp.model.user.User;
|
||||||
import org.opencdmp.query.*;
|
import org.opencdmp.query.*;
|
||||||
|
import org.opencdmp.service.externalfetcher.config.entities.SourceBaseConfiguration;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
@ -137,7 +138,10 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
||||||
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId()));
|
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId()));
|
||||||
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
|
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
|
||||||
if (dmpDescriptionTemplatesMap != null && !dmpDescriptionTemplatesMap.isEmpty() && dmpDescriptionTemplatesMap.containsKey(d.getId())) m.setDmpDescriptionTemplates(dmpDescriptionTemplatesMap.get(d.getId()));
|
if (dmpDescriptionTemplatesMap != null && !dmpDescriptionTemplatesMap.isEmpty() && dmpDescriptionTemplatesMap.containsKey(d.getId())) m.setDmpDescriptionTemplates(dmpDescriptionTemplatesMap.get(d.getId()));
|
||||||
if (otherDmpVersionsMap != null && !otherDmpVersionsMap.isEmpty() && otherDmpVersionsMap.containsKey(d.getGroupId())) m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId()));
|
if (otherDmpVersionsMap != null && !otherDmpVersionsMap.isEmpty() && otherDmpVersionsMap.containsKey(d.getGroupId())) {
|
||||||
|
m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId()));
|
||||||
|
m.getOtherDmpVersions().sort(Comparator.comparing(Dmp::getVersion));
|
||||||
|
}
|
||||||
if (!propertiesFields.isEmpty() && d.getProperties() != null){
|
if (!propertiesFields.isEmpty() && d.getProperties() != null){
|
||||||
DmpPropertiesEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, d.getProperties());
|
DmpPropertiesEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, d.getProperties());
|
||||||
m.setProperties(this.builderFactory.builder(DmpPropertiesBuilder.class).authorize(this.authorize).build(propertiesFields, propertyDefinition));
|
m.setProperties(this.builderFactory.builder(DmpPropertiesBuilder.class).authorize(this.authorize).build(propertiesFields, propertyDefinition));
|
||||||
|
@ -310,7 +314,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
||||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(this.authorize).groupIds(data.stream().map(DmpEntity::getGroupId).distinct().collect(Collectors.toList()));
|
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, Dmp::getGroupId);
|
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asMasterKey(query, clone, Dmp::getGroupId);
|
||||||
|
|
||||||
if (!fields.hasField(this.asIndexer(Dmp._otherDmpVersions, Dmp._id))) {
|
if (!fields.hasField(Dmp._id)) {
|
||||||
itemMap.values().stream().flatMap(List::stream).filter(Objects::nonNull).forEach(x -> {
|
itemMap.values().stream().flatMap(List::stream).filter(Objects::nonNull).forEach(x -> {
|
||||||
x.setId(null);
|
x.setId(null);
|
||||||
});
|
});
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class FieldPersist {
|
||||||
.must(() -> !this.isEmpty(item.getTextValue()))
|
.must(() -> !this.isEmpty(item.getTextValue()))
|
||||||
.failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> fieldType.equals(FieldType.FREE_TEXT) && DescriptionStatus.Finalized.equals(this.status) && isVisible && isUrlRequired)
|
.iff(()-> fieldType.equals(FieldType.FREE_TEXT) && DescriptionStatus.Finalized.equals(this.status) && isVisible && isUrlRequired && (required || !this.isEmpty(item.getTextValue())))
|
||||||
.must(() -> this.isValidURL(item.getTextValue()))
|
.must(() -> this.isValidURL(item.getTextValue()))
|
||||||
.failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_UrlRequired", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_UrlRequired", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
|
|
|
@ -343,7 +343,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
.groupIds(data.getGroupId());
|
.groupIds(data.getGroupId());
|
||||||
|
|
||||||
dmpQuery.setOrder(new Ordering().addDescending(Dmp._version));
|
dmpQuery.setOrder(new Ordering().addDescending(Dmp._version));
|
||||||
previousDmp = dmpQuery.first();
|
previousDmp = dmpQuery.collect().get(0);
|
||||||
if (previousDmp != null){
|
if (previousDmp != null){
|
||||||
if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
|
if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
|
||||||
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
|
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
|
||||||
|
@ -566,7 +566,8 @@ public class DmpServiceImpl implements DmpService {
|
||||||
|
|
||||||
if (newStatus.equals(DmpStatus.Finalized)) {
|
if (newStatus.equals(DmpStatus.Finalized)) {
|
||||||
List<DmpEntity> latestVersionDmps = this.queryFactory.query(DmpQuery.class)
|
List<DmpEntity> latestVersionDmps = this.queryFactory.query(DmpQuery.class)
|
||||||
.versionStatuses(DmpVersionStatus.Current).isActive(IsActive.Active).groupIds(data.getGroupId()).collect();
|
.versionStatuses(DmpVersionStatus.Current).excludedIds(data.getId())
|
||||||
|
.isActive(IsActive.Active).groupIds(data.getGroupId()).collect();
|
||||||
if (latestVersionDmps.size() > 1)
|
if (latestVersionDmps.size() > 1)
|
||||||
throw new MyValidationException("Multiple previous template found");
|
throw new MyValidationException("Multiple previous template found");
|
||||||
DmpEntity oldDmpEntity = latestVersionDmps.stream().findFirst().orElse(null);
|
DmpEntity oldDmpEntity = latestVersionDmps.stream().findFirst().orElse(null);
|
||||||
|
@ -1086,11 +1087,28 @@ public class DmpServiceImpl implements DmpService {
|
||||||
|
|
||||||
dmp.setStatus(DmpStatus.Draft);
|
dmp.setStatus(DmpStatus.Draft);
|
||||||
dmp.setUpdatedAt(Instant.now());
|
dmp.setUpdatedAt(Instant.now());
|
||||||
dmp.setVersionStatus(DmpVersionStatus.NotFinalized);
|
|
||||||
|
|
||||||
this.entityManager.merge(dmp);
|
this.entityManager.merge(dmp);
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
this.updateVersionStatusAndSave(dmp, DmpStatus.Finalized, dmp.getStatus());
|
||||||
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).disableTracking()
|
||||||
|
.versionStatuses(DmpVersionStatus.Previous)
|
||||||
|
.excludedIds(dmp.getId())
|
||||||
|
.isActive(IsActive.Active)
|
||||||
|
.groupIds(dmp.getGroupId());
|
||||||
|
|
||||||
|
dmpQuery.setOrder(new Ordering().addDescending(Dmp._version));
|
||||||
|
DmpEntity previousDmp = dmpQuery.collect().get(0);
|
||||||
|
if (previousDmp != null){
|
||||||
|
if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
|
||||||
|
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
|
||||||
|
this.entityManager.merge(previousDmp);
|
||||||
|
}
|
||||||
|
this.entityManager.flush();
|
||||||
|
|
||||||
this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmp.getId());
|
this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmp.getId());
|
||||||
this.sendNotification(dmp);
|
this.sendNotification(dmp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue