2020-06-24 18:34:42 +02:00
|
|
|
|
|
|
|
package eu.dnetlib.dhp.oa.provision.model;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
2020-06-24 19:01:15 +02:00
|
|
|
import com.google.common.base.Objects;
|
2020-06-24 18:34:42 +02:00
|
|
|
import com.google.common.collect.ComparisonChain;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.Relation;
|
|
|
|
|
2020-06-25 10:19:56 +02:00
|
|
|
public class SortableRelationKey implements Comparable<SortableRelationKey>, Serializable {
|
|
|
|
|
|
|
|
private static final Map<String, Integer> weights = Maps.newHashMap();
|
|
|
|
|
|
|
|
static {
|
|
|
|
weights.put("outcome", 0);
|
|
|
|
weights.put("supplement", 1);
|
|
|
|
weights.put("review", 2);
|
|
|
|
weights.put("citation", 3);
|
|
|
|
weights.put("affiliation", 4);
|
|
|
|
weights.put("relationship", 5);
|
|
|
|
weights.put("publicationDataset", 6);
|
|
|
|
weights.put("similarity", 7);
|
|
|
|
|
|
|
|
weights.put("provision", 8);
|
|
|
|
weights.put("participation", 9);
|
|
|
|
weights.put("dedup", 10);
|
|
|
|
}
|
2020-06-24 18:34:42 +02:00
|
|
|
|
2020-06-25 10:19:56 +02:00
|
|
|
private static final long serialVersionUID = 3232323;
|
2020-06-24 18:34:42 +02:00
|
|
|
|
2020-06-25 10:19:56 +02:00
|
|
|
private String groupingKey;
|
2020-06-24 18:34:42 +02:00
|
|
|
|
|
|
|
private String subRelType;
|
|
|
|
|
|
|
|
public static SortableRelationKey create(Relation r, String groupingKey) {
|
|
|
|
SortableRelationKey sr = new SortableRelationKey();
|
|
|
|
sr.setGroupingKey(groupingKey);
|
|
|
|
sr.setSubRelType(r.getSubRelType());
|
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-24 19:01:15 +02:00
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o)
|
|
|
|
return true;
|
|
|
|
if (o == null || getClass() != o.getClass())
|
|
|
|
return false;
|
|
|
|
SortableRelationKey that = (SortableRelationKey) o;
|
|
|
|
return Objects.equal(getGroupingKey(), that.getGroupingKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hashCode(getGroupingKey());
|
2020-06-24 18:34:42 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 10:19:56 +02:00
|
|
|
@Override
|
|
|
|
public int compareTo(SortableRelationKey o) {
|
|
|
|
return ComparisonChain
|
|
|
|
.start()
|
2020-06-25 11:04:12 +02:00
|
|
|
.compare(getGroupingKey(), o.getGroupingKey())
|
2020-06-25 10:19:56 +02:00
|
|
|
.compare(getWeight(this), getWeight(o))
|
2020-06-25 11:04:12 +02:00
|
|
|
.result();
|
2020-06-24 18:34:42 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 10:19:56 +02:00
|
|
|
private Integer getWeight(SortableRelationKey o) {
|
|
|
|
return Optional.ofNullable(weights.get(o.getSubRelType())).orElse(Integer.MAX_VALUE);
|
2020-06-24 18:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getSubRelType() {
|
|
|
|
return subRelType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubRelType(String subRelType) {
|
|
|
|
this.subRelType = subRelType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getGroupingKey() {
|
|
|
|
return groupingKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGroupingKey(String groupingKey) {
|
|
|
|
this.groupingKey = groupingKey;
|
|
|
|
}
|
2020-06-25 10:19:56 +02:00
|
|
|
|
2020-06-24 18:34:42 +02:00
|
|
|
}
|