7
7
import cz .incad .kramerius .fedora .ProcessingIndexAccess ;
8
8
import cz .incad .kramerius .fedora .RepositoryAccess ;
9
9
import cz .incad .kramerius .fedora .DatastreamAccess ;
10
- import cz .incad .kramerius .fedora .impl .tmp .ContentFormat ;
11
- import cz .incad .kramerius .fedora .impl .tmp .ResultMapper ;
12
- import cz .incad .kramerius .fedora .impl .tmp .ProcessingIndexQueryParameters ;
13
- import cz .incad .kramerius .fedora .impl .tmp .UnsupportedContentFormatException ;
10
+ import cz .incad .kramerius .fedora .impl .tmp .*;
14
11
import cz .incad .kramerius .fedora .om .repository .AkubraRepository ;
15
12
import cz .incad .kramerius .fedora .om .repository .RepositoryDatastream ;
16
13
import cz .incad .kramerius .fedora .om .repository .RepositoryException ;
17
14
import cz .incad .kramerius .fedora .om .repository .RepositoryObject ;
18
15
import cz .incad .kramerius .fedora .om .repository .impl .AkubraDOManager ;
19
16
import cz .incad .kramerius .fedora .om .repository .impl .AkubraRepositoryImpl ;
20
- import cz .incad .kramerius .fedora .utils .AkubraUtils ;
21
17
import cz .incad .kramerius .fedora .om .resourceindex .ProcessingIndexFeeder ;
22
18
import cz .incad .kramerius .statistics .accesslogs .AggregatedAccessLogs ;
23
19
import cz .incad .kramerius .utils .Dom4jUtils ;
24
- import cz .incad .kramerius .utils .StringUtils ;
25
- import cz .incad .kramerius .utils .java .Pair ;
26
- import org .apache .solr .client .solrj .SolrServerException ;
27
- import org .apache .solr .common .SolrDocument ;
28
20
import org .dom4j .Attribute ;
29
21
import org .dom4j .QName ;
30
22
import org .ehcache .CacheManager ;
40
32
import java .nio .charset .Charset ;
41
33
import java .nio .charset .StandardCharsets ;
42
34
import java .time .LocalDateTime ;
43
- import java .time .format .DateTimeParseException ;
44
35
import java .util .*;
45
36
import java .util .concurrent .locks .Lock ;
46
37
import java .util .logging .Level ;
@@ -68,6 +59,7 @@ public RepositoryAccessImpl(ProcessingIndexFeeder feeder, @Nullable AggregatedAc
68
59
}
69
60
70
61
//-------- Object ------------------------------------------
62
+ // TODO result
71
63
@ Override
72
64
public boolean isObjectAvailable (String pid ) throws IOException {
73
65
try {
@@ -76,26 +68,16 @@ public boolean isObjectAvailable(String pid) throws IOException {
76
68
throw new IOException (e );
77
69
}
78
70
}
79
- public <T > T getFoxml (String pid , KnownDatastreams dsId , Class <T > returnType ) {
80
- // Determine supported formats for the content
81
- ContentFormat supportedFormat = determineSupportedFormat (id );
82
- // Validate the requested format
83
- if ((contentType == String .class && !supportedFormat .supportsString ()) ||
84
- (contentType == InputStream .class && !supportedFormat .supportsStream ()) ||
85
- (contentType == Document .class && !supportedFormat .supportsXml ())) {
86
- throw new UnsupportedContentFormatException ("Format not supported for content ID: " + id );
87
- }
71
+ public RepositoryObjectWrapper getFoxml (String pid ) {
72
+ SupportedFormats supportedFormat = determineSupportedFormat (pid );
88
73
// Retrieve content as bytes
89
- byte [] rawContent = fetchContentFromStorage (id );
90
- // Convert content to the requested format
91
- if (contentType == String .class ) {
92
- return contentType .cast (new String (rawContent , StandardCharsets .UTF_8 ));
93
- } else if (contentType == InputStream .class ) {
94
- return contentType .cast (new ByteArrayInputStream (rawContent ));
95
- } else if (contentType == Document .class ) {
96
- return contentType .cast (parseXml (rawContent ));
74
+ RepositoryObject rawContent = null ;
75
+ try {
76
+ rawContent = fetchContentFromStorage (pid );
77
+ return new RepositoryObjectWrapper (rawContent , supportedFormat );
78
+ } catch (RepositoryException e ) {
79
+ throw new RuntimeException (e );
97
80
}
98
- throw new IllegalArgumentException ("Unsupported content type: " + contentType );
99
81
}
100
82
public <T > T getProperty (String pid , String propertyName , Class <T > returnType ) {
101
83
org .dom4j .Document objectFoxml = getFoxml (pid );
@@ -131,52 +113,34 @@ public boolean isDatastreamAvailable(String pid, KnownDatastreams dsId) {
131
113
boolean exists = this .repositoryApi .datastreamExists (pid , dsId );
132
114
return exists ;
133
115
}
134
- public <T > T getDatastreamFoxml (String pid , KnownDatastreams dsId , Class <T > returnType ) {
135
- // Determine supported formats for the content
136
- ContentFormat supportedFormat = determineSupportedFormat (id );
137
- // Validate the requested format
138
- if ((contentType == String .class && !supportedFormat .supportsString ()) ||
139
- (contentType == InputStream .class && !supportedFormat .supportsStream ()) ||
140
- (contentType == Document .class && !supportedFormat .supportsXml ())) {
141
- throw new UnsupportedContentFormatException ("Format not supported for content ID: " + id );
142
- }
143
- // Retrieve content as bytes
144
- byte [] rawContent = fetchContentFromStorage (id );
145
- // Convert content to the requested format
146
- if (contentType == String .class ) {
147
- return contentType .cast (new String (rawContent , StandardCharsets .UTF_8 ));
148
- } else if (contentType == InputStream .class ) {
149
- return contentType .cast (new ByteArrayInputStream (rawContent ));
150
- } else if (contentType == Document .class ) {
151
- return contentType .cast (parseXml (rawContent ));
152
- }
153
- throw new IllegalArgumentException ("Unsupported content type: " + contentType );
116
+ // TODO archive format.. kdo to pouziva a proc
117
+ // TODO versions - nepouziva se, ale je treba zkontrolovat, ze se bere urcite posledni verze
118
+ public <T > T getDatastreamFoxmlElement (String pid , KnownDatastreams dsId ) {
119
+ return null ;
154
120
}
155
- public <T > T getDatastreamProperty (String pid , KnownDatastreams dsId , String propertyName , Class <T > returnType ) {
121
+
122
+ public <T > T getDatastreamProperty (String pid , KnownDatastreams dsId , String propertyName , Class <T > returnType ) {
156
123
org .dom4j .Document objectFoxml = getFoxml (pid );
157
124
return objectFoxml == null ? null : extractProperty (objectFoxml , propertyName );
158
125
}
159
- public <T > T getDatastreamContent (String pid , KnownDatastreams dsId , Class <T > returnType ) {
160
- // Determine supported formats for the content
161
- ContentFormat supportedFormat = determineSupportedFormat (id );
162
- // Validate the requested format
163
- if ((contentType == String .class && !supportedFormat .supportsString ()) ||
164
- (contentType == InputStream .class && !supportedFormat .supportsStream ()) ||
165
- (contentType == Document .class && !supportedFormat .supportsXml ())) {
166
- throw new UnsupportedContentFormatException ("Format not supported for content ID: " + id );
167
- }
126
+ // TODO nazev, Triplet, Tuple, ????????
127
+ public <T > T getRDFSimpleProperty (String pid , String propertyName , Class <T > returnType ) {
128
+ org .dom4j .Document objectFoxml = getFoxml (pid );
129
+ return objectFoxml == null ? null : extractProperty (objectFoxml , propertyName );
130
+ }
131
+
132
+ public DatastreamContentWrapper getDatastreamContent (String pid , KnownDatastreams dsId ) {
133
+ SupportedFormats supportedFormat = determineSupportedFormat (dsId );
168
134
// Retrieve content as bytes
169
- byte [] rawContent = fetchContentFromStorage (id );
170
- // Convert content to the requested format
171
- if (contentType == String .class ) {
172
- return contentType .cast (new String (rawContent , StandardCharsets .UTF_8 ));
173
- } else if (contentType == InputStream .class ) {
174
- return contentType .cast (new ByteArrayInputStream (rawContent ));
175
- } else if (contentType == Document .class ) {
176
- return contentType .cast (parseXml (rawContent ));
135
+ RepositoryDatastream rawContent = null ;
136
+ try {
137
+ rawContent = fetchContentFromStorage (pid , dsId );
138
+ return new DatastreamContentWrapper (rawContent , supportedFormat );
139
+ } catch (RepositoryException e ) {
140
+ throw new RuntimeException (e );
177
141
}
178
- throw new IllegalArgumentException ("Unsupported content type: " + contentType );
179
142
}
143
+
180
144
public List <String > getDatastreamNames (String pid ) {
181
145
Lock readLock = AkubraDOManager .getReadLock (pid );
182
146
try {
@@ -314,17 +278,24 @@ private void reportAccess(String pid, String streamName) {
314
278
LOGGER .log (Level .WARNING , "Can't write statistic records for " + pid + ", stream name: " + streamName , e );
315
279
}
316
280
}
317
- private ContentFormat determineSupportedFormat (String id ) {
281
+ private SupportedFormats determineSupportedFormat (KnownDatastreams id ) {
318
282
// Example logic to determine supported formats
319
- if (id . startsWith ( "streamOnly" ) ) {
320
- return new ContentFormat (false , true , false );
283
+ if (id == KnownDatastreams . BIBLIO_DC ) {
284
+ return new SupportedFormats (false , true , false );
321
285
} else {
322
- return new ContentFormat (true , true , true );
286
+ return new SupportedFormats (true , true , true );
323
287
}
324
288
}
325
- private byte [] fetchContentFromStorage (String id ) {
289
+ private RepositoryDatastream fetchContentFromStorage (String pid , KnownDatastreams dsId ) throws RepositoryException {
290
+ RepositoryObject object = akubraRepositoryImpl .getObject (pid );
291
+ if (object .streamExists (dsId )) {
292
+ RepositoryDatastream stream = object .getStream (dsId );
293
+ return stream ;
294
+ } else {
295
+ return null ;
296
+ }
326
297
// Mock: Fetch content as bytes from your storage
327
- return ("<xml>Content for ID: " + id + "</xml>" ).getBytes (StandardCharsets .UTF_8 );
298
+ // return ("<xml>Content for ID: " + id + "</xml>").getBytes(StandardCharsets.UTF_8);
328
299
}
329
300
private Document parseXml (byte [] content ) throws IOException {
330
301
try {
0 commit comments