Refactors Organisation external fetching and fixes how reference prefix is added in respect of the that change.

This commit is contained in:
gkolokythas 2020-01-16 13:34:12 +02:00
parent 6bb9ef444d
commit 116aa365c5
6 changed files with 144 additions and 28 deletions

View File

@ -2,12 +2,10 @@ package eu.eudat.controllers;
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
import eu.eudat.logic.managers.OrganisationsManager;
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.models.data.dmp.Organisation;
import eu.eudat.models.data.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
@ -19,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
@RestController
@ -28,6 +25,8 @@ import java.util.Map;
public class Organisations extends BaseController {
private OrganisationsManager organisationsManager;
private ApiContext apiContext;
@Autowired
public Organisations(ApiContext apiContext, OrganisationsManager organisationsManager) {
super(apiContext);
@ -36,13 +35,11 @@ public class Organisations extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/external/organisations"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(
ResponseEntity<ResponseItem<List<Organisation>>> listExternalOrganisations(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type);
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(organisationsExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
List<Organisation> organisations = organisationsManager.getCriteriaWithExternal(query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Organisation>>().payload(organisations).status(ApiMessageCode.NO_MESSAGE));
}
@RequestMapping(method = RequestMethod.POST, value = {"/internal/organisations"}, produces = "application/json")

View File

@ -7,9 +7,7 @@ import eu.eudat.logic.builders.model.criteria.RegistryCriteriaBuilder;
import eu.eudat.logic.builders.model.models.*;
import org.springframework.stereotype.Service;
/**
* Created by ikalyvas on 2/15/2018.
*/
@Service("builderFactory")
public class BuilderFactoryImpl implements BuilderFactory {
@ -29,6 +27,7 @@ public class BuilderFactoryImpl implements BuilderFactory {
if (tClass.equals(ResearcherBuilder.class)) return (T) new ResearcherBuilder();
if (tClass.equals(ExternalDatasetCriteriaBuilder.class)) return (T) new ExternalDatasetCriteriaBuilder();
if (tClass.equals(RecentActivityDataBuilder.class)) return (T) new RecentActivityDataBuilder();
if (tClass.equals(OrganisationBuilder.class)) return (T) new OrganisationBuilder();
return null;
}

View File

@ -0,0 +1,88 @@
package eu.eudat.logic.builders.model.models;
import eu.eudat.logic.builders.Builder;
import eu.eudat.models.data.dmp.Organisation;
public class OrganisationBuilder extends Builder<Organisation> {
private String label;
private String name;
private String id;
private String reference;
private int status;
private String tag;
private String key;
public String getLabel() {
return label;
}
public OrganisationBuilder label(String label) {
this.label = label;
return this;
}
public String getName() {
return name;
}
public OrganisationBuilder name(String name) {
this.name = name;
return this;
}
public String getId() {
return id;
}
public OrganisationBuilder id(String id) {
this.id = id;
return this;
}
public String getReference() { return reference; }
public OrganisationBuilder reference(String reference) {
this.reference = reference;
return this;
}
public int getStatus() {
return status;
}
public OrganisationBuilder status(int status) {
this.status = status;
return this;
}
public String getTag() {
return tag;
}
public OrganisationBuilder tag(String tag) {
this.tag = tag;
return this;
}
public String getKey() {
return key;
}
public OrganisationBuilder key(String key) {
this.key = key;
return this;
}
@Override
public Organisation build() {
Organisation Organisation = new Organisation();
Organisation.setId(id);
Organisation.setReference(reference);
Organisation.setLabel(label);
Organisation.setName(name);
Organisation.setStatus(status);
Organisation.setTag(tag);
Organisation.setKey(key);
return Organisation;
}
}

View File

@ -1,24 +1,25 @@
package eu.eudat.logic.managers;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.dao.entities.OrganisationDao;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
import eu.eudat.logic.builders.model.models.OrganisationBuilder;
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.logic.services.operations.DatabaseRepository;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.external.ExternalSourcesItemModel;
import eu.eudat.models.data.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
@ -64,4 +65,21 @@ public class OrganisationsManager {
return organisationDataTableData;
}
public List<Organisation> getCriteriaWithExternal(String query, String type) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = apiContext.getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type);
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
List<Organisation> organisations = new LinkedList<>();
for (ExternalSourcesItemModel externalListingItem : organisationsExternalSourcesModel) {
Organisation organisation = apiContext.getOperationsContext().getBuilderFactory().getBuilder(OrganisationBuilder.class)
.name(externalListingItem.getName())
.reference(externalListingItem.getRemoteId())
.tag(externalListingItem.getTag())
.key(externalListingItem.getKey())
.build();
organisations.add(organisation);
}
return organisations.stream().distinct().collect(Collectors.toList());
}
}

View File

@ -9,8 +9,10 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
private String label;
private String name;
private String id;
private String reference;
private int status;
private String tag;
private String tag; // how the external source is displayed. ex: "Cristin".
private String key; // the external source. ex: "cristin".
public String getLabel() {
return label;
@ -33,6 +35,13 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
this.id = id;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public int getStatus() {
return status;
}
@ -47,26 +56,30 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
this.tag = tag;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public Organisation fromDataModel(eu.eudat.data.entities.Organisation entity) {
this.id = entity.getReference();
this.id = entity.getId().toString();
this.name = entity.getLabel();
this.label = entity.getUri();
if (entity.getReference().contains(":cristin")) {
this.tag = "cristin";
} else {
this.tag = entity.getReference().substring(0, entity.getReference().indexOf(":"));
}
this.reference = entity.getReference();
this.key = entity.getReference().substring(0, entity.getReference().indexOf(":"));
return this;
}
@Override
public eu.eudat.data.entities.Organisation toDataModel() {
eu.eudat.data.entities.Organisation organisationEntity = new eu.eudat.data.entities.Organisation();
if (this.tag.equals(this.id.substring(0, this.tag.length()))) {
organisationEntity.setReference(this.id);
if ((this.key + ":").equals(this.reference.substring(0, this.key.length() + 1))) {
organisationEntity.setReference(this.reference);
} else {
organisationEntity.setReference(this.tag + ":" + this.id);
organisationEntity.setReference(this.key + ":" + this.reference);
}
organisationEntity.setLabel(this.name);
organisationEntity.setUri(this.label);

View File

@ -11,10 +11,11 @@ public class OrganisationsExternalSourcesModel extends ExternalListingItem<Organ
public OrganisationsExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
for (Map<String, String> item : values) {
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setRemoteId(item.get("pid"));
model.setUri(item.get("uri"));
model.setName(item.get("name"));
model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model);
}
return this;