CatalogRolloverAction extends BaseRolloverAction { @Override public MetacardImpl doAction(MetacardImpl metacard, File tempFile) throws RolloverActionException { return context.modifyParentOrChild( isParentDirty -> { Subject subject = context.getUdpStreamProcessor().getSubject(); if (subject == null) { LOGGER.debug("no security subject available, cannot upload video chunk"); return metacard; } return subject.execute( () -> { String fileName = generateFilename(); enforceRequiredMetacardFields(metacard, fileName); ContentItem contentItem = createContentItem(metacard, fileName, Files.asByteSource(tempFile)); CreateStorageRequest createStorageRequest = createStorageRequest(contentItem); CreateResponse createResponse = submitStorageCreateRequest(createStorageRequest); for (Metacard childMetacard : createResponse.getCreatedMetacards()) { LOGGER.trace("created catalog content with id={}", childMetacard.getId()); linkChildToParent(childMetacard); updateParentWithChildMetadata(childMetacard); } isParentDirty.set(true); return metacard; }); }); } CatalogRolloverAction(
      FilenameGenerator filenameGenerator,
      String filenameTemplate,
      CatalogFramework catalogFramework,
      Context context,
      MetacardUpdater parentMetacardUpdater,
      UuidGenerator uuidGenerator,
      SubjectOperations subjectOperations); void setCatalogUpdateRetry(CatalogUpdateRetry catalogUpdateRetry); @Override String toString(); @Override MetacardImpl doAction(MetacardImpl metacard, File tempFile);  }
@Test public void testTemporalStart() throws RolloverActionException, SourceUnavailableException, IngestException { catalogRolloverAction.doAction(tempFile); ArgumentCaptor<UpdateRequest> argumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class); verify(catalogFramework, times(2)).update(argumentCaptor.capture()); ArgumentCaptor<Attribute> attributeCaptor = ArgumentCaptor.forClass(Attribute.class); verify(createdParentMetacard, atLeastOnce()).setAttribute(attributeCaptor.capture()); List<Attribute> geoAttributeList = attributeCaptor.getAllValues().stream() .filter(attr -> attr.getName().equals(AttributeNameConstants.TEMPORAL_START)) .collect(Collectors.toList()); assertThat(geoAttributeList, hasSize(1)); assertThat(geoAttributeList.get(0).getValue(), is(TEMPORAL_START_DATE)); }
@Test public void testTemporalEnd() throws RolloverActionException, SourceUnavailableException, IngestException { catalogRolloverAction.doAction(tempFile); ArgumentCaptor<UpdateRequest> argumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class); verify(catalogFramework, times(2)).update(argumentCaptor.capture()); ArgumentCaptor<Attribute> attributeCaptor = ArgumentCaptor.forClass(Attribute.class); verify(createdParentMetacard, atLeastOnce()).setAttribute(attributeCaptor.capture()); List<Attribute> geoAttributeList = attributeCaptor.getAllValues().stream() .filter(attr -> attr.getName().equals(AttributeNameConstants.TEMPORAL_END)) .collect(Collectors.toList()); assertThat(geoAttributeList, hasSize(1)); assertThat(geoAttributeList.get(0).getValue(), is(TEMPORAL_END_DATE)); }
@Test public void testRetry() throws RolloverActionException, SourceUnavailableException, IngestException { when(catalogFramework.update(any(UpdateRequest.class))) .thenThrow(IngestException.class) .thenReturn(childUpdateResponse) .thenReturn(parentUpdateResponse); catalogRolloverAction.doAction(tempFile); ArgumentCaptor<UpdateRequest> argumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class); verify(catalogFramework, times(3)).update(argumentCaptor.capture()); ArgumentCaptor<Attribute> attributeCaptor = ArgumentCaptor.forClass(Attribute.class); verify(createdParentMetacard, atLeastOnce()).setAttribute(attributeCaptor.capture()); List<Attribute> geoAttributeList = attributeCaptor.getAllValues().stream() .filter(attr -> attr.getName().equals(Core.MODIFIED)) .collect(Collectors.toList()); assertThat(geoAttributeList, hasSize(1)); assertThat(geoAttributeList.get(0).getValue(), is(TEMPORAL_END_DATE)); }