Search in sources :

Example 31 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class DefaultPluginDependencyManager method getDependenciesToUpdate.

@Override
public PluginDependencyResult getDependenciesToUpdate(final Plugin existingPlugin, final Plugin newPlugin, final PluginStatusResolver pluginStatusResolver) {
    Set<PluginDependencyInformation> dependentPlugins = getDependentPlugins(Collections.singletonList(existingPlugin), false, pluginStatusResolver);
    Set<PluginDependencyInformation> dependenciesToDisableUnsatisfiedAfterUpdate = new HashSet<PluginDependencyInformation>();
    for (Plugin plugin : pluginAccessor.getPlugins()) {
        if (pluginStatusResolver.isPluginNotInstalled(plugin)) {
            continue;
        }
        for (PluginDependencyInformation dependencyInfo : plugin.getRequiredPlugins()) {
            if (dependencyInfo.getIdentifier().equals(existingPlugin.getIdentifier())) {
                if (!dependencyInfo.contains(newPlugin.getVersion())) {
                    dependenciesToDisableUnsatisfiedAfterUpdate.add(new PluginDependencyInformation(plugin.getIdentifier()));
                }
                break;
            }
        }
    }
    return PluginDependencyResultImpl.dependenciesToUpdate(dependentPlugins, dependenciesToDisableUnsatisfiedAfterUpdate);
}
Also used : PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin)

Example 32 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class DefaultPluginDependencyManager method createPluginsMapWithDependencies.

private Map<String, Set<String>> createPluginsMapWithDependencies(final Collection<Plugin> plugins) {
    Map<String, Set<String>> resultMap = new HashMap<String, Set<String>>();
    for (Plugin plugin : plugins) {
        resultMap.put(plugin.getIdentifier(), null);
    }
    for (Plugin plugin : plugins) {
        Set<String> dependencyIdentifiers = new HashSet<String>();
        for (PluginDependencyInformation dependency : plugin.getRequiredPlugins()) {
            if (resultMap.containsKey(dependency.getIdentifier())) {
                dependencyIdentifiers.add(dependency.getIdentifier());
            }
        }
        resultMap.put(plugin.getIdentifier(), dependencyIdentifiers);
    }
    return resultMap;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Plugin(com.qcadoo.plugin.api.Plugin) HashSet(java.util.HashSet)

Example 33 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class DefaultPluginManager method enablePlugin.

@Override
public PluginOperationResult enablePlugin(final String... keys) {
    List<Plugin> plugins = new ArrayList<Plugin>();
    for (String key : keys) {
        Plugin plugin = pluginAccessor.getPlugin(key);
        if (!plugin.hasState(PluginState.ENABLED)) {
            plugins.add(plugin);
        }
    }
    if (plugins.isEmpty()) {
        return PluginOperationResultImpl.success();
    }
    PluginDependencyResult pluginDependencyResult = pluginDependencyManager.getDependenciesToEnable(plugins, pluginStatusResolver);
    if (pluginDependencyResult.isCyclic()) {
        return PluginOperationResultImpl.dependenciesCyclesExists();
    }
    if (!pluginDependencyResult.isDependenciesSatisfied()) {
        if (!pluginDependencyResult.getUnsatisfiedDependencies().isEmpty()) {
            return PluginOperationResultImpl.unsatisfiedDependencies(pluginDependencyResult);
        }
        if (!pluginDependencyResult.getDependenciesToEnable().isEmpty()) {
            return PluginOperationResultImpl.dependenciesToEnable(pluginDependencyResult);
        }
    }
    boolean shouldRestart = false;
    List<String> fileNames = new ArrayList<String>();
    for (Plugin plugin : plugins) {
        if (plugin.hasState(PluginState.TEMPORARY)) {
            fileNames.add(plugin.getFilename());
        }
    }
    if (!fileNames.isEmpty()) {
        if (!pluginFileManager.installPlugin(fileNames.toArray(new String[fileNames.size()]))) {
            return PluginOperationResultImpl.cannotInstallPlugin();
        }
        shouldRestart = true;
    }
    plugins = pluginDependencyManager.sortPluginsInDependencyOrder(plugins);
    for (Plugin plugin : plugins) {
        if (plugin.hasState(PluginState.TEMPORARY)) {
            ((InternalPlugin) plugin).changeStateTo(PluginState.ENABLING);
        } else {
            try {
                ((InternalPlugin) plugin).changeStateTo(PluginState.ENABLED);
            } catch (Exception e) {
                LOG.error(e.getMessage());
                ((InternalPlugin) plugin).changeStateTo(PluginState.DISABLED);
                return PluginOperationResultImpl.pluginEnablingEncounteredErrors();
            }
        }
        pluginDao.save(plugin);
        pluginAccessor.savePlugin(plugin);
    }
    if (shouldRestart) {
        return PluginOperationResultImpl.successWithRestart();
    } else {
        return PluginOperationResultImpl.success();
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PluginException(com.qcadoo.plugin.internal.PluginException) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin)

Example 34 with Plugin

use of com.qcadoo.plugin.api.Plugin in project mes by qcadoo.

the class AdvancedGenealogyTreeServiceTest method shouldReturnCorrectUsedToProduceTreeForOrders.

@Test
@Ignore
public void shouldReturnCorrectUsedToProduceTreeForOrders() {
    // given
    Plugin plugin = mock(Plugin.class);
    when(pluginAccessor.getPlugin("advancedGenealogyForOrders")).thenReturn(plugin);
    when(batch1Tr.getStringField("entityType")).thenReturn(TrackingRecordType.FOR_ORDER);
    Entity genProdInComp = mock(Entity.class);
    EntityList genProdInComps = mockEntityList(asList(genProdInComp));
    Entity prodInBatch = mock(Entity.class);
    when(prodInBatch.getBelongsToField("batch")).thenReturn(batch2);
    EntityList prodInBatches = mockEntityList(asList(prodInBatch));
    when(genProdInComp.getHasManyField("productInBatches")).thenReturn(prodInBatches);
    when(batch1Tr.getHasManyField("genealogyProductInComponents")).thenReturn(genProdInComps);
    // when
    List<Entity> tree = treeService.getUsedToProduceTree(batch2, true, false);
    // then
    assertEquals(2, tree.size());
    assertEquals(batch2, tree.get(0));
    assertEquals(batch1, tree.get(1));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) Plugin(com.qcadoo.plugin.api.Plugin) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with Plugin

use of com.qcadoo.plugin.api.Plugin in project mes by qcadoo.

the class AdvancedGenealogyTreeServiceTest method shouldReturnCorrectProducedFromTreeForOrders.

@Test
@Ignore
public void shouldReturnCorrectProducedFromTreeForOrders() {
    // given
    Plugin plugin = mock(Plugin.class);
    when(pluginAccessor.getPlugin("advancedGenealogyForOrders")).thenReturn(plugin);
    when(batch1Tr.getStringField("entityType")).thenReturn(TrackingRecordType.FOR_ORDER);
    Entity genProdInComp = mock(Entity.class);
    EntityList genProdInComps = mockEntityList(asList(genProdInComp));
    Entity prodInBatch = mock(Entity.class);
    when(prodInBatch.getBelongsToField("batch")).thenReturn(batch2);
    EntityList prodInBatches = mockEntityList(asList(prodInBatch));
    when(genProdInComp.getHasManyField("productInBatches")).thenReturn(prodInBatches);
    when(batch1Tr.getHasManyField("genealogyProductInComponents")).thenReturn(genProdInComps);
    // when
    List<Entity> tree = treeService.getProducedFromTree(batch1, true, false);
    // then
    assertEquals(2, tree.size());
    assertEquals(batch1, tree.get(0));
    assertEquals(batch2, tree.get(1));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) Plugin(com.qcadoo.plugin.api.Plugin) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Plugin (com.qcadoo.plugin.api.Plugin)71 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)59 Test (org.junit.Test)58 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)38 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)28 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)15 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)13 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)11 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)8 Version (com.qcadoo.plugin.api.Version)8 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)8 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 InOrder (org.mockito.InOrder)6 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)5 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)4 Entity (com.qcadoo.model.api.Entity)2 EntityList (com.qcadoo.model.api.EntityList)2 Module (com.qcadoo.plugin.api.Module)2 PluginException (com.qcadoo.plugin.internal.PluginException)2