Skip to content

Commit

Permalink
#192 Fix ConfigurationArtifact and improve PluginGenerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeijer committed Feb 26, 2015
1 parent 6db7cfb commit a7751c7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 120 deletions.
187 changes: 71 additions & 116 deletions src/plugin/coreplugins/ConfigurationArtifact/ConfigurationArtifact.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/*globals define*/
/**
* Generated by PluginGenerator from webgme on Mon May 05 2014 14:59:04 GMT-0500 (Central Daylight Time).
*/
* Simple plugin illustrating how to configure a configuration for the plugin and how to generate
* and return artifacts from a plugin.
*
* @author pmeijer /
*/

define(['plugin/PluginConfig',
'plugin/PluginBase'], function (PluginConfig, PluginBase) {
'use strict';

/**
* Initializes a new instance of ConfigurationArtifact.
* @class
* @augments {PluginBase}
* @classdesc This class represents the plugin ConfigurationArtifact.
* @constructor
*/
* Initializes a new instance of ConfigurationArtifact.
* @class
* @augments {PluginBase}
* @classdesc This class represents the plugin ConfigurationArtifact.
* @constructor
*/
var ConfigurationArtifact = function () {
// Call base class' constructor.
PluginBase.call(this);
Expand All @@ -23,30 +27,30 @@ define(['plugin/PluginConfig',
ConfigurationArtifact.prototype.constructor = ConfigurationArtifact;

/**
* Gets the name of the ConfigurationArtifact.
* @returns {string} The name of the plugin.
* @public
*/
* Gets the name of the ConfigurationArtifact.
* @returns {string} The name of the plugin.
* @public
*/
ConfigurationArtifact.prototype.getName = function () {
return "Configuration and Artifacts";
return 'Configuration and Artifacts';
};

/**
* Gets the semantic version (semver.org) of the ConfigurationArtifact.
* @returns {string} The version of the plugin.
* @public
*/
* Gets the semantic version (semver.org) of the ConfigurationArtifact.
* @returns {string} The version of the plugin.
* @public
*/
ConfigurationArtifact.prototype.getVersion = function () {
return "0.1.0";
return '1.0.0';
};

/**
* Gets the configuration structure for the ConfigurationArtifact.
* The ConfigurationStructure defines the configuration for the plugin
* and will be used to populate the GUI when invoking the plugin from webGME.
* @returns {object} The version of the plugin.
* @public
*/
* Gets the configuration structure for the ConfigurationArtifact.
* The ConfigurationStructure defines the configuration for the plugin
* and will be used to populate the GUI when invoking the plugin from webGME.
* @returns {object} The version of the plugin.
* @public
*/
ConfigurationArtifact.prototype.getConfigStructure = function () {
return [
{
Expand Down Expand Up @@ -99,8 +103,8 @@ define(['plugin/PluginConfig',
'valueType': 'string'
},
{
'name': 'xmlFile',
'displayName': 'XML File',
'name': 'file',
'displayName': 'File',
'description': '',
'value': '',
'valueType': 'asset',
Expand All @@ -111,88 +115,56 @@ define(['plugin/PluginConfig',


/**
* Main function for the plugin to execute. This will perform the execution.
* Notes:
* - Always log with the provided logger.[error,warning,info,debug].
* - Do NOT put any user interaction logic UI, etc. inside this method.
* - callback always has to be called even if error happened.
*
* @param {function(string, plugin.PluginResult)} callback - the result callback
*/
* Main function for the plugin to execute. This will perform the execution.
* Notes:
* - Always log with the provided logger.[error,warning,info,debug].
* - Do NOT put any user interaction logic UI, etc. inside this method.
* - callback always has to be called even if error happened.
*
* @param {function(string, plugin.PluginResult)} callback - the result callback
*/
ConfigurationArtifact.prototype.main = function (callback) {
var self = this,
currentConfig = self.getCurrentConfig();
// xml2json = new Converter.Xml2json({
// attrTag: '@',
// textTag: '#text',
// skipWSText: true
// }),
// json2xml = new Converter.Json2xml({
// attrTag: '@',
// textTag: '#text',
// xmlDeclaration: '<?xml version="1.0"?>'
// }),
// addFilesAndSaveArtifact = function (xmlAsJson) {
// var filesToAdd = {
// 'xmlConverted.json': JSON.stringify(xmlAsJson, null, 4),
// 'jsonConverted.xml': json2xml.convertToString(xmlAsJson)
// },
// artifact = self.blobClient.createArtifact('xmlAndJson');
// artifact.addFiles(filesToAdd, function (err, hashes) {
// if (err) {
// self.result.setSuccess(false);
// return callback('Could not add files : err' + err.toString(), self.result);
// }
// self.logger.info('Files (meta-data) have hashes: ' + hashes.toString());
// artifact.save(function (err, hash) {
// if (err) {
// self.result.setSuccess(false);
// return callback('Could not save artifact : err' + err.toString(), self.result);
// }
// self.logger.info('Artifact (meta-data) has hash: ' + hash);
// self.result.setSuccess(true);
// self.result.addArtifact(hash);
// callback(null, self.result);
// });
// });
// }

currentConfig = self.getCurrentConfig(),
artifact,
filesToAdd;

self.logger.info('Current configuration ' + JSON.stringify(currentConfig, null, 4));
self.logger.info('Animal Species = ' + currentConfig.species);
self.logger.info('Age = ' + currentConfig.age.toString());
self.logger.info('Carnivore = ' + currentConfig.carnivore.toString());
self.logger.info('Classification = ' + currentConfig.classification);
self.logger.info('Color = ' + currentConfig.color);
self.logger.info('XML File = ' + currentConfig.xmlFile);

// if (currentConfig.xmlFile) {
// self.blobClient.getObject(currentConfig.xmlFile, function (err, content) {
// var xmlAsJson = xml2json.convertFromBuffer(content);
// if (xmlAsJson instanceof Error) {
// self.createMessage(null, 'Parsing provided xml returned with error :' + xmlAsJson.message);
// self.createMessage(null, 'Converted default xml-string instead.');
// xmlAsJson = xml2json.convertFromString(self.getDefaultXmlString());
// }
// addFilesAndSaveArtifact(xmlAsJson);
// });
// } else {
// self.createMessage(null, 'No xml-file given, converted default xml-string.');
// addFilesAndSaveArtifact(xml2json.convertFromString(self.getDefaultXmlString()));
// }

if (self.activeNode) {
self.createMessage(self.activeNode, 'Active node was given');
}


if (currentConfig.xmlFile) {
self.result.setSuccess(true);
} else {
self.createMessage(null, 'No xml-file given, converted default xml-string.');
}

callback(null, self.result);
self.logger.info('File = ' + currentConfig.file);

self.createMessage(self.activeNode, 'Links to activeNode unless plugin is invoked from the rootNode');

artifact = self.blobClient.createArtifact('generatedfiles');
filesToAdd = {
'anXMLFile.xml': self.getDefaultXmlString(),
'aJSONFile.json': JSON.stringify({a: 1, b: 2}, null, 4),
'aTextFile.txt': 'This is a text file.'
};

artifact.addFiles(filesToAdd, function (err, hashes) {
if (err) {
self.result.setSuccess(false);
callback('Could not add files : err' + err.toString(), self.result);
return;
}
self.logger.info('Files (meta-data) have hashes: ' + hashes.toString());
artifact.save(function (err, hash) {
if (err) {
self.result.setSuccess(false);
callback('Could not save artifact : err' + err.toString(), self.result);
return;
}
self.logger.info('Artifact (meta-data) has hash: ' + hash);
self.result.setSuccess(true);
self.result.addArtifact(hash);
callback(null, self.result);
});
});
};

/**
Expand Down Expand Up @@ -222,23 +194,6 @@ define(['plugin/PluginConfig',
' </RootContainer>' +
'</Design>';
};
/**
* Checks if the given node is of the given meta-type.
* Usage: <tt>self.isMetaTypeOf(aNode, self.META['FCO']);</tt>
* @param node - Node to be checked for type.
* @param metaNode - Node object defining the meta type.
* @returns {boolean} - True if the given object was of the META type.
*/
ConfigurationArtifact.prototype.isMetaTypeOf = function (node, metaNode) {
var self = this;
while (node) {
if (node === metaNode) {
return true;
}
node = self.core.getBase(node);
}
return false;
};

return ConfigurationArtifact;
});
Loading

0 comments on commit a7751c7

Please sign in to comment.