Search in sources :

Example 1 with ExporterDescriptor

use of com.liferay.imex.rest.trigger.api.dto.v1_0.ExporterDescriptor in project liferay-imex by jpdacunha.

the class ExportersResourceImpl method getExportersPage.

@Override
public Page<ExporterDescriptor> getExportersPage() throws Exception {
    List<ExporterDescriptor> descriptors = new ArrayList<>();
    Map<String, ServiceReference<Exporter>> exporters = trackerService.getExporters();
    if (exporters != null && exporters.size() > 0) {
        for (Map.Entry<String, ServiceReference<Exporter>> entry : exporters.entrySet()) {
            ServiceReference<Exporter> serviceReference = entry.getValue();
            Bundle bundle = serviceReference.getBundle();
            Exporter exporter = bundle.getBundleContext().getService(serviceReference);
            String ranking = (Integer) serviceReference.getProperty(OSGIServicePropsKeys.SERVICE_RANKING) + "";
            String description = (String) serviceReference.getProperty(OSGIServicePropsKeys.IMEX_COMPONENT_DESCRIPTION);
            String priority = (String) serviceReference.getProperty(OSGIServicePropsKeys.IMEX_COMPONENT_EXECUTION_PRIORITY);
            String name = bundle.getSymbolicName();
            boolean profiled = exporter.isProfiled();
            ExporterDescriptor descriptor = new ExporterDescriptor();
            descriptor.setDescription(description);
            descriptor.setName(name);
            descriptor.setPriority(Integer.valueOf(priority));
            descriptor.setProfiled(profiled);
            descriptor.setRanking(ranking);
            ImexProperties config = new ImexProperties();
            configurationService.loadCoreConfiguration(config);
            Properties configAsProperties = config.getProperties();
            String[] supportedProfilesIds = CollectionUtil.getArray(configAsProperties.getProperty(ImExCorePropsKeys.MANAGES_PROFILES_LIST));
            descriptor.setSupportedProfilesIds(supportedProfilesIds);
            descriptors.add(descriptor);
            Collections.sort(descriptors, new ExporterDescriptorNameComparator());
        }
    } else {
        _log.debug("No registered exporters");
    }
    return Page.of(descriptors);
}
Also used : Bundle(org.osgi.framework.Bundle) ExporterDescriptorNameComparator(com.liferay.imex.rest.trigger.api.comparator.ExporterDescriptorNameComparator) ArrayList(java.util.ArrayList) Exporter(com.liferay.imex.core.api.exporter.Exporter) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) ExporterDescriptor(com.liferay.imex.rest.trigger.api.dto.v1_0.ExporterDescriptor) Map(java.util.Map)

Aggregations

ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)1 Exporter (com.liferay.imex.core.api.exporter.Exporter)1 ExporterDescriptorNameComparator (com.liferay.imex.rest.trigger.api.comparator.ExporterDescriptorNameComparator)1 ExporterDescriptor (com.liferay.imex.rest.trigger.api.dto.v1_0.ExporterDescriptor)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Bundle (org.osgi.framework.Bundle)1 ServiceReference (org.osgi.framework.ServiceReference)1