-
Notifications
You must be signed in to change notification settings - Fork 86
/
Parameter.java
146 lines (117 loc) · 3.81 KB
/
Parameter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package edu.cornell.mannlib.vitro.webapp.dynapi.components;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import edu.cornell.mannlib.vitro.webapp.dynapi.components.validators.Validator;
import edu.cornell.mannlib.vitro.webapp.dynapi.data.Data;
import edu.cornell.mannlib.vitro.webapp.dynapi.data.conversion.InitializationException;
import edu.cornell.mannlib.vitro.webapp.dynapi.data.types.ParameterType;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
public class Parameter implements Removable {
private String name;
private String description;
private Validators validators = new Validators();
private ParameterType type;
private String defaultValue;
private Boolean internal;
private boolean optional;
public String getName() {
return name;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasType", minOccurs = 1, maxOccurs = 1)
public void setType(ParameterType type) throws InitializationException {
type.initialize();
this.type = type;
}
public ParameterType getType() {
return type;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#defaultValue", minOccurs = 0, maxOccurs = 1)
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#isInternal", minOccurs = 0, maxOccurs = 1)
public void setInternal(boolean internal) {
if (!optional) {
this.internal = internal;
}
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#isOptionalParam", minOccurs = 0, maxOccurs = 1)
public void setOptional(boolean optional) {
this.optional = optional;
if (optional) {
this.internal = true;
}
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1)
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#description", maxOccurs = 1)
public void setDescription(String description) {
this.description = description;
}
@Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasValidator")
public void addValidator(Validator validator) {
validators.add(validator);
}
public boolean isValid(String name, Data data) {
return validators.isAllValid(name, data);
}
@Override
public void dereference() {
}
public boolean isInternal() {
if (internal != null) {
return internal;
}
return type.isInternal();
}
public boolean isString() {
return type.isString();
}
public boolean isPlainString() {
return type.isPlainString();
}
public String getInputPath() {
return "";
}
public String getOutputPath() {
return "";
}
public boolean isOptional() {
return optional;
}
public boolean isJsonContainer() {
return type.isJsonContainer();
}
public String getDefaultValue() {
if (defaultValue != null) {
return defaultValue;
}
return type.getImplementationType().getDefaultValue();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Parameter)) {
return false;
}
if (object == this) {
return true;
}
Parameter compared = (Parameter) object;
return new EqualsBuilder()
.append(getName(), compared.getName())
.append(getType(), compared.getType())
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(43, 205)
.append(getName())
.append(getType())
.toHashCode();
}
}