Conditions | 2 |
Paths | 5 |
Total Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var spauth = require('node-sp-auth'); |
||
13 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'Lists', data)).then(function (response) { |
||
14 | var dataObjectLists = response.d.results; |
||
15 | if (Object.keys(dataObjectLists).length > 0) { |
||
16 | var wStreamListViews = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Views + '.csv', {encoding: 'utf8'}); // initiate MetaData for Views |
||
17 | wStreamListViews.write('"List Name"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Views).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Views |
||
18 | var dataListLight = []; |
||
19 | var counter = 0; |
||
20 | dataObjectLists.forEach(function (item) { |
||
21 | dataListLight[counter] = MyCustomFunctions.buildCurrentListAttributeValues(config.SharePoint.MetaDataOutput.Lists, item); |
||
22 | ListNameArray[counter] = item.Title; |
||
23 | counter++; |
||
24 | }); |
||
25 | var wStreamList = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Lists + '.csv', {encoding: 'utf8'}); // initiate MetaData for Lists |
||
26 | wStreamList.write('"' + Object.keys(dataListLight[0]).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Lists |
||
27 | var wStreamListFields = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Fields + '.csv', {encoding: 'utf8'}); // initiate MetaData for Fields |
||
28 | wStreamListFields.write('"List"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Fields).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Fields |
||
29 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
30 | if (MyCustomFunctions.decideBlackListWhiteList(crtListParameters.Hidden, false, config.SharePoint.Filters.Lists.NotHidden.BlackList, true, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
31 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
32 | return crtListParameters[x]; |
||
33 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
34 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Fields', data)).then(function (response) { // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
35 | var dataObject = response.d.results; |
||
36 | if (Object.keys(dataObject).length > 0) { |
||
37 | var fieldAttributes = []; |
||
38 | var counter = 0; |
||
39 | dataObject.forEach(function (item) { |
||
40 | var crtRecordFieldWillBeExtracted = MyCustomFunctions.decideBlackListWhiteList(item.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, item.InternalName); // check current Field against configured BlackList and WhiteList besides considering user defined Fields |
||
41 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { // for certain Lists all existing fields should be retrieved |
||
42 | crtRecordFieldWillBeExtracted = true; |
||
43 | } |
||
44 | if (crtRecordFieldWillBeExtracted) { |
||
45 | fieldAttributes[item.Title] = { |
||
46 | 'Technical Name': item.StaticName, |
||
47 | 'Type': item.TypeAsString |
||
48 | }; |
||
49 | counter++; |
||
50 | var crtListField = MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Fields, item); |
||
51 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtListField.join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
52 | } |
||
53 | }); |
||
54 | var internalQueryStructureItem = MyCustomFunctions.internalQueryStructureArray(crtListParameters.Records); |
||
55 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureItem, crtListParameters.Title, 'Items', data)).then(function (response) { // Get the actual values from current list |
||
56 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListParameters.Title + '.csv', {encoding: 'utf8'}); |
||
57 | wstream.write('"' + Object.keys(fieldAttributes).join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); // writing headers for records within current list |
||
58 | var dataObjectValues = response.d.results; |
||
59 | if (Object.keys(dataObjectValues).length > 0) { |
||
60 | dataObjectValues.forEach(function (item) { |
||
61 | var crtRecord = MyCustomFunctions.buildCurrentItemValues(fieldAttributes, item); |
||
62 | wstream.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); // writing current record values |
||
63 | }); |
||
64 | } |
||
65 | wstream.end(); |
||
66 | }); |
||
67 | } |
||
68 | }); |
||
69 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Views', data)).then(function (responseViews) { |
||
70 | var dataViewObject = responseViews.d.results; |
||
71 | if (Object.keys(dataViewObject).length > 0) { |
||
72 | dataViewObject.forEach(function (crtView) { |
||
73 | var crtRecordView = MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Views, crtView); |
||
74 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtRecordView.join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
75 | }); |
||
76 | } |
||
77 | }); |
||
78 | } |
||
79 | }); |
||
80 | wStreamList.end(); |
||
81 | } |
||
82 | }); |
||
83 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'SiteGroups', data)).then(function (response) { |
||
107 |