-
Notifications
You must be signed in to change notification settings - Fork 242
/
JavaNetURIPropertyTypeDescriptor.java
146 lines (122 loc) · 3.98 KB
/
JavaNetURIPropertyTypeDescriptor.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
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.integrationtest.mapper.pojo.testsupport.types;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.hibernate.search.integrationtest.mapper.pojo.testsupport.types.expectations.DefaultIdentifierBridgeExpectations;
import org.hibernate.search.integrationtest.mapper.pojo.testsupport.types.expectations.DefaultValueBridgeExpectations;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
public class JavaNetURIPropertyTypeDescriptor extends PropertyTypeDescriptor<URI> {
private static final String[] STRING_URLS = {
"https://www.google.com",
"https://twitter.com/Hibernate/status/1093118957194801152",
"https://twitter.com/Hibernate/status/1092803949533507584",
"https://access.redhat.com/",
"https://access.redhat.com/products",
"https://access.redhat.com/products/red-hat-fuse/",
"https://access.redhat.com/products/red-hat-openshift-container-platform/",
"mailto:java-net@java.sun.com",
"urn:isbn:096139210x",
"file:///~calendar"
};
JavaNetURIPropertyTypeDescriptor() {
super( URI.class );
}
@Override
public Optional<DefaultIdentifierBridgeExpectations<URI>> getDefaultIdentifierBridgeExpectations() {
return Optional.empty();
}
@Override
public Optional<DefaultValueBridgeExpectations<URI, ?>> getDefaultValueBridgeExpectations() {
return Optional.of( new DefaultValueBridgeExpectations<URI, String>() {
@Override
public Class<URI> getProjectionType() {
return URI.class;
}
@Override
public Class<String> getIndexFieldJavaType() {
return String.class;
}
@Override
public List<URI> getEntityPropertyValues() {
return Arrays.stream( STRING_URLS ).map( s -> URI.create( s ) ).collect( Collectors.toList() );
}
@Override
public List<String> getDocumentFieldValues() {
return Arrays.asList( STRING_URLS );
}
@Override
public Class<?> getTypeWithValueBridge1() {
return TypeWithValueBridge1.class;
}
@Override
public Object instantiateTypeWithValueBridge1(int identifier, URI propertyValue) {
TypeWithValueBridge1 instance = new TypeWithValueBridge1();
instance.id = identifier;
instance.myProperty = propertyValue;
return instance;
}
@Override
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}
@Override
public String getNullAsValueBridge1() {
return "https://www.redhat.com";
}
@Override
public String getNullAsValueBridge2() {
return "file:///~calendar";
}
@Override
public String getUnparsableNullAsValue() {
return "http://www.wrong.uri.com?param1=0 param7=0";
}
} );
}
@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {
Integer id;
URI myProperty;
URI indexNullAsProperty;
@DocumentId
public Integer getId() {
return id;
}
@GenericField
public URI getMyProperty() {
return myProperty;
}
@GenericField(indexNullAs = "https://www.redhat.com")
public URI getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {
Integer id;
URI myProperty;
URI indexNullAsProperty;
@DocumentId
public Integer getId() {
return id;
}
@GenericField
public URI getMyProperty() {
return myProperty;
}
@GenericField(indexNullAs = "file:///~calendar")
public URI getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
}