use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.
the class CatalogFrameworkImplTest method testGetAllSiteNames.
@Test
public void testGetAllSiteNames() {
String frameworkName = "DDF";
CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
// Expected Set of Names
Set<String> expectedNameSet = new HashSet<String>();
for (FederatedSource curSite : federatedSources) {
expectedNameSet.add(curSite.getId());
}
// Mock register the provider in the container
// Mock the source poller
SourcePoller mockPoller = mock(SourcePoller.class);
when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
FrameworkProperties frameworkProperties = new FrameworkProperties();
frameworkProperties.setSourcePoller(mockPoller);
Map<String, FederatedSource> sources = new HashMap<>();
for (FederatedSource federatedSource : federatedSources) {
sources.put(federatedSource.getId(), federatedSource);
}
frameworkProperties.setFederatedSources(sources);
frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
CatalogFrameworkImpl framework = createFramework(frameworkProperties);
framework.setId(frameworkName);
// Returned Set of Names
// Returned Sites
SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
SourceInfoResponse response = null;
try {
response = framework.getSourceInfo(request);
} catch (SourceUnavailableException e) {
LOGGER.debug("SourceUnavilable", e);
fail();
}
assert (response != null);
Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
// should contain ONLY the original federated sites
assertEquals(expectedNameSet.size(), sourceDescriptors.size());
Set<String> returnedSourceIds = new HashSet<String>();
for (SourceDescriptor sd : sourceDescriptors) {
returnedSourceIds.add(sd.getSourceId());
}
for (String id : returnedSourceIds) {
LOGGER.debug("returned sourceId: {}", id);
}
assertTrue(expectedNameSet.equals(returnedSourceIds));
}
use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise 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.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.
the class RESTEndpoint method getDocument.
/**
* REST Get. Retrieves information regarding sources available.
*
* @param uriInfo
* @param httpRequest
* @return
*/
@GET
@Path(SOURCES_PATH)
public Response getDocument(@Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
BinaryContent content;
ResponseBuilder responseBuilder;
String sourcesString = null;
JSONArray resultsList = new JSONArray();
SourceInfoResponse sources;
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()));
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);
content = new BinaryContentImpl(new ByteArrayInputStream(sourcesString.getBytes(StandardCharsets.UTF_8)), jsonMimeType);
responseBuilder = Response.ok(content.getInputStream(), content.getMimeTypeValue());
// Add the Accept-ranges header to let the client know that we accept ranges in bytes
responseBuilder.header(HEADER_ACCEPT_RANGES, BYTES);
return responseBuilder.build();
}
use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.
the class SearchService method getSourceIds.
private Set<String> getSourceIds(String sources) {
Set<String> sourceIds;
if (StringUtils.equalsIgnoreCase(sources, LOCAL_SOURCE)) {
LOGGER.debug("Received local query");
sourceIds = new HashSet<String>(Arrays.asList(searchController.getFramework().getId()));
} else if (!(StringUtils.isEmpty(sources))) {
LOGGER.debug("Received source names from client: {}", sources);
sourceIds = new HashSet<String>(Arrays.asList(StringUtils.stripAll(sources.split(","))));
} else {
LOGGER.debug("Received enterprise query");
SourceInfoResponse sourceInfo = null;
try {
sourceInfo = searchController.getFramework().getSourceInfo(new SourceInfoRequestEnterprise(true));
} catch (SourceUnavailableException e) {
LOGGER.debug("Exception while getting source status. Defaulting to all sources. " + "This could include unavailable sources.", e);
}
if (sourceInfo != null) {
sourceIds = new HashSet<String>();
for (SourceDescriptor source : sourceInfo.getSourceInfo()) {
if (source.isAvailable()) {
sourceIds.add(source.getSourceId());
}
}
} else {
sourceIds = searchController.getFramework().getSourceIds();
}
}
return sourceIds;
}
use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.
the class SourceConfigurationAdminPlugin method getConfigurationData.
/**
* Returns a map of configuration data that should be appended to the configurationDataMap
* parameter. The configurationDataMap that is passed into this function is unmodifiable and is
* passed in to simply expose what information already exists.
*
* @param configurationPid service.pid for the ConfigurationAdmin configuration
* @param configurationDataMap map of what properties have already been added to the configuration in question
* @param bundleContext used to retrieve list of services
* @return Map defining additional properties to add to the configuration
*/
@Override
public Map<String, Object> getConfigurationData(String configurationPid, Map<String, Object> configurationDataMap, BundleContext bundleContext) {
LOGGER.debug("Obtaining configuration data for the following configuration PID: {}", configurationPid);
Map<String, Object> statusMap = new HashMap<String, Object>();
try {
List<ServiceReference<? extends Source>> refs = new ArrayList<ServiceReference<? extends Source>>();
refs.addAll(bundleContext.getServiceReferences(FederatedSource.class, null));
refs.addAll(bundleContext.getServiceReferences(CatalogProvider.class, null));
Set<SourceDescriptor> sources = null;
if (catalogFramework != null) {
sources = catalogFramework.getSourceInfo(new SourceInfoRequestEnterprise(true)).getSourceInfo();
}
boolean foundSources = CollectionUtils.isNotEmpty(sources);
for (ServiceReference<? extends Source> ref : refs) {
Source superService = bundleContext.getService(ref);
if (superService instanceof ConfiguredService) {
ConfiguredService cs = (ConfiguredService) superService;
LOGGER.debug("ConfiguredService configuration PID: {}", cs.getConfigurationPid());
boolean csConfigPidMatchesTargetPid = false;
if (StringUtils.isNotEmpty(cs.getConfigurationPid()) && cs.getConfigurationPid().equals(configurationPid)) {
csConfigPidMatchesTargetPid = true;
}
if (foundSources) {
// class name, then we can match them up this way.
if (csConfigPidMatchesTargetPid || cs.getClass().getCanonicalName().equals(configurationPid)) {
for (SourceDescriptor descriptor : sources) {
if (descriptor.getSourceId().equals(superService.getId())) {
statusMap.put("available", descriptor.isAvailable());
statusMap.put("sourceId", descriptor.getSourceId());
return statusMap;
}
}
}
} else if (csConfigPidMatchesTargetPid) {
// we don't want to call isAvailable because that can
// potentially block execution but if for some reason we
// have no catalog framework, just hit the source
// directly
statusMap.put("available", superService.isAvailable());
return statusMap;
}
}
}
} catch (org.osgi.framework.InvalidSyntaxException ise) {
// this should never happen because the filter is always null
LOGGER.debug("Error reading LDAP service filter", ise);
} catch (SourceUnavailableException sue) {
LOGGER.info("Unable to retrieve sources from Catalog Framework", sue);
}
return statusMap;
}
Aggregations