use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class RESTEndpoint method generateMetacard.
private Metacard generateMetacard(MimeType mimeType, String id, InputStream message, String transformerId) throws MetacardCreationException {
Metacard generatedMetacard = null;
List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
List<String> stackTraceList = new ArrayList<>();
LOGGER.trace("Entering generateMetacard.");
LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
if (null != message) {
IOUtils.copy(message, fileBackedOutputStream);
} else {
throw new MetacardCreationException("Could not copy bytes of content message. Message was NULL.");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not copy bytes of content message.", e);
}
Iterator<InputTransformer> it = listOfCandidates.iterator();
if (StringUtils.isNotEmpty(transformerId)) {
BundleContext bundleContext = getBundleContext();
Collection<ServiceReference<InputTransformer>> serviceReferences = bundleContext.getServiceReferences(InputTransformer.class, "(id=" + transformerId + ")");
it = serviceReferences.stream().map(bundleContext::getService).iterator();
}
while (it.hasNext()) {
InputTransformer transformer = it.next();
try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) {
generatedMetacard = transformer.transform(inputStreamMessageCopy);
} catch (CatalogTransformerException | IOException e) {
List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
stackTraceList.add(String.format("Transformer [%s] could not create metacard.", transformer));
stackTraceList.addAll(stackTraces);
LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e);
}
if (generatedMetacard != null) {
break;
}
}
if (generatedMetacard == null) {
throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeType, StringUtils.join(stackTraceList, "\n")));
}
if (id != null) {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
} else {
LOGGER.debug("Metacard had a null id");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not create metacard.", e);
} catch (InvalidSyntaxException e) {
throw new MetacardCreationException("Could not determine transformer", e);
}
return generatedMetacard;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryObjectsWithEmptyMetadata.
@Test(expected = FederationAdminException.class)
public void testGetRegistryObjectsWithEmptyMetadata() throws Exception {
Metacard metacard = getTestMetacard();
metacard.setAttribute(new AttributeImpl(Metacard.METADATA, ""));
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, metacard);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
federationAdminServiceImpl.getRegistryObjects();
verify(catalogFramework).query(any(QueryRequest.class));
verify(parser, never()).unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class));
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryMetacards.
@Test
public void testGetRegistryMetacards() throws Exception {
Metacard findThisMetacard = testMetacard;
findThisMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true));
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, findThisMetacard, getTestMetacard());
when(security.getSystemSubject()).thenReturn(subject);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
List<Metacard> metacards = federationAdminServiceImpl.getRegistryMetacards();
assertThat(metacards, hasSize(2));
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminServiceImplTest method getPopulatedRemoteTestRegistryMetacard.
private Metacard getPopulatedRemoteTestRegistryMetacard() {
Metacard mcard = getPopulatedTestRegistryMetacard();
mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_REGISTRY_ID, "RemoteRegId"));
return mcard;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntryWithInvalidMetacardNoRegistryTag.
@Test(expected = FederationAdminException.class)
public void testAddRegistryEntryWithInvalidMetacardNoRegistryTag() throws Exception {
String destination = TEST_DESTINATION;
Metacard metacard = getTestMetacard();
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, Collections.singletonList(null)));
Set<String> destinations = new HashSet<>();
destinations.add(destination);
federationAdminServiceImpl.addRegistryEntry(metacard, destinations);
verify(catalogFramework, never()).create(any(CreateRequest.class));
}
Aggregations