Search in sources :

Example 1 with ImporterDescriptor

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

the class ImportersResourceImpl method getImportersPage.

@Override
public Page<ImporterDescriptor> getImportersPage() throws Exception {
    List<ImporterDescriptor> descriptors = new ArrayList<>();
    Map<String, ServiceReference<Importer>> importers = trackerService.getImporters();
    if (importers != null && importers.size() > 0) {
        for (Map.Entry<String, ServiceReference<Importer>> entry : importers.entrySet()) {
            ServiceReference<Importer> serviceReference = entry.getValue();
            Bundle bundle = serviceReference.getBundle();
            Importer importer = 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 = importer.isProfiled();
            ImporterDescriptor descriptor = new ImporterDescriptor();
            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();
            if (profiled) {
                String[] supportedProfilesIds = CollectionUtil.getArray(configAsProperties.getProperty(ImExCorePropsKeys.MANAGES_PROFILES_LIST));
                descriptor.setSupportedProfilesIds(supportedProfilesIds);
            }
            descriptors.add(descriptor);
            Collections.sort(descriptors, new ImporterDescriptorNameComparator());
        }
    } else {
        _log.debug("No registered importers");
    }
    return Page.of(descriptors);
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ImporterDescriptor(com.liferay.imex.rest.trigger.api.dto.v1_0.ImporterDescriptor) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) ImporterDescriptorNameComparator(com.liferay.imex.rest.trigger.api.comparator.ImporterDescriptorNameComparator) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Map(java.util.Map) Importer(com.liferay.imex.core.api.importer.Importer)

Aggregations

ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)1 Importer (com.liferay.imex.core.api.importer.Importer)1 ImporterDescriptorNameComparator (com.liferay.imex.rest.trigger.api.comparator.ImporterDescriptorNameComparator)1 ImporterDescriptor (com.liferay.imex.rest.trigger.api.dto.v1_0.ImporterDescriptor)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