use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFrameworkImplTest method testGetFederatedSources.
@Test
public void testGetFederatedSources() {
SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
SourceInfoResponse response = null;
try {
response = framework.getSourceInfo(request);
} catch (SourceUnavailableException e) {
fail();
}
Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
for (SourceDescriptor descriptor : sourceDescriptors) {
LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
}
// The "+1" is to account for the CatalogFramework source descriptor.
// Even if no local catalog provider is configured, the catalog framework's
// site info is included in the SourceDescriptos list.
assertEquals(federatedSources.size() + 1, sourceDescriptors.size());
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFrameworkImplTest method testGetUnavailableFederatedSources.
@Test
public void testGetUnavailableFederatedSources() {
List<FederatedSource> federatedSources = createDefaultFederatedSourceList(false);
CatalogProvider catalogProvider = mock(CatalogProvider.class);
FrameworkProperties frameworkProperties = new FrameworkProperties();
frameworkProperties.setFederatedSources(federatedSources);
frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
CatalogFrameworkImpl framework = createFramework(frameworkProperties);
SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
SourceInfoResponse response = null;
try {
response = framework.getSourceInfo(request);
} catch (SourceUnavailableException e) {
fail();
}
Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
for (SourceDescriptor descriptor : sourceDescriptors) {
LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
if (StringUtils.isNotBlank(descriptor.getId())) {
assertFalse(descriptor.isAvailable());
// No contentTypes should be listed if the source is unavailable
assertTrue(descriptor.getContentTypes().isEmpty());
}
}
// The "+1" is to account for the CatalogFramework source descriptor.
// Even if no local catalog provider is configured, the catalog
// framework's
// site info is included in the SourceDescriptos list.
assertEquals(federatedSources.size() + 1, sourceDescriptors.size());
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogServiceImpl method getSourcesInfo.
@Override
public BinaryContent getSourcesInfo() {
JSONArray resultsList = new JSONArray();
SourceInfoResponse sources;
String sourcesString;
try {
SourceInfoRequestEnterprise sourceInfoRequestEnterprise = new SourceInfoRequestEnterprise(true);
sources = catalogFramework.getSourceInfo(sourceInfoRequestEnterprise);
for (SourceDescriptor source : sources.getSourceInfo()) {
JSONObject sourceObj = new JSONObject();
sourceObj.put("id", source.getSourceId());
sourceObj.put("version", source.getVersion() != null ? source.getVersion() : "");
sourceObj.put("available", Boolean.valueOf(source.isAvailable()));
List<JSONObject> sourceActions = source.getActions().stream().map(super::sourceActionToJSON).collect(Collectors.toList());
sourceObj.put("sourceActions", sourceActions);
JSONArray contentTypesObj = new JSONArray();
if (source.getContentTypes() != null) {
for (ContentType contentType : source.getContentTypes()) {
if (contentType != null && contentType.getName() != null) {
JSONObject contentTypeObj = new JSONObject();
contentTypeObj.put("name", contentType.getName());
contentTypeObj.put("version", contentType.getVersion() != null ? contentType.getVersion() : "");
contentTypesObj.add(contentTypeObj);
}
}
}
sourceObj.put("contentTypes", contentTypesObj);
resultsList.add(sourceObj);
}
} catch (SourceUnavailableException e) {
LOGGER.info("Unable to retrieve Sources. {}", e.getMessage());
LOGGER.debug("Unable to retrieve Sources", e);
}
sourcesString = JSONValue.toJSONString(resultsList);
return new BinaryContentImpl(new ByteArrayInputStream(sourcesString.getBytes(StandardCharsets.UTF_8)), jsonMimeType);
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFeatureIndexer method findMetacardForFeature.
private Metacard findMetacardForFeature(SimpleFeature feature) throws FeatureIndexingException {
Object nameObject = feature.getAttribute(NAME_KEY);
if (nameObject instanceof String) {
String name = (String) nameObject;
QueryRequest queryRequest = new QueryRequestImpl(catalogHelper.getQueryForName(name));
try {
SourceResponse response = catalogFramework.query(queryRequest);
if (response.getResults().isEmpty()) {
return null;
}
return response.getResults().get(0).getMetacard();
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
throw new FeatureIndexingException(e.getMessage());
}
}
throw new FeatureIndexingException("Unable to find feature");
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFrameworkQueryTest method testDuringQuery.
@Test
public void testDuringQuery() {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard1 = new MetacardImpl();
newCard1.setId(null);
Calendar duringStart = Calendar.getInstance();
Calendar card1Exp = Calendar.getInstance();
card1Exp.add(Calendar.YEAR, 1);
Calendar duringEnd1 = Calendar.getInstance();
duringEnd1.add(Calendar.YEAR, 2);
Calendar card2Exp = Calendar.getInstance();
card2Exp.add(Calendar.YEAR, 3);
Calendar duringEnd2 = Calendar.getInstance();
duringEnd2.add(Calendar.YEAR, 4);
newCard1.setExpirationDate(card1Exp.getTime());
metacards.add(newCard1);
MetacardImpl newCard2 = new MetacardImpl();
newCard2.setId(null);
newCard2.setExpirationDate(card2Exp.getTime());
metacards.add(newCard2);
String mcId1 = null;
String mcId2 = null;
CreateResponse createResponse = null;
try {
createResponse = framework.create(new CreateRequestImpl(metacards, null));
} catch (IngestException e1) {
LOGGER.error("Failure", e1);
fail();
} catch (SourceUnavailableException e1) {
LOGGER.error("Failure", e1);
fail();
}
assertEquals(createResponse.getCreatedMetacards().size(), metacards.size());
for (Metacard curCard : createResponse.getCreatedMetacards()) {
if (curCard.getExpirationDate().equals(card1Exp.getTime())) {
mcId1 = curCard.getId();
} else {
mcId2 = curCard.getId();
}
assertNotNull(curCard.getId());
}
FilterFactory filterFactory = new FilterFactoryImpl();
Period duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd1.getTime())));
QueryImpl query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
QueryRequest queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("Expecting return 1 result.", 1, response.getHits());
assertEquals("During filter should return metacard[" + mcId1 + "]", mcId1, response.getResults().get(0).getMetacard().getId());
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Failure", e);
fail();
}
duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(card1Exp.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("During filter should return 1 result", 1, response.getHits());
assertEquals("During filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Failure", e);
fail();
}
duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("During filter should return 2 result", 2, response.getHits());
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Failure", e);
fail();
}
}
Aggregations