Search in sources :

Example 1 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class ComponentManager method getOrderedComponents.

private List<Component> getOrderedComponents(List<Component> components) {
    List<Component> ordered = new ArrayList<Component>();
    for (int i = 0; i < components.size(); i++) {
        Component component = components.get(i);
        boolean added = false;
        for (int j = 0; j < ordered.size(); j++) {
            Component current = ordered.get(j);
            if (null != current.getDependencies() && current.getDependencies().contains(component.getCode())) {
                ordered.add(j, component);
                added = true;
                break;
            }
        }
        if (!added) {
            ordered.add(component);
        }
    }
    return ordered;
}
Also used : ArrayList(java.util.ArrayList) Component(org.entando.entando.aps.system.init.model.Component)

Example 2 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class ComponentManager method loadComponents.

protected void loadComponents() throws ApsSystemException {
    try {
        ComponentLoader loader = new ComponentLoader(this.getLocationPatterns(), this.getPostProcessClasses());
        Map<String, Component> componentMap = loader.getComponents();
        List<Component> components = new ArrayList<Component>();
        components.addAll(componentMap.values());
        List<Component> orderedComponents = this.getOrderedComponents(components);
        this.setComponents(orderedComponents);
    } catch (Throwable t) {
        _logger.error("Error loading components definitions", t);
        throw new ApsSystemException("Error loading components definitions", t);
    }
}
Also used : ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Component(org.entando.entando.aps.system.init.model.Component) ComponentLoader(org.entando.entando.aps.system.init.util.ComponentLoader)

Example 3 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class ComponentDefDOM method getComponent.

protected Component getComponent(Map<String, String> postProcessClasses) {
    Component component = null;
    try {
        Element rootElement = this._doc.getRootElement();
        component = new Component(rootElement, postProcessClasses);
    } catch (Throwable t) {
        _logger.error("Error loading component", t);
    }
    return component;
}
Also used : Element(org.jdom.Element) Component(org.entando.entando.aps.system.init.model.Component)

Example 4 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class ComponentLoader method loadComponent.

private void loadComponent(String locationPattern, Map<String, String> postProcessClasses) throws Throwable {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources(locationPattern);
    ComponentDefDOM dom = null;
    Set<String> codes = new HashSet<String>();
    for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        InputStream is = null;
        String path = resource.getURL().getPath();
        try {
            is = resource.getInputStream();
            String xml = FileTextReader.getText(is);
            dom = new ComponentDefDOM(xml, path);
            Component component = dom.getComponent(postProcessClasses);
            if (null != component) {
                if (codes.add(component.getCode())) {
                    _logger.debug("Component '{}' loaded", component.getCode());
                    this.getComponents().put(component.getCode(), component);
                } else {
                    _logger.debug("Component '{}' already loaded", component.getCode());
                }
            }
        } catch (Throwable t) {
            _logger.error("Error loading Component definition by location Pattern '{}'", path, t);
        } finally {
            if (null != is) {
                is.close();
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Component(org.entando.entando.aps.system.init.model.Component) HashSet(java.util.HashSet)

Example 5 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class DatabaseAction method checkRestore.

public boolean checkRestore(List<Component> currentComponents, DataSourceDumpReport report) {
    List<String> codes = new ArrayList<String>();
    codes.add("entandoCore");
    for (int i = 0; i < currentComponents.size(); i++) {
        Component component = currentComponents.get(i);
        codes.add(component.getCode());
    }
    List<ComponentInstallationReport> reports = report.getComponentsHistory();
    if (reports.size() != codes.size()) {
        return false;
    }
    for (int i = 0; i < reports.size(); i++) {
        ComponentInstallationReport componentReport = reports.get(i);
        if (!codes.contains(componentReport.getComponentCode())) {
            return false;
        }
    }
    return true;
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) ArrayList(java.util.ArrayList) Component(org.entando.entando.aps.system.init.model.Component)

Aggregations

Component (org.entando.entando.aps.system.init.model.Component)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 ArrayList (java.util.ArrayList)3 ComponentInstallationReport (org.entando.entando.aps.system.init.model.ComponentInstallationReport)2 DataSourceDumpReport (org.entando.entando.aps.system.init.model.DataSourceDumpReport)2 Resource (org.springframework.core.io.Resource)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ComponentEnvironment (org.entando.entando.aps.system.init.model.ComponentEnvironment)1 IPostProcess (org.entando.entando.aps.system.init.model.IPostProcess)1 SystemInstallationReport (org.entando.entando.aps.system.init.model.SystemInstallationReport)1 ComponentLoader (org.entando.entando.aps.system.init.util.ComponentLoader)1 Element (org.jdom.Element)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1