Search in sources :

Example 1 with ReportImpl

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;
}
Also used : IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL) ReportImpl(org.codice.ddf.admin.common.report.ReportImpl)

Example 2 with ReportImpl

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;
}
Also used : Configurator(org.codice.ddf.admin.configurator.Configurator) ReportImpl(org.codice.ddf.admin.common.report.ReportImpl)

Example 3 with ReportImpl

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;
}
Also used : Configurator(org.codice.ddf.admin.configurator.Configurator) ReportImpl(org.codice.ddf.admin.common.report.ReportImpl)

Example 4 with ReportImpl

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;
}
Also used : Source(ddf.catalog.source.Source) List(java.util.List) StringField(org.codice.ddf.admin.common.fields.base.scalar.StringField) SourceUtilCommons.getAllSourceReferences(org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.getAllSourceReferences) ConfiguredService(ddf.catalog.service.ConfiguredService) ReportImpl(org.codice.ddf.admin.common.report.ReportImpl) ConfiguratorFactory(org.codice.ddf.admin.configurator.ConfiguratorFactory) SourceMessages.duplicateSourceNameError(org.codice.ddf.admin.sources.commons.SourceMessages.duplicateSourceNameError) Source(ddf.catalog.source.Source) ReportImpl(org.codice.ddf.admin.common.report.ReportImpl)

Example 5 with ReportImpl

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;
}
Also used : Configurator(org.codice.ddf.admin.configurator.Configurator) OperationReport(org.codice.ddf.admin.configurator.OperationReport) ReportImpl(org.codice.ddf.admin.common.report.ReportImpl)

Aggregations

ReportImpl (org.codice.ddf.admin.common.report.ReportImpl)5 Configurator (org.codice.ddf.admin.configurator.Configurator)3 ConfiguredService (ddf.catalog.service.ConfiguredService)1 Source (ddf.catalog.source.Source)1 IOException (java.io.IOException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 List (java.util.List)1 StringField (org.codice.ddf.admin.common.fields.base.scalar.StringField)1 ConfiguratorFactory (org.codice.ddf.admin.configurator.ConfiguratorFactory)1 OperationReport (org.codice.ddf.admin.configurator.OperationReport)1 SourceMessages.duplicateSourceNameError (org.codice.ddf.admin.sources.commons.SourceMessages.duplicateSourceNameError)1 SourceUtilCommons.getAllSourceReferences (org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.getAllSourceReferences)1