|
7 | 7 | */ |
8 | 8 | package org.roda.core.plugins.base.ingest; |
9 | 9 |
|
| 10 | +import java.io.IOException; |
10 | 11 | import java.io.UnsupportedEncodingException; |
11 | 12 | import java.net.URLDecoder; |
12 | 13 | import java.util.Collections; |
|
16 | 17 | import java.util.Optional; |
17 | 18 |
|
18 | 19 | import org.apache.commons.io.FilenameUtils; |
| 20 | +import org.apache.commons.io.IOUtils; |
19 | 21 | import org.roda.core.common.PremisV3Utils; |
20 | 22 | import org.roda.core.data.common.RodaConstants; |
21 | 23 | import org.roda.core.data.exceptions.AlreadyExistsException; |
|
39 | 41 | import org.roda.core.model.ModelService; |
40 | 42 | import org.roda.core.plugins.Plugin; |
41 | 43 | import org.roda.core.plugins.PluginHelper; |
| 44 | +import org.roda.core.storage.Binary; |
42 | 45 | import org.roda.core.storage.ContentPayload; |
43 | 46 | import org.roda.core.storage.ExternalFileManifestContentPayload; |
44 | 47 | import org.roda.core.storage.StorageService; |
@@ -225,10 +228,19 @@ private static void processPreservationMetadata(ModelService model, List<IPMetad |
225 | 228 | agentComplexType.getVersion()); |
226 | 229 |
|
227 | 230 | try { |
228 | | - if (model.retrievePreservationAgent( |
229 | | - agentComplexType.getAgentIdentifier().getFirst().getAgentIdentifierValue()) != null) { |
230 | | - model.updatePreservationMetadata(PreservationMetadataType.AGENT, |
231 | | - agentComplexType.getAgentIdentifier().getFirst().getAgentIdentifierValue(), premisAgentBinary, true); |
| 231 | + Binary existingPA = model |
| 232 | + .retrievePreservationAgent(agentComplexType.getAgentIdentifier().getFirst().getAgentIdentifierValue()); |
| 233 | + if (existingPA != null) { |
| 234 | + try { |
| 235 | + if (!IOUtils.contentEquals(existingPA.getContent().createInputStream(), |
| 236 | + premisAgentBinary.createInputStream())) { |
| 237 | + model.updatePreservationMetadata(PreservationMetadataType.AGENT, |
| 238 | + agentComplexType.getAgentIdentifier().getFirst().getAgentIdentifierValue(), premisAgentBinary, |
| 239 | + true); |
| 240 | + } |
| 241 | + } catch (IOException e) { |
| 242 | + throw new GenericException("Could not update binary content", e); |
| 243 | + } |
232 | 244 | } else { |
233 | 245 | model.createPreservationMetadata(PreservationMetadataType.AGENT, |
234 | 246 | agentComplexType.getAgentIdentifier().getFirst().getAgentIdentifierValue(), premisAgentBinary, true); |
|
0 commit comments