remove old code

This commit is contained in:
Efstratios Giannopoulos 2024-02-01 17:46:28 +02:00
parent 55fb0f3e00
commit 5f6eab6e11
31 changed files with 32 additions and 3071 deletions

View File

@ -17,7 +17,7 @@ import java.util.*;
@Entity @Entity
@Table(name = "\"Description\"") @Table(name = "\"Description\"")
public class DescriptionEntity extends TenantScopedBaseEntity implements DataEntity<DescriptionEntity, UUID> { public class DescriptionEntity extends TenantScopedBaseEntity {
@Id @Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
@ -190,22 +190,5 @@ public class DescriptionEntity extends TenantScopedBaseEntity implements DataEnt
public void setDescriptionTemplateId(UUID descriptionTemplateId) { public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId; this.descriptionTemplateId = descriptionTemplateId;
} }
@Override
public void update(DescriptionEntity entity) {
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DescriptionEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
} }

View File

@ -1,23 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DatasetCriteria;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.queryable.QueryableList;
import javax.management.InvalidApplicationException;
import java.util.List;
import java.util.UUID;
public interface DatasetDao extends DatabaseAccessLayer<DescriptionEntity, UUID> {
QueryableList<DescriptionEntity> getWithCriteria(DatasetCriteria criteria);
QueryableList<DescriptionEntity> filterFromElastic(DatasetCriteria criteria, List<UUID> ids);
QueryableList<DescriptionEntity> getAuthenticated(QueryableList<DescriptionEntity> query, UserEntity principal, List<Integer> roles);
DescriptionEntity isPublicDataset(UUID id) throws InvalidApplicationException;
}

View File

@ -1,152 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DatasetCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import eu.eudat.types.grant.GrantStateType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import javax.management.InvalidApplicationException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@Component("datasetDao")
public class DatasetDaoImpl extends DatabaseAccess<DescriptionEntity> implements DatasetDao {
@Autowired
public DatasetDaoImpl(DatabaseService<DescriptionEntity> databaseService) { super(databaseService); }
@Override
public QueryableList<DescriptionEntity> getWithCriteria(DatasetCriteria criteria) {
QueryableList<DescriptionEntity> query = getDatabaseService().getQueryable(new HashSet<>(Arrays.asList("datasetListingModel")), DescriptionEntity.class);
if (criteria.getIsPublic() != null && criteria.getIsPublic()) {
query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true));
query.where((builder, root) -> builder.equal(root.get("status"), DescriptionStatus.Finalized));
/*query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")),
Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));*/
}
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%")));
if (criteria.getStatus() != null)
query.where((builder, root) -> builder.equal(root.get("status"), criteria.getStatus()));
if (criteria.getProfileDatasetId() != null)
query.where((builder, root) -> builder.equal(root.get("profile").get("id"), criteria.getProfileDatasetId()));
if (criteria.getPeriodEnd() != null)
query.where((builder, root) -> builder.lessThan(root.get("created"), criteria.getPeriodEnd()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), Integer.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("groupId").in(criteria.getGroupIds()));
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds()));
/*if (criteria.getRole() != null) {
query.where((builder, root) -> builder.equal(root.join("dmp").join("users").get("role"), criteria.getRole()));
} else {
query.where((builder, root) -> root.join("dmp").join("users").get("role").in(UserDMP.UserDMPRoles.getAllValues()));
}*/
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty())
query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations()));
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
query.where((builder, root) -> root.join("dmp").join("grant").get("id").in(criteria.getGrants()));
if (criteria.getGrantStatus() != null) {
if (criteria.getGrantStatus().equals(GrantStateType.FINISHED.getValue().shortValue()))
query.where((builder, root) -> builder.lessThan(root.get("dmp").get("grant").get("enddate"), new Date()));
if (criteria.getGrantStatus().equals(GrantStateType.ONGOING.getValue().shortValue()))
query.where((builder, root) ->
builder.or(builder.greaterThan(root.get("dmp").get("grant").get("enddate"), new Date())
, builder.isNull(root.get("dmp").get("grant").get("enddate"))));
}
if (criteria.getCollaborators() != null && !criteria.getCollaborators().isEmpty())
query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty())
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.join("dmp").join("dois").get("id"))));
}
query.where((builder, root) -> builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive));
query.where((builder, root) -> builder.notEqual(root.get("status"), DescriptionStatus.Canceled));
return query;
}
public QueryableList<DescriptionEntity> filterFromElastic(DatasetCriteria criteria, List<UUID> ids) {
QueryableList<DescriptionEntity> query = getDatabaseService().getQueryable(new HashSet<>(Arrays.asList("datasetListingModel")), DescriptionEntity.class);
query.where(((builder, root) -> root.get("id").in(ids)));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
return query;
}
@Override
public DescriptionEntity createOrUpdate(DescriptionEntity item) {
return getDatabaseService().createOrUpdate(item, DescriptionEntity.class);
}
@Override
public DescriptionEntity find(UUID id) throws InvalidApplicationException {
return getDatabaseService().getQueryable(DescriptionEntity.class)
.where((builder, root) -> builder.and(builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive), builder.notEqual(root.get("status"), DescriptionStatus.Canceled), builder.equal((root.get("id")), id))).getSingle();
}
@Override
public DescriptionEntity find(UUID id, String hint) throws InvalidApplicationException {
return getDatabaseService().getQueryable(new HashSet<>(Arrays.asList("datasetListingModel")), DescriptionEntity.class).withHint(hint)
.where((builder, root) -> builder.and(builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive), builder.notEqual(root.get("status"), DescriptionStatus.Canceled), builder.equal((root.get("id")), id))).getSingle();
}
@Override
public DescriptionEntity isPublicDataset(UUID id) throws InvalidApplicationException {
QueryableList<DescriptionEntity> query = getDatabaseService().getQueryable(new HashSet<>(Arrays.asList("datasetListingModel")), DescriptionEntity.class);
query.where(((builder, root) -> builder.equal(root.get("id"), id)));
return query.withHint("datasetListingModel").getSingle();
}
@Override
public QueryableList<DescriptionEntity> getAuthenticated(QueryableList<DescriptionEntity> query, UserEntity principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()));
}
return query;
}
@Override
public void delete(DescriptionEntity item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DescriptionEntity> asQueryable() {
return this.getDatabaseService().getQueryable(DescriptionEntity.class);
}
@Async
public CompletableFuture<DescriptionEntity> createOrUpdateAsync(DescriptionEntity item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
}

View File

@ -1,55 +0,0 @@
package eu.eudat.query;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import jakarta.persistence.criteria.Subquery;
import javax.management.InvalidApplicationException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DatasetQuery extends Query<DescriptionEntity, UUID> {
private UUID id;
private String label;
public DatasetQuery(DatabaseAccessLayer<DescriptionEntity, UUID> databaseAccessLayer) {
super(databaseAccessLayer);
}
public DatasetQuery(DatabaseAccessLayer<DescriptionEntity, UUID> databaseAccessLayer, List<String> selectionFields) {
super(databaseAccessLayer, selectionFields);
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@Override
public QueryableList<DescriptionEntity> getQuery() throws InvalidApplicationException {
QueryableList<DescriptionEntity> query = this.databaseAccessLayer.asQueryable();
if (this.id != null) {
query.where((builder, root) -> builder.equal(root.get("id"), this.id));
}
return query;
}
}

View File

@ -20,8 +20,8 @@ import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.model.file.FileEnvelope; import eu.eudat.model.file.FileEnvelope;
import eu.eudat.models.HintedModelFactory; import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery; import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
@ -141,7 +141,7 @@ public class FileController {
} }
if(fileUpload.getEntityType().name().equals(FileUpload.EntityType.DATASET.name())) { if(fileUpload.getEntityType().name().equals(FileUpload.EntityType.DATASET.name())) {
DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(fileUpload.getEntityId(), HintedModelFactory.getHint(DatasetWizardModel.class)); DescriptionEntity descriptionEntityEntity = this.queryFactory.query(DescriptionQuery.class).ids(fileUpload.getEntityId()).first();
if (descriptionEntityEntity == null) { if (descriptionEntityEntity == null) {
throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id); throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id);
} }

View File

@ -1,115 +0,0 @@
package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.managers.QuickWizardManager;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel;
import eu.eudat.models.data.quickwizard.QuickWizardModel;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.transaction.Transactional;
import jakarta.validation.Valid;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/quick-wizard/"})
public class QuickWizardController extends BaseController {
private QuickWizardManager quickWizardManager;
private DatasetManager datasetManager;
private final AuthorizationService authorizationService;
private final UserScope userScope;
@Autowired
public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager, DatasetManager datasetManager, AuthorizationService authorizationService, UserScope userScope) {
super(apiContext);
this.quickWizardManager = quickWizardManager;
this.datasetManager = datasetManager;
this.authorizationService = authorizationService;
this.userScope = userScope;
}
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<QuickWizardModel>> addQuickWizardModel(@Valid @RequestBody QuickWizardModel quickWizard) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
// Funder funderEntity;//TODO
// //Create Funder
// if (quickWizard.getFunder() == null) {
// funderEntity = null;
// } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
// funderEntity = null;
// } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
// funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder());
// } else {
// funderEntity = quickWizard.getFunder().getExistFunder().toDataModel();
// }
// Grant grantEntity; //TODO
// //Create Grant
// if (quickWizard.getGrant() == null) {
// grantEntity = null;
// } else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) {
// grantEntity = null;
// } else if (quickWizard.getGrant().getExistGrant() == null) {
// grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant());
// } else {
// grantEntity = quickWizard.getGrant().getExistGrant().toDataModel();
// }
// Project projectEntity; //TODO
// //Create Project
// if (quickWizard.getProject().getExistProject() == null
// && quickWizard.getProject().getLabel() == null) {
// projectEntity = null;
// } else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != null) {
// projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject());
// } else {
// projectEntity = quickWizard.getProject().getExistProject().toDataModel();
// }
//Create Dmp
// DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(/*grantEntity,*/ userScope);
// DmpEntity dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan/*, funderEntity*/);
//
// //Create Datasets
// quickWizard.getDmp().setId(dmpEntity.getId());
// for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) {
// DataManagementPlan dmp = quickWizard.getDmp().toDataDmp(/*grantEntity , projectEntity, */ userScope);
// DescriptionTemplateEntity profile = quickWizard.getDmp().getDatasetProfile();
// DatasetWizardModel datasetWizardModel = dataset.toDataModel(dmp, profile);
// this.datasetManager.createOrUpdate(datasetWizardModel);
// }
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
}
@RequestMapping(method = RequestMethod.POST, value = {"/datasetcreate"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DatasetCreateWizardModel>> addDatasetWizard(@RequestBody DatasetCreateWizardModel datasetCreateWizardModel) throws Exception{
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
for(DatasetDescriptionQuickWizardModel dataset : datasetCreateWizardModel.getDatasets().getDatasetsList()){
DescriptionTemplateEntity profile = new DescriptionTemplateEntity();
// profile.setId(datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getId());
// profile.setLabel(datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getLabel());
this.datasetManager.createOrUpdate(dataset.toDataModel(profile));
}
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetCreateWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset added!"));
}
}

View File

@ -1,10 +1,8 @@
package eu.eudat.controllers.v2; package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.models.data.dataset.DatasetOverviewModel; import eu.eudat.models.v2.Account;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.v2.AccountBuilder; import eu.eudat.models.v2.AccountBuilder;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
import gr.cite.commons.web.oidc.principal.MyPrincipal; import gr.cite.commons.web.oidc.principal.MyPrincipal;
import gr.cite.tools.auditing.AuditService; import gr.cite.tools.auditing.AuditService;
@ -13,11 +11,9 @@ import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
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.http.HttpStatus; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import eu.eudat.models.v2.Account;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;

View File

@ -7,7 +7,6 @@ import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.databind.node.JsonNodeType;
import eu.eudat.criteria.entities.Criteria; import eu.eudat.criteria.entities.Criteria;
import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.query.DatasetQuery;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@ -58,10 +57,4 @@ public class DatasetCriteria {
return new LinkedList<>(fields); return new LinkedList<>(fields);
} }
public DatasetQuery buildQuery(DatabaseRepository dao) {
List<String> fields = this.buildFields("");
DatasetQuery datasetQuery = new DatasetQuery(dao.getDatasetDao(), fields);
if (this.id != null) datasetQuery.setId(this.id.getValue());
return datasetQuery;
}
} }

View File

@ -1,65 +0,0 @@
package eu.eudat.logic.managers;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.queryable.QueryableList;
import gr.cite.tools.data.query.QueryFactory;
import javax.management.InvalidApplicationException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
public class DatasetWizardManager {
// public static List<DataManagentPlanListingModel> getUserDmps(DMPDao dmpRepository, DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, UserScope userScope) throws InstantiationException, IllegalAccessException, InvalidApplicationException {
// UserEntity userInfo = new UserEntity();
// userInfo.setId(userScope.getUserId());
// QueryableList<DmpEntity> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest.getCriteria(), userInfo);
// List<DataManagentPlanListingModel> dataManagementPlans = items.select(item -> new DataManagentPlanListingModel().fromDataModel(item));
// return dataManagementPlans;
// }
// public static List<AssociatedProfile> getAvailableProfiles(DMPDao dmpRepository, DatasetProfileDao profileDao, DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest) throws InstantiationException, IllegalAccessException, InvalidApplicationException {
// DataManagementPlan dataManagementPlan = new DataManagementPlan().fromDataModel(dmpRepository.find(datasetProfileWizardAutocompleteRequest.getCriteria().getId()));
// if (dataManagementPlan.getProfiles() == null || dataManagementPlan.getProfiles().isEmpty()) {
// return new LinkedList<>();
// }
// DatasetProfileCriteria criteria = new DatasetProfileCriteria();
// criteria.setIds(dataManagementPlan.getProfiles().stream().map(AssociatedProfile::getDescriptionTemplateId).collect(Collectors.toList()));
// List<DescriptionTemplateEntity> descriptionTemplateEntities = profileDao.getWithCriteria(criteria).toList();
// criteria.setIds(null);
// criteria.setGroupIds(descriptionTemplateEntities.stream().map(DescriptionTemplateEntity::getGroupId).collect(Collectors.toList()));
// descriptionTemplateEntities = profileDao.getWithCriteria(criteria).toList();
// List<AssociatedProfile> profiles = descriptionTemplateEntities.stream().map(profile -> new AssociatedProfile().fromData(profile)).collect(Collectors.toList());
// return profiles;
// }
// public void unlock(ApiContext apiContext, QueryFactory queryFactory, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException {
// DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
// DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.getDescriptionTemplateId());
// if(dmp.getStatus().equals(DmpStatus.Finalized)) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation");
// descriptionEntity.setStatus(DescriptionStatus.Draft);
// apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity);
// return;
// }
public void delete(ApiContext apiContext, UUID uuid) throws IOException, InvalidApplicationException {
DescriptionEntity oldDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
// eu.eudat.elastic.entities.Dataset oldDatasetElasitc = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(uuid.toString()); //TODO
oldDescriptionEntity.setIsActive(IsActive.Inactive);
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDescriptionEntity);
// if (oldDatasetElasitc != null && uuid != null && oldDatasetElasitc.getId()!= null) {
// oldDatasetElasitc.setStatus(oldDescriptionEntity.getStatus().getValue());
// apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(oldDatasetElasitc);
// }
}
}

View File

@ -352,7 +352,8 @@ public class MetricsManager {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria(); eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setStatus(0); criteria.setStatus(0);
if (countNexus) criteria.setPeriodStart(getNexusDate()); if (countNexus) criteria.setPeriodStart(getNexusDate());
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count(); // return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
return 0;
} }
public long countAllFinalizedDatasets() throws InvalidApplicationException { public long countAllFinalizedDatasets() throws InvalidApplicationException {
@ -363,7 +364,8 @@ public class MetricsManager {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria(); eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setStatus(1); criteria.setStatus(1);
if (countNexus) criteria.setPeriodStart(getNexusDate()); if (countNexus) criteria.setPeriodStart(getNexusDate());
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count(); // return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
return 0;
} }
public long countAllPublicDatasets() throws InvalidApplicationException { public long countAllPublicDatasets() throws InvalidApplicationException {
@ -374,7 +376,8 @@ public class MetricsManager {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria(); eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setIsPublic(true); criteria.setIsPublic(true);
if (countNexus) criteria.setPeriodStart(getNexusDate()); if (countNexus) criteria.setPeriodStart(getNexusDate());
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count(); // return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
return 0;
} }
public long countAllDatasetsWithDoi() throws InvalidApplicationException { public long countAllDatasetsWithDoi() throws InvalidApplicationException {
@ -385,7 +388,8 @@ public class MetricsManager {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria(); eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setHasDoi(true); criteria.setHasDoi(true);
if (countNexus) criteria.setPeriodStart(getNexusDate()); if (countNexus) criteria.setPeriodStart(getNexusDate());
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count(); // return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
return 0;
} }
public long countAllDraftTemplates() throws InvalidApplicationException { public long countAllDraftTemplates() throws InvalidApplicationException {

View File

@ -1,140 +0,0 @@
package eu.eudat.logic.managers;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.data.old.*;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.query.QueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.io.IOException;
import java.text.ParseException;
@Component
public class QuickWizardManager {
private ApiContext apiContext;
private DatabaseRepository databaseRepository;
private DatasetManager datasetManager;
private final QueryFactory queryFactory;
private final UserScope userScope;
@Autowired
public QuickWizardManager(ApiContext apiContext, DatasetManager datasetManager, QueryFactory queryFactory, UserScope userScope) {
this.apiContext = apiContext;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.datasetManager = datasetManager;
this.queryFactory = queryFactory;
this.userScope = userScope;
}
//TODO
// public Funder createOrUpdate(eu.eudat.models.data.funder.Funder funder) {
// Funder funderEntity = funder.toDataModel();
// return databaseRepository.getFunderDao().createOrUpdate(funderEntity);
// }
//TODO
// public Grant createOrUpdate(eu.eudat.models.data.grant.Grant grant) throws ParseException, IOException, InvalidApplicationException {
// Grant grantEntity = grant.toDataModel();
// grantEntity.setType(Grant.GrantType.INTERNAL.getValue());
// grantEntity.setCreationUser(this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first());
// return databaseRepository.getGrantDao().createOrUpdate(grantEntity);
// }
//TODO
// public Project createOrUpdate(eu.eudat.models.data.project.Project project) throws InvalidApplicationException {
// Project projectEntity = project.toDataModel();
// projectEntity.setCreationUser(this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first());
// return databaseRepository.getProjectDao().createOrUpdate(projectEntity);
// }
// public DmpEntity createOrUpdate(DataManagementPlan dataManagementPlan/*, Funder funderEntity*/) throws Exception {
// DmpEntity newDmp = dataManagementPlan.toDataModel();
//// if (funderEntity != null) {
//// //TODO
//// //newDmp.getGrant().setFunder(funderEntity);
//// }
// UserEntity user = this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first();
// createFunderIfItDoesntExist(newDmp, user);
// createGrantIfItDoesntExist(newDmp, user);
// //TODO
//// if (newDmp.getProject() == null) {
//// newDmp.setProject(new Project());
//// newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
//// }
// createProjectIfItDoesntExist(newDmp, user);
//
// //TODO
// //apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
// DmpEntity dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
//// if (dataManagementPlan.getAssociatedUsers().size() == 0)
//// assignUser(newDmp, user, apiContext);
//
//// this.updateIndex(dmpret);
//
// return dmpret;
// }
// private void updateIndex(DMP dmp) throws IOException, InvalidApplicationException {
// DmpMapper mapper = new DmpMapper(apiContext, datasetManager);
// Dmp elastic = mapper.toElastic(dmp);
// apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);
// }
private void assignUser(DmpEntity dmp, UserEntity userInfo, ApiContext apiContext) {
DmpUserEntity userDMP = new DmpUserEntity();
userDMP.setDmpId(dmp.getId());
userDMP.setUserId(userInfo.getId());
userDMP.setRole(DmpUserRole.User);
//apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
}
private void createGrantIfItDoesntExist(DmpEntity newDmp, UserEntity userInfo) throws InvalidApplicationException {
// if (newDmp.getGrant() != null) {
// Grant grant = newDmp.getGrant();
// GrantCriteria criteria = new GrantCriteria();
// criteria.setReference(grant.getReference());
// Grant grantEntity = databaseRepository.getGrantDao().getWithCriteria(criteria).getSingleOrDefault();
// if (grantEntity != null) grant.setId(grantEntity.getId());
// else {
// grant.setType(Grant.GrantType.EXTERNAL.getValue());
// databaseRepository.getGrantDao().createOrUpdate(grant);
// }
// }
}
private void createFunderIfItDoesntExist(DmpEntity newDmp, UserEntity userInfo) throws InvalidApplicationException {
// if (newDmp.getGrant().getFunder() != null) { //TODO
// Funder funder = newDmp.getGrant().getFunder();
// FunderCriteria criteria = new FunderCriteria();
// criteria.setReference(funder.getReference());
// Funder funderEntity = databaseRepository.getFunderDao().getWithCritetia(criteria).getSingleOrDefault();
// if (funderEntity != null) funder.setId(funderEntity.getId());
// else {
// funder.setType(Funder.FunderType.EXTERNAL.getValue());
// databaseRepository.getFunderDao().createOrUpdate(funder);
// }
// }
}
private void createProjectIfItDoesntExist(DmpEntity newDmp, UserEntity userInfo) throws InvalidApplicationException {
// if (newDmp.getProject() != null) { //TODO
// Project project = newDmp.getProject();
// ProjectCriteria criteria = new ProjectCriteria();
// criteria.setReference(project.getReference());
// Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
// if (projectEntity != null) project.setId(projectEntity.getId());
// else {
// if (project.getId() == null) project.setId(UUID.randomUUID());
// project.setType(Project.ProjectType.EXTERNAL.getValue());
// databaseRepository.getProjectDao().createOrUpdate(project);
// }
// }
}
}

View File

@ -1,279 +0,0 @@
package eu.eudat.logic.mapper.prefilling;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.TagEntity;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.service.remotefetcher.config.entities.DefaultPrefillingMapping;
import eu.eudat.service.remotefetcher.config.entities.PrefillingFixedMapping;
import eu.eudat.service.remotefetcher.config.entities.PrefillingGet;
import eu.eudat.service.remotefetcher.config.entities.PrefillingMapping;
import eu.eudat.utilities.helpers.StreamDistinctBy;
import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalSelectDataEntity;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import eu.eudat.commons.enums.FieldType;
@Component
public class PrefillingMapper {
private static final Logger logger = LoggerFactory.getLogger(PrefillingMapper.class);
private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
private final DatasetProfileManager datasetProfileManager;
@Autowired
public PrefillingMapper(DatasetProfileManager datasetProfileManager) {
this.datasetProfileManager = datasetProfileManager;
}
public DatasetWizardModel mapPrefilledEntityToDatasetWizard(Map<String, Object> prefilledEntity, PrefillingGet prefillingGet, String type,
DescriptionTemplateEntity profile, DatasetManager datasetManager /*, LicenseManager licenseManager*/) throws Exception {
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
// datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile));
DescriptionEntity descriptionEntity = new DescriptionEntity();
//descriptionEntity.setDescriptionTemplateId(profile.getId()); //TODO
Map<String, Object> properties = new HashMap<>();
JsonNode parentNode = mapper.readTree(mapper.writeValueAsString(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity)));
for (DefaultPrefillingMapping prefillingMapping: prefillingGet.getMappings()) {
List<String> sourceKeys = Arrays.asList(prefillingMapping.getSource().split("\\."));
Object sourceValue = null;
for (String sourceKey: sourceKeys) {
if (sourceValue == null) {
sourceValue = prefilledEntity.get(sourceKey);
} else if (sourceValue instanceof Map) {
sourceValue = ((Map)sourceValue).get(sourceKey);
}
}
try {
setValue(prefillingMapping, mapper.writeValueAsString(sourceValue), datasetWizardModel, parentNode, properties, type/*, licenseManager*/);
}
catch (Exception e) {
if (prefillingMapping.getSemanticTarget() != null && !prefillingMapping.getSemanticTarget().isEmpty()) {
logger.warn("Couldn't map " + prefillingMapping.getSemanticTarget());
}
else if (prefillingMapping.getTarget() != null && !prefillingMapping.getTarget().isEmpty()) {
logger.warn("Couldn't map " + prefillingMapping.getTarget());
}
}
}
for (PrefillingFixedMapping fixedMapping: prefillingGet.getFixedMappings()) {
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties, type/*, licenseManager*/);
}
descriptionEntity.setProperties(mapper.writeValueAsString(properties));
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity));
return datasetWizardModel;
}
private void setValue(PrefillingMapping prefillingMapping, String value, DatasetWizardModel datasetWizardModel, JsonNode parentNode, Map<String, Object> properties, String type/*, LicenseManager licenseManager*/) throws InvocationTargetException, IllegalAccessException, JsonProcessingException {
String trimRegex = prefillingMapping.getTrimRegex() != null ? prefillingMapping.getTrimRegex() : "";
if (!value.startsWith("\"") && !value.startsWith("[") && !value.equals("null")) {
value = "\"" + value + "\"";
}
JsonNode valueNode = mapper.readTree(value);
List<String> parsedValues = new ArrayList<>();
if (valueNode.isArray() && (valueNode.get(0) != null && !valueNode.get(0).isTextual())) {
if (prefillingMapping.getSubSource() == null || prefillingMapping.getSubSource().isEmpty()) {
throw new IllegalArgumentException("Source value is an array but no subSource field have been set");
}
String parsedValue;
for(int i = 0; i < valueNode.size(); i++){
JsonNode jsonObj = valueNode.get(i);
String subSource = jsonObj.get(prefillingMapping.getSubSource()).asText();
parsedValue = subSource.replaceAll(trimRegex, "");
parsedValues.add(parsedValue);
}
parsedValues = parsedValues.stream().distinct().collect(Collectors.toList());
}
String parsedValue = null;
if (valueNode.isTextual()) {
parsedValue = valueNode.textValue().replace(trimRegex, "");
}else if (valueNode.isArray() && (valueNode.get(0) != null && valueNode.get(0).isTextual())) {
List<String> values = new LinkedList<>();
for (int i = 0; i < valueNode.size(); i++) {
values.add(valueNode.get(i).textValue().replace(trimRegex, ""));
}
parsedValue = String.join(", ", values);
}
if (prefillingMapping.getTarget() != null) {
try {
String methodName = "set" + prefillingMapping.getTarget().substring(0, 1).toUpperCase(Locale.ROOT) + prefillingMapping.getTarget().substring(1);
Method setterMethod = Arrays.stream(DatasetWizardModel.class.getDeclaredMethods())
.filter(method -> method.getName().equals(methodName)).collect(Collectors.toList()).get(0);
Class<?>[] params = setterMethod.getParameterTypes();
//GK: Tags Special logic
if (parsedValue != null && !parsedValue.equals("null") && prefillingMapping.getTarget().equals("tags")) {
parsedValue = mapper.valueToTree(parseTags(parsedValue)).toString();
}
else if(!parsedValues.isEmpty() && prefillingMapping.getTarget().equals("tags")) {
parsedValue = mapper.valueToTree(parseTags(String.join(", ", parsedValues))).toString();
}
else {
parsedValue = mapper.valueToTree(parsedValue).toString();
}
setterMethod.invoke(datasetWizardModel, mapper.readValue(parsedValue, params[0]));
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
throw e;
}
} else {
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "schematics", prefillingMapping.getSemanticTarget());
// zenodo prefilling customizations
if(type.equals("zenodo")){
if(prefillingMapping.getSemanticTarget().equals("rda.dataset.distribution.data_access")){
if(parsedValue != null && parsedValue.equals("open")){
List<JsonNode> issuedNodes = JsonSearcher.findNodes(parentNode, "schematics", "rda.dataset.issued");
if(!issuedNodes.isEmpty()){
String issuedIdNode = issuedNodes.get(0).get("id").asText();
String issuedValue = (String) properties.get(issuedIdNode);
List<JsonNode> licStartDateNodes = JsonSearcher.findNodes(parentNode, "schematics", "rda.dataset.distribution.license.start_date");
for (JsonNode licStartDateNode : licStartDateNodes) {
String licStartDateId = licStartDateNode.get(0) != null ? licStartDateNode.get(0).get("id").asText() : licStartDateNode.get("id").asText();
properties.put(licStartDateId, issuedValue);
}
}
}
}
if (prefillingMapping.getSemanticTarget().equals("rda.dataset.distribution.available_until") && parsedValue != null && !parsedValue.equals("null")) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
LocalDate date = LocalDate.parse(parsedValue, formatter);
date = date.plusYears(20);
parsedValue = date.toString();
}
}
for (JsonNode node: nodes) {
String id = node.isArray() ? node.get(0).get("id").asText() : node.get("id").asText();
String renderStyle = node.isArray() ? node.get(0).get("viewStyle").get("renderStyle").asText() : node.get("viewStyle").get("renderStyle").asText();
switch (FieldType.of(renderStyle)) {
case EXTERNAL_SELECT:
case SELECT:
if (parsedValues.isEmpty())
parsedValues.add(parsedValue);
if (!parsedValues.stream().allMatch(Objects::isNull)) {
properties.put(id, parseComboBoxValues(node, parsedValues));
}
break;
case TAGS:
if(parsedValues.isEmpty()) {
properties.put(id, mapper.valueToTree(parseTags(parsedValue)).toString());
}
else {
properties.put(id, mapper.valueToTree(parseTags(String.join(", ", parsedValues))).toString());
}
break;
case DATASET_IDENTIFIER:
JSONObject datasetID = new JSONObject();
datasetID.put("identifier", parsedValue);
if(type.equals("zenodo")){
datasetID.put("type", "doi");
}
properties.put(id, datasetID.toString());
break;
case LICENSES:
// try {
// List<LicenseModel> licenses = licenseManager.getLicenses("", "");
// String finalParsedValue = parsedValue;
// licenses = licenses.stream().filter(license -> license.getPid().equals(finalParsedValue)).collect(Collectors.toList());
// boolean isMultiAutocomplete = node.isArray() ? node.get(0).get("data").get("multiAutoComplete").booleanValue() : node.get("data").get("multiAutoComplete").booleanValue();
// if(isMultiAutocomplete){
// List<String> lic = new ArrayList<>();
// for(LicenseModel license: licenses){
// lic.add(mapper.writeValueAsString(license));
// }
// properties.put(id, mapper.writeValueAsString(lic));
// } else {
// properties.put(id, mapper.writeValueAsString(licenses.get(0)));
// }
// }
// catch (MyNotFoundException | HugeResultSetException e){
// properties.put(id, parsedValue);
// }
break;
default:
if (!parsedValues.isEmpty())
properties.put(id, String.join(", ", parsedValues));
else {
properties.put(id, parsedValue);
}
break;
}
}
}
}
private Object parseComboBoxValues(JsonNode node, List<String> parsedValues) throws JsonProcessingException {
List<Object> normalizedValues = new ArrayList<>();
boolean isMultiSelect;
String type = node.isArray() ? node.get(0).get("data").get("type").asText() : node.get("data").get("type").asText();
if(type.equals("autocomplete")) {
JsonNode dataNode = node.isArray() ? node.get(0).get("data") : node.get("data");
ExternalSelectDataEntity externalSelectDataEntity = mapper.treeToValue(dataNode, ExternalSelectDataEntity.class);
isMultiSelect = externalSelectDataEntity.getMultipleSelect();
for (String format : parsedValues) {
List<ExternalAutocompleteFieldResult> result = new ArrayList<>();
try {
result = datasetProfileManager.getAutocomplete(externalSelectDataEntity, format);
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldResult::getId)).collect(Collectors.toList());
if(!result.isEmpty()){
List<String> tempValues = new LinkedList<>();
for (ExternalAutocompleteFieldResult f : result) {
if (format.equals(f.getId()) || f.getLabel().toUpperCase(Locale.ROOT).contains(format.toUpperCase(Locale.ROOT)))
tempValues.add(mapper.valueToTree(f).toString());
}
if (isMultiSelect)
normalizedValues.addAll(tempValues);
else if (!tempValues.isEmpty())
normalizedValues.add(tempValues.get(0));
}
}
return !normalizedValues.isEmpty() ? (isMultiSelect ? normalizedValues : normalizedValues.get(0)) : null;
} else {
JsonNode optionsNode = node.isArray() ? node.get(0).get("data").get("options") : node.get("data").get("options");
isMultiSelect = node.isArray() ? node.get(0).get("data").get("multiList").booleanValue() : node.get("data").get("multiList").booleanValue();
for (int i = 0; i < optionsNode.size(); i++) {
String value = optionsNode.get(i).get("value").textValue();
if (parsedValues.contains(value)) {
normalizedValues.add(value);
}
}
List<String> normalizedStringValues = normalizedValues.stream().map(Object::toString).collect(Collectors.toList());
return !normalizedValues.isEmpty() ? (isMultiSelect ? String.join(", ", normalizedStringValues) : normalizedValues.get(0)) : null;
}
}
private static List<TagEntity> parseTags(String value) throws JsonProcessingException {
if (value == null || value.isEmpty())
return new LinkedList<>();
String[] rawTags = value.split(", ");
List<TagEntity> parsedTags = new LinkedList<>();
for (String rawTag : rawTags) {
parsedTags.add(new TagEntity());
}
return parsedTags;
}
}

View File

@ -4,13 +4,6 @@ import eu.eudat.data.dao.entities.*;
public interface DatabaseRepository { public interface DatabaseRepository {
DatasetDao getDatasetDao();
FileUploadDao getFileUploadDao(); FileUploadDao getFileUploadDao();
<T> void detachEntity(T entity); <T> void detachEntity(T entity);

View File

@ -8,8 +8,6 @@ import org.springframework.stereotype.Service;
@Service("databaseRepository") @Service("databaseRepository")
public class DatabaseRepositoryImpl implements DatabaseRepository { public class DatabaseRepositoryImpl implements DatabaseRepository {
private DatasetDao datasetDao;
@ -18,20 +16,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
private EntityManager entityManager; private EntityManager entityManager;
@Autowired
private void setDatasetDao(DatasetDao datasetDao) {
this.datasetDao = datasetDao;
}
@Autowired
@Override
public DatasetDao getDatasetDao() {
return datasetDao;
}
@Autowired @Autowired
public void setEntityManager(EntityManager entityManager) { public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager; this.entityManager = entityManager;

View File

@ -1,83 +0,0 @@
package eu.eudat.models.data.dashboard.recent.model;
import eu.eudat.data.DescriptionEntity;
public class RecentDatasetModel extends RecentActivityModel<DescriptionEntity, RecentDatasetModel> {
private String dmp;
private String dmpId;
public String getDmp() {
return dmp;
}
public void setDmp(String dmp) {
this.dmp = dmp;
}
public String getDmpId() {
return dmpId;
}
public void setDmpId(String dmpId) {
this.dmpId = dmpId;
}
@Override
public RecentActivityModel fromEntity(DescriptionEntity entity) {
//TODO
this.setType(RecentActivityType.DATASET.getIndex());
// this.setId(entity.getId().toString());
// this.setTitle(entity.getLabel());
// this.setCreated(entity.getCreated());
// this.setModified(entity.getModified());
// this.setStatus(entity.getStatus());
// this.setVersion(entity.getDmp() != null ? entity.getDmp().getVersion(): 0);
// this.setFinalizedAt(entity.getFinalizedAt());
// this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date());
// this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()): null);
// if (entity.getDmp() != null && entity.getDmp().getGrant() != null) {
// this.setGrant(entity.getDmp().getGrant().getLabel());
// }
// this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : "");
// this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : "");
// this.setPublic(entity.getDmp().isPublic());
// this.setUsers(entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()));
return this;
}
public RecentDatasetModel fromDmpEntity(DescriptionEntity entity) {
//TODO
this.setType(RecentActivityType.DATASET.getIndex());
// this.setId(entity.getId().toString());
// this.setTitle(entity.getLabel());
// this.setCreated(entity.getCreated());
// this.setModified(entity.getModified());
// this.setStatus(entity.getStatus());
// this.setVersion(entity.getDmp() != null ? entity.getDmp().getVersion(): 0);
// this.setFinalizedAt(entity.getFinalizedAt());
// this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date());
// this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null);
// if (entity.getDmp() != null && entity.getDmp().getGrant() != null) {
// this.setGrant(entity.getDmp().getGrant().getLabel());
// }
// this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : "");
// this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : "");
return this;
}
@Override
public RecentDatasetModel fromDataModel(DescriptionEntity entity) {
return (RecentDatasetModel) this.fromEntity(entity);
}
@Override
public DescriptionEntity toDataModel() throws Exception {
return null;
}
@Override
public String getHint() {
return "recentDatasetModel";
}
}

View File

@ -1,155 +0,0 @@
package eu.eudat.models.data.dataset;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.models.DataModel;
import java.util.Date;
import java.util.UUID;
public class Dataset implements DataModel<DescriptionEntity, Dataset> {
private UUID id;
private String label;
private String reference;
private String uri;
private String description;
private short status;
private String properties;
private Date created;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public short getStatus() {
return status;
}
public void setStatus(short status) {
this.status = status;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
// public DataManagementPlan getDmp() {
// return dmp;
// }
//
// public void setDmp(DataManagementPlan dmp) {
// this.dmp = dmp;
// }
public Dataset fromDataModel(DescriptionEntity entity) {
//TODO
// this.id = entity.getId();
// this.label = entity.getLabel();
// this.properties = entity.getProperties();
// this.reference = entity.getReference();
// this.description = entity.getDescription();
// this.profile = new DatasetProfileListingModel();
// this.profile.fromDataModel(entity.getProfile());
// this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList());
// this.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList());
// this.services = entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList());
// this.created = entity.getCreated();
return this;
}
public DescriptionEntity toDataModel() throws Exception {
DescriptionEntity entity = new DescriptionEntity();
//TODO
// entity.setId(this.id);
// entity.setLabel(this.label);
// entity.setReference(this.reference);
// entity.setUri(this.uri);
// entity.setProperties(this.properties);
// entity.setStatus(this.status);
// entity.setDmp(dmp.toDataModel());
// entity.setDescription(this.description);
// entity.setCreated(this.created != null ? this.created : new Date());
// entity.setModified(new Date());
// entity.setProfile(profile.toDataModel()); ///TODO
// if (!this.registries.isEmpty()) {
// entity.setRegistries(new HashSet<eu.eudat.data.old.Registry>());
// for (Registry registry : this.registries) {
// entity.getRegistries().add(registry.toDataModel());
// }
// }
//
// if (!this.dataRepositories.isEmpty()) {
// entity.setDatasetDataRepositories(new HashSet<>());
// for (DataRepository dataRepositoryModel : this.dataRepositories) {
// DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
// eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel();
// datasetDataRepository.setDataRepository(dataRepository);
// entity.getDatasetDataRepositories().add(datasetDataRepository);
// }
// }
//
// if (!this.services.isEmpty()) {
// entity.setServices(new HashSet<DatasetService>());
// for (Service serviceModel : this.services) {
// eu.eudat.data.old.Service service = serviceModel.toDataModel();
// DatasetService datasetService = new DatasetService();
// datasetService.setService(service);
// entity.getServices().add(datasetService);
// }
// }
return entity;
}
@Override
public String getHint() {
return null;
}
}

View File

@ -1,122 +0,0 @@
package eu.eudat.models.data.dataset;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.model.DmpUser;
import eu.eudat.models.DataModel;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
public class DatasetOverviewModel implements DataModel<DescriptionEntity, DatasetOverviewModel> {
private UUID id;
private String label;
private DescriptionStatus status;
private List<DmpUser> users;
// private DataManagementPlanOverviewModel dmp;
private String description;
private Boolean isPublic;
private Instant modified;
private Instant created;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public List<DmpUser> getUsers() {
return users;
}
public void setUsers(List<DmpUser> users) {
this.users = users;
}
// public DataManagementPlanOverviewModel getDmp() {
// return dmp;
// }
//
// public void setDmp(DataManagementPlanOverviewModel dmp) {
// this.dmp = dmp;
// }
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getPublic() {
return isPublic;
}
public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
@Override
public DatasetOverviewModel fromDataModel(DescriptionEntity entity) {
//TODO Implement it on transfer
// this.id = entity.getId();
// this.label = entity.getLabel();
// this.status = entity.getStatus();
// this.datasetTemplate = new DatasetProfileOverviewModel().fromDataModel(entity.getProfile());
// this.users = entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
// this.dmp = new DataManagementPlanOverviewModel().fromDataModel(entity.getDmp());
// if (entity.getDmp().getGrant() != null) {
// this.grant = new GrantOverviewModel().fromDataModel(entity.getDmp().getGrant());
// }
// this.description = entity.getDescription();
// this.isPublic = entity.getDmp().isPublic();
// this.modified = entity.getCreatedAt();
// this.created = entity.getUpdatedAt();
return this;
}
@Override
public DescriptionEntity toDataModel() throws Exception {
return null;
}
@Override
public String getHint() {
return null;
}
}

View File

@ -1,274 +0,0 @@
package eu.eudat.models.data.datasetwizard;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
public class DatasetWizardModel implements DataModel<DescriptionEntity, DatasetWizardModel> {
private UUID id;
private String label;
private String reference;
private String uri;
private String description;
private DescriptionStatus status;
private Instant created;
// private DataManagementPlan dmp;
private Integer dmpSectionIndex;
private PagedDatasetProfile datasetProfileDefinition;
// private List<Tag> tags; //TODO
private Boolean isProfileLatestVersion;
private Instant modified;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
// public DataManagementPlan getDmp() {
// return dmp;
// }
// public void setDmp(DataManagementPlan dmp) {
// this.dmp = dmp;
// }
public Integer getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(Integer dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
public PagedDatasetProfile getDatasetProfileDefinition() {
return datasetProfileDefinition;
}
public void setDatasetProfileDefinition(PagedDatasetProfile datasetProfileDefinition) {
this.datasetProfileDefinition = datasetProfileDefinition;
}
// public List<Tag> getTags() {
// return tags;
// }
// public void setTags(List<Tag> tags) {
// this.tags = tags;
// }
public Boolean getIsProfileLatestVersion() {
return isProfileLatestVersion;
}
public void setIsProfileLatestVersion(Boolean profileLatestVersion) {
isProfileLatestVersion = profileLatestVersion;
}
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
@Override
public DatasetWizardModel fromDataModel(DescriptionEntity entity) {
//TODO Implement it on transfer
// this.id = entity.getId();
// this.label = entity.getLabel();
// this.status = entity.getStatus();
// this.reference = entity.getReference();
// this.description = entity.getDescription();
// this.profile = new DatasetProfileOverviewModel();
// this.profile = this.profile.fromDataModel(entity.getProfile());
// this.uri = entity.getUri();
// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> {
// DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// dataRepository.setInfo(values.get("info"));
// }
// return dataRepository;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
// this.created = entity.getCreated();
// this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
// this.dmpSectionIndex = entity.getDmpSectionIndex();
// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
// ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// externalDatasetListingModel.setInfo(values.get("info"));
// externalDatasetListingModel.setType(Integer.parseInt(values.get("type")));
// }
// return externalDatasetListingModel;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.modified = entity.getUpdatedAt();
return this;
}
public DatasetWizardModel fromDataModelNoDmp(DescriptionEntity entity) {
//TODO Implement it on transfer
// this.id = entity.getId();
// this.label = entity.getLabel();
// this.status = entity.getStatus();
// this.reference = entity.getReference();
// this.description = entity.getDescription();
// this.profile = new DatasetProfileOverviewModel();
// this.profile = this.profile.fromDataModel(entity.getProfile());
// this.uri = entity.getUri();
// this.dmpSectionIndex = entity.getDmpSectionIndex();
// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> {
// DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// dataRepository.setInfo(values.get("info"));
// }
// return dataRepository;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
// this.created = entity.getCreated();
// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
// ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// externalDatasetListingModel.setInfo(values.get("info"));
// externalDatasetListingModel.setType(Integer.parseInt(values.get("type")));
// }
// return externalDatasetListingModel;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.modified = entity.getModified();
return this;
}
@Override
public DescriptionEntity toDataModel() throws Exception {
DescriptionEntity entity = new DescriptionEntity();
//TODO Implement it on transfer
// entity.setId(this.id);
// entity.setLabel(this.label);
// entity.setReference(this.reference);
// entity.setUri(this.uri);
// entity.setStatus(this.status);
// if (this.status == (int) DescriptionEntity.Status.FINALISED.getValue())
// entity.setFinalizedAt(new Date());
// DMP dmp = new DMP();
// dmp.setId(this.dmp.getId());
// entity.setDmp(dmp);
// entity.setDmpSectionIndex(this.dmpSectionIndex);
// entity.setDescription(this.description);
// entity.setCreated(this.created != null ? this.created : new Date());
// entity.setModified(new Date());
// DescriptionTemplateEntity profile = new DescriptionTemplateEntity();
// profile.setId(this.profile.getId());
// entity.setProfile(profile);
// if (this.registries != null && !this.registries.isEmpty()) {
// entity.setRegistries(new HashSet<>());
// for (Registry registry : this.registries) {
// entity.getRegistries().add(registry.toDataModel());
// }
// }
//
// if (this.dataRepositories != null && !this.dataRepositories.isEmpty()) {
// entity.setDatasetDataRepositories(new HashSet<>());
// for (DataRepository dataRepositoryModel : this.dataRepositories) {
// eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel();
// DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
// datasetDataRepository.setDataRepository(dataRepository);
// Map<String, Map<String, String>> data = new HashMap<>();
// Map<String, String> values = new HashMap<>();
// values.put("info", dataRepositoryModel.getInfo());
// data.put("data", values);
// datasetDataRepository.setData(JSONValue.toJSONString(data));
// entity.getDatasetDataRepositories().add(datasetDataRepository);
// }
// }
//
// if (this.services != null && !this.services.isEmpty()) {
// entity.setServices(new HashSet<>());
// for (Service serviceModel : this.services) {
// eu.eudat.data.old.Service service = serviceModel.toDataModel();
// DatasetService datasetService = new DatasetService();
// datasetService.setService(service);
// entity.getServices().add(datasetService);
// }
// }
//
// if (this.externalDatasets != null && !this.externalDatasets.isEmpty()) {
// entity.setDatasetExternalDatasets(new HashSet<>());
// for (ExternalDatasetListingModel externalDataset : this.externalDatasets) {
// ExternalDataset externalDatasetEntity = externalDataset.toDataModel();
// DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset();
// datasetExternalDataset.setExternalDataset(externalDatasetEntity);
// Map<String,Map<String,String>> data = new HashMap<>();
// Map<String,String> values = new HashMap<>();
// values.put("info",externalDataset.getInfo());
// values.put("type",externalDataset.getType().toString());
// data.put("data",values);
// datasetExternalDataset.setData(JSONValue.toJSONString(data));
// entity.getDatasetExternalDatasets().add(datasetExternalDataset);
// }
// }
return entity;
}
@Override
public String getHint() {
return "datasetWizardModel";
}
}

View File

@ -1,15 +0,0 @@
package eu.eudat.models.data.datasetwizard;
import java.util.List;
import java.util.UUID;
public class DatasetsToBeFinalized {
private List<UUID> uuids;
public List<UUID> getUuids() {
return uuids;
}
public void setUuids(List<UUID> uuids) {
this.uuids = uuids;
}
}

View File

@ -1,186 +0,0 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.model.DmpUser;
import eu.eudat.models.DataModel;
import java.time.Instant;
import java.util.List;
public class DatasetListingModel implements DataModel<DescriptionEntity, DatasetListingModel> {
private String id;
private String label;
private String grant;
private String dmp;
private String dmpId;
private DescriptionStatus status;
private Instant created;
private Instant modified;
private String description;
private Instant finalizedAt;
private Instant dmpPublishedAt;
private int version;
private List<DmpUser> users;
private Boolean isPublic;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getGrant() {
return grant;
}
public void setGrant(String grant) {
this.grant = grant;
}
public String getDmp() {
return dmp;
}
public void setDmp(String dmp) {
this.dmp = dmp;
}
public String getDmpId() {
return dmpId;
}
public void setDmpId(String dmpId) {
this.dmpId = dmpId;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Instant getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Instant finalizedAt) {
this.finalizedAt = finalizedAt;
}
public Instant getDmpPublishedAt() {
return dmpPublishedAt;
}
public void setDmpPublishedAt(Instant dmpPublishedAt) {
this.dmpPublishedAt = dmpPublishedAt;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public List<DmpUser> getUsers() {
return users;
}
public void setUsers(List<DmpUser> users) {
this.users = users;
}
public Boolean getPublic() {
return isPublic;
}
public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}
@Override
public DatasetListingModel fromDataModel(DescriptionEntity entity) {
//TODO Implement it on transfer
// this.id = entity.getId() != null ? entity.getId().toString() : "";
// this.label = entity.getLabel();
// this.created = entity.getCreatedAt();
// this.modified = entity.getUpdatedAt();
// this.grant = (entity.getDmp() != null && entity.getDmp().getGrant() != null) ? entity.getDmp().getGrant().getLabel() : "";
// this.dmp = entity.getDmp() != null ? entity.getDmp().getLabel() : "";
// this.dmpId = entity.getDmp() != null ? entity.getDmp().getId().toString() : "";
// this.profile = entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null;
// this.description = entity.getDescription();
// this.status = entity.getStatus();
// if (entity.getFinalizedAt() == null && entity.getStatus() == DescriptionStatus.Finalized) {
// this.finalizedAt = entity.getDmp().getFinalizedAt();
// } else {
// this.finalizedAt = entity.getFinalizedAt();
// }
// this.dmpPublishedAt = entity.getDmp().getPublishedAt();
// this.version = entity.getDmp().getVersion();
// this.users = entity.getDmp() != null ? entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>();
// this.isPublic = entity.getDmp() != null ? entity.getDmp().isPublic() : false;
return this;
}
@Override
public DescriptionEntity toDataModel() {
//TODO Implement it on transfer
DescriptionEntity entity = new DescriptionEntity();
// entity.setId(UUID.fromString(this.getId()));
// entity.setLabel(this.getLabel());
// entity.setCreatedAt(this.getCreated());
// entity.setUpdatedAt(this.getModified());
// entity.setDescription(this.getDescription());
// entity.setFinalizedAt(this.getFinalizedAt());
// entity.setStatus(this.getStatus());
// DMP dmp = new DMP();
// if (this.getGrant() != null && !this.getGrant().isEmpty()) {
// Grant grant = new Grant();
// grant.setLabel(this.getGrant());
// dmp.setGrant(grant);
// }
// dmp.setLabel(this.getDmp());
// dmp.setId(UUID.fromString(this.getDmpId()));
// dmp.setPublishedAt(this.getDmpPublishedAt());
// dmp.setVersion(this.getVersion());
// dmp.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet()));
// dmp.setPublic(this.getPublic());
// dmp.setFinalizedAt(this.getFinalizedAt());
// entity.setDmp(dmp);
// entity.setProfile(this.getProfile() != null ? this.getProfile().toDataModel() : null);
return entity;
}
@Override
public String getHint() {
return "datasetListingModel";
}
}

View File

@ -1,14 +0,0 @@
package eu.eudat.models.data.quickwizard;
public class DatasetCreateWizardModel {
private DatasetQuickWizardModel datasets;
public DatasetQuickWizardModel getDatasets() {
return datasets;
}
public void setDatasets(DatasetQuickWizardModel datasets) {
this.datasets = datasets;
}
}

View File

@ -1,40 +0,0 @@
package eu.eudat.models.data.quickwizard;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import java.time.Instant;
import java.util.Date;
public class DatasetDescriptionQuickWizardModel extends PagedDatasetProfile {
private String datasetLabel;
public String getDatasetLabel() {
return datasetLabel;
}
public void setDatasetLabel(String datasetLabel) {
this.datasetLabel = datasetLabel;
}
public DatasetWizardModel toDataModel(DescriptionTemplateEntity profile){
DatasetWizardModel newDataset = new DatasetWizardModel();
newDataset.setLabel(datasetLabel);
newDataset.setCreated(Instant.now());
// newDataset.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile));
// newDataset.setDmp(dmp);
newDataset.setStatus(DescriptionStatus.of((short)this.getStatus()));
//newDataset.setStatus(Dataset.Status.SAVED.getValue());
newDataset.setDatasetProfileDefinition((PagedDatasetProfile) this);
return newDataset;
}
}

View File

@ -1,14 +0,0 @@
package eu.eudat.models.data.quickwizard;
import java.util.UUID;
public class DatasetProfileCreateWizardModel {
private UUID id;
private String label;
public UUID getId() { return id; }
public void setId(UUID id) { this.id = id; }
public String getLabel() { return label; }
public void setLabel(String label) { this.label = label; }
}

View File

@ -1,15 +0,0 @@
package eu.eudat.models.data.quickwizard;
import java.util.List;
public class DatasetQuickWizardModel {
private List<DatasetDescriptionQuickWizardModel> datasetsList;
public List<DatasetDescriptionQuickWizardModel> getDatasetsList() {
return datasetsList;
}
public void setDatasetsList(List<DatasetDescriptionQuickWizardModel> datasetsList) {
this.datasetsList = datasetsList;
}
}

View File

@ -1,22 +0,0 @@
package eu.eudat.models.data.quickwizard;
public class QuickWizardModel {
private DatasetQuickWizardModel datasets;
private int status;
public DatasetQuickWizardModel getDatasets() {
return datasets;
}
public void setDatasets(DatasetQuickWizardModel datasets) {
this.datasets = datasets;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}

View File

@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.xml.XmlBuilder; import eu.eudat.logic.xml.XmlBuilder;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -150,7 +149,7 @@ public class DatasetRDAExportModel {
} }
public DatasetRDAExportModel fromDataModel(DescriptionEntity descriptionEntity, DatasetManager datasetManager) { public DatasetRDAExportModel fromDataModel(DescriptionEntity descriptionEntity) {
// Map of template Ids to rda values. // Map of template Ids to rda values.
JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); JSONObject jObject = new JSONObject(descriptionEntity.getProperties());
Map<String, Object> templateIdsToValues = jObject.toMap(); Map<String, Object> templateIdsToValues = jObject.toMap();
@ -166,9 +165,11 @@ public class DatasetRDAExportModel {
// Transform the answered dataset description to json so we can parse it and fill the rda model. // Transform the answered dataset description to json so we can parse it and fill the rda model.
JSONObject datasetDescriptionJson = null; JSONObject datasetDescriptionJson = null;
try { try {
String jsonResult = mapper.writeValueAsString(datasetManager.getSingle(descriptionEntity.getId().toString()).getDatasetProfileDefinition()); //TODO
//String jsonResult = mapper.writeValueAsString(datasetManager.getSingle(descriptionEntity.getId().toString()).getDatasetProfileDefinition());
String jsonResult = mapper.writeValueAsString(null);
datasetDescriptionJson = new JSONObject(jsonResult); datasetDescriptionJson = new JSONObject(jsonResult);
} catch (JsonProcessingException | InvalidApplicationException e) { } catch (JsonProcessingException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
setMultiplicityIdToFieldSetId(datasetDescriptionJson); setMultiplicityIdToFieldSetId(datasetDescriptionJson);

View File

@ -1,17 +1,8 @@
package eu.eudat.models.data.rda; package eu.eudat.models.data.rda;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.logic.managers.DatasetManager;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class DmpRDAExportModel { public class DmpRDAExportModel {
private ContactRDAExportModel contact; private ContactRDAExportModel contact;
@ -127,7 +118,7 @@ public class DmpRDAExportModel {
this.title = title; this.title = title;
} }
public DmpRDAExportModel fromDataModel(DmpEntity entity, DatasetManager datasetManager) { public DmpRDAExportModel fromDataModel(DmpEntity entity) {
DmpRDAExportModel dmpRda = new DmpRDAExportModel(); DmpRDAExportModel dmpRda = new DmpRDAExportModel();
//TODO //TODO
// dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); // dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());

View File

@ -1,7 +1,6 @@
package eu.eudat.models.data.rda; package eu.eudat.models.data.rda;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.logic.managers.DatasetManager;
public class RDAExportModel { public class RDAExportModel {
private DmpRDAExportModel dmp; private DmpRDAExportModel dmp;
@ -13,8 +12,8 @@ public class RDAExportModel {
this.dmp = dmp; this.dmp = dmp;
} }
public RDAExportModel fromDataModel(DmpEntity dmp, DatasetManager datasetManager) { public RDAExportModel fromDataModel(DmpEntity dmp) {
this.dmp = new DmpRDAExportModel().fromDataModel(dmp, datasetManager); this.dmp = new DmpRDAExportModel().fromDataModel(dmp);
return this; return this;
} }
} }

View File

@ -1,30 +0,0 @@
package eu.eudat.models.data.urls;
import eu.eudat.data.DescriptionEntity;
import java.util.UUID;
/**
* Created by ikalyvas on 7/23/2018.
*/
public class DatasetUrlListing extends UrlListing<DescriptionEntity, DatasetUrlListing> {
@Override
public DatasetUrlListing fromDataModel(DescriptionEntity entity) {
this.setLabel(entity.getLabel());
this.setUrl(entity.getId().toString());
return this;
}
@Override
public DescriptionEntity toDataModel() {
DescriptionEntity entity = new DescriptionEntity();
entity.setId(UUID.fromString(this.getUrl()));
entity.setLabel(this.getLabel());
return entity;
}
@Override
public String getHint() {
return null;
}
}

View File

@ -6,10 +6,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.TagEntity; import eu.eudat.data.TagEntity;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.rda.*; import eu.eudat.models.rda.*;
import eu.eudat.query.DmpDescriptionTemplateQuery; import eu.eudat.query.DmpDescriptionTemplateQuery;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
@ -33,13 +31,11 @@ import java.util.stream.StreamSupport;
public class DatasetRDAMapper { public class DatasetRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class); private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
private DatasetManager datasetManager;
private ApiContext apiContext; private ApiContext apiContext;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
@Autowired @Autowired
public DatasetRDAMapper(DatasetManager datasetManager, ApiContext apiContext, QueryFactory queryFactory) { public DatasetRDAMapper(ApiContext apiContext, QueryFactory queryFactory) {
this.datasetManager = datasetManager;
this.apiContext = apiContext; this.apiContext = apiContext;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
} }
@ -57,10 +53,11 @@ public class DatasetRDAMapper {
try { try {
JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); JSONObject jObject = new JSONObject(descriptionEntity.getProperties());
Map<String, Object> templateIdsToValues = jObject.toMap(); Map<String, Object> templateIdsToValues = jObject.toMap();
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(descriptionEntity); // DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(descriptionEntity);
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity)); // datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity));
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition()); // String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition());
String datasetDescriptionJson = mapper.writeValueAsString(null);
JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson); JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson);
List<JsonNode> idNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.dataset_id"); List<JsonNode> idNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.dataset_id");
if (!idNodes.isEmpty()) { if (!idNodes.isEmpty()) {
@ -298,12 +295,13 @@ public class DatasetRDAMapper {
} }
try { try {
Map<String, Object> properties = new HashMap<>(); Map<String, Object> properties = new HashMap<>();
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
//TODO //TODO
//DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
//datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(entity.getProfile())); //datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()));
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, entity)); // datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, entity));
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition()); // String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition());
String datasetDescriptionJson = mapper.writeValueAsString(null);
JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson); JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson);
List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.type"); List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.type");