35
60
for
(Blog blog : allBlogs) {
61 System.out.println(
"Blog "
+ ++currentBlog)
;
62 List listaKomentara = Comment.find(
"to_blog = ?"
,
blog.getInteger(
"id"
)).limit(
1
).orderBy(
"date ASC"
)
;
63
if
(listaKomentara.isEmpty()){
64
continue
;
65 }
66
DateTime
prviKomentar
=
new
DateTime(listaKomentara.get(
0
).get(
"date"
))
;
67 createNode(graph
,
blog.getString(
"url"
)
,
prviKomentar.toDate())
;
68 }
69
70 UrlValidator validator =
new
UrlValidator()
;
71
72
int
currentComment =
0
;
73 System.out.println(
"Found "
+ allComments.size() +
" comments..."
)
;
74
for
(Comment comment : allComments) {
75 System.out.println(
"Current comment:"
+ ++currentComment)
;
76
String
fromNode
=
((String)
(Blog.findById((comment.get(
"from_blog"
))).get(
"url"
)))
;
77
String
toNode
=
((String)
(Blog.findById((comment.get(
"to_blog"
))).get(
"url"
)))
;
78
if
(validator.isValid(fromNode)) {
79 DateTime commentDate =
new
DateTime(comment.get((
"date"
)))
;
80
81
if
(findNode(graph
,
fromNode) !=
null
) {
82 System.out.println(
"Node exists! "
+ fromNode)
;
83 }
else
{
84 System.out.println(
"Creating new node..."
)
;
85 createNode(graph
,
fromNode
,
commentDate.toDate())
;
86 }
87
88
if
(findEdge(graph
,
findNode(graph
,
fromNode)
,
findNode(graph
,
toNode)) !=
null
)
{
89 Edge edge = findEdge(graph
,
findNode(graph
,
fromNode)
,
findNode(graph
,
toNode))
;
90 AttributeValueList edgeAtributi = edge.getAttributeValues()
;
91 AttributeValue dynWeight =
edgeAtributi.get(edgeAtributi.size() -
1
)
;
92 DateTime datum =
new
DateTime(dynWeight.getStartValue())
;
93
94
int
currentWeight = Integer.decode(dynWeight.getValue())
;
95 currentWeight++
;
96
97
if
(datum.getYear() == commentDate.getYear() && datum.getMonthOfYear() ==
commentDate.getMonthOfYear()
98 && datum.getDayOfMonth() == commentDate.getDayOfMonth()) {
99 System.out.println(
"Same date attribute detected!"
)
;
100 dynWeight.setValue(
""
+ currentWeight)
;
101 }
else
{
102 AttributeValue newWeight =
edgeAtributi.createValue(attWeight
,
""
+ currentWeight)
;
103 newWeight.setStartValue(commentDate.toDate())
;
104 }
105 }
else
{
106 Edge edge = findNode(graph
,
fromNode).connectTo(
""
+
edgeCount
,
findNode(graph
,
toNode))
;
107 edge.setEdgeType(EdgeType.DIRECTED)
;
108 AttributeValue dynWeight =
edge.getAttributeValues().createValue(attWeight
,
"1"
)
;
109 dynWeight.setStartValue(commentDate.toDate())
;