ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [1/2] ignite git commit: POJO generation
Date Mon, 21 Sep 2015 09:43:11 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843 f17d4a928 -> 7ca041957


POJO generation


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c4709f8f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c4709f8f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c4709f8f

Branch: refs/heads/ignite-843
Commit: c4709f8f1ddb7e68212b6e26014b3fee1ee90f21
Parents: 8696710
Author: vsisko <vsisko@gridgain.com>
Authored: Mon Sep 21 16:42:48 2015 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Mon Sep 21 16:42:48 2015 +0700

----------------------------------------------------------------------
 .../src/main/js/controllers/common-module.js    |  2 +-
 .../main/js/controllers/summary-controller.js   | 61 +++++++++++++++++---
 .../js/routes/generator/generator-common.js     |  4 ++
 .../main/js/routes/generator/generator-java.js  | 41 +++++++++----
 .../src/main/js/routes/summary.js               |  2 +-
 .../js/views/configuration/summary-tabs.jade    |  1 +
 .../main/js/views/configuration/summary.jade    | 21 +++++++
 7 files changed, 109 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/controllers/common-module.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/common-module.js b/modules/control-center-web/src/main/js/controllers/common-module.js
index 5d4f52b..8125ff0 100644
--- a/modules/control-center-web/src/main/js/controllers/common-module.js
+++ b/modules/control-center-web/src/main/js/controllers/common-module.js
@@ -225,7 +225,7 @@ controlCenterModule.service('$common', [
 
         function isValidJavaIdentifier(msg, ident, elemId) {
             if (isEmptyString(ident))
-                return showPopoverMessage(null, null, elemId, msg + ' could not be empty!');
+                return showPopoverMessage(null, null, elemId, msg + ' is invalid!');
 
             if (_.contains(JAVA_KEYWORDS, ident))
                 return showPopoverMessage(null, null, elemId, msg + ' could not contains
reserved java keyword: "' + ident + '"!');

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/controllers/summary-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/summary-controller.js b/modules/control-center-web/src/main/js/controllers/summary-controller.js
index dfaa574..08670fd 100644
--- a/modules/control-center-web/src/main/js/controllers/summary-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/summary-controller.js
@@ -33,6 +33,17 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
'$common
         {value: undefined, label: 'Not set'}
     ];
 
+    $scope.pojoClasses = function() {
+        var classes = [];
+
+        _.forEach($generatorJava.metadatas, function(meta) {
+            classes.push(meta.keyType);
+            classes.push(meta.valueType);
+        });
+
+        return classes;
+    };
+
     $scope.oss = ['debian:8', 'ubuntu:14.10'];
 
     $scope.configServer = {javaClassServer: 1, os: undefined};
@@ -71,8 +82,44 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
'$common
         $scope.javaServer = $generatorJava.cluster($scope.selectedItem, $scope.configServer.javaClassServer
=== 2);
     };
 
+    function selectPojoClass() {
+        _.forEach($generatorJava.metadatas, function(meta) {
+            if (meta.keyType == $scope.configServer.pojoClass)
+                $scope.pojoClass = meta.keyClass;
+            else if (meta.valueType == $scope.configServer.pojoClass)
+                $scope.pojoClass = meta.valueClass;
+        });
+    }
+
+    $scope.updatePojos = function() {
+        if ($common.isDefined($scope.selectedItem)) {
+            var curCls = $scope.configServer.pojoClass;
+
+            $generatorJava.pojos($scope.selectedItem.caches, $scope.configServer.useConstructor,
$scope.configServer.includeKeyFields);
+
+            if (_.findIndex($generatorJava.metadatas, function (meta) {
+                    return meta.keyType == curCls || meta.valueType == curCls;
+                }) < 0) {
+                if ($generatorJava.metadatas.length > 0)
+                    $scope.configServer.pojoClass = $generatorJava.metadatas[0].keyType;
+                else
+                    $scope.configServer.pojoClass = undefined;
+            }
+            else
+                $scope.configServer.pojoClass = curCls;
+
+            selectPojoClass();
+        }
+    };
+
     $scope.$watch('configServer.javaClassServer', $scope.generateJavaServer, true);
 
+    $scope.$watch('configServer.pojoClass', selectPojoClass, true);
+
+    $scope.$watch('configServer.useConstructor', $scope.updatePojos, true);
+
+    $scope.$watch('configServer.includeKeyFields', $scope.updatePojos, true);
+
     $scope.generateDockerServer = function() {
         var os = $scope.configServer.os ? $scope.configServer.os : $scope.oss[0];
 
@@ -84,7 +131,7 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
'$common
     $scope.generateClient = function () {
         $scope.xmlClient = $generatorXml.cluster($scope.selectedItem, $scope.backupItem.nearConfiguration);
         $scope.javaClient = $generatorJava.cluster($scope.selectedItem, $scope.backupItem.javaClassClient
=== 2,
-            $scope.backupItem.nearConfiguration);
+            $scope.backupItem.nearConfiguration, $scope.configServer.useConstructor);
     };
 
     $scope.$watch('backupItem', $scope.generateClient, true);
@@ -102,16 +149,12 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
'$common
         $scope.generateDockerServer();
 
         $scope.generateClient();
+
+        $scope.updatePojos();
     };
 
-    $scope.download = function () {
-        $http.post('summary/download', {_id: $scope.selectedItem._id, os: $scope.os})
-            .success(function (data) {
-                $common.download('application/octet-stream', $scope.selectedItem.name + '-configuration.zip',
data);
-            })
-            .error(function (errMsg) {
-                $common.showError('Failed to generate zip: ' + errMsg);
-            });
+    $scope.pojoAvailable = function() {
+        return $common.isDefined($generatorJava.metadatas) && $generatorJava.metadatas.length
> 0;
     };
 
     $http.post('clusters/list').success(function (data) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/routes/generator/generator-common.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/generator/generator-common.js b/modules/control-center-web/src/main/js/routes/generator/generator-common.js
index 490dda3..9e8a34b 100644
--- a/modules/control-center-web/src/main/js/routes/generator/generator-common.js
+++ b/modules/control-center-web/src/main/js/routes/generator/generator-common.js
@@ -69,6 +69,10 @@ $generatorCommon.builder = function () {
     res.safeDatasources = [];
     res.safePoint = -1;
 
+    function getLineStart() {
+        return this.lineStart ? _.repeat('    ', this.deep) : '';
+    }
+
     res.startSafeBlock = function () {
         res.safeDeep = this.deep;
         this.safeNeedEmptyLine = this.needEmptyLine;

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/routes/generator/generator-java.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/generator/generator-java.js b/modules/control-center-web/src/main/js/routes/generator/generator-java.js
index a9814f1..4b1e68b 100644
--- a/modules/control-center-web/src/main/js/routes/generator/generator-java.js
+++ b/modules/control-center-web/src/main/js/routes/generator/generator-java.js
@@ -1125,9 +1125,10 @@ $generatorJava.clusterCaches = function (caches, res) {
  * @param meta Metadata object.
  * @param key If 'true' then key class should be generated.
  * @param pkg Package name.
- * @param constructor If 'true' then empty and full constructors should be generated.
+ * @param useConstructor If 'true' then empty and full constructors should be generated.
+ * @param includeKeyFields If 'true' then include key fields into value POJO.
  */
-$generatorJava.javaClassCode = function (meta, key, pkg, constructor, res) {
+$generatorJava.javaClassCode = function (meta, key, pkg, useConstructor, includeKeyFields,
res) {
     if (!res)
         res = $generatorCommon.builder();
 
@@ -1147,7 +1148,21 @@ $generatorJava.javaClassCode = function (meta, key, pkg, constructor,
res) {
     res.line('private static final long serialVersionUID = 0L;');
     res.needEmptyLine = true;
 
-    var fields = key ? meta.keyFields : meta.valueFields;
+    var fields = (key || includeKeyFields) ? meta.keyFields : [];
+
+    if (!key)
+        fields.push.apply(fields, meta.valueFields);
+
+    for (var fldIx = fields.length - 1; fldIx >= 0; fldIx --) {
+        var field = fields[fldIx];
+
+        var ix = _.findIndex(fields, function(fld) {
+            return fld.javaName == field.javaName;
+        });
+
+        if (ix >= 0 && ix < fldIx)
+            fields.splice(fldIx, 1);
+    }
 
     // Generate fields declaration.
     _.forEach(fields, function (field) {
@@ -1161,7 +1176,7 @@ $generatorJava.javaClassCode = function (meta, key, pkg, constructor,
res) {
     });
 
     // Generate constructors.
-    if (constructor) {
+    if (useConstructor) {
         res.line('/**');
         res.line(' * Empty constructor.');
         res.line(' */');
@@ -1176,9 +1191,11 @@ $generatorJava.javaClassCode = function (meta, key, pkg, constructor,
res) {
         res.line(' */');
         res.startBlock('public ' + type + '(');
 
-        res.line(_.map(fields, function (field) {
-            return res.importClass(field.javaType) + ' ' + field.javaName;
-        }).join(',\n'));
+        for (fldIx = 0; fldIx < fields.length; fldIx ++) {
+            field = fields[fldIx];
+
+            res.line(res.importClass(field.javaType) + ' ' + field.javaName + (fldIx <
fields.length - 1 ? ',' : ''))
+        }
 
         res.endBlock(') {');
 
@@ -1284,11 +1301,11 @@ $generatorJava.javaClassCode = function (meta, key, pkg, constructor,
res) {
     res.startBlock('@Override public String toString() {');
 
     if (fields.length > 0) {
-        var field = fields[0];
+        field = fields[0];
 
         res.startBlock('return \"' + type + ' [' + field.javaName + '=\" + ' + field.javaName
+ ' +', type);
 
-        for (var fldIx = 1; fldIx < fields.length; fldIx ++) {
+        for (fldIx = 1; fldIx < fields.length; fldIx ++) {
             field = fields[fldIx];
 
             var javaName = field.javaName;
@@ -1311,7 +1328,7 @@ $generatorJava.javaClassCode = function (meta, key, pkg, constructor,
res) {
  *
  * @param caches TODO.
  */
-$generatorJava.pojos = function (caches) {
+$generatorJava.pojos = function (caches, useConstructor, includeKeyFields) {
     var metadataNames = [];
 
     $generatorJava.metadatas = [];
@@ -1333,11 +1350,11 @@ $generatorJava.pojos = function (caches) {
                     // Key class generation only if key is not build in java class.
                     if ($commonUtils.isDefined(meta.keyFields) && meta.keyFields.length
> 0) {
                         metadata.keyType = meta.keyType;
-                        metadata.keyClass = $generatorJava.javaClassCode(meta, true, pkg);
+                        metadata.keyClass = $generatorJava.javaClassCode(meta, true, pkg,
useConstructor, includeKeyFields);
                     }
 
                     metadata.valueType = meta.valueType;
-                    metadata.valueClass = $generatorJava.javaClassCode(meta, false, pkg);
+                    metadata.valueClass = $generatorJava.javaClassCode(meta, false, pkg,
useConstructor, includeKeyFields);
 
                     $generatorJava.metadatas.push(metadata);
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/routes/summary.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/summary.js b/modules/control-center-web/src/main/js/routes/summary.js
index 01895c0..941a5e7 100644
--- a/modules/control-center-web/src/main/js/routes/summary.js
+++ b/modules/control-center-web/src/main/js/routes/summary.js
@@ -80,7 +80,7 @@ router.post('/download', function (req, res) {
             .append($generatorJava.cluster(cluster, true, clientNearConfiguration),
                 {name: 'ConfigurationFactory.java'});
 
-        $generatorJava.pojos(cluster.caches);
+        $generatorJava.pojos(cluster.caches, req.body.useConstructor, req.body.includeKeyFields);
 
         var metadatas = $generatorJava.metadatas;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/views/configuration/summary-tabs.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/configuration/summary-tabs.jade
b/modules/control-center-web/src/main/js/views/configuration/summary-tabs.jade
index a28e5a7..49bd36f 100644
--- a/modules/control-center-web/src/main/js/views/configuration/summary-tabs.jade
+++ b/modules/control-center-web/src/main/js/views/configuration/summary-tabs.jade
@@ -19,5 +19,6 @@ ul.nav(ng-class='$navClass', role='tablist')
         a.summary-tab(ng-switch='$pane.title' role='tab' data-toggle='tab' ng-click='!$pane.disabled
&& $setActive($pane.name || $index)' data-index='{{ $index }}' aria-controls='$pane.title')
{{$pane.title}}
             img(ng-switch-when='XML' src='/images/xml.png')
             img(ng-switch-when='Java' src='/images/java.png')
+            img(ng-switch-when='POJO' src='/images/java.png')
             img(ng-switch-when='Dockerfile' src='/images/docker.png')
 .tab-content(ng-transclude)

http://git-wip-us.apache.org/repos/asf/ignite/blob/c4709f8f/modules/control-center-web/src/main/js/views/configuration/summary.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/configuration/summary.jade b/modules/control-center-web/src/main/js/views/configuration/summary.jade
index c93e680..f559b24 100644
--- a/modules/control-center-web/src/main/js/views/configuration/summary.jade
+++ b/modules/control-center-web/src/main/js/views/configuration/summary.jade
@@ -53,6 +53,8 @@ block content
                         input(type='hidden' name='_id' value='{{selectedItem._id}}')
                         input(type='hidden' name='os' value='{{os}}')
                         input(type='hidden' name='javaClass' value='{{javaClassServer}}')
+                        input(type='hidden' name='useConstructor' value='{{configServer.useConstructor}}')
+                        input(type='hidden' name='includeKeyFields' value='{{configServer.includeKeyFields}}')
                         +btn-download('server')
                     .panel-collapse(role='tabpanel' bs-collapse-target)
                         .summary-tabs(bs-tabs ng-show='selectedItem' template='summary/summary-tabs')
@@ -65,6 +67,23 @@ block content
                                     .col-xs-4.col-sm-3.col-md-3
                                         button.form-control(type='button' ng-model='configServer.javaClassServer'
bs-select data-placeholder='{{detail.placeholder}}' bs-options='item.value as item.label for
item in javaClassItems' data-sort='false')
                                 div(ui-ace='{ onLoad: aceInit, mode: "java" }' ng-model='javaServer')
+                            div(ng-if='pojoAvailable()' bs-pane title='POJO')
+                                .details-row
+                                    .col-xs-2.col-sm-2.col-md-1
+                                        label File:
+                                    .col-xs-4.col-sm-3.col-md-3
+                                        button.form-control(type='button' ng-model='configServer.pojoClass'
bs-select data-placeholder='{{detail.placeholder}}' bs-options='item for item in pojoClasses()'
data-sort='false')
+                                    .col-xs-1.col-sm-1.col-md-1
+                                        label
+                                    .col-xs-4.col-sm-3.col-md-3
+                                        input(type='checkbox' ng-model='configServer.useConstructor')
+                                        | Generate constructors
+                                    .col-xs-1.col-sm-1.col-md-1
+                                        label
+                                    .col-xs-4.col-sm-S3.col-md-3
+                                        input(type='checkbox' ng-model='configServer.includeKeyFields')
+                                        | Include key fields
+                                div(ui-ace='{ onLoad: aceInit, mode: "java" }' ng-model='pojoClass')
                             div(bs-pane title='Dockerfile')
                                 .details-row
                                     p
@@ -87,6 +106,8 @@ block content
                         input(type='hidden' name='_id' value='{{selectedItem._id}}')
                         input(type='hidden' name='javaClass' value='{{javaClassClient}}')
                         input(type='hidden' name='clientNearConfiguration' value='{{backupItem}}')
+                        input(type='hidden' name='useConstructor' value='{{configServer.useConstructor}}')
+                        input(type='hidden' name='includeKeyFields' value='{{configServer.includeKeyFields}}')
                         +btn-download('client')
                     .panel-collapse(role='tabpanel' bs-collapse-target)
                         div(ng-show='selectedItem')


Mime
View raw message