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);
}
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;
}
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();
}
}
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));
}
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));
}
Aggregations