Search in sources :

Example 1 with ServiceBindingType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType in project ddf by codice.

the class ServiceBindingWebConverter method convert.

/**
     * This method creates a Map<String, Object> representation of the ServiceBindingType provided.
     * The following keys will be added to the map (Taken from EbrimConstants):
     * <p>
     * ACCESS_URI = "accessUri";
     * SERVICE = "service";
     * TARGET_BINDING = "targetBinding";
     * SPECIFICATION_LINK_KEY = "SpecificationLink";
     * <p>
     * This will also try to parse RegistryObjectType values to the map.
     * <p>
     * Uses:
     * SpecificationLinkWebConverter
     *
     * @param binding the ServiceBindingType to be converted into a map, null returns empty Map
     * @return Map<String, Object> representation of the ServiceBindingType provided
     */
public Map<String, Object> convert(ServiceBindingType binding) {
    Map<String, Object> bindingMap = new HashMap<>();
    if (binding == null) {
        return bindingMap;
    }
    webMapHelper.putAllIfNotEmpty(bindingMap, super.convertRegistryObject(binding));
    webMapHelper.putIfNotEmpty(bindingMap, ACCESS_URI, binding.getAccessURI());
    webMapHelper.putIfNotEmpty(bindingMap, SERVICE, binding.getService());
    if (binding.isSetSpecificationLink()) {
        List<Map<String, Object>> specificationLinks = new ArrayList<>();
        SpecificationLinkWebConverter specificationLinkConverter = new SpecificationLinkWebConverter();
        for (SpecificationLinkType specificationLink : binding.getSpecificationLink()) {
            Map<String, Object> specificationLinkMap = specificationLinkConverter.convert(specificationLink);
            if (MapUtils.isNotEmpty(specificationLinkMap)) {
                specificationLinks.add(specificationLinkMap);
            }
        }
        webMapHelper.putIfNotEmpty(bindingMap, SPECIFICATION_LINK_KEY, specificationLinks);
    }
    webMapHelper.putIfNotEmpty(bindingMap, TARGET_BINDING, binding.getTargetBinding());
    return bindingMap;
}
Also used : HashMap(java.util.HashMap) SpecificationLinkType(oasis.names.tc.ebxml_regrep.xsd.rim._3.SpecificationLinkType) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ServiceBindingType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType in project ddf by codice.

the class SourceConfigurationHandler method getServiceBindingProperties.

/**
     * Returns the service binding slots as a map of string properties with the slot name as the key
     *
     * @param binding ServiceBindingType to generate the map from
     * @return A map of service binding slots
     */
private Map<String, Object> getServiceBindingProperties(ServiceBindingType binding) {
    Map<String, Object> properties = new HashMap<>();
    for (SlotType1 slot : binding.getSlot()) {
        List<String> slotValues = slotHelper.getStringValues(slot);
        if (CollectionUtils.isEmpty(slotValues)) {
            continue;
        }
        properties.put(slot.getName(), slotValues.size() == 1 ? slotValues.get(0) : slotValues);
    }
    if (binding.isSetAccessURI() && properties.get(urlBindingName) != null) {
        properties.put(properties.get(urlBindingName).toString(), binding.getAccessURI());
    }
    return properties;
}
Also used : SlotType1(oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with ServiceBindingType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType in project ddf by codice.

the class SourceConfigurationHandler method updateRegistryConfigurations.

/**
     * Finds all source configurations associated with the registry metacard creates/updates them
     * with the information in the metacards service bindings. This method will enable/disable
     * configurations if the right conditions are met but will never delete a configuration other
     * than for switching a configuration from enabled to disabled or vice-versa
     *
     * @param metacard       Registry metacard with new service binding info
     * @param activationHint Flag indicating if the created/updated configuration should be activated.
     *                       Configuration activation is not determined solely on this field but in
     *                       conjunction with {@see setActivateConfigurations} and {@see setPreserveActiveConfigurations}.
     * @throws IOException
     * @throws InvalidSyntaxException
     * @throws ParserException
     */
private synchronized void updateRegistryConfigurations(Metacard metacard, boolean activationHint) throws IOException, InvalidSyntaxException, ParserException {
    if (RegistryUtility.isIdentityNode(metacard)) {
        return;
    }
    boolean autoActivateConfigurations = activateConfigurations && (activationHint || !preserveActiveConfigurations);
    List<ServiceBindingType> bindingTypes = registryTypeHelper.getBindingTypes(metacardMarshaller.getRegistryPackageFromMetacard(metacard));
    String registryId = RegistryUtility.getRegistryId(metacard);
    String configId = getDeconflictedConfigId(metacard.getTitle(), registryId);
    Map<String, Configuration> fpidToConfigurationMap = getCurrentConfigurations(registryId);
    String bindingTypeToActivate = "";
    if (autoActivateConfigurations) {
        bindingTypeToActivate = getBindingTypeToActivate(bindingTypes);
        if (StringUtils.isNotEmpty(bindingTypeToActivate)) {
            String fPidToActivate = bindingTypeToFactoryPidMap.get(bindingTypeToActivate);
            activateDeactivateExistingConfiguration(fPidToActivate, fpidToConfigurationMap, bindingTypeToActivate);
        }
    }
    for (ServiceBindingType bindingType : bindingTypes) {
        Map<String, Object> slotMap = this.getServiceBindingProperties(bindingType);
        String factoryPidMask = (String) slotMap.get(BINDING_TYPE);
        if (factoryPidMask == null) {
            continue;
        }
        String factoryPid = bindingTypeToFactoryPidMap.get(factoryPidMask);
        if (StringUtils.isBlank(factoryPid)) {
            continue;
        }
        Configuration curConfig = findOrCreateConfig(factoryPid, fpidToConfigurationMap, factoryPidMask, (autoActivateConfigurations && factoryPidMask.equals(bindingTypeToActivate)));
        Hashtable<String, Object> serviceConfigurationProperties = new Hashtable<>();
        if (fpidToConfigurationMap.containsKey(curConfig.getFactoryPid().concat(getConfigStringProperty(curConfig, BINDING_TYPE)))) {
            serviceConfigurationProperties.putAll(getConfigurationsFromDictionary(curConfig.getProperties()));
        } else {
            serviceConfigurationProperties.putAll(getMetatypeDefaults(factoryPid));
        }
        serviceConfigurationProperties.putAll(slotMap);
        serviceConfigurationProperties.put(ID, configId);
        serviceConfigurationProperties.put(SHORTNAME, configId);
        serviceConfigurationProperties.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, registryId);
        curConfig.update(serviceConfigurationProperties);
        LOGGER.debug("Updating source configuration {} with registry-id {}", configId, registryId);
        fpidToConfigurationMap.remove(curConfig.getFactoryPid().concat(factoryPidMask));
    }
    //if a binding was removed the configuration could still exist, If the registry
    //entry gets renamed the non-binding configs will not get renamed appropriately so we
    //go through them here and make sure the name is set correctly.
    fpidToConfigurationMap.values().stream().forEach(config -> {
        try {
            Dictionary<String, Object> properties = config.getProperties();
            properties.put(ID, configId);
            properties.put(SHORTNAME, configId);
            config.update(properties);
        } catch (IOException e) {
            LOGGER.debug("Could not remove configuration for {}:{}", config.getProperties().get(ID), config.getFactoryPid());
        }
    });
}
Also used : ServiceBindingType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType) RegistrySourceConfiguration(org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) IOException(java.io.IOException)

Example 4 with ServiceBindingType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType in project ddf by codice.

the class SourceConfigurationHandler method getBindingTypeToActivate.

private String getBindingTypeToActivate(List<ServiceBindingType> bindingTypes) {
    String bindingTypeToActivate = null;
    String topPriority = sourceActivationPriorityOrder.get(0);
    List<String> bindingTypesNames = new ArrayList<>();
    for (ServiceBindingType bindingType : bindingTypes) {
        Map<String, Object> slotMap = this.getServiceBindingProperties(bindingType);
        if (slotMap.get(BINDING_TYPE) == null) {
            continue;
        }
        String factoryPidMask = slotMap.get(BINDING_TYPE).toString();
        if (StringUtils.isNotBlank(factoryPidMask)) {
            if (factoryPidMask.equals(topPriority)) {
                return factoryPidMask;
            }
            bindingTypesNames.add(factoryPidMask);
        }
    }
    for (String prioritySource : sourceActivationPriorityOrder.subList(1, sourceActivationPriorityOrder.size())) {
        if (bindingTypesNames.contains(prioritySource)) {
            return prioritySource;
        }
    }
    return bindingTypeToActivate;
}
Also used : ServiceBindingType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with ServiceBindingType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType in project ddf by codice.

the class ServiceWebConverter method convert.

/**
     * This method creates a Map<String, Object> representation of the ServiceType provided.
     * The following keys will be added to the map (Taken from EbrimConstants):
     * <p>
     * SERVICE_BINDING_KEY = "ServiceBinding";
     * <p>
     * This will also try to parse RegistryObjectType values to the map.
     * <p>
     * Uses:
     * ServiceBindingWebConverter
     *
     * @param service the ServiceType to be converted into a map, null returns empty Map
     * @return Map<String, Object> representation of the ServiceType provided
     */
public Map<String, Object> convert(ServiceType service) {
    Map<String, Object> serviceMap = new HashMap<>();
    if (service == null) {
        return serviceMap;
    }
    webMapHelper.putAllIfNotEmpty(serviceMap, super.convertRegistryObject(service));
    if (service.isSetServiceBinding()) {
        List<Map<String, Object>> bindings = new ArrayList<>();
        ServiceBindingWebConverter bindingConverter = new ServiceBindingWebConverter();
        for (ServiceBindingType binding : service.getServiceBinding()) {
            Map<String, Object> bindingMap = bindingConverter.convert(binding);
            if (MapUtils.isNotEmpty(bindingMap)) {
                bindings.add(bindingMap);
            }
        }
        webMapHelper.putIfNotEmpty(serviceMap, SERVICE_BINDING_KEY, bindings);
    }
    return serviceMap;
}
Also used : ServiceBindingType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ServiceBindingType (oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceBindingType)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 List (java.util.List)2 Map (java.util.Map)2 SlotType1 (oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1)2 IOException (java.io.IOException)1 Hashtable (java.util.Hashtable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 RegistryObjectListType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectListType)1 RegistryPackageType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType)1 SpecificationLinkType (oasis.names.tc.ebxml_regrep.xsd.rim._3.SpecificationLinkType)1 RegistrySourceConfiguration (org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration)1 Test (org.junit.Test)1 Configuration (org.osgi.service.cm.Configuration)1