Skip to content

Commit 869f9bb

Browse files
committed
Fix for Oracle, Fix for kind conversion, Added kind conversion mapping example
1 parent aea6e15 commit 869f9bb

File tree

6 files changed

+266
-5
lines changed

6 files changed

+266
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55

66
apply plugin: 'java'
77

8-
version = "1.3.5"
8+
version = "1.3.6"
99

1010
if (!project.hasProperty('release.scope')) {
1111
project.ext['release.scope'] = 'patch'
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"systemType": "xlr",
3+
"description": "migration script for xlr-jira-plugin, migration from community to official xlr-jira-plugin",
4+
"actions": [
5+
{
6+
"order": 1,
7+
"action": "update",
8+
"type": "task",
9+
"description": "migrate existing task type CreateIssueJson to new task type - 1",
10+
"properties": {
11+
"taskParentType": "pythonScript",
12+
"oldValue": "jira.CreateIssueJson",
13+
"newValue": "jira.CreateIssueJson"
14+
},
15+
"contentActionsXLR": [
16+
{
17+
"action": "updateName",
18+
"order": 1,
19+
"properties": {
20+
"name": "jsonObj",
21+
"newName": "jsonObject",
22+
"valueDataType": "string_value"
23+
}
24+
}
25+
]
26+
},
27+
{
28+
"order": 2,
29+
"action": "update",
30+
"type": "task",
31+
"description": "migrate existing task type CreateSubtask to new task type - 2",
32+
"properties": {
33+
"taskParentType": "pythonScript",
34+
"oldValue": "jira.CreateSubtask",
35+
"newValue": "jira.CreateSubtask"
36+
},
37+
"contentActionsXLR": [
38+
{
39+
"action": "delete",
40+
"order": 1,
41+
"properties": {
42+
"name": "issueTypeId"
43+
}
44+
}
45+
]
46+
},
47+
{
48+
"order": 3,
49+
"action": "update",
50+
"type": "task",
51+
"description": "migrate existing task type CheckQuery to new task type - 3",
52+
"properties": {
53+
"taskParentType": "pythonScript",
54+
"oldValue": "jira.CheckQuery",
55+
"newValue": "jira.CheckQuery"
56+
},
57+
"contentActionsXLR": [
58+
{
59+
"action": "delete",
60+
"order": 1,
61+
"properties": {
62+
"name": "expectedStatus"
63+
}
64+
}
65+
]
66+
},
67+
{
68+
"order": 4,
69+
"action": "update",
70+
"type": "task",
71+
"description": "migrate existing task type CheckQueryNoPoll to existing Query task type - 4",
72+
"properties": {
73+
"taskParentType": "pythonScript",
74+
"oldValue": "jira.CheckQueryNoPoll",
75+
"newValue": "jira.Query"
76+
}
77+
},
78+
{
79+
"order": 5,
80+
"action": "update",
81+
"type": "task",
82+
"description": "migrate existing task type queryForIssueIds to new task type - 5",
83+
"properties": {
84+
"taskParentType": "pythonScript",
85+
"oldValue": "jira.queryForIssueIds",
86+
"newValue": "jira.QueryForIssueIds"
87+
}
88+
},
89+
{
90+
"order": 6,
91+
"action": "update",
92+
"type": "task",
93+
"description": "migrate existing task type getVersions to new task type - 6",
94+
"properties": {
95+
"taskParentType": "pythonScript",
96+
"oldValue": "jira.getVersions",
97+
"newValue": "jira.GetVersions"
98+
}
99+
},
100+
{
101+
"order": 7,
102+
"action": "update",
103+
"type": "task",
104+
"description": "migrate existing task type getAllSprints to new task type - 7",
105+
"properties": {
106+
"taskParentType": "pythonScript",
107+
"oldValue": "jira.getAllSprints",
108+
"newValue": "jira.GetAllSprints"
109+
}
110+
},
111+
{
112+
"order": 8,
113+
"action": "update",
114+
"type": "task",
115+
"description": "migrate existing task type jira.CheckIssue to new official jira.CheckIssue. Note: In this case we are changing the properties of the task only - 8",
116+
"properties": {
117+
"taskParentType": "pythonScript",
118+
"oldValue": "jira.CheckIssue",
119+
"newValue": "jira.CheckIssue"
120+
},
121+
"contentActionsXLR": [
122+
{
123+
"action": "updateName",
124+
"order": 1,
125+
"description": "In this example we first change the name of the property, the next action changes its kind",
126+
"properties": {
127+
"name": "expectedStatus",
128+
"newName": "expectedStatusList",
129+
"valueDataType": "string_value"
130+
}
131+
},
132+
{
133+
"action": "updateKind",
134+
"order": 2,
135+
"description": "Identify the property using its new, current name in order to change its kind. We retain its current value.",
136+
"properties": {
137+
"name": "expectedStatusList",
138+
"oldKindType": "string_value",
139+
"newKindType": "list_of_string_value"
140+
}
141+
}
142+
]
143+
}
144+
]
145+
}

src/main/java/com/xebialabs/migration/MigrationRunnerXLR.java

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.gson.JsonParser;
2929
import com.xebialabs.migration.action.ContentActionType;
3030
import com.xebialabs.migration.action.ContentActionXLR;
31+
import com.xebialabs.migration.action.KindConversionType;
3132
import com.xebialabs.migration.action.PropertyValueType;
3233
import com.xebialabs.migration.action.RepositoryAction;
3334
import com.xebialabs.migration.util.CompressionUtils;
@@ -48,6 +49,8 @@ public class MigrationRunnerXLR extends MigrationRunner {
4849
private static final String NAME = "name";
4950
private static final String NEW_NAME = "newName";
5051
private static final String VALUE = "value";
52+
private static final String OLD_KIND_TYPE = "oldKindType";
53+
private static final String NEW_KIND_TYPE = "newKindType";
5154

5255
protected MigrationRunnerXLR(SystemType xlSystem, Connection dbconn, DbType dbType,
5356
Connection reportDbconn, DbType reportDbType, PrintStream os) {
@@ -109,9 +112,14 @@ protected void updateCI(RepositoryAction action, boolean preview)
109112
// Now, update blob
110113
String updatedBlobString = updateBlob(blobString, "type", newValue);
111114

115+
//System.out.println("******BEGIN - this is the updated content blob for xlr - update ci");
116+
//System.out.println(updatedBlobString);
117+
112118
byte[] newByteArray = CompressionUtils.compress(updatedBlobString.getBytes());
113119
Blob blobFromBytes = dbconn.createBlob();
114120
int numWritten = blobFromBytes.setBytes(1, newByteArray);
121+
//System.out.println("******END - numWritten to blob = "+numWritten+", size = "+blobFromBytes.length()+", this is the updated content blob for xlr - update ci");
122+
115123
//Blob blobFromBytes = new javax.sql.rowset.serial.SerialBlob(newByteArray);
116124

117125
secondPstmtUpdate = dbconn.prepareStatement(stringArray[1]);
@@ -254,12 +262,17 @@ protected void updateTask(RepositoryAction action, boolean preview)
254262
String updatedBlobString = updateReleaseDataBlob(blobString, taskParentTypeStr, oldValue,
255263
contentActions, action);
256264

265+
//System.out.println("******BEGIN - this is the updated content blob for xlr - update task");
266+
//System.out.println(updatedBlobString);
267+
//System.out.println("******END - this is the updated content blob for xlr - update task");
268+
257269
// We now have the updated blob, commit it to the database
258270
byte[] newByteArray = CompressionUtils.compress(updatedBlobString.getBytes());
259271

260272
Blob blobFromBytes = dbconn.createBlob();
261273
int numWritten = blobFromBytes.setBytes(1, newByteArray);
262-
274+
//System.out.println("******END - numWritten to blob = "+numWritten+", size = "+blobFromBytes.length()+", this is the updated content blob for xlr - update task");
275+
263276
// Blob blobFromBytes = new javax.sql.rowset.serial.SerialBlob(newByteArray);
264277
pstmtUpdateContent = dbconn.prepareStatement(stringArray[2]);
265278
pstmtUpdateContent.setBlob(1, blobFromBytes);
@@ -292,9 +305,15 @@ protected void updateTask(RepositoryAction action, boolean preview)
292305
// (NOT the xlrContentActions)
293306
updateParentObject(parentObject2, contentActions, jsonParser, action);
294307

308+
//System.out.println("******BEGIN - this is the updated content blob for xlr - update task - backup");
309+
//System.out.println(objectFromString2.toString());
310+
//System.out.println("******END - this is the updated content blob for xlr - update update task - backup");
311+
295312
byte[] newByteArray2 = CompressionUtils.compress(objectFromString2.toString().getBytes());
296313
Blob blobFromBytes2 = dbconn.createBlob();
297314
int numWritten = blobFromBytes2.setBytes(1, newByteArray2);
315+
//System.out.println("******END - numWritten to blob = "+numWritten+", size = "+blobFromBytes2.length()+", this is the updated content blob for xlr - update task - backup");
316+
298317
//Blob blobFromBytes2 = new javax.sql.rowset.serial.SerialBlob(newByteArray2);
299318
pstmtUpdateContent2 = dbconn.prepareStatement(stringArray[4]);
300319
pstmtUpdateContent2.setBlob(1, blobFromBytes2);
@@ -416,10 +435,15 @@ private void updateReportTasks(String[] stringArray, RepositoryAction action)
416435
String updatedBlobString = updateReleaseDataBlob(blobString, taskParentTypeStr, oldValue,
417436
contentActions, action);
418437

438+
//System.out.println("******BEGIN - this is the updated content blob for xlr - update report task");
439+
//System.out.println(updatedBlobString);
440+
441+
419442
// We now have the updated blob, commit it to the database
420443
byte[] newByteArray = updatedBlobString.getBytes();
421-
Blob blobFromBytes = dbconn.createBlob();
444+
Blob blobFromBytes = reportDbconn.createBlob();
422445
int numWritten = blobFromBytes.setBytes(1, newByteArray);
446+
//System.out.println("******END - numWritten to blob = "+numWritten+", size = "+blobFromBytes.length()+", this is the updated content blob for xlr - update report task");
423447
//Blob blobFromBytes = new javax.sql.rowset.serial.SerialBlob(newByteArray);
424448
pstmtUpdateContent = reportDbconn.prepareStatement(stringArray[8]);
425449
pstmtUpdateContent.setBlob(1, blobFromBytes);
@@ -554,6 +578,10 @@ private JsonObject updateParentObject(JsonObject parentObject, List<ContentActio
554578
updateContentPropertyValue(conAction, parentObject, jsonParser);
555579
break;
556580

581+
case UPDATEKIND:
582+
updateContentPropertyKind(conAction, parentObject, jsonParser);
583+
break;
584+
557585
default:
558586
String msg = String.format(
559587
"ContentActionXLR %s is not supported for type %s",
@@ -583,6 +611,10 @@ private void validateContentActions(List<ContentActionXLR> contentActions) throw
583611
conAction.assertHasProperty(NAME);
584612
conAction.assertHasProperty(NEW_VALUE);
585613
conAction.assertHasProperty(VALUE_DATA_TYPE);
614+
} else if (ContentActionType.UPDATEKIND.equals(conAction.getAction())) {
615+
conAction.assertHasProperty(NAME);
616+
conAction.assertHasProperty(OLD_KIND_TYPE);
617+
conAction.assertHasProperty(NEW_KIND_TYPE);
586618
} else {
587619
String msg = String.format("ContentActionXLR %s is not currently supported.",
588620
conAction.getAction().name());
@@ -621,6 +653,17 @@ private void createContentProperty(ContentActionXLR conAction, JsonObject parent
621653
case STRING_VALUE:
622654
parentObject.addProperty(name, conAction.getProperties().get(VALUE));
623655
break;
656+
657+
case LIST_OF_STRING_VALUE:
658+
try{
659+
String jsonString = conAction.getProperties().get(VALUE);
660+
JsonArray newArray = jsonParser.parse(jsonString).getAsJsonArray();
661+
parentObject.add(name, newArray);
662+
} catch (Exception e){
663+
String msg = String.format("ContentActionXLR - Failed to convert string value %s to list(array)", conAction.getProperties().get(VALUE));
664+
throw new IllegalArgumentException(msg);
665+
}
666+
break;
624667

625668
case BOOLEAN_VALUE:
626669
try{
@@ -699,6 +742,12 @@ private void updateContentPropertyName(ContentActionXLR conAction, JsonObject pa
699742
parentObject.remove(name);
700743
parentObject.addProperty(conAction.getProperties().get(NEW_NAME), currentStrValue);
701744
break;
745+
746+
case LIST_OF_STRING_VALUE:
747+
JsonArray currentArrayValue = parentObject.get(name).getAsJsonArray();
748+
parentObject.remove(name);
749+
parentObject.add(conAction.getProperties().get(NEW_NAME), currentArrayValue);
750+
break;
702751

703752
case BOOLEAN_VALUE:
704753
try{
@@ -767,6 +816,21 @@ private void updateContentPropertyValue(ContentActionXLR conAction, JsonObject p
767816
parentObject.remove(name);
768817
parentObject.addProperty(name, strValue);
769818
break;
819+
820+
case LIST_OF_STRING_VALUE:
821+
try{
822+
String jsonString = conAction.getProperties().get(NEW_VALUE);
823+
JsonArray newArray = new JsonArray();
824+
if(jsonString != null && !(jsonString.trim().equals(""))){
825+
newArray = jsonParser.parse(jsonString).getAsJsonArray();
826+
}
827+
parentObject.remove(name);
828+
parentObject.add(name, newArray);
829+
} catch (Exception e){
830+
String msg = String.format("ContentActionXLR - Failed to get new value of %s as list(array) and so could not update the value", name);
831+
throw new IllegalArgumentException(msg);
832+
}
833+
break;
770834

771835
case BOOLEAN_VALUE:
772836
try{
@@ -794,6 +858,42 @@ private void updateContentPropertyValue(ContentActionXLR conAction, JsonObject p
794858
name);
795859
os.println("\nWARNING - "+msg);
796860
//throw new IllegalArgumentException(msg);
861+
}
862+
}
863+
864+
private void updateContentPropertyKind(ContentActionXLR conAction, JsonObject parentObject, JsonParser jsonParser){
865+
KindConversionType conversionType = KindConversionType.valueOf(conAction.getProperties().get(OLD_KIND_TYPE).toUpperCase() + "_TO_" +
866+
conAction.getProperties().get(NEW_KIND_TYPE).toUpperCase());
867+
String name = conAction.getProperties().get(NAME);
868+
if(parentObject.has(name))
869+
{
870+
switch (conversionType) {
871+
case STRING_VALUE_TO_LIST_OF_STRING_VALUE:
872+
String currentStrValue = parentObject.get(name).getAsString();
873+
JsonArray newArray = new JsonArray();
874+
if(currentStrValue != null && !(currentStrValue.trim().equals(""))){
875+
newArray.add(currentStrValue);
876+
}
877+
parentObject.remove(name);
878+
parentObject.add(name, newArray);
879+
break;
880+
881+
default:
882+
String msg = String.format(
883+
"ContentActionXLR kind type conversion from %s to %s is not supported for action %s",
884+
conAction.getProperties().get(OLD_KIND_TYPE),
885+
conAction.getProperties().get(NEW_KIND_TYPE),
886+
conAction.getAction().name());
887+
throw new IllegalArgumentException(msg);
888+
}
889+
}
890+
else
891+
{
892+
String msg = String.format(
893+
"ContentActionXLR property '%s' does not exist and so the kind type cannot be converted.",
894+
name);
895+
os.println("\nWARNING - "+msg);
896+
//throw new IllegalArgumentException(msg);
797897
}
798898
}
799899

src/main/java/com/xebialabs/migration/action/ContentActionType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
public enum ContentActionType
1414
{
15-
CREATE, UPDATENAME, UPDATEVALUE, DELETE;
15+
CREATE, UPDATENAME, UPDATEVALUE, UPDATEKIND, DELETE;
1616
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright 2019 XEBIALABS
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
*
6+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
*/
10+
11+
package com.xebialabs.migration.action;
12+
13+
public enum KindConversionType
14+
{
15+
STRING_VALUE_TO_LIST_OF_STRING_VALUE;
16+
}

src/main/java/com/xebialabs/migration/action/PropertyValueType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
public enum PropertyValueType
1414
{
15-
STRING_VALUE, BOOLEAN_VALUE, INTEGER_VALUE, DATE_VALUE, JSON_VALUE;
15+
STRING_VALUE, BOOLEAN_VALUE, INTEGER_VALUE, DATE_VALUE, JSON_VALUE, LIST_OF_STRING_VALUE;
1616
}

0 commit comments

Comments
 (0)