use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagCreateStorageRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagCreateStorageRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
CatalogProvider catalogProvider = mock(CatalogProvider.class);
doReturn(true).when(catalogProvider).isAvailable();
StorageProvider storageProvider = new MockMemoryStorageProvider();
MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
doReturn("extension").when(mimeTypeMapper).getFileExtensionForMimeType(anyString());
InputTransformer transformer = mock(InputTransformer.class);
doReturn(metacard).when(transformer).transform(any(InputStream.class));
MimeTypeToTransformerMapper mimeTypeToTransformerMapper = mock(MimeTypeToTransformerMapper.class);
doReturn(Collections.singletonList(transformer)).when(mimeTypeToTransformerMapper).findMatches(any(Class.class), any(MimeType.class));
frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
frameworkProperties.setMimeTypeMapper(mimeTypeMapper);
frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
sourceOperations.bind(catalogProvider);
sourceOperations.bind(storageProvider);
TransformOperations transformOperations = new TransformOperations(frameworkProperties);
QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
OperationsMetacardSupport opsMetacardSupport = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
// Need to set these for InputValidation to work
System.setProperty("bad.files", "none");
System.setProperty("bad.file.extensions", "none");
System.setProperty("bad.mime.types", "none");
CreateOperations createOperations = new CreateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacardSupport, opsCatStore, opsStorage);
framework = new CatalogFrameworkImpl(createOperations, null, null, queryOperations, resourceOperations, sourceOperations, transformOperations);
framework.setId(NEW_SOURCE_ID);
framework.setFanoutEnabled(true);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
CreateStorageRequest request = new CreateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
framework.create(request);
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class OverrideAttributesSupportTest method testNoContentItems.
@Test
public void testNoContentItems() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata("original");
metacard.setTitle("original");
metacard.setId("original");
metacard.setResourceURI(new URI("content:stuff"));
metacardMap.put(metacard.getId(), metacard);
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("original"));
assertThat(metacardMap.get("original").getTitle(), is("original"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:stuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class CreateOperations method populateMetacardMap.
private void populateMetacardMap(Map<String, Metacard> metacardMap, CreateStorageResponse createStorageResponse) throws IOException {
for (ContentItem contentItem : createStorageResponse.getCreatedContentItems()) {
if (StringUtils.isBlank(contentItem.getQualifier())) {
Metacard metacard = metacardMap.get(contentItem.getId());
Metacard overrideMetacard = contentItem.getMetacard();
Metacard updatedMetacard = OverrideAttributesSupport.overrideMetacard(metacard, overrideMetacard, true, true);
updatedMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_URI, contentItem.getUri()));
updatedMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_SIZE, String.valueOf(contentItem.getSize())));
metacardMap.put(contentItem.getId(), updatedMetacard);
}
}
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ContentItemValidatorTest method testInvalidIdWithQualifier.
@Test
public void testInvalidIdWithQualifier() throws Exception {
String id = "634e8505-bd4b-436e-97e8-2045d1b0d265-abcdef".replace("-", "");
String qualifier = "zoom-and-enhanced-overview";
ContentItem item = new ContentItemImpl(id, qualifier, null, "", null);
assertThat(ContentItemValidator.validate(item), is(false));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ContentItemValidatorTest method testInvalidId.
@Test
public void testInvalidId() throws Exception {
// "123456789 is not a guid
ContentItem item = new ContentItemImpl("123456789", "good-qualifier", null, "", null);
assertThat(ContentItemValidator.validate(item), is(false));
}
Aggregations