fix issue
This commit is contained in:
parent
b7d22b5b07
commit
b2119abc08
|
@ -1,124 +0,0 @@
|
|||
package eu.eudat.model;
|
||||
|
||||
import eu.eudat.data.entities.DataRepository;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExternalReference {
|
||||
private UUID id;
|
||||
private String name;
|
||||
private String pid;
|
||||
private String abbreviation;
|
||||
private String uri;
|
||||
private Date created;
|
||||
private Date modified;
|
||||
private String tag; // Api fetching the data
|
||||
private String source; // Actual harvested source
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getAbbreviation() {
|
||||
return abbreviation;
|
||||
}
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return modified;
|
||||
}
|
||||
public void setModified(Date modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
public ExternalReference fromDataModel(DataRepository entity) {
|
||||
this.setAbbreviation(entity.getAbbreviation());
|
||||
this.setName(entity.getLabel());
|
||||
this.setUri(entity.getUri());
|
||||
this.setId(entity.getId());
|
||||
this.setPid(entity.getReference());
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataRepository toDataModel() throws Exception {
|
||||
DataRepository dataRepository = new DataRepository();
|
||||
dataRepository.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
dataRepository.setAbbreviation(this.abbreviation);
|
||||
dataRepository.setCreated(this.created != null ? this.created : new Date());
|
||||
dataRepository.setModified(new Date());
|
||||
dataRepository.setLabel(this.name);
|
||||
if (this.source != null) {
|
||||
if (this.source.equals("Internal") || this.source.equals(this.id.toString().substring(0, this.source.length()))) {
|
||||
dataRepository.setReference(this.id.toString());
|
||||
} else {
|
||||
dataRepository.setReference(this.source + ":" + dataRepository.getId());
|
||||
}
|
||||
} else {
|
||||
dataRepository.setReference("dmp:" + dataRepository.getId());
|
||||
}
|
||||
dataRepository.setUri(this.uri);
|
||||
dataRepository.setStatus((short) 0);
|
||||
dataRepository.setCreationUser(new UserInfo());
|
||||
return dataRepository;
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
package eu.eudat.model;
|
||||
|
||||
import eu.eudat.data.entities.Registry;
|
||||
import eu.eudat.data.entities.Service;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExternalReference2 {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private String name;
|
||||
private String pid;
|
||||
private String abbreviation;
|
||||
private String uri;
|
||||
private Date created;
|
||||
private Date modified;
|
||||
private String reference;
|
||||
private String tag;
|
||||
private String source;
|
||||
|
||||
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 getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getAbbreviation() {
|
||||
return abbreviation;
|
||||
}
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return modified;
|
||||
}
|
||||
public void setModified(Date modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public ExternalReference2 fromDataModel(Service entity) {
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.created = entity.getCreated();
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
this.name = entity.getLabel();
|
||||
this.modified = entity.getModified();
|
||||
this.uri = entity.getUri();
|
||||
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExternalReference2 fromDataModel(Registry entity) {
|
||||
this.id = entity.getId();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.created = entity.getCreated();
|
||||
this.label = entity.getLabel();
|
||||
this.name = entity.getLabel();
|
||||
this.modified = entity.getModified();
|
||||
this.uri = entity.getUri();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
this.reference = entity.getReference();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Service toDataModelService() throws Exception {
|
||||
Service service = new Service();
|
||||
service.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
service.setAbbreviation(this.abbreviation);
|
||||
service.setCreated(this.created != null ? this.created : new Date());
|
||||
service.setLabel(this.label != null ? this.label : this.name);
|
||||
service.setModified(new Date());
|
||||
service.setUri(this.uri);
|
||||
if (this.source == null) this.source = "dmp";
|
||||
if (this.reference == null) this.reference = service.getId().toString();
|
||||
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
|
||||
service.setReference(this.reference);
|
||||
} else {
|
||||
service.setReference(this.source + ":" + this.reference);
|
||||
}
|
||||
service.setModified(new Date());
|
||||
service.setStatus((short) 0);
|
||||
service.setCreationUser(new UserInfo());
|
||||
return service;
|
||||
}
|
||||
|
||||
public Registry toDataModelRegistry() throws Exception {
|
||||
Registry registry = new Registry();
|
||||
registry.setAbbreviation(this.abbreviation);
|
||||
registry.setCreated(this.created != null ? this.created : new Date());
|
||||
registry.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
registry.setLabel(this.label != null ? this.label : this.name);
|
||||
registry.setUri(this.uri);
|
||||
registry.setModified(new Date());
|
||||
if (this.source == null) this.source = "dmp";
|
||||
if (this.source.equals(registry.getId().toString().substring(0, this.source.length()))) {
|
||||
registry.setReference(registry.getId().toString());
|
||||
} else {
|
||||
registry.setReference(this.source + ":" + registry.getId());
|
||||
}
|
||||
registry.setStatus((short)0);
|
||||
registry.setCreationUser(new UserInfo());
|
||||
return registry;
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package eu.eudat.service;
|
||||
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ValidationService {
|
||||
|
||||
private RemoteFetcher remoteFetcher;
|
||||
|
||||
@Autowired
|
||||
public ValidationService(RemoteFetcher remoteFetcher) {
|
||||
super();
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
}
|
||||
|
||||
public Boolean validateIdentifier(String identifier, String type, Principal principal) throws NoURLFound, HugeResultSet {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(identifier);
|
||||
Integer count = this.remoteFetcher.findEntries(externalUrlCriteria, type);
|
||||
return principal != null && count > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package eu.eudat.service.externalreferences;
|
||||
|
||||
import gr.cite.tools.cache.CacheOptions;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "cache.external-reference")
|
||||
public class ExternalReferencesCacheOptions extends CacheOptions {
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package eu.eudat.service.externalreferences;
|
||||
|
||||
import eu.eudat.proxy.config.ExternalUrlCriteria;
|
||||
import gr.cite.tools.cache.CacheService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
@Service
|
||||
public class ExternalReferencesCacheService extends CacheService<ExternalReferencesCacheService.ExternalReferencesCacheValue> {
|
||||
|
||||
public static class ExternalReferencesCacheValue {
|
||||
|
||||
public ExternalReferencesCacheValue() {}
|
||||
|
||||
public ExternalReferencesCacheValue(String externalType, ExternalUrlCriteria externalUrlCriteria) {
|
||||
this.externalType = externalType;
|
||||
this.externalUrlCriteria = externalUrlCriteria;
|
||||
}
|
||||
|
||||
private String externalType;
|
||||
|
||||
private ExternalUrlCriteria externalUrlCriteria;
|
||||
|
||||
public String getExternalType() {
|
||||
return externalType;
|
||||
}
|
||||
|
||||
public void setExternalType(String externalType) {
|
||||
this.externalType = externalType;
|
||||
}
|
||||
|
||||
public ExternalUrlCriteria getExternalUrlCriteria() {
|
||||
return externalUrlCriteria;
|
||||
}
|
||||
|
||||
public void setExternalUrlCriteria(ExternalUrlCriteria externalUrlCriteria) {
|
||||
this.externalUrlCriteria = externalUrlCriteria;
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public ExternalReferencesCacheService(ExternalReferencesCacheOptions options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<ExternalReferencesCacheService.ExternalReferencesCacheValue> valueClass() {return ExternalReferencesCacheService.ExternalReferencesCacheValue.class;}
|
||||
|
||||
public String keyOf(ExternalReferencesCacheService.ExternalReferencesCacheValue value) {
|
||||
return this.buildKey(value.getExternalType(), value.getExternalUrlCriteria());
|
||||
}
|
||||
|
||||
public String buildKey(String externalType, ExternalUrlCriteria externalUrlCriteria) {
|
||||
HashMap<String, String> keyParts = new HashMap<>();
|
||||
|
||||
keyParts.put("$type$", externalType.toLowerCase(Locale.ROOT));
|
||||
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(externalUrlCriteria);
|
||||
keyParts.put("$criteria$", stringBuffer.toString().toLowerCase(Locale.ROOT));
|
||||
|
||||
return this.generateKey(keyParts);
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package eu.eudat.service.externalreferences;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
|
||||
import eu.eudat.data.dao.criteria.RegistryCriteria;
|
||||
import eu.eudat.data.dao.criteria.ServiceCriteria;
|
||||
import eu.eudat.data.entities.DataRepository;
|
||||
import eu.eudat.data.entities.Registry;
|
||||
import eu.eudat.data.entities.Service;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.model.ExternalReference2;
|
||||
import eu.eudat.model.ExternalReference;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ExternalReferencesServiceImpl implements ExternalReferencesService{
|
||||
|
||||
private final ApiContext apiContext;
|
||||
|
||||
public ExternalReferencesServiceImpl(ApiContext apiContext) {
|
||||
this.apiContext = apiContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataRepository create(ExternalReference externalReference, Principal principal) throws Exception {
|
||||
// only dataRepositories, pubRepositories, journals
|
||||
DataRepository dataRepository = externalReference.toDataModel();
|
||||
dataRepository.getCreationUser().setId(principal.getId());
|
||||
return apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExternalReference> getExternal(String externalType, String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
|
||||
|
||||
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
|
||||
List<ExternalReference> list = new LinkedList<>();
|
||||
if((externalType.equals("dataRepositories") || externalType.equals("pubRepositories") || externalType.equals("journals"))){
|
||||
criteria.setCreationUserId(principal.getId());
|
||||
if (type.equals("")) {
|
||||
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
|
||||
list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataModel(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference.class)).collect(Collectors.toList()));
|
||||
list = list.stream().filter(licenseModel -> licenseModel.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ExternalReference2> getExternal2(String externalType, String query, String type, Principal principal) throws HugeResultSet,NoURLFound {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType,externalUrlCriteria, type);
|
||||
|
||||
List<ExternalReference2> list = new LinkedList<>();
|
||||
|
||||
if (externalType.equals("registries")){
|
||||
RegistryCriteria criteria = new RegistryCriteria();
|
||||
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(principal.getId());
|
||||
|
||||
if (type.equals("")) {
|
||||
List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
|
||||
list = registryList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
|
||||
}
|
||||
} else if (externalType.equals("services")) {
|
||||
ServiceCriteria criteria = new ServiceCriteria();
|
||||
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(principal.getId());
|
||||
|
||||
if (type.equals("")) {
|
||||
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
|
||||
list = serviceList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference2.class)).collect(Collectors.toList()));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package eu.eudat.service.externalreferences;
|
||||
|
||||
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
|
||||
import eu.eudat.logic.builders.model.models.FunderBuilder;
|
||||
import eu.eudat.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||
import eu.eudat.models.data.external.FundersExternalSourcesModel;
|
||||
import eu.eudat.models.data.funder.Funder;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FunderService {
|
||||
|
||||
private ApiContext apiContext;
|
||||
private RemoteFetcher remoteFetcher;
|
||||
private ListHelper listHelper;
|
||||
|
||||
public FunderService(ApiContext apiContext, RemoteFetcher remoteFetcher, ListHelper listHelper) {
|
||||
this.apiContext = apiContext;
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
this.listHelper = listHelper;
|
||||
}
|
||||
|
||||
public List<Funder> getCriteriaWithExternal(FunderCriteriaRequest funderCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
||||
eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo();
|
||||
userInfo.setId(principal.getId());
|
||||
funderCriteria.getCriteria().setReference("dmp:");
|
||||
QueryableList<eu.eudat.data.entities.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria());
|
||||
QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
|
||||
List<Funder> funders = authItems.select(item -> new Funder().fromDataModel(item));
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(funderCriteria.getCriteria().getLike());
|
||||
List<Map<String, String>> remoteRepos = remoteFetcher.getFunders(externalUrlCriteria);
|
||||
FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) {
|
||||
Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class)
|
||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.status(eu.eudat.data.entities.Funder.Status.fromInteger(0))
|
||||
.key(externalListingItem.getKey())
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
if (externalListingItem.getSource() != null) {
|
||||
funder.setSource(externalListingItem.getSource());
|
||||
} else {
|
||||
funder.setSource(externalListingItem.getTag());
|
||||
}
|
||||
|
||||
funders.add(funder);
|
||||
}
|
||||
funders.sort(Comparator.comparing(Funder::getLabel));
|
||||
funders = funders.stream().filter(listHelper.distinctByKey(Funder::getLabel)).collect(Collectors.toList());
|
||||
return funders;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package eu.eudat.service.externalreferences;
|
||||
|
||||
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
|
||||
import eu.eudat.logic.builders.model.models.ProjectBuilder;
|
||||
import eu.eudat.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||
import eu.eudat.models.data.external.ProjectsExternalSourcesModel;
|
||||
import eu.eudat.models.data.project.Project;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private ApiContext apiContext;
|
||||
private RemoteFetcher remoteFetcher;
|
||||
private ListHelper listHelper;
|
||||
|
||||
public ProjectService(ApiContext apiContext, ListHelper listHelper) {
|
||||
this.apiContext = apiContext;
|
||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||
this.listHelper = listHelper;
|
||||
}
|
||||
|
||||
public List<Project> getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
||||
eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo();
|
||||
userInfo.setId(principal.getId());
|
||||
projectCriteria.getCriteria().setReference("dmp:");
|
||||
QueryableList<eu.eudat.data.entities.Project> items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria());
|
||||
QueryableList<eu.eudat.data.entities.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo);
|
||||
List<Project> projects = authItems.select(item -> new Project().fromDataModel(item));
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(projectCriteria.getCriteria().getLike());
|
||||
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(externalUrlCriteria);
|
||||
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
||||
Project project = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ProjectBuilder.class)
|
||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
|
||||
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Project.Status.fromInteger(0))
|
||||
.key(externalListingItem.getKey())
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
|
||||
projects.add(project);
|
||||
}
|
||||
projects.sort(Comparator.comparing(Project::getLabel));
|
||||
projects = projects.stream().filter(listHelper.distinctByKey(Project::getLabel)).collect(Collectors.toList());
|
||||
return projects;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue