Search in sources :

Example 6 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method addRegistryEntries.

@Override
public List<String> addRegistryEntries(List<Metacard> metacards, Set<String> destinations) throws FederationAdminException {
    validateRegistryMetacards(metacards);
    List<String> registryIds;
    Map<String, Serializable> properties = new HashMap<>();
    CreateRequest createRequest = new CreateRequestImpl(metacards, properties, destinations);
    try {
        CreateResponse createResponse = security.runWithSubjectOrElevate(() -> catalogFramework.create(createRequest));
        //loop through to get id's
        if (!createResponse.getProcessingErrors().isEmpty()) {
            throw new FederationAdminException("Processing error occurred while creating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(createResponse.getProcessingErrors()));
        }
        registryIds = createResponse.getCreatedMetacards().stream().filter(RegistryUtility::isRegistryMetacard).map(RegistryUtility::getRegistryId).collect(Collectors.toList());
    } catch (SecurityServiceException | InvocationTargetException e) {
        throw new FederationAdminException("Error adding local registry entry.", e);
    }
    return registryIds;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl)

Example 7 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdmin method allRegistryMetacardsSummary.

@Override
public Map<String, Object> allRegistryMetacardsSummary() {
    Map<String, Object> nodes = new HashMap<>();
    if (!cacheInitialized) {
        try {
            federationAdminService.getRegistryMetacards().stream().forEach(metacard -> summaryCache.put(RegistryUtility.getRegistryId(metacard), getSummaryMap(metacard)));
            cacheInitialized = true;
        } catch (FederationAdminException e) {
            LOGGER.info("Couldn't get remote registry metacards ", e);
        }
    }
    if (customSlots != null) {
        nodes.put(CUSTOM_SLOTS_KEY, customSlots);
    }
    Map<String, Object> autoPopulateMap = new HashMap<>();
    autoPopulateMap.put(SERVICE_BINDINGS_KEY, endpointMap.values());
    nodes.put(AUTO_POPULATE_VALUES_KEY, autoPopulateMap);
    nodes.put(NODES_KEY, new ArrayList(summaryCache.values()));
    return nodes;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 8 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class SourceConfigurationHandler method regenerateOneSource.

@Override
public void regenerateOneSource(String registryId) throws FederationAdminException {
    try {
        List<Metacard> metacards = federationAdminService.getRegistryMetacardsByRegistryIds(Collections.singletonList(registryId));
        if (metacards.size() != 1) {
            throw new FederationAdminException("Error looking up metacard to regenerate sources. registry-id=" + registryId);
        }
        deleteRegistryConfigurations(metacards.get(0));
        updateRegistryConfigurations(metacards.get(0), true);
    } catch (IOException | ParserException | InvalidSyntaxException e) {
        throw new FederationAdminException("Error regenerating sources for registry entry " + registryId, e);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) ParserException(org.codice.ddf.parser.ParserException) Metacard(ddf.catalog.data.Metacard) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException)

Example 9 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method getLocalRegistryIdentityMetacard.

@Override
public Optional<Metacard> getLocalRegistryIdentityMetacard() throws FederationAdminException {
    Optional<Metacard> metacardOptional = Optional.empty();
    List<Filter> filters = getBasicFilter();
    filters.add(filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE).is().bool(true));
    Filter filter = filterBuilder.allOf(filters);
    List<Metacard> identityMetacards = getRegistryMetacardsByFilter(filter);
    if (CollectionUtils.isNotEmpty(identityMetacards)) {
        if (identityMetacards.size() > 1) {
            String message = "Error getting registry identity metacard. More than one result found.";
            LOGGER.debug("{} Found these: {}", message, identityMetacards);
            throw new FederationAdminException(message);
        }
        metacardOptional = Optional.of(identityMetacards.get(0));
    }
    return metacardOptional;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter)

Example 10 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method updateRegistryEntry.

@Override
public void updateRegistryEntry(Metacard updateMetacard, Set<String> destinations) throws FederationAdminException {
    validateRegistryMetacards(Collections.singletonList(updateMetacard));
    Map<String, Serializable> properties = new HashMap<>();
    String mcardId = updateMetacard.getId();
    if (isRemoteMetacard(updateMetacard) || CollectionUtils.isNotEmpty(destinations)) {
        Filter idFilter = filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(updateMetacard.getId());
        Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
        List<Metacard> results = this.getRegistryMetacardsByFilter(filterBuilder.allOf(tagFilter, idFilter), destinations);
        if (results.size() != 1) {
            throw new FederationAdminException("Could not find metacard to update.");
        }
        mcardId = results.get(0).getId();
        LOGGER.debug("Looked up remote-mcard-id {} and got id {}", updateMetacard.getId(), mcardId);
    }
    List<Map.Entry<Serializable, Metacard>> updateList = new ArrayList<>();
    updateList.add(new AbstractMap.SimpleEntry<>(mcardId, updateMetacard));
    UpdateRequest updateRequest = new UpdateRequestImpl(updateList, Metacard.ID, properties, destinations);
    try {
        UpdateResponse updateResponse = security.runWithSubjectOrElevate(() -> catalogFramework.update(updateRequest));
        if (!updateResponse.getProcessingErrors().isEmpty()) {
            throw new FederationAdminException("Processing error occurred while updating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(updateResponse.getProcessingErrors()));
        }
    } catch (SecurityServiceException | InvocationTargetException e) {
        String message = "Error updating registry entry.";
        LOGGER.debug("{} Metacard ID: {}", message, updateMetacard.getId());
        throw new FederationAdminException(message, e);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractMap(java.util.AbstractMap) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl)

Aggregations

FederationAdminException (org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException)30 Metacard (ddf.catalog.data.Metacard)16 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 SecurityServiceException (ddf.security.service.SecurityServiceException)7 Serializable (java.io.Serializable)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 RegistryPackageType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType)7 Filter (org.opengis.filter.Filter)7 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)6 Result (ddf.catalog.data.Result)5 PropertyNameImpl (ddf.catalog.filter.impl.PropertyNameImpl)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 List (java.util.List)5 Map (java.util.Map)5 RegistryUtility (org.codice.ddf.registry.common.metacard.RegistryUtility)5 SortByImpl (org.geotools.filter.SortByImpl)5