Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
58c1a20c
Commit
58c1a20c
authored
Apr 13, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge conflicts
parent
7ccb2447
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
97 deletions
+7
-97
PropertyResolver.java
...p/apollo/portal/service/txtresolver/PropertyResolver.java
+7
-8
SimpleKVCResolver.java
.../apollo/portal/service/txtresolver/SimpleKVCResolver.java
+0
-89
No files found.
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/PropertyResolver.java
View file @
58c1a20c
...
@@ -4,11 +4,10 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
...
@@ -4,11 +4,10 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
com.sun.tools.javac.util.Assert
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -43,7 +42,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -43,7 +42,7 @@ public class PropertyResolver implements ConfigTextResolver {
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
result
.
setChangeSets
(
changeSets
);
result
.
setChangeSets
(
changeSets
);
Map
<
Integer
,
String
>
newLineNumMapItem
=
new
Hash
ed
Map
();
//use for delete blank and comment item
Map
<
Integer
,
String
>
newLineNumMapItem
=
new
HashMap
();
//use for delete blank and comment item
int
lineCounter
=
1
;
int
lineCounter
=
1
;
for
(
String
newItem
:
newItems
)
{
for
(
String
newItem
:
newItems
)
{
newItem
=
newItem
.
trim
();
newItem
=
newItem
.
trim
();
...
@@ -82,13 +81,13 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -82,13 +81,13 @@ public class PropertyResolver implements ConfigTextResolver {
String
oldComment
=
oldItemByLine
==
null
?
""
:
oldItemByLine
.
getComment
();
String
oldComment
=
oldItemByLine
==
null
?
""
:
oldItemByLine
.
getComment
();
//create comment. implement update comment by delete old comment and create new comment
//create comment. implement update comment by delete old comment and create new comment
if
(!(
isCommentItem
(
oldItemByLine
)
&&
newItem
.
equals
(
oldComment
)))
{
if
(!(
isCommentItem
(
oldItemByLine
)
&&
newItem
.
equals
(
oldComment
)))
{
changeSets
.
addCreate
d
Item
(
buildCommentItem
(
0
l
,
newItem
,
lineCounter
));
changeSets
.
addCreateItem
(
buildCommentItem
(
0
l
,
newItem
,
lineCounter
));
}
}
}
}
private
void
handleBlankLine
(
ItemDTO
oldItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
private
void
handleBlankLine
(
ItemDTO
oldItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
if
(!
isBlankItem
(
oldItem
))
{
if
(!
isBlankItem
(
oldItem
))
{
changeSets
.
addCreate
d
Item
(
buildBlankItem
(
0
l
,
lineCounter
));
changeSets
.
addCreateItem
(
buildBlankItem
(
0
l
,
lineCounter
));
}
}
}
}
...
@@ -110,7 +109,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -110,7 +109,7 @@ public class PropertyResolver implements ConfigTextResolver {
ItemDTO
oldItem
=
keyMapOldItem
.
get
(
newKey
);
ItemDTO
oldItem
=
keyMapOldItem
.
get
(
newKey
);
if
(
oldItem
==
null
)
{
//new item
if
(
oldItem
==
null
)
{
//new item
changeSets
.
addCreate
d
Item
(
buildNormalItem
(
0
l
,
newKey
,
newValue
,
""
,
lineCounter
));
changeSets
.
addCreateItem
(
buildNormalItem
(
0
l
,
newKey
,
newValue
,
""
,
lineCounter
));
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())){
//update item
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())){
//update item
changeSets
.
addUpdateItem
(
changeSets
.
addUpdateItem
(
buildNormalItem
(
oldItem
.
getId
(),
newKey
,
newValue
,
oldItem
.
getComment
(),
buildNormalItem
(
oldItem
.
getId
(),
newKey
,
newValue
,
oldItem
.
getComment
(),
...
@@ -139,7 +138,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -139,7 +138,7 @@ public class PropertyResolver implements ConfigTextResolver {
private
void
deleteNormalKVItem
(
Map
<
String
,
ItemDTO
>
baseKeyMapItem
,
ItemChangeSets
changeSets
)
{
private
void
deleteNormalKVItem
(
Map
<
String
,
ItemDTO
>
baseKeyMapItem
,
ItemChangeSets
changeSets
)
{
//surplus item is to be deleted
//surplus item is to be deleted
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
changeSets
.
addDelete
d
Item
(
entry
.
getValue
());
changeSets
.
addDeleteItem
(
entry
.
getValue
());
}
}
}
}
...
@@ -156,7 +155,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -156,7 +155,7 @@ public class PropertyResolver implements ConfigTextResolver {
//2.old is comment by now is not exist or modified
//2.old is comment by now is not exist or modified
if
((
isBlankItem
(
oldItem
)
&&
!
isBlankItem
(
newItem
))
if
((
isBlankItem
(
oldItem
)
&&
!
isBlankItem
(
newItem
))
||
isCommentItem
(
oldItem
)
&&
(
newItem
==
null
||
!
newItem
.
equals
(
oldItem
)))
{
||
isCommentItem
(
oldItem
)
&&
(
newItem
==
null
||
!
newItem
.
equals
(
oldItem
)))
{
changeSets
.
addDelete
d
Item
(
oldItem
);
changeSets
.
addDeleteItem
(
oldItem
);
}
}
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/SimpleKVCResolver.java
deleted
100644 → 0
View file @
7ccb2447
package
com
.
ctrip
.
apollo
.
portal
.
service
.
txtresolver
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
/**
* config item format is K:V##C
*
* @Autor lepdou
*/
@Component
public
class
SimpleKVCResolver
implements
ConfigTextResolver
{
private
static
final
String
KV_SEPARATOR
=
":"
;
private
static
final
String
VC_SEPARATOR
=
"##"
;
private
static
final
String
ITEM_SEPARATOR
=
"\n"
;
@Override
public
TextResolverResult
resolve
(
String
configText
,
List
<
ItemDTO
>
baseItems
)
{
TextResolverResult
result
=
new
TextResolverResult
();
if
(
StringUtils
.
isEmpty
(
configText
))
{
result
.
setCode
(
TextResolverResult
.
Code
.
SIMPLE_KVC_TEXT_EMPTY
);
return
result
;
}
Map
<
String
,
ItemDTO
>
baseKeyMapItem
=
BeanUtils
.
mapByKey
(
"key"
,
baseItems
);
String
[]
items
=
configText
.
split
(
ITEM_SEPARATOR
);
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
int
lineCounter
=
1
;
int
kvSeparator
,
vcSeparator
;
String
key
,
value
,
comment
;
for
(
String
item
:
items
)
{
kvSeparator
=
item
.
indexOf
(
KV_SEPARATOR
);
vcSeparator
=
item
.
indexOf
(
VC_SEPARATOR
);
if
(
kvSeparator
==
-
1
||
vcSeparator
==
-
1
)
{
result
.
setCode
(
TextResolverResult
.
Code
.
SIMPLTE_KVC_INVALID_FORMAT
);
result
.
setExtensionMsg
(
" line:"
+
lineCounter
);
return
result
;
}
key
=
item
.
substring
(
0
,
kvSeparator
).
trim
();
value
=
item
.
substring
(
kvSeparator
+
1
,
vcSeparator
).
trim
();
comment
=
item
.
substring
(
vcSeparator
+
2
,
item
.
length
()).
trim
();
ItemDTO
baseItem
=
baseKeyMapItem
.
get
(
key
);
if
(
baseItem
==
null
)
{
//new item
changeSets
.
addCreateItem
(
buildItem
(
key
,
value
,
comment
));
}
else
if
(!
value
.
equals
(
baseItem
.
getValue
())
||
!
comment
.
equals
(
baseItem
.
getComment
()))
{
//update item
changeSets
.
addUpdateItem
(
buildItem
(
key
,
value
,
comment
));
}
//deleted items:items in baseItems but not in configText
baseKeyMapItem
.
remove
(
key
);
lineCounter
++;
}
//deleted items
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
changeSets
.
addDeleteItem
(
entry
.
getValue
());
}
result
.
setCode
(
TextResolverResult
.
Code
.
OK
);
result
.
setChangeSets
(
changeSets
);
return
result
;
}
private
ItemDTO
buildItem
(
String
key
,
String
value
,
String
comment
)
{
ItemDTO
item
=
new
ItemDTO
();
item
.
setKey
(
key
);
item
.
setValue
(
value
);
item
.
setComment
(
comment
);
return
item
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment