Adds Funder entity on backend.

This commit is contained in:
gkolokythas 2019-08-02 18:24:43 +03:00
parent e8efe54479
commit 5dcf8397df
8 changed files with 451 additions and 24 deletions

View File

@ -0,0 +1,14 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Funder;
public class FunderCriteria extends Criteria<Funder> {
private String reference;
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
}

View File

@ -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<Funder, UUID> {
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> tuple, List<String> fields, String base) {
return null;
}
}

View File

@ -96,7 +96,6 @@ public class Grant implements DataEntity<Grant, UUID> {
@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<Grant, UUID> {
@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<Grant, UUID> {
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<Grant, UUID> {
public Date getStartdate() {
return startdate;
}
public void setStartdate(Date startdate) {
this.startdate = startdate;
}
@ -193,7 +186,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public Date getEnddate() {
return enddate;
}
public void setEnddate(Date enddate) {
this.enddate = enddate;
}
@ -201,7 +193,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
@ -209,7 +200,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@ -217,7 +207,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
@ -225,7 +214,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
@ -233,7 +221,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
@ -241,16 +228,13 @@ public class Grant implements DataEntity<Grant, UUID> {
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
public Set<DMP> getDmps() {
return dmps;
}
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
}
@ -258,7 +242,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public UserInfo getCreationUser() {
return creationUser;
}
public void setCreationUser(UserInfo creationUser) {
this.creationUser = creationUser;
}
@ -266,7 +249,6 @@ public class Grant implements DataEntity<Grant, UUID> {
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
@ -274,12 +256,18 @@ public class Grant implements DataEntity<Grant, UUID> {
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<Grant, UUID> {
this.enddate = entity.getEnddate();
this.modified = new Date();
this.uri = entity.getUri();
this.funder = entity.funder;
if (entity.getContent() != null) this.content = entity.getContent();
}

View File

@ -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<FunderCriteria, Funder> {
@Override
public QueryableList<Funder> applyCriteria() {
QueryableList<Funder> 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;
}
}

View File

@ -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<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException {
List<Funder> dataTable = this.funderManager.getCriteriaWithExternal(funderCriteria, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.funder.Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
}
}

View File

@ -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<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());
// QueryableList<Funder> 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 eu.eudat.models.data.project.Project().fromDataModel(item));
// List<Map<String, String>> 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;
}
}

View File

@ -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<eu.eudat.data.entities.Funder, Funder> {
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;
}
}

View File

@ -168,6 +168,48 @@
</projects>
<funders>
<urls>
<urlConfig>
<key>cristin</key>
<label>Cristin</label>
<ordinal>1</ordinal>
<url>https://eestore.paas2.uninett.no/api/projectrepo/</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
<id>'pid'</id>
<name>'name'</name>
<uri>'uri'</uri>
<description>'description'</description>
</fields>
</data>
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>
<urlConfig>
<key>openAire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<url>https://eestore.paas2.uninett.no/api/projectrepo/</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
<id>'pid'</id>
<name>'name'</name>
<uri>'uri'</uri>
<description>'description'</description>
</fields>
</data>
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>
</urls>
<fetchMode>FIRST</fetchMode> <!-- EITHER 'FIRST' OR 'ALL' -->
</funders>
<repositories>
<urls>