1
|
package eu.dnetlib.actionmanager.actions;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.apache.hadoop.hbase.client.Put;
|
6
|
import org.apache.hadoop.hbase.util.Bytes;
|
7
|
|
8
|
import com.google.common.collect.Lists;
|
9
|
|
10
|
import eu.dnetlib.actionmanager.ActionManagerConstants;
|
11
|
import eu.dnetlib.actionmanager.ActionManagerConstants.ACTION_TYPE;
|
12
|
import eu.dnetlib.actionmanager.common.Agent;
|
13
|
import eu.dnetlib.actionmanager.common.Operation;
|
14
|
import eu.dnetlib.actionmanager.common.Provenance;
|
15
|
import eu.dnetlib.actionmanager.hbase.HBasePutFactory;
|
16
|
|
17
|
public class AtomicAction extends AbstractAction {
|
18
|
|
19
|
private String targetRowKey;
|
20
|
private String targetColumnFamily;
|
21
|
private String targetColumn;
|
22
|
|
23
|
private byte[] targetValue;
|
24
|
|
25
|
public AtomicAction(final String rawSet, final Agent agent) {
|
26
|
super(ACTION_TYPE.aac, rawSet, agent);
|
27
|
}
|
28
|
|
29
|
public AtomicAction(final String rawSet, final Agent agent, final Operation operation, final String targetRowKey, final String targetColumnFamily,
|
30
|
final String targetColumn, final byte[] targetValue) {
|
31
|
this(rawSet, agent);
|
32
|
this.targetRowKey = targetRowKey;
|
33
|
this.targetColumnFamily = targetColumnFamily;
|
34
|
this.targetColumn = targetColumn;
|
35
|
this.targetValue = targetValue;
|
36
|
}
|
37
|
|
38
|
public List<Put> asPutOperations(final String parentId, final Provenance provenance, final String trust, final String nsprefix) {
|
39
|
final Put put = HBasePutFactory.createPutOperation(getRowKey(), getRawSet(), getAgent());
|
40
|
|
41
|
put.add(ActionManagerConstants.SET_COLFAMILY, Bytes.toBytes(getRawSet()), Bytes.toBytes(getRawSet()));
|
42
|
put.add(ActionManagerConstants.TARGET_COLFAMILY, ActionManagerConstants.TARGET_KEY_COL, Bytes.toBytes(targetRowKey));
|
43
|
put.add(ActionManagerConstants.TARGET_COLFAMILY, ActionManagerConstants.TARGET_COLFAMILY_COL, Bytes.toBytes(targetColumnFamily));
|
44
|
put.add(ActionManagerConstants.TARGET_COLFAMILY, ActionManagerConstants.TARGET_COL_COL, Bytes.toBytes(targetColumn));
|
45
|
put.add(ActionManagerConstants.TARGET_COLFAMILY, ActionManagerConstants.TARGET_OAF_COL, targetValue);
|
46
|
|
47
|
if ((parentId != null) && !parentId.isEmpty()) {
|
48
|
put.add(ActionManagerConstants.RELATION_COLFAMILY, Bytes.toBytes(parentId), ActionManagerConstants.ISPARTOF);
|
49
|
}
|
50
|
|
51
|
return Lists.newArrayList(put);
|
52
|
}
|
53
|
|
54
|
public String getTargetRowKey() {
|
55
|
return targetRowKey;
|
56
|
}
|
57
|
|
58
|
public void setTargetRowKey(final String targetRowKey) {
|
59
|
this.targetRowKey = targetRowKey;
|
60
|
}
|
61
|
|
62
|
public String getTargetColumnFamily() {
|
63
|
return targetColumnFamily;
|
64
|
}
|
65
|
|
66
|
public void setTargetColumnFamily(final String targetColumnFamily) {
|
67
|
this.targetColumnFamily = targetColumnFamily;
|
68
|
}
|
69
|
|
70
|
public String getTargetColumn() {
|
71
|
return targetColumn;
|
72
|
}
|
73
|
|
74
|
public void setTargetColumn(final String targetColumn) {
|
75
|
this.targetColumn = targetColumn;
|
76
|
}
|
77
|
|
78
|
public byte[] getTargetValue() {
|
79
|
return targetValue;
|
80
|
}
|
81
|
|
82
|
public void setTargetValue(final byte[] targetValue) {
|
83
|
this.targetValue = targetValue;
|
84
|
}
|
85
|
|
86
|
public boolean isValid() {
|
87
|
return ((getRowKey() != null) && !getRowKey().isEmpty() && (getRawSet() != null) && !getRawSet().isEmpty() && (targetRowKey != null)
|
88
|
&& !targetRowKey.isEmpty() && (targetColumnFamily != null) && !targetColumnFamily.isEmpty() && (targetColumn != null)
|
89
|
&& !targetColumn.isEmpty() && (targetValue != null) && (targetValue.length > 0));
|
90
|
}
|
91
|
|
92
|
}
|