switch plan versions in overview

This commit is contained in:
amentis 2024-05-10 14:57:21 +03:00
parent d024212985
commit 402897fabc
9 changed files with 85 additions and 18 deletions

View File

@ -60,6 +60,9 @@ public class PublicDmp {
private List<PublicEntityDoi> entityDois;
public static final String _entityDois = "entityDois";
private List<PublicDmp> otherDmpVersions;
public static final String _otherDmpVersions = "otherDmpVersions";
public UUID getId() {
return id;
}
@ -171,4 +174,12 @@ public class PublicDmp {
public void setEntityDois(List<PublicEntityDoi> entityDois) {
this.entityDois = entityDois;
}
public List<PublicDmp> getOtherDmpVersions() {
return otherDmpVersions;
}
public void setOtherDmpVersions(List<PublicDmp> otherDmpVersions) {
this.otherDmpVersions = otherDmpVersions;
}
}

View File

@ -9,13 +9,11 @@ import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.EntityType;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DmpEntity;
import org.opencdmp.model.*;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DmpReferenceQuery;
import org.opencdmp.query.DmpUserQuery;
import org.opencdmp.query.EntityDoiQuery;
import org.opencdmp.query.*;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -70,6 +68,9 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
FieldSet entityDoisFields = fields.extractPrefixed(this.asPrefix(PublicDmp._entityDois));
Map<UUID, List<PublicEntityDoi>> entityDoisMap = this.collectEntityDois(entityDoisFields, data);
FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asPrefix(PublicDmp._otherDmpVersions));
Map<UUID, List<PublicDmp>> otherDmpVersionsMap = this.collectOtherDmpVersions(otherDmpVersionsFields, data);
for (DmpEntity d : data) {
PublicDmp m = new PublicDmp();
if (fields.hasField(this.asIndexer(PublicDmp._id))) m.setId(d.getId());
@ -87,6 +88,7 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
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 (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()));
models.add(m);
}
@ -167,4 +169,22 @@ public class PublicDmpBuilder extends BaseBuilder<PublicDmp, DmpEntity> {
return itemMap;
}
private Map<UUID, List<PublicDmp>> collectOtherDmpVersions(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", PublicDmp.class.getSimpleName());
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());
if (!fields.hasField(this.asIndexer(PublicDmp._otherDmpVersions, PublicDmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null).peek(x -> {
x.setId(null);
});
}
return itemMap;
}
}

View File

@ -105,6 +105,9 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
FieldSet dmpDescriptionTemplatesFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptionTemplates));
Map<UUID, List<DmpDescriptionTemplate>> dmpDescriptionTemplatesMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplatesFields, data);
FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asPrefix(Dmp._otherDmpVersions));
Map<UUID, List<Dmp>> otherDmpVersionsMap = this.collectOtherDmpVersions(otherDmpVersionsFields, data);
Set<String> authorizationFlags = this.extractAuthorizationFlags(fields, Dmp._authorizationFlags, this.authorizationContentResolver.getPermissionNames());
Map<UUID, AffiliatedResource> affiliatedResourceMap = authorizationFlags == null || authorizationFlags.isEmpty() ? null : this.authorizationContentResolver.dmpsAffiliation(data.stream().map(DmpEntity::getId).collect(Collectors.toList()));
@ -134,6 +137,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
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 (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 (!propertiesFields.isEmpty() && d.getProperties() != null){
DmpPropertiesEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, d.getProperties());
m.setProperties(this.builderFactory.builder(DmpPropertiesBuilder.class).authorize(this.authorize).build(propertiesFields, propertyDefinition));
@ -297,4 +301,22 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
return itemMap;
}
private Map<UUID, List<Dmp>> collectOtherDmpVersions(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
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());
if (!fields.hasField(this.asIndexer(Dmp._otherDmpVersions, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null).peek(x -> {
x.setId(null);
});
}
return itemMap;
}
}

View File

@ -44,6 +44,8 @@ public class PublicDmpCensor extends BaseCensor {
this.censorFactory.censor(PublicDmpUserCensor.class).censor(dmpDescriptionsFields);
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmp._dmpReferences));
this.censorFactory.censor(PublicDmpReferenceCensor.class).censor(dmpReferencesFields);
FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmp._otherDmpVersions));
this.censorFactory.censor(PublicDmpCensor.class).censor(otherDmpVersionsFields);
}
}

View File

@ -52,5 +52,7 @@ public class DmpCensor extends BaseCensor {
this.censorFactory.censor(EntityDoiCensor.class).censor(doisFields, userId);
FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._properties));
this.censorFactory.censor(DmpPropertiesCensor.class).censor(propertiesFields, userId);
FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._otherDmpVersions));
this.censorFactory.censor(DmpCensor.class).censor(otherDmpVersionsFields, userId);
}
}

View File

@ -91,6 +91,9 @@ public class Dmp {
private List<String> authorizationFlags;
public static final String _authorizationFlags = "authorizationFlags";
private List<Dmp> otherDmpVersions;
public static final String _otherDmpVersions = "otherDmpVersions";
private Boolean belongsToCurrentTenant;
public static final String _belongsToCurrentTenant = "belongsToCurrentTenant";
@ -302,4 +305,12 @@ public class Dmp {
public void setBelongsToCurrentTenant(Boolean belongsToCurrentTenant) {
this.belongsToCurrentTenant = belongsToCurrentTenant;
}
public List<Dmp> getOtherDmpVersions() {
return otherDmpVersions;
}
public void setOtherDmpVersions(List<Dmp> otherDmpVersions) {
this.otherDmpVersions = otherDmpVersions;
}
}

View File

@ -35,6 +35,7 @@ export interface Dmp extends BaseEntity {
descriptions?: Description[];
dmpDescriptionTemplates?: DmpDescriptionTemplate[];
entityDois?: EntityDoi[];
otherDmpVersions?: Dmp[];
authorizationFlags?: AppPermission[];
}
@ -169,6 +170,7 @@ export interface PublicDmp extends BaseEntity {
dmpUsers: PublicDmpUser[];
descriptions: PublicDescription[];
entityDois: PublicEntityDoi[];
otherDmpVersions?: PublicDmp[];
}
export interface PublicDmpReference {

View File

@ -34,8 +34,8 @@
</div>
<div class="col-auto">
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="dense-3 versions-select">
<mat-select placeholder="{{'DMP-OVERVIEW.VERSION' | translate}} {{dmp.version}}" [(ngModel)]="version" (ngModelChange)="versionChanged(version.id)">
<mat-option *ngFor="let version of pastVersions" [value]="version">
<mat-select placeholder="{{'DMP-OVERVIEW.VERSION' | translate}} {{dmp.version}}" [(ngModel)]="selectedDmpVersion" (selectionChange)="versionChanged(selectedDmpVersion.id)">
<mat-option *ngFor="let version of dmp?.otherDmpVersions" [value]="version">
{{'DMP-OVERVIEW.VERSION' | translate}} {{version.version}}</mat-option>
</mat-select>
</mat-form-field>

View File

@ -58,6 +58,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
dmp: any;
selectedBlueprint: DmpBlueprint;
selectedDmpVersion: any;
researchers: DmpReference[] = [];
isNew = true;
isFinalized = false;
@ -67,7 +68,6 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
// isUserOwner: boolean;
isLocked: Boolean;
textMessage: any;
pastVersions: Dmp[]; //TODO: get these from the backend
selectedModel: EntityDoi;
fileTransformerEntityTypeEnum = FileTransformerEntityType;
@ -121,6 +121,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
.subscribe(data => {
this.dmp = data;
this.dmp.dmpUsers = data.dmpUsers.filter(x => x.isActive === IsActive.Active);
this.dmp.otherDmpVersions = data.otherDmpVersions?.filter(x => x.isActive === IsActive.Active) || null;
if (this.dmp.descriptions) {
if (this.dmp.status == DmpStatus.Finalized) {
this.dmp.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized);
@ -134,9 +135,9 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
if (!this.hasDoi()) {
this.selectedModel = this.dmp.entityDois[0];
}
this.selectedDmpVersion = this.dmp;
this.checkLockStatus(this.dmp.id);
// this.setIsUserOwner();
this.getAllVersions(this.dmp);
// const breadCrumbs = [];
// breadCrumbs.push({ parentComponentName: null, label: this.language.instant('NAV-BAR.MY-DMPS'), url: "/plans" });
// breadCrumbs.push({ parentComponentName: 'DmpListingComponent', label: this.dmp.label, url: '/plans/overview/' + this.dmp.id });
@ -162,8 +163,8 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
if (!this.hasDoi()) {
this.selectedModel = this.dmp.entityDois[0];
}
this.selectedDmpVersion = this.dmp;
// this.checkLockStatus(this.dmp.id);
this.getAllVersions(this.dmp);
// const breadCrumbs = [];
// breadCrumbs.push({ parentComponentName: null, label: this.language.instant('NAV-BAR.PUBLIC-DMPS'), url: "/explore-plans" });
// breadCrumbs.push({ parentComponentName: 'DmpListingComponent', label: this.dmp.label, url: '/plans/overview/public/' + this.dmp.id });
@ -476,15 +477,6 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
return (this.dmp.entityDois == null || this.dmp.entityDois.length == 0);
}
getAllVersions(dmp: Dmp) {
//TODO: add this
// this.dmpService.getAllVersions(dmp.groupId, this.isPublicView)
// .pipe(takeUntil(this._destroyed))
// .subscribe(items => {
// this.versions = items;
// });
}
afterDeposit(result: EntityDoi[]) {
if (result.length > 0) {
this.dmp.entityDois = result;
@ -771,6 +763,11 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
[nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
[nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
[nameof<Dmp>(x => x.otherDmpVersions), nameof<Dmp>(x => x.id)].join('.'),
[nameof<Dmp>(x => x.otherDmpVersions), nameof<Dmp>(x => x.groupId)].join('.'),
[nameof<Dmp>(x => x.otherDmpVersions), nameof<Dmp>(x => x.version)].join('.'),
[nameof<Dmp>(x => x.otherDmpVersions), nameof<Dmp>(x => x.isActive)].join('.'),
nameof<Dmp>(x => x.hash),
]
}