This commit is contained in:
annampak 2018-01-19 17:19:13 +02:00
commit 4f2fb712cf
3 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.dao.entities.*;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
import eu.eudat.models.HintedModelFactory; import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.criteria.DataRepositoryCriteria; import eu.eudat.models.criteria.DataRepositoryCriteria;
import eu.eudat.models.criteria.ExternalDatasetCriteria;
import eu.eudat.models.criteria.RegistryCriteria; import eu.eudat.models.criteria.RegistryCriteria;
import eu.eudat.models.criteria.ServiceCriteria; import eu.eudat.models.criteria.ServiceCriteria;
import eu.eudat.models.dataset.Dataset; import eu.eudat.models.dataset.Dataset;
@ -65,6 +66,7 @@ public class DatasetManager {
createRegistriesIfTheyDontExist(apiContext.getDatabaseRepository().getRegistryDao(), dataset); createRegistriesIfTheyDontExist(apiContext.getDatabaseRepository().getRegistryDao(), dataset);
createDataRepositoriesIfTheyDontExist(apiContext.getDatabaseRepository().getDataRepositoryDao(), dataset); createDataRepositoriesIfTheyDontExist(apiContext.getDatabaseRepository().getDataRepositoryDao(), dataset);
createServicesIfTheyDontExist(apiContext.getDatabaseRepository().getServiceDao(), dataset); createServicesIfTheyDontExist(apiContext.getDatabaseRepository().getServiceDao(), dataset);
createExternalDatasetsIfTheyDontExist(apiContext.getDatabaseRepository().getExternalDatasetDao(), dataset);
return apiContext.getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); return apiContext.getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
} }
@ -105,6 +107,18 @@ public class DatasetManager {
} }
} }
private static void createExternalDatasetsIfTheyDontExist(ExternalDatasetDao externalDatasetDao, eu.eudat.entities.Dataset dataset) {
if (dataset.getExternalDatasets() != null && !dataset.getExternalDatasets().isEmpty()) {
for (eu.eudat.entities.ExternalDataset externalDataset : dataset.getExternalDatasets()) {
ExternalDatasetCriteria criteria = new ExternalDatasetCriteria();
criteria.setLike(externalDataset.getReference());
List<eu.eudat.entities.ExternalDataset> entries = externalDatasetDao.getWithCriteria(criteria).toList();
if (entries != null && !entries.isEmpty()) externalDataset.setId(entries.get(0).getId());
else externalDataset = externalDatasetDao.createOrUpdate(externalDataset);
}
}
}
public static void makePublic(DatasetDao datasetDao, UUID id) throws Exception { public static void makePublic(DatasetDao datasetDao, UUID id) throws Exception {
eu.eudat.entities.Dataset dataset = datasetDao.find(id); eu.eudat.entities.Dataset dataset = datasetDao.find(id);
if (dataset.getStatus() != eu.eudat.entities.Dataset.Status.FINALISED.getValue()) if (dataset.getStatus() != eu.eudat.entities.Dataset.Status.FINALISED.getValue())

View File

@ -168,6 +168,7 @@ public class DatasetWizardModel implements DataModel<Dataset> {
this.reference = entity.getReference(); this.reference = entity.getReference();
this.description = entity.getDescription(); this.description = entity.getDescription();
this.profile = new DatasetProfileListingModel(); this.profile = new DatasetProfileListingModel();
this.uri = entity.getUri();
this.profile.fromDataModel(entity.getProfile()); this.profile.fromDataModel(entity.getProfile());
this.registries = new DomainModelConverter<eu.eudat.entities.Registry, Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), Registry.class); this.registries = new DomainModelConverter<eu.eudat.entities.Registry, Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), Registry.class);
this.dataRepositories = new DomainModelConverter<eu.eudat.entities.DataRepository, DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), DataRepository.class); this.dataRepositories = new DomainModelConverter<eu.eudat.entities.DataRepository, DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), DataRepository.class);

View File

@ -34,8 +34,8 @@ public class ConfigLoader {
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class); JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
is = new URL("file:///"+System.getenv("CATALINA_HOME")+fileUrl).openStream(); //is = new URL("file:///"+System.getenv("CATALINA_HOME")+fileUrl).openStream();
//is = new URL("file:///C:/Users/ikalyvas/Documents/Projects/OpenAIRE-EUDAT-DMP-service-pilot/dmp-backend/src/main/resources/ExternalUrls.xml").openStream(); is = new URL("file:///C:/Users/ikalyvas/Documents/Projects/OpenAIRE-EUDAT-DMP-service-pilot/dmp-backend/src/main/resources/ExternalUrls.xml").openStream();
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is); externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
// System.out.println(new ObjectMapper().writeValueAsString(externalUrls)); // System.out.println(new ObjectMapper().writeValueAsString(externalUrls));
} catch (Exception ex) { } catch (Exception ex) {