This repository was archived by the owner on Jul 20, 2024. It is now read-only.
forked from splunk/splunk-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataModelField.java
More file actions
135 lines (116 loc) · 4.71 KB
/
DataModelField.java
File metadata and controls
135 lines (116 loc) · 4.71 KB
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
/*
* Copyright 2014 Splunk, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"): you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.splunk;
import com.google.gson.JsonElement;
import java.util.Map.Entry;
/**
* Represents a field of a data model object.
*/
public class DataModelField {
private String[] ownerLineage;
private String name;
private FieldType type;
private boolean required;
private boolean multivalued;
private boolean hidden;
private String displayName;
private String comment;
private boolean editable;
private String fieldSearch;
private DataModelField() {}
/**
* @return a search query fragment for this field.
*/
public String getFieldSearch() { return this.fieldSearch; }
/**
* @return The name of this field.
*/
public String getName() { return this.name; };
/**
* Return the name of the data model object on which this field is defined. That need not
* be the data model object you accessed it from. It can be one of its ancestors.
*
* @return The name of the DataModelObject that owns this field.
*/
public String getOwnerName() { return this.ownerLineage[this.ownerLineage.length-1]; }
/**
* Return the lineage of the data model object on which this field is defined. That need not
* be the data model object you accessed it from. It can be one of its ancestors.
*
* @return An array of names of DataModelObjects representing the lineage of this field's owner.
*/
public String[] getOwnerLineage() { return this.ownerLineage; }
/**
* @return The type of this field.
*/
public FieldType getType() { return this.type; }
/**
* Some fields are part of system objects such as BaseEvent or are part
* of the structure of the object, such as a field with the same name
* as the object. Those fields cannot be edited. This method returns
* whether the field is one of these protected fields.
*
* @return whether this field can be edited.
*/
public boolean isEditable() { return editable; }
/**
* @return whether this field is required on events in the object.
*/
public boolean isRequired() { return required; }
/**
* @return whether this field is can be multivalued.
*/
public boolean isMultivalued() { return multivalued; }
/**
* @return whether this field should be displayed in a data model UI.
*/
public boolean isHidden() { return hidden; }
/**
* @return a human readable name for this field.
*/
public String getDisplayName() { return displayName; }
/**
* @return a comment on this field (if there is one), or null.
*/
public String getComment() { return comment; }
public static DataModelField parse(JsonElement fieldJson) {
DataModelField field = new DataModelField();
for (Entry<String, JsonElement> entry : fieldJson.getAsJsonObject().entrySet()) {
if (entry.getKey().equals("fieldName")) {
field.name = entry.getValue().getAsString();
} else if (entry.getKey().equals("owner")) {
field.ownerLineage = entry.getValue().getAsString().split("\\.");
} else if (entry.getKey().equals("type")) {
field.type = FieldType.parseType(entry.getValue().getAsString());
} else if (entry.getKey().equals("required")) {
field.required = entry.getValue().getAsBoolean();
} else if (entry.getKey().equals("multivalue")) {
field.multivalued = entry.getValue().getAsBoolean();
} else if (entry.getKey().equals("hidden")) {
field.hidden = entry.getValue().getAsBoolean();
} else if (entry.getKey().equals("displayName")) {
field.displayName = entry.getValue().getAsString();
} else if (entry.getKey().equals("comment")) {
field.comment = entry.getValue().getAsString();
} else if (entry.getKey().equals("editable")) {
field.editable = entry.getValue().getAsBoolean();
} else if (entry.getKey().equals("fieldSearch")) {
field.fieldSearch = entry.getValue().getAsString();
}
}
return field;
}
}