Revision 51138
Added by Claudio Atzori about 6 years ago
FileSystemObjectStore.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.objectstore.filesystem; |
2 | 2 |
|
3 |
import com.google.common.base.Function; |
|
3 |
import java.io.ByteArrayInputStream; |
|
4 |
import java.io.IOException; |
|
5 |
import java.nio.file.FileSystems; |
|
6 |
import java.nio.file.Files; |
|
7 |
import java.nio.file.Path; |
|
8 |
import java.util.regex.Pattern; |
|
9 |
|
|
4 | 10 |
import com.google.common.collect.Iterables; |
5 | 11 |
import com.google.common.collect.Lists; |
6 | 12 |
import com.google.gson.Gson; |
... | ... | |
17 | 23 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
18 | 24 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
19 | 25 |
import eu.dnetlib.miscutils.collections.Pair; |
20 |
import org.apache.commons.lang.StringUtils; |
|
26 |
import org.apache.commons.lang3.StringUtils;
|
|
21 | 27 |
import org.apache.commons.logging.Log; |
22 | 28 |
import org.apache.commons.logging.LogFactory; |
23 | 29 |
import org.bson.conversions.Bson; |
24 | 30 |
|
25 |
import java.io.ByteArrayInputStream; |
|
26 |
import java.io.IOException; |
|
27 |
import java.nio.file.FileSystems; |
|
28 |
import java.nio.file.Files; |
|
29 |
import java.nio.file.Path; |
|
30 |
import java.util.regex.Pattern; |
|
31 |
|
|
32 | 31 |
/** |
33 | 32 |
* The Class FileSystemObjectStore. |
34 | 33 |
* |
... | ... | |
122 | 121 |
throw new ObjectStoreServiceException("Error can't feed objects because the folder " + baseDirPath + " does not exist"); |
123 | 122 |
|
124 | 123 |
int addedCounter = 0; |
124 |
int nulls = 0; |
|
125 | 125 |
for (ObjectStoreRecord record : records) { |
126 | 126 |
String url = feedObject(record); |
127 | 127 |
if (StringUtils.isNotBlank(url)) { |
128 | 128 |
addedCounter++; |
129 |
} else { |
|
130 |
nulls++; |
|
129 | 131 |
} |
130 | 132 |
} |
133 |
if (nulls > 0) { |
|
134 |
log.warn(String.format("Found %s null records", nulls)); |
|
135 |
} |
|
131 | 136 |
return addedCounter; |
132 | 137 |
} |
133 | 138 |
|
... | ... | |
140 | 145 |
*/ |
141 | 146 |
@Override |
142 | 147 |
public int feedMetadataRecord(final Iterable<MetadataObjectRecord> records, final boolean incremental) throws ObjectStoreServiceException { |
143 |
Iterable<ObjectStoreRecord> it = Iterables.transform(records, new Function<MetadataObjectRecord, ObjectStoreRecord>() { |
|
144 |
@Override |
|
145 |
public ObjectStoreRecord apply(final MetadataObjectRecord metadataObjectRecord) { |
|
146 |
ObjectStoreRecord r = new ObjectStoreRecord(); |
|
147 |
r.setInputStream(new ByteArrayInputStream(metadataObjectRecord.getRecord().getBytes())); |
|
148 |
ObjectStoreFile fileMetadata = new ObjectStoreFile(); |
|
149 |
fileMetadata.setObjectID(metadataObjectRecord.getId()); |
|
150 |
fileMetadata.setMimeType(metadataObjectRecord.getMime()); |
|
151 |
r.setFileMetadata(fileMetadata); |
|
152 |
return r; |
|
153 |
} |
|
148 |
Iterable<ObjectStoreRecord> it = Iterables.transform(records, mor -> { |
|
149 |
ObjectStoreRecord r = new ObjectStoreRecord(); |
|
150 |
r.setInputStream(new ByteArrayInputStream(mor.getRecord().getBytes())); |
|
151 |
ObjectStoreFile fileMetadata = new ObjectStoreFile(); |
|
152 |
fileMetadata.setObjectID(mor.getId()); |
|
153 |
fileMetadata.setMimeType(mor.getMime()); |
|
154 |
r.setFileMetadata(fileMetadata); |
|
155 |
return r; |
|
154 | 156 |
}); |
155 | 157 |
return feed(it, incremental); |
156 | 158 |
} |
... | ... | |
217 | 219 |
} |
218 | 220 |
} |
219 | 221 |
} |
220 |
log.warn("Record for object store is null"); |
|
221 | 222 |
return null; |
222 | 223 |
} |
223 | 224 |
|
Also available in: Unified diff
using apache commons lang3