use of org.codice.ddf.admin.common.report.ReportImpl in project admin-console-beta by connexta.
the class RequestUtils method endpointIsReachable.
/**
* Attempts to open a connection to a URL.
*
* Possible Error Codes to be returned
* - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#CANNOT_CONNECT}
*
* @param urlField {@link UrlField} containing the URL to connect to
* @return a {@link ReportImpl} containing no messages on success, or containing {@link org.codice.ddf.admin.common.report.message.ErrorMessage}s on failure.
*/
public ReportImpl endpointIsReachable(UrlField urlField) {
ReportImpl report = new ReportImpl();
try {
URLConnection urlConnection = (new URL(urlField.getValue()).openConnection());
urlConnection.setConnectTimeout(500);
urlConnection.connect();
LOGGER.debug("Successfully reached {}.", urlField);
} catch (IOException e) {
LOGGER.debug("Failed to reach {}, returning an error.", urlField, e);
report.addArgumentMessage(cannotConnectError(urlField.path()));
}
return report;
}
use of org.codice.ddf.admin.common.report.ReportImpl in project admin-console-beta by connexta.
the class ServiceCommons method createManagedService.
public static ReportImpl createManagedService(Map<String, Object> serviceProps, String factoryPid, ConfiguratorFactory configuratorFactory) {
ReportImpl report = new ReportImpl();
Configurator configurator = configuratorFactory.getConfigurator();
configurator.createManagedService(factoryPid, serviceProps);
if (configurator.commit("Service saved with details [{}]", serviceProps.toString()).containsFailedResults()) {
report.addResultMessage(failedPersistError());
}
return report;
}
use of org.codice.ddf.admin.common.report.ReportImpl in project admin-console-beta by connexta.
the class ServiceCommons method deleteService.
public static ReportImpl deleteService(PidField servicePid, ConfiguratorFactory configuratorFactory) {
ReportImpl report = new ReportImpl();
Configurator configurator = configuratorFactory.getConfigurator();
configurator.deleteManagedService(servicePid.getValue());
if (configurator.commit("Deleted source with pid [{}].", servicePid.getValue()).containsFailedResults()) {
report.addResultMessage(failedDeleteError());
}
return report;
}
use of org.codice.ddf.admin.common.report.ReportImpl in project admin-console-beta by connexta.
the class SourceValidationUtils method validateSourceName.
/**
* Validates the {@code sourceName} against the existing source names in the system. An empty {@link ReportImpl} will be returned
* if there are no existing source names with with name {@code sourceName}, or a {@link ReportImpl} with error messages.
*
* @param sourceName source name to validate
* @param configuratorFactory configurator factory for reading FederatedSource service references
* @return a {@link ReportImpl} containing a {@link org.codice.ddf.admin.sources.commons.SourceMessages#DUPLICATE_SOURCE_NAME} error, or a Report with
* no messages on success.
*/
public static ReportImpl validateSourceName(StringField sourceName, ConfiguratorFactory configuratorFactory) {
List<Source> sources = getAllSourceReferences(configuratorFactory);
boolean matchFound = sources.stream().map(source -> source.getId()).anyMatch(id -> id.equals(sourceName.getValue()));
ReportImpl report = new ReportImpl();
if (matchFound) {
report.addArgumentMessage(duplicateSourceNameError(sourceName.path()));
}
return report;
}
use of org.codice.ddf.admin.common.report.ReportImpl in project admin-console-beta by connexta.
the class ServiceCommons method updateService.
public static ReportImpl updateService(PidField servicePid, Map<String, Object> newConfig, ConfiguratorFactory configuratorFactory) {
ReportImpl report = new ReportImpl();
report.addMessages(serviceConfigurationExists(servicePid, configuratorFactory));
if (report.containsErrorMsgs()) {
return report;
}
String pid = servicePid.getValue();
Configurator configurator = configuratorFactory.getConfigurator();
configurator.updateConfigFile(pid, newConfig, true);
OperationReport operationReport = configurator.commit("Updated config with pid [{}] and new service properties [{}]", pid, newConfig.toString());
if (operationReport.containsFailedResults()) {
return report.addResultMessage(failedUpdateError());
}
return report;
}
Aggregations