diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/FunderCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/FunderCriteria.java new file mode 100644 index 000000000..c8c23038c --- /dev/null +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/FunderCriteria.java @@ -0,0 +1,14 @@ +package eu.eudat.data.dao.criteria; + +import eu.eudat.data.entities.Funder; + +public class FunderCriteria extends Criteria { + private String reference; + + public String getReference() { + return reference; + } + public void setReference(String reference) { + this.reference = reference; + } +} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Funder.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Funder.java new file mode 100644 index 000000000..d2be5ce28 --- /dev/null +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Funder.java @@ -0,0 +1,171 @@ +package eu.eudat.data.entities; + +import eu.eudat.queryable.queryableentity.DataEntity; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Type; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@Entity +@Table(name = "\"Funder\"") +public class Funder implements DataEntity { + + public enum Status { + ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99); + + private short value; + + Status(short value) { + this.value = value; + } + + public short getValue() { + return value; + } + + public static Status fromInteger(int value) { + switch (value) { + case 0: + return INACTIVE; + case 1: + return ACTIVE; + case 99: + return DELETED; + default: + throw new RuntimeException("Unsupported Funder Status"); + } + } + } + + public enum FunderType { + EXTERNAL(0), INTERNAL(1); + + private Integer value; + + FunderType(Integer value) { + this.value = value; + } + + public Integer getValue() { + return value; + } + + public static FunderType fromInteger(int value) { + switch (value) { + case 0: + return EXTERNAL; + case 1: + return INTERNAL; + default: + throw new RuntimeException("Unsupported Grant Type"); + } + } + } + + @Id + @GeneratedValue + @GenericGenerator(name = "uuid2", strategy = "uuid2") + @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + private UUID id; + + @Column(name = "\"Label\"") + private String label; + + @Type(type = "eu.eudat.configurations.typedefinition.XMLType") + @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + private String reference; + + @Type(type = "eu.eudat.configurations.typedefinition.XMLType") + @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + private String definition; + + @Column(name = "\"Status\"", nullable = false) + private Short status; + + @Column(name = "\"Created\"") + private Date created = null; + + @Column(name = "\"Modified\"") + private Date modified = new Date(); + + @Column(name = "\"Type\"") + private Integer type; + + + 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 getDefinition() { + return definition; + } + public void setDefinition(String definition) { + this.definition = definition; + } + + public Short getStatus() { + return status; + } + public void setStatus(Short status) { + this.status = status; + } + + 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 Integer getType() { + return type; + } + public void setType(Integer type) { + this.type = type; + } + + @Override + public void update(Funder entity) { + this.label = entity.getLabel(); + this.created = entity.getCreated(); + this.definition = entity.getDefinition(); + this.modified = new Date(); + } + + @Override + public UUID getKeys() { + return this.id; + } + + @Override + public Funder buildFromTuple(List tuple, List fields, String base) { + return null; + } +} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Grant.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Grant.java index 021f587b2..640a9a9b9 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Grant.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Grant.java @@ -96,7 +96,6 @@ public class Grant implements DataEntity { @Column(name = "\"Abbreviation\"") private String abbreviation; - @Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) private String reference; @@ -138,6 +137,10 @@ public class Grant implements DataEntity { @JoinColumn(name = "\"Content\"") private Content content; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "\"Funder\"") + private Funder funder; + public Grant() { } @@ -148,36 +151,27 @@ public class Grant implements DataEntity { public String getDescription() { return description; } - public void setDescription(String description) { this.description = description; } - public Short getStatus() { return status; } - - public void setStatus(Short status) { this.status = status; } - 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; } @@ -185,7 +179,6 @@ public class Grant implements DataEntity { public Date getStartdate() { return startdate; } - public void setStartdate(Date startdate) { this.startdate = startdate; } @@ -193,7 +186,6 @@ public class Grant implements DataEntity { public Date getEnddate() { return enddate; } - public void setEnddate(Date enddate) { this.enddate = enddate; } @@ -201,7 +193,6 @@ public class Grant implements DataEntity { public UUID getId() { return id; } - public void setId(UUID id) { this.id = id; } @@ -209,7 +200,6 @@ public class Grant implements DataEntity { public String getLabel() { return label; } - public void setLabel(String label) { this.label = label; } @@ -217,7 +207,6 @@ public class Grant implements DataEntity { public String getAbbreviation() { return abbreviation; } - public void setAbbreviation(String abbreviation) { this.abbreviation = abbreviation; } @@ -225,7 +214,6 @@ public class Grant implements DataEntity { public String getReference() { return reference; } - public void setReference(String reference) { this.reference = reference; } @@ -233,7 +221,6 @@ public class Grant implements DataEntity { public String getUri() { return uri; } - public void setUri(String uri) { this.uri = uri; } @@ -241,16 +228,13 @@ public class Grant implements DataEntity { public String getDefinition() { return definition; } - public void setDefinition(String definition) { this.definition = definition; } - public Set getDmps() { return dmps; } - public void setDmps(Set dmps) { this.dmps = dmps; } @@ -258,7 +242,6 @@ public class Grant implements DataEntity { public UserInfo getCreationUser() { return creationUser; } - public void setCreationUser(UserInfo creationUser) { this.creationUser = creationUser; } @@ -266,7 +249,6 @@ public class Grant implements DataEntity { public Integer getType() { return type; } - public void setType(Integer type) { this.type = type; } @@ -274,12 +256,18 @@ public class Grant implements DataEntity { public Content getContent() { return content; } - public void setContent(Content content) { this.content = content; } - @Override + public Funder getFunder() { + return funder; + } + public void setFunder(Funder funder) { + this.funder = funder; + } + + @Override public void update(Grant entity) { this.description = entity.getDescription(); this.label = entity.getLabel(); @@ -291,6 +279,7 @@ public class Grant implements DataEntity { this.enddate = entity.getEnddate(); this.modified = new Date(); this.uri = entity.getUri(); + this.funder = entity.funder; if (entity.getContent() != null) this.content = entity.getContent(); } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/funder/FunderCriteriaRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/funder/FunderCriteriaRequest.java new file mode 100644 index 000000000..49e5a4ef5 --- /dev/null +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/funder/FunderCriteriaRequest.java @@ -0,0 +1,17 @@ +package eu.eudat.data.query.items.item.funder; + +import eu.eudat.data.dao.criteria.FunderCriteria; +import eu.eudat.data.entities.Funder; +import eu.eudat.data.query.definition.Query; +import eu.eudat.queryable.QueryableList; + +public class FunderCriteriaRequest extends Query { + @Override + public QueryableList applyCriteria() { + QueryableList query = this.getQuery(); + if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty()) + query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%")); + query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue())); + return query; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Funders.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Funders.java new file mode 100644 index 000000000..7997dd6bc --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Funders.java @@ -0,0 +1,35 @@ +package eu.eudat.controllers; + +import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest; +import eu.eudat.logic.managers.FunderManager; +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.funder.Funder; +import eu.eudat.models.data.helpers.responses.ResponseItem; +import eu.eudat.models.data.security.Principal; +import eu.eudat.types.ApiMessageCode; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@CrossOrigin +@RequestMapping(value = {"/api/funders/"}) +public class Funders extends BaseController { + private FunderManager funderManager; + + public Funders(ApiContext apiContext, FunderManager funderManager) { + super(apiContext); + this.funderManager = funderManager; + } + + @RequestMapping(method = RequestMethod.POST, value = {"/external"}, consumes = "application/json", produces = "application/json") + public @ResponseBody + ResponseEntity>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException { + List dataTable = this.funderManager.getCriteriaWithExternal(funderCriteria, principal); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FunderManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FunderManager.java new file mode 100644 index 000000000..22ba78425 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FunderManager.java @@ -0,0 +1,53 @@ +package eu.eudat.logic.managers; + +import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest; +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.logic.services.ApiContext; +import eu.eudat.models.data.external.ExternalSourcesItemModel; +import eu.eudat.models.data.external.ProjectsExternalSourcesModel; +import eu.eudat.models.data.funder.Funder; +import eu.eudat.models.data.project.Project; +import eu.eudat.models.data.security.Principal; +import eu.eudat.queryable.QueryableList; +import org.springframework.stereotype.Component; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +@Component +public class FunderManager { + + private ApiContext apiContext; + private RemoteFetcher remoteFetcher; + + public FunderManager(ApiContext apiContext, RemoteFetcher remoteFetcher) { + this.apiContext = apiContext; + this.remoteFetcher = remoteFetcher; + } + + public List getCriteriaWithExternal(FunderCriteriaRequest funderCriteria, Principal principal) throws HugeResultSet, NoURLFound { +// eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo(); +// userInfo.setId(principal.getId()); +// QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria()); +// QueryableList authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo); +// List projects = authItems.select(item -> new eu.eudat.models.data.project.Project().fromDataModel(item)); +// List> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike()); +// ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); +// for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) { +// eu.eudat.models.data.project.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)) +// .build(); +// +// projects.add(project); +// } +// projects.sort(Comparator.comparing(x -> x.getLabel())); +// return projects; + + return null; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/funder/Funder.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/funder/Funder.java new file mode 100644 index 000000000..39b66382f --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/funder/Funder.java @@ -0,0 +1,106 @@ +package eu.eudat.models.data.funder; + +import eu.eudat.models.DataModel; + +import java.util.Date; +import java.util.UUID; + +public class Funder implements DataModel { + + private UUID id; + private String label; + private String reference; + private String definition; + private eu.eudat.data.entities.Funder.Status status; + private Date created; + private Date modified; + private Integer type; + + 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 getDefinition() { + return definition; + } + public void setDefinition(String definition) { + this.definition = definition; + } + + public Short getStatus() { + return status.getValue(); + } + public void setStatus(Short status) { + this.status = eu.eudat.data.entities.Funder.Status.fromInteger(status); + } + + 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 Integer getType() { + return type; + } + public void setType(Integer type) { + this.type = type; + } + + @Override + public Funder fromDataModel(eu.eudat.data.entities.Funder entity) { + this.id = entity.getId(); + this.label = entity.getLabel(); + this.reference = entity.getReference(); + this.type = entity.getType(); + this.definition = entity.getDefinition(); + this.setStatus(entity.getStatus()); + this.created = entity.getCreated(); + this.modified = entity.getModified(); + return this; + } + + @Override + public eu.eudat.data.entities.Funder toDataModel() throws Exception { + eu.eudat.data.entities.Funder entity = new eu.eudat.data.entities.Funder(); + entity.setId(this.id); + entity.setLabel(this.label); + entity.setType(this.type); + entity.setReference(this.reference == null ? "dmp:" + this.label : this.reference); + entity.setDefinition(this.definition); + entity.setCreated(this.created == null ? new Date() : this.created); + entity.setStatus(this.status != null ? this.getStatus() : eu.eudat.data.entities.Grant.Status.ACTIVE.getValue()); + entity.setModified(new Date()); + return entity; + } + + @Override + public String getHint() { + return null; + } +} diff --git a/dmp-backend/web/src/main/resources/ExternalUrls.xml b/dmp-backend/web/src/main/resources/ExternalUrls.xml index 2c17ce6f6..bab16ae8e 100644 --- a/dmp-backend/web/src/main/resources/ExternalUrls.xml +++ b/dmp-backend/web/src/main/resources/ExternalUrls.xml @@ -168,6 +168,48 @@ + + + + + cristin + + 1 + https://eestore.paas2.uninett.no/api/projectrepo/ + + $['data'][*]['attributes'] + + 'pid' + 'name' + 'uri' + 'description' + + + $['meta']['pagination']['page','pages','count'] + + + openAire + + 1 + https://eestore.paas2.uninett.no/api/projectrepo/ + + $['data'][*]['attributes'] + + 'pid' + 'name' + 'uri' + 'description' + + + $['meta']['pagination']['page','pages','count'] + + + + + FIRST + + +