|
|
@ -1,7 +1,9 @@
|
|
|
|
package eu.eudat.logic.managers;
|
|
|
|
package eu.eudat.logic.managers;
|
|
|
|
|
|
|
|
|
|
|
|
import eu.eudat.data.dao.criteria.*;
|
|
|
|
import eu.eudat.data.dao.criteria.*;
|
|
|
|
import eu.eudat.data.dao.entities.*;
|
|
|
|
import eu.eudat.data.dao.entities.DataRepositoryDao;
|
|
|
|
|
|
|
|
import eu.eudat.data.dao.entities.DatasetDao;
|
|
|
|
|
|
|
|
import eu.eudat.data.dao.entities.RegistryDao;
|
|
|
|
import eu.eudat.data.entities.*;
|
|
|
|
import eu.eudat.data.entities.*;
|
|
|
|
import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest;
|
|
|
|
import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest;
|
|
|
|
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
|
|
|
|
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
|
|
|
@ -17,13 +19,13 @@ import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
|
|
|
|
import eu.eudat.logic.utilities.documents.word.WordBuilder;
|
|
|
|
import eu.eudat.logic.utilities.documents.word.WordBuilder;
|
|
|
|
import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
|
|
|
import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
|
|
|
import eu.eudat.models.HintedModelFactory;
|
|
|
|
import eu.eudat.models.HintedModelFactory;
|
|
|
|
import eu.eudat.models.data.datasetImport.*;
|
|
|
|
import eu.eudat.models.data.datasetImport.DatasetImportField;
|
|
|
|
|
|
|
|
import eu.eudat.models.data.datasetImport.DatasetImportPagedDatasetProfile;
|
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
|
|
import eu.eudat.models.data.dmp.AssociatedProfile;
|
|
|
|
import eu.eudat.models.data.dmp.AssociatedProfile;
|
|
|
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
|
|
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
|
|
|
import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
|
|
|
import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
|
|
|
import eu.eudat.models.data.user.composite.DatasetProfilePage;
|
|
|
|
|
|
|
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|
|
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|
|
|
import eu.eudat.queryable.QueryableList;
|
|
|
|
import eu.eudat.queryable.QueryableList;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
@ -33,20 +35,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
|
import org.springframework.http.*;
|
|
|
|
import org.springframework.http.*;
|
|
|
|
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
|
|
|
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
|
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.activation.MimetypesFileTypeMap;
|
|
|
|
import javax.activation.MimetypesFileTypeMap;
|
|
|
|
import javax.mail.Multipart;
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
@ -84,19 +81,17 @@ public class DatasetManager {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && datasetRepository.exists() ?
|
|
|
|
datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && datasetRepository.exists() ?
|
|
|
|
datasetRepository.query(datasetCriteria) : new LinkedList<>();
|
|
|
|
datasetRepository.query(datasetCriteria) : new LinkedList<>();
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
catch (Exception ex){
|
|
|
|
|
|
|
|
datasets = null;
|
|
|
|
datasets = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserInfo userInfo = builderFactory.getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
|
|
|
UserInfo userInfo = builderFactory.getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
|
|
|
QueryableList<eu.eudat.data.entities.Dataset> items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
|
|
|
QueryableList<eu.eudat.data.entities.Dataset> items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
|
|
|
if (datasets != null && datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) {
|
|
|
|
if (datasets != null && datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) {
|
|
|
|
if (!datasets.isEmpty()){
|
|
|
|
if (!datasets.isEmpty()) {
|
|
|
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
|
|
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
|
|
|
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
|
|
|
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
else
|
|
|
|
|
|
|
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
|
|
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QueryableList<eu.eudat.data.entities.Dataset> authItems = databaseRepository.getDatasetDao().getAuthenticated(items, userInfo);
|
|
|
|
QueryableList<eu.eudat.data.entities.Dataset> authItems = databaseRepository.getDatasetDao().getAuthenticated(items, userInfo);
|
|
|
@ -121,11 +116,10 @@ public class DatasetManager {
|
|
|
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
|
|
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
|
|
|
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
|
|
|
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
|
|
|
List<eu.eudat.elastic.entities.Dataset> datasets;
|
|
|
|
List<eu.eudat.elastic.entities.Dataset> datasets;
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && datasetRepository.exists() ?
|
|
|
|
datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && datasetRepository.exists() ?
|
|
|
|
datasetRepository.query(datasetCriteria) : new LinkedList<>();
|
|
|
|
datasetRepository.query(datasetCriteria) : new LinkedList<>();
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
catch (Exception ex){
|
|
|
|
|
|
|
|
datasets = null;
|
|
|
|
datasets = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)));
|
|
|
|
datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)));
|
|
|
@ -134,8 +128,7 @@ public class DatasetManager {
|
|
|
|
if (!datasets.isEmpty()) {
|
|
|
|
if (!datasets.isEmpty()) {
|
|
|
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
|
|
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
|
|
|
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
|
|
|
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
else
|
|
|
|
|
|
|
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
|
|
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QueryableList<eu.eudat.data.entities.Dataset> pagedItems = PaginationManager.applyPaging(items, datasetTableRequest);
|
|
|
|
QueryableList<eu.eudat.data.entities.Dataset> pagedItems = PaginationManager.applyPaging(items, datasetTableRequest);
|
|
|
@ -158,11 +151,10 @@ public class DatasetManager {
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
|
|
|
eu.eudat.elastic.entities.Dataset datasetElastic;
|
|
|
|
eu.eudat.elastic.entities.Dataset datasetElastic;
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
datasetElastic = datasetRepository.exists() ?
|
|
|
|
datasetElastic = datasetRepository.exists() ?
|
|
|
|
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
|
|
|
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
catch (Exception ex){
|
|
|
|
|
|
|
|
datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
|
|
|
datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
|
|
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
|
|
@ -182,9 +174,9 @@ public class DatasetManager {
|
|
|
|
List<DatasetProfile> profileVersionsIncluded = new LinkedList<>();
|
|
|
|
List<DatasetProfile> profileVersionsIncluded = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
|
|
// Iterate through the versions and remove those that are not included in the DMP of the dataset in question.
|
|
|
|
// Iterate through the versions and remove those that are not included in the DMP of the dataset in question.
|
|
|
|
for(DatasetProfile version : profileVersions) {
|
|
|
|
for (DatasetProfile version : profileVersions) {
|
|
|
|
for(AssociatedProfile p : dataset.getDmp().getProfiles()){
|
|
|
|
for (AssociatedProfile p : dataset.getDmp().getProfiles()) {
|
|
|
|
if(version.getId().toString().equals(p.getId().toString())) {
|
|
|
|
if (version.getId().toString().equals(p.getId().toString())) {
|
|
|
|
profileVersionsIncluded.add(version);
|
|
|
|
profileVersionsIncluded.add(version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -208,12 +200,11 @@ public class DatasetManager {
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id));
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id));
|
|
|
|
|
|
|
|
|
|
|
|
if (datasetEntity != null && datasetEntity.getStatus() == 1 && datasetEntity.getDmp().getStatus() == 1){
|
|
|
|
if (datasetEntity != null && datasetEntity.getStatus() == 1 && datasetEntity.getDmp().getStatus() == 1) {
|
|
|
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
|
|
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
|
|
|
dataset.fromDataModel(datasetEntity);
|
|
|
|
dataset.fromDataModel(datasetEntity);
|
|
|
|
return dataset;
|
|
|
|
return dataset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw new Exception("Selected dataset is not public");
|
|
|
|
throw new Exception("Selected dataset is not public");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -465,7 +456,7 @@ public class DatasetManager {
|
|
|
|
InputStream in = importFile.getInputStream();
|
|
|
|
InputStream in = importFile.getInputStream();
|
|
|
|
jaxbContext = JAXBContext.newInstance(DatasetImportPagedDatasetProfile.class);
|
|
|
|
jaxbContext = JAXBContext.newInstance(DatasetImportPagedDatasetProfile.class);
|
|
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
|
|
DatasetImportPagedDatasetProfile datasetImport = (DatasetImportPagedDatasetProfile)jaxbUnmarshaller.unmarshal(in);
|
|
|
|
DatasetImportPagedDatasetProfile datasetImport = (DatasetImportPagedDatasetProfile) jaxbUnmarshaller.unmarshal(in);
|
|
|
|
importModel = datasetImport;
|
|
|
|
importModel = datasetImport;
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -533,11 +524,10 @@ public class DatasetManager {
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
|
|
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
|
|
|
eu.eudat.elastic.entities.Dataset datasetElastic;
|
|
|
|
eu.eudat.elastic.entities.Dataset datasetElastic;
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
datasetElastic = datasetRepository.exists() ?
|
|
|
|
datasetElastic = datasetRepository.exists() ?
|
|
|
|
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
|
|
|
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
catch (Exception ex){
|
|
|
|
|
|
|
|
datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
|
|
|
datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
|
|
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
|
|
|