cob-cli 2.6.0 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cob-cli",
3
- "version": "2.6.0",
3
+ "version": "2.6.3",
4
4
  "description": "A command line utility to help Cult of Bits partners develop with higher speed and reusing common code and best practices.",
5
5
  "preferGlobal": true,
6
6
  "repository": {
@@ -5,35 +5,40 @@ import com.google.common.cache.*
5
5
  import java.util.concurrent.TimeUnit
6
6
 
7
7
  // ========================================================================================================
8
+ if (msg.product != "recordm-definition" && msg.product != "recordm" ) return
9
+
8
10
  @Field static cacheOfAuditFieldsForDefinition = CacheBuilder.newBuilder()
9
11
  .expireAfterWrite(5, TimeUnit.MINUTES)
10
12
  .build();
11
13
 
12
14
  if (msg.product == "recordm-definition") cacheOfAuditFieldsForDefinition.invalidate(msg.type)
13
- def auditFields = cacheOfAuditFieldsForDefinition.get(msg.type, { getAuditFields(msg.type) })
14
15
 
15
16
  // ========================================================================================================
16
-
17
+ def auditFields = cacheOfAuditFieldsForDefinition.get(msg.type, { getAuditFields(msg.type) })
17
18
  if (auditFields.size() > 0
18
- && msg.product == "recordm"
19
19
  && msg.user != "integrationm"
20
20
  && msg.action =~ "add|update" ) {
21
21
 
22
- def updates = updateUser(auditFields,msg.instance.fields)
22
+ def updates = getAuditFieldsUpdates(auditFields,msg.instance.fields)
23
23
  def result = actionPacks.recordm.update(msg.type, "recordmInstanceId:" + msg.instance.id, updates);
24
- /**/log.info("[\$audit] ACTUALIZADA '${msg.type}' {{id:${msg.instance.id}, result:${result}, updates: ${updates}}}");
24
+ if(updates) log.info("[\$audit] UPDATE '${msg.type}' id:${msg.instance.id}, updates: ${updates}, result:${result.getStatus()} | ${result.getStatusInfo()} ");
25
25
  }
26
26
 
27
27
  // ========================================================================================================
28
- def updateUser(auditFields,instanceFields) {
29
- def userm = actionPacks.get("userm");
28
+ def getAuditFieldsUpdates(auditFields,instanceFields) {
30
29
  def updates = [:]
31
30
  auditFields.each { auditField ->
32
- if( auditField.op == "creator" && msg.action == "update") return
33
- if( auditField.args == "usermRef") {
34
- updates << [(auditField.name) : userm.getUser(msg.user).data._links.self]
35
- } else {
31
+ if( auditField.op == "creator" && msg.action == "update" && msg.value(auditField.name) != null) return // 'creator' fields are only changed in 'update' if the previous value was empty (meaning it was a field that was not visible)
32
+ if( msg.action == 'update' && !msg.diff) return // Only continues if there is at least one change
33
+ if( auditField.args == "uri") {
34
+ updates << [(auditField.name) : actionPacks.get("userm").getUser(msg.user).data._links.self]
35
+
36
+ } else if( auditField.args == "username") {
36
37
  updates << [(auditField.name) : msg.user]
38
+
39
+ } else if( auditField.args == "time") {
40
+ if(msg.action == 'add' && Math.abs(msg.value(auditField.name, Long.class)?:0 - msg._timestamp_) < 30000) return // Ignore changes less then 30s
41
+ updates << [(auditField.name) : "" + msg._timestamp_]
37
42
  }
38
43
  }
39
44
  return updates
@@ -41,8 +46,7 @@ def updateUser(auditFields,instanceFields) {
41
46
 
42
47
  // ========================================================================================================
43
48
  def getAuditFields(definitionName) {
44
- /**/log.info("[\$audit] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
45
- /**/log.info("[\$audit] Update auditFields for $definitionName ... ");
49
+ log.info("[\$audit] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
46
50
 
47
51
  // Obtém detalhes da definição
48
52
  def definitionEncoded = URLEncoder.encode(definitionName, "utf-8").replace("+", "%20")
@@ -63,14 +67,14 @@ def getAuditFields(definitionName) {
63
67
  // Finalmente obtém a lista de campos que é necessário calcular
64
68
  def auditFields = [];
65
69
  fields.each { fieldId,field ->
66
- def matcher = field.description =~ /[$]audit\.(creator|updater)\.(username|usermRef)/
70
+ def matcher = field.description =~ /[$]audit\.(creator|updater)\.(username|uri|time)/
67
71
  if(matcher) {
68
72
  def op = matcher[0][1]
69
73
  def arg = matcher[0][2]
70
74
  auditFields << [fieldId: fieldId, name:field.name, op : op, args: arg]
71
75
  }
72
76
  }
73
- log.info("[\$audit] fields for '$definitionName': $auditFields");
74
- /**/log.info("[\$audit] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
77
+ log.info("[\$audit] Update 'auditFields' for '$definitionName': $auditFields");
78
+ log.info("[\$audit] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
75
79
  return auditFields
76
80
  }
@@ -2,16 +2,19 @@
2
2
  cob.custom.customize.push(function (core, utils, ui) {
3
3
  core.customizeAllInstances((instance, presenter) =>
4
4
  {
5
- let userFPs = presenter.findFieldPs( fp => /[$]audit\.(creator|updater)\.(username|usermRef)/.exec(fp.field.fieldDefinition.description && fp.field.fieldDefinition.description) )
5
+ let userFPs = presenter.findFieldPs( fp => /[$]audit\.(creator|updater)\.(username|uri|time)/.exec(fp.field.fieldDefinition.description) )
6
6
  userFPs.forEach( fp => {
7
7
  fp.disable()
8
8
  if(!instance.isNew() || presenter.isGroupEdit()) return //Only update if it's on create interface (updates will only be changed by the backend)
9
9
  if(/[$]audit\.(creator|updater)\.username/.exec(fp.field.fieldDefinition.description)) {
10
10
  fp.setValue(core.getCurrentLoggedInUser())
11
11
  }
12
- if(/[$]audit\.(creator|updater)\.usermRef/.exec(fp.field.fieldDefinition.description)) {
12
+ if(/[$]audit\.(creator|updater)\.uri/.exec(fp.field.fieldDefinition.description)) {
13
13
  fp.setValue(core.getCurrentLoggedInUserUri())
14
14
  }
15
+ if(/[$]audit\.(creator|updater)\.time/.exec(fp.field.fieldDefinition.description)) {
16
+ fp.setValue(Date.now())
17
+ }
15
18
  })
16
19
  })
17
20
  });
@@ -7,14 +7,16 @@ import com.google.common.cache.*
7
7
  import java.util.concurrent.TimeUnit
8
8
 
9
9
  // ========================================================================================================
10
+ if (msg.product != "recordm-definition" && msg.product != "recordm" ) return
11
+
10
12
  @Field static cacheOfCalcFieldsForDefinition = CacheBuilder.newBuilder()
11
13
  .expireAfterWrite(5, TimeUnit.MINUTES)
12
14
  .build();
13
15
 
14
16
  if (msg.product == "recordm-definition") cacheOfCalcFieldsForDefinition.invalidate(msg.type)
15
- def calculationFields = cacheOfCalcFieldsForDefinition.get(msg.type, { getAllCalculationFields(msg.type) })
16
17
 
17
18
  // ========================================================================================================
19
+ def calculationFields = cacheOfCalcFieldsForDefinition.get(msg.type, { getAllCalculationFields(msg.type) })
18
20
  if (calculationFields.size() > 0
19
21
  && msg.product == "recordm"
20
22
  && msg.user != "integrationm"
@@ -22,7 +24,7 @@ if (calculationFields.size() > 0
22
24
 
23
25
  def updates = executeCalculations(calculationFields, msg.instance.fields)
24
26
  def result = actionPacks.recordm.update(messageMap.type, "recordmInstanceId:" + messageMap.instance.id, updates);
25
- log.info("[\$calc] ACTUALIZADA '${messageMap.type}' {{id:${messageMap.instance.id}, result:${result}, updates: ${updates}}}");
27
+ if(updates) log.info("[\$calc] UPDATE '${msg.type}' id:${msg.instance.id}, updates: ${updates}, result:${result.getStatus()} | ${result.getStatusInfo()} ");
26
28
  }
27
29
 
28
30
  // ==================================================
@@ -117,7 +119,6 @@ def getAllAplicableValuesForVarName(fieldId,varName,varFieldIds,instanceFields,t
117
119
  // ========================================================================================================
118
120
  def getAllCalculationFields(definitionName) {
119
121
  log.info("[\$calc] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
120
- log.info("[\$calc] update calculationFields for $definitionName... ");
121
122
 
122
123
  // Obtém detalhes da definição
123
124
  def definitionEncoded = URLEncoder.encode(definitionName, "utf-8").replace("+", "%20")
@@ -154,7 +155,7 @@ def getAllCalculationFields(definitionName) {
154
155
  }
155
156
  previousId = fieldId
156
157
  }
157
- log.info("[\$calc] fields for '$definitionName': $calculationFields");
158
+ log.info("[\$calc] Update 'calculationFields' for '$definitionName': $calculationFields");
158
159
  log.info("[\$calc] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
159
160
  return calculationFields
160
161
  }
@@ -17,7 +17,7 @@ function calc_automation(instance, presenter) {
17
17
  //=========================================================
18
18
  function getAllCalculationsFields() {
19
19
  return presenter
20
- .findFieldPs( fp => fp.field.fieldDefinition.description && fp.field.fieldDefinition.description.includes("$calc.") )
20
+ .findFieldPs( fp => /[$]calc\.(.*)/.exec(fp.field.fieldDefinition.description) )
21
21
  .map( calculationFp => {
22
22
  calculationFp.disable()
23
23
  return {